@0perator/operator 0.1.275 → 0.1.277
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/engine/agent.js +72 -5
- package/dist/engine/aurora.js +26 -9
- package/package.json +1 -1
package/dist/engine/agent.js
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
@@ -591,7 +658,7 @@ export async function runTurn(userInput, conversation, opts) {
|
|
|
591
658
|
const mKey = endpointKey(endpoint.base, endpoint.model);
|
|
592
659
|
if (response.promptTokens && response.promptTokens > 0) {
|
|
593
660
|
globalTokenMeter.observePrompt(mKey, requestChars(messages, opts.toolSchemas), response.promptTokens);
|
|
594
|
-
opts.onCacheStats?.({ promptTokens: response.promptTokens, cached: response.cacheN
|
|
661
|
+
opts.onCacheStats?.({ promptTokens: response.promptTokens, cached: response.cacheN, promptMs: response.promptMs });
|
|
595
662
|
}
|
|
596
663
|
if (response.tokensExact && response.tokens && response.tokens > 0) {
|
|
597
664
|
const outChars = (response.content?.length ?? 0) + (response.reasoningContent?.length ?? 0)
|
|
@@ -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/dist/engine/aurora.js
CHANGED
|
@@ -192,11 +192,22 @@ export function trimLoop(text) {
|
|
|
192
192
|
}
|
|
193
193
|
return out.join("\n").trim();
|
|
194
194
|
}
|
|
195
|
+
/** Pure decision: do llama.cpp cache/speculation knobs ship to this endpoint? YES for the llama
|
|
196
|
+
* dialect (fleet/local) and for OUR OWN vendor gateway (*.axe.onl — OpenAI on the wire, llama.cpp
|
|
197
|
+
* at the end of it). NO for third-party openai-dialect BYO (strict fields only — unknown keys may 400).
|
|
198
|
+
* Exported so the scope is pinned by unit tests without needing a resolvable axe.onl echo server. */
|
|
199
|
+
export function shipsLlamaCacheKnobs(base, transport) {
|
|
200
|
+
return transport !== "openai" || requiresOperatorToken(base);
|
|
201
|
+
}
|
|
195
202
|
function requestBody(messages, o, stream) {
|
|
196
|
-
// Transport dialect: llama.cpp-only fields ship
|
|
197
|
-
//
|
|
198
|
-
//
|
|
203
|
+
// Transport dialect: llama.cpp-only fields ship to Aurora/fleet (default "llama") AND to our OWN
|
|
204
|
+
// vendor gateway (*.axe.onl — LiteLLM terminating at our llama.cpp, so the wire is OpenAI but the
|
|
205
|
+
// BACKEND understands the knobs; measured live 2026-10-11: extras pass api.axe.onl with no 400 and
|
|
206
|
+
// no fallback trip). A genuine third-party "openai" BYO (qwencloudapi.com, …) still gets standard
|
|
207
|
+
// fields only — third-party gateways can 400 on unknown keys, and silence on extras is not a
|
|
208
|
+
// contract we should bank on.
|
|
199
209
|
const llama = o.transport !== "openai";
|
|
210
|
+
const cacheKnobs = shipsLlamaCacheKnobs(o.base, o.transport); // KV-reuse + speculation-off: llama.cpp semantics, ours to send
|
|
200
211
|
return JSON.stringify({
|
|
201
212
|
model: o.model, messages, stream,
|
|
202
213
|
// Ask the server for an exact usage report on the final SSE chunk. Without this, llama.cpp omits
|
|
@@ -209,16 +220,16 @@ function requestBody(messages, o, stream) {
|
|
|
209
220
|
// (system + tools + history) every round, and cache-safe compaction re-sends the evicted span as an exact
|
|
210
221
|
// PREFIX of the last live request. Without cache_prompt the single-slot server RE-PREFILLS that whole
|
|
211
222
|
// prefix each time — the "compaction takes 4-5 min at 80k ctx" and "long sessions crawl" symptom. With it,
|
|
212
|
-
// the server prefix-matches and prefills only the new tail. llama dialect
|
|
213
|
-
...(
|
|
223
|
+
// the server prefix-matches and prefills only the new tail. llama dialect (and our own gateway).
|
|
224
|
+
...(cacheKnobs ? { cache_prompt: true } : {}),
|
|
214
225
|
// GW-26 — ngram speculation is DEFAULT-ON in modern llama.cpp and a NET LOSS on the DeltaNet-hybrid
|
|
215
226
|
// Aurora at untuned draft params: measured live on :8097 (b11146, ctx 307K), acceptance 3-17% and
|
|
216
227
|
// 4-6 tok/s decode WITH it vs 20-25 tok/s WITHOUT — every rejected draft forces a multi-token
|
|
217
228
|
// re-verify + recache on the hybrid. Shape verified live: {"speculative":{"ngram":{"enabled":false}}}
|
|
218
229
|
// -> timings.draft_n drops to 0 and decode jumps 4x; a `{"type":"none"}` variant is silently IGNORED,
|
|
219
|
-
// so keep this exact shape. llama dialect
|
|
220
|
-
// lands: enableSpeculation: true.
|
|
221
|
-
...(
|
|
230
|
+
// so keep this exact shape. llama dialect (and our own gateway). Escape hatch when a retuned/
|
|
231
|
+
// high-acceptance bless lands: enableSpeculation: true.
|
|
232
|
+
...(cacheKnobs && !o.enableSpeculation ? { speculative: { ngram: { enabled: false } } } : {}),
|
|
222
233
|
max_tokens: o.maxTokens ?? 8192, temperature: o.temperature ?? 0.7,
|
|
223
234
|
...(o.tools?.length ? { tools: o.tools, tool_choice: "auto", parallel_tool_calls: true } : {}),
|
|
224
235
|
// /think: re-enable the model's native reasoning for THIS request, overriding the server's
|
|
@@ -479,7 +490,13 @@ export async function chat(messages, o) {
|
|
|
479
490
|
* (when present) prices the bust in wall-seconds — the number that makes "why is it crawling" answerable. */
|
|
480
491
|
export function cacheBustNotice(o) {
|
|
481
492
|
const min = o.minTokens ?? 8000;
|
|
482
|
-
|
|
493
|
+
// Only name a bust when the SERVER MEASURED zero reuse. `cached === undefined` means the server
|
|
494
|
+
// reported no cache telemetry at all (a gateway that strips llama.cpp `timings` and does not return
|
|
495
|
+
// prompt_tokens_details — measured live on api.axe.onl, 2026-10-11: every continuation looked like a
|
|
496
|
+
// 0-cached bust while the backend was in fact serving warm (38.5s cold vs 4.5s same-prompt)). An
|
|
497
|
+
// unknown must never be fabricated into a measurement — the false alarm made a healthy session look
|
|
498
|
+
// like it was re-prefilling 254K tokens.
|
|
499
|
+
if (o.requestIndex <= 1 || o.promptTokens < min || o.cached !== 0)
|
|
483
500
|
return null;
|
|
484
501
|
const secs = o.promptMs ? ` (~${(o.promptMs / 1000).toFixed(1)}s prefill)` : "";
|
|
485
502
|
return `prefix cache missed on a continuation — ${o.promptTokens.toLocaleString()} tokens re-prefilled${secs}`;
|