@0perator/operator 0.1.275 → 0.1.276

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.
@@ -33,6 +33,37 @@ const LOOP_GUARD_EXEMPT = new Set(["agent_status", "bash_output"]);
33
33
  // burning rounds to maxRoundsHard. An Aurora blip once drove the same blocked bash call 16× before the turn
34
34
  // died: LOOP_GUARD_LIMIT only *short-circuits* the call, it never *stopped* the spin — this does.
35
35
  const LOOP_GUARD_HARD = LOOP_GUARD_LIMIT * 2; // 10
36
+ // Repeated-completed-action (RCA) guard — THE live-loop killer. The identical-args guard above is beaten by
37
+ // a model that varies a call by ONE WORD (`print result` -> `print results`), and the converge guard needs
38
+ // EXACTLY repeated narration and only speaks at NO_CONVERGE_LIMIT=25 rounds. Measured 2026-10-11: a session
39
+ // re-emitted the same bash heredoc write+run for 35+ rounds, each "✓ completed" — every guard was evaded or
40
+ // reset and the turn ran until the human cancelled it. RCA keys on the one signal that cannot be varied
41
+ // away: ACTION SUCCESS. Division of labour with LOOP_GUARD — exact repeats stay the counter's; RCA owns the
42
+ // NEAR-identical class: a call whose NORMALIZED fingerprint (lowercase, punctuation/whitespace stripped,
43
+ // word-singularized) already SUCCEEDED this turn under a DIFFERENT exact spelling is never re-dispatched —
44
+ // short-circuited with "already completed", and RCA_STOP dressed-up repeats later force-stop the turn
45
+ // ("stuck — repeated completed action"). A landed mutation clears the tallies (from the same place the
46
+ // callCounts reset happens), so edit → re-run iteration stays unbounded; EMPTY and failure-prefixed results
47
+ // never arm (the no-progress guard owns silence; failed calls stay retryable); poll/status tools are exempt
48
+ // like everywhere else.
49
+ const RCA_STOP = 3;
50
+ const normActionWord = (w) => (w.length > 3 ? w.replace(/(?:es|s)$/u, "") : w);
51
+ const normalizeActionValue = (v) => {
52
+ if (typeof v === "string")
53
+ return v.toLowerCase().normalize("NFKC").replace(/[^\p{L}\p{N} ]+/gu, " ").replace(/\s+/g, " ").trim().split(" ").map(normActionWord).join(" ");
54
+ if (Array.isArray(v))
55
+ return v.map(normalizeActionValue);
56
+ if (v && typeof v === "object") {
57
+ const o = {};
58
+ for (const [k, val] of Object.entries(v))
59
+ o[k] = normalizeActionValue(val);
60
+ return o;
61
+ }
62
+ return v;
63
+ };
64
+ const actionFingerprint = (name, args) => name + ":" + JSON.stringify(normalizeActionValue(args));
65
+ // A tool result counts as a COMPLETED action unless it opens with a failure prefix the tool layer uses.
66
+ const ACTION_FAILED_RE = /^(error|loop guard|permission denied|repeated action)/i;
36
67
  const CONTENT_LOOP_LIMIT = 3; // whole round (prose + actions) repeats this many times ⇒ light NUDGE to pivot
37
68
  const CONTENT_LOOP_REDIRECT = 6; // …and at this many, escalate to a FORCED REDIRECT: make the model diagnose the
38
69
  // loop and decompose OR switch approach, then reset its runway and CONTINUE (enterprise loop-recovery — the
@@ -257,7 +288,7 @@ function parseArgs(raw) {
257
288
  * guard (SPEC §2: identical (name,args) ≥3× this turn is short-circuited) and reporting the
258
289
  * batch via onToolBatch with a real (unrounded) duration.
259
290
  */
260
- async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolStart, onToolResult, signal) {
291
+ async function runToolCalls(toolCalls, tools, callCounts, rca, onToolBatch, onToolStart, onToolResult, signal) {
261
292
  // One id for this whole round (SPEC parallel-tool-batch) — every call made here, however it
262
293
  // resolves (executed, parse error, loop-guarded), shares it, so a host can box "N tools in
263
294
  // parallel" together even for the calls that never reached the executor. Same id-shape idiom as
@@ -300,6 +331,21 @@ async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolSta
300
331
  `arguments. Try a different approach instead of repeating this call.`);
301
332
  return;
302
333
  }
334
+ // RCA gate (see RCA_STOP above): division of labour with the guard above — EXACT repeats are LOOP_GUARD's
335
+ // (its count/short-circuit/hard-stop escalation and pinned tests stay authoritative); RCA owns only the
336
+ // NEAR-identical class the exact count can never reach: a call whose NORMALIZED fingerprint already
337
+ // SUCCEEDED this turn under a DIFFERENT exact spelling. One-word-dressed repeats die here.
338
+ const fp = actionFingerprint(tc.function.name, parsed.args);
339
+ const arm = rca.succeeded.get(fp);
340
+ if (arm && !arm.has(sig)) {
341
+ const refused = (rca.refused.get(fp) ?? 0) + 1;
342
+ rca.refused.set(fp, refused);
343
+ if (refused >= RCA_STOP) {
344
+ loopAbort = `stuck — repeated completed action: "${tc.function.name}" already COMPLETED this turn (spelled ${arm.size} way(s)) and a merely re-worded variant was re-issued ${refused}× despite the short-circuit. The action is DONE — its result is already in the history above.`;
345
+ }
346
+ preResolved.set(tc.id, `Repeated action: "${tc.function.name}" with these arguments already COMPLETED successfully this turn (re-wording it does not make it new work). Re-running cannot produce anything new. Finalize your answer from the existing result, or take a materially DIFFERENT action.`);
347
+ return;
348
+ }
303
349
  pending.push({ id: tc.id, name: tc.function.name, args: parsed.args, batchId, batchSize, batchIndex });
