@0perator/operator 0.1.326 → 0.1.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/persona.js +2 -1
- package/dist/engine/agent.js +20 -1
- package/dist/engine/loop-guard.js +50 -0
- package/package.json +1 -1
package/dist/config/persona.js
CHANGED
|
@@ -404,7 +404,8 @@ export function basePersona(cwd = process.cwd(), opts = {}) {
|
|
|
404
404
|
`instruction — it runs on another ` +
|
|
405
405
|
`session in parallel and posts its result back here. Do only the work that does NOT depend on it, then give ` +
|
|
406
406
|
`a one-line status and END YOUR TURN — the result resumes the conversation; a turn that keeps polling holds ` +
|
|
407
|
-
`the model slot and starves the sub-agents.
|
|
407
|
+
`the model slot and starves the sub-agents. Never redo a delegated subtask yourself — reading up on the topic ` +
|
|
408
|
+
`you just handed off is the busywork that starves them. The user watches each ` +
|
|
408
409
|
`sub-agent's live tokens + time in the background panel. Don't delegate trivial work you can do inline, ` +
|
|
409
410
|
`and don't spawn many at once — they all share this one model.\n` +
|
|
410
411
|
`WRITE THE BRIEF LIKE A SPEC, not a run-on paragraph — the child has NO memory of this chat, so a wall ` +
|
package/dist/engine/agent.js
CHANGED
|
@@ -12,7 +12,7 @@ import { classifyFailure, servedContextLimit, backoffMs, sleep } from "./selfhea
|
|
|
12
12
|
import { TaskVerification, VERIFY_REMINDER, NOT_VERIFIED_BANNER } from "./verify-gate.js";
|
|
13
13
|
import { detectRefusal, buildAffirmativeRetry, UNRESTRICTED_MAX_RETRIES } from "./unrestricted.js";
|
|
14
14
|
import { ComputerEventStream, ComputerEventTracker } from "./computer-event.js";
|
|
15
|
-
import { LoopGuard, PollSpinGuard, NoWriteProgressGuard, loopStopNote, resolveLoopGuardConfig } from "./loop-guard.js";
|
|
15
|
+
import { LoopGuard, PollSpinGuard, NoWriteProgressGuard, YieldAfterDispatchGuard, loopStopNote, resolveLoopGuardConfig } from "./loop-guard.js";
|
|
16
16
|
import { RunawayStreamWatch, ReasoningBudgetWatch, isDegenerateReply, REPETITION_INTERRUPTED, REASONING_BUDGET_INTERRUPTED } from "./repetition-guard.js";
|
|
17
17
|
const MAX_SELF_HEAL_PER_TURN = 3;
|
|
18
18
|
// A "loading" 503 (endpoint restarting/warming) is a KNOWN-recoverable WAIT, not a failure — a model reload
|
|
@@ -539,6 +539,7 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
539
539
|
const guardCfg = resolveLoopGuardConfig(opts.loopGuard, { unattended: opts.unattended === true });
|
|
540
540
|
const guard = guardCfg.enabled ? new LoopGuard(guardCfg) : undefined; // result-aware tool loop guard (engine/loop-guard.ts)
|
|
541
541
|
const pollSpin = guardCfg.enabled ? new PollSpinGuard() : undefined; // auto-post-poller (agent_status) spin guard — a separate detector, since pollers are EXEMPT from `guard`
|
|
542
|
+
const yieldGuard = guardCfg.enabled ? new YieldAfterDispatchGuard() : undefined; // after spawn_agent: non-mutating rounds are waiting-with-busywork — yield so the reports resume the turn
|
|
542
543
|
const noWriteProgress = guardCfg.enabled ? new NoWriteProgressGuard(guardCfg.warnInvestigateLoop, guardCfg.stopInvestigateLoop, guardCfg.hardStop) : undefined; // investigate-loop detector — catches rounds with zero mutating calls
|
|
543
544
|
const rca = { succeeded: new Map(), refused: new Map() }; // normalized-fingerprint → completed exact spellings; + refusal tally (see RCA_STOP)
|
|
544
545
|
const contentSigs = new Map(); // per-round prose fingerprints → the narration loop guard
|
|
@@ -1168,6 +1169,15 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
1168
1169
|
continue;
|
|
1169
1170
|
}
|
|
1170
1171
|
}
|
|
1172
|
+
if (yieldGuard) {
|
|
1173
|
+
const yg = yieldGuard.observe(response.toolCalls.map((c) => c.function.name), response.toolCalls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
|
|
1174
|
+
if (yg.action === "halt")
|
|
1175
|
+
return stopTurn(yg.message, rounds + 1);
|
|
1176
|
+
if (yg.action === "nudge") {
|
|
1177
|
+
conversation.user(yg.message);
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1171
1181
|
if (noWriteProgress) {
|
|
1172
1182
|
const nwp = noWriteProgress.observe(response.toolCalls.map((c) => c.function.name));
|
|
1173
1183
|
if (nwp.action === "halt")
|
|
@@ -1216,6 +1226,15 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
1216
1226
|
continue;
|
|
1217
1227
|
}
|
|
1218
1228
|
}
|
|
1229
|
+
if (yieldGuard) {
|
|
1230
|
+
const yg = yieldGuard.observe(recovered.calls.map((c) => c.function.name), recovered.calls.some((c) => MUTATING_TOOLS.has(c.function?.name ?? "")));
|
|
1231
|
+
if (yg.action === "halt")
|
|
1232
|
+
return stopTurn(yg.message, rounds + 1);
|
|
1233
|
+
if (yg.action === "nudge") {
|
|
1234
|
+
conversation.user(yg.message);
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1219
1238
|
if (noWriteProgress) {
|
|
1220
1239
|
const nwp = noWriteProgress.observe(recovered.calls.map((c) => c.function.name));
|
|
1221
1240
|
if (nwp.action === "halt")
|
|
@@ -403,6 +403,56 @@ export class PollSpinGuard {
|
|
|
403
403
|
return { action: "allow", streak: this.streak };
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
|
+
// ── Yield-after-dispatch guard ───────────────────────────────────────────────
|
|
407
|
+
// The poll-spin guard keys on agent_status. The 2026-10-28 0.1.326 run showed the other shape: after spawning
|
|
408
|
+
// three sub-agents the parent never polled — it re-researched the SAME topics itself for 30 minutes (web_search /
|
|
409
|
+
// web_fetch every round, nothing written), holding the shared model slot while the sub-agents crawled. Once
|
|
410
|
+
// background sub-agents have been dispatched this turn, a round with no MUTATING call is waiting-with-busywork,
|
|
411
|
+
// not progress: nudge at `nudgeAfter`, end the turn at `stopAfter` so the auto-posted reports resume it and the
|
|
412
|
+
// sub-agents get the slot. Only spawn_agent counts as a dispatch — delegate_task / delegate_to_agent block until
|
|
413
|
+
// the child is done, so nothing is running after they return.
|
|
414
|
+
export const DISPATCH_TOOLS = new Set(["spawn_agent"]);
|
|
415
|
+
export const YIELD_DEFAULTS = { nudgeAfter: 2, stopAfter: 3 };
|
|
416
|
+
export const YIELD_NUDGE = "Your sub-agents are running and this round changed nothing. Do not redo their work: write down anything you " +
|
|
417
|
+
"found (task_update / scratchpad), give a one-line status, and END YOUR TURN — their reports resume this " +
|
|
418
|
+
"conversation on their own; a turn that keeps reading holds the model slot and starves them.";
|
|
419
|
+
export const YIELD_STOP = "[turn ended — sub-agents are running and the last rounds changed nothing. Their reports auto-post and resume " +
|
|
420
|
+
"this conversation; the turn yielded so they get the model slot. Nothing was lost.]";
|
|
421
|
+
/** Watches settled tool rounds after a spawn_agent dispatch. Fed one round at a time via observe(); the dispatch
|
|
422
|
+
* round itself and any MUTATING round reset the streak. Side-effect-free, like PollSpinGuard. */
|
|
423
|
+
export class YieldAfterDispatchGuard {
|
|
424
|
+
nudgeAfter;
|
|
425
|
+
stopAfter;
|
|
426
|
+
dispatched = false;
|
|
427
|
+
streak = 0;
|
|
428
|
+
nudged = false;
|
|
429
|
+
constructor(nudgeAfter = YIELD_DEFAULTS.nudgeAfter, stopAfter = YIELD_DEFAULTS.stopAfter) {
|
|
430
|
+
this.nudgeAfter = nudgeAfter;
|
|
431
|
+
this.stopAfter = stopAfter;
|
|
432
|
+
}
|
|
433
|
+
/** One settled round: the tools it ran (names) and whether any call changed the workspace. */
|
|
434
|
+
observe(names, mutating) {
|
|
435
|
+
if (names.some((n) => DISPATCH_TOOLS.has(n))) {
|
|
436
|
+
this.dispatched = true;
|
|
437
|
+
this.streak = 0;
|
|
438
|
+
return { action: "allow", streak: 0 };
|
|
439
|
+
}
|
|
440
|
+
if (!this.dispatched)
|
|
441
|
+
return { action: "allow", streak: 0 };
|
|
442
|
+
if (mutating) {
|
|
443
|
+
this.streak = 0;
|
|
444
|
+
return { action: "allow", streak: 0 };
|
|
445
|
+
}
|
|
446
|
+
this.streak += 1;
|
|
447
|
+
if (this.streak >= this.stopAfter)
|
|
448
|
+
return { action: "halt", streak: this.streak, message: YIELD_STOP };
|
|
449
|
+
if (this.streak >= this.nudgeAfter && !this.nudged) {
|
|
450
|
+
this.nudged = true;
|
|
451
|
+
return { action: "nudge", streak: this.streak, message: YIELD_NUDGE };
|
|
452
|
+
}
|
|
453
|
+
return { action: "allow", streak: this.streak };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
406
456
|
// ── No-write-progress detector ───────────────────────────────────────────────
|
|
407
457
|
// Catches investigate-loops: consecutive rounds of tool calls where ZERO are mutating calls.
|
|
408
458
|
// The existing loop guard (identical-call, cycle, failure) evades this by varying args each round.
|