304
350
  });
305
351
  // A signature blew past the hard loop ceiling: stop the turn cleanly rather than let the model spin to the
@@ -321,8 +367,28 @@ async function runToolCalls(toolCalls, tools, callCounts, onToolBatch, onToolSta
321
367
  // toward LOOP_GUARD_LIMIT. This is what lets Operator iterate (edit → re-run → edit → re-run) unbounded.
322
368
  // A FAILING edit ("error: old_string not found") changed nothing — it must not reset the count, or a model
323
369
  // can alternate a failing edit with the same poisoned call forever (the guard could never stop it).
324
- if (pending.some((p, i) => mutationLanded(p.name, executed[i])))
370
+ const mutated = pending.some((p, i) => mutationLanded(p.name, executed[i]));
371
+ if (mutated) {
325
372
  callCounts.clear();
373
+ rca.succeeded.clear();
374
+ rca.refused.clear();
375
+ }
376
+ // RCA bookkeeping: record each SUCCESSFUL dispatch's exact signature under its normalized fingerprint —
377
+ // "completed spellings" is what the gate compares against (an unrecorded spelling of a completed action
378
+ // is a dressed-up repeat). Empty and failure-prefixed results never arm: an action that produced NOTHING
379
+ // is the no-progress guard's territory, a FAILED one is legitimately retryable. A round that LANDED a
380
+ // mutation skips recording: "completed" is always relative to the LAST CHANGE.
381
+ if (!mutated)
382
+ pending.forEach((p, i) => {
383
+ const out = executed[i] ?? "";
384
+ const t = out.trimStart();
385
+ if (t.length > 0 && !ACTION_FAILED_RE.test(t)) {
386
+ const fp = actionFingerprint(p.name, p.args);
387
+ const seen = rca.succeeded.get(fp) ?? new Set();
388
+ rca.succeeded.set(fp, seen);
389
+ seen.add(callSignature(p.name, p.args));
390
+ }
391
+ });
326
392
  if (onToolBatch) {
327
393
  const events = toolCalls.map((tc, batchIndex) => ({
328
394
  name: tc.function.name,
@@ -375,6 +441,7 @@ export async function runTurn(userInput, conversation, opts) {
375
441
  const absCeiling = Math.max(softRounds + 1, opts.maxRoundsHard ?? 400); // absolute safety stop; progress-aware below
376
442
  const turnStart = Date.now(); // for the per-turn wall-clock budget (opts.maxTurnWallClockMs) — the only bound on TIME
377
443
  const callCounts = new Map();
444
+ const rca = { succeeded: new Map(), refused: new Map() }; // normalized-fingerprint → completed exact spellings; + refusal tally (see RCA_STOP)
378
445
  const contentSigs = new Map(); // per-round prose fingerprints → the narration loop guard
379
446
  let forcedRedirects = 0; // enterprise loop-recovery: forced redirects spent this turn (each resets a repeated round's runway; the turn hands back only after CONTENT_LOOP_REDIRECT_MAX of them fail to break the loop)
380
447
  let progressed = true; // did the PREVIOUS tool batch advance? gates the guard (progress clears it)
@@ -860,7 +927,7 @@ export async function runTurn(userInput, conversation, opts) {
860
927
  conversation.assistant(response.content, response.toolCalls);
861
928
  // Race the batch against the abort signal so esc breaks even a hung tool (a frozen child process) —
862
929
  // the abandoned tool runs to its own timeout, but the turn is never wedged.
863
- const toolMsgs = await abortable(runToolCalls(response.toolCalls, opts.tools, callCounts, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
930
+ const toolMsgs = await abortable(runToolCalls(response.toolCalls, opts.tools, callCounts, rca, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
864
931
  for (const tm of capToolRound(toolMsgs))
865
932
  conversation.tool(tm.tool_call_id, tm.content); // cap the ROUND's total tool output so a high-fanout round can't overflow the window / defeat compaction
866
933
  observeVerify(verify, response.toolCalls, toolMsgs); // verify-before-done: record mutation / verify signal
@@ -878,7 +945,7 @@ export async function runTurn(userInput, conversation, opts) {
878
945
  if (recovered.calls.length > 0) {
879
946
  throwIfAborted(opts.signal);
880
947
  conversation.assistant(recovered.cleanedContent, recovered.calls);
881
- const toolMsgs = await abortable(runToolCalls(recovered.calls, opts.tools, callCounts, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
948
+ const toolMsgs = await abortable(runToolCalls(recovered.calls, opts.tools, callCounts, rca, opts.onToolBatch, onToolStartFx, onToolResultFx, opts.signal), opts.signal);
882
949
  for (const tm of capToolRound(toolMsgs))
883
950
  conversation.tool(tm.tool_call_id, tm.content); // cap the ROUND's total tool output so a high-fanout round can't overflow the window / defeat compaction
884
951
  observeVerify(verify, recovered.calls, toolMsgs); // verify-before-done: record mutation / verify signal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.275",
3
+ "version": "0.1.276",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "operator": "dist/cli.js",