@tangle-network/agent-runtime 0.220.0 → 0.220.1
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/{activation-C-8VqFSN.js → activation-D3yrSA_b.js} +2 -2
- package/dist/{activation-C-8VqFSN.js.map → activation-D3yrSA_b.js.map} +1 -1
- package/dist/agent.js +2 -2
- package/dist/{coordination-driver-DwgDZ6nf.js → coordination-driver-BxGh-Tnj.js} +2 -2
- package/dist/{coordination-driver-DwgDZ6nf.js.map → coordination-driver-BxGh-Tnj.js.map} +1 -1
- package/dist/{delegate-BYMK7jGe.js → delegate-CiGfF17V.js} +2 -2
- package/dist/{delegate-BYMK7jGe.js.map → delegate-CiGfF17V.js.map} +1 -1
- package/dist/durable.js +2 -2
- package/dist/{graph-DHx2fTiH.js → graph-D9tSg6Vd.js} +3 -3
- package/dist/{graph-DHx2fTiH.js.map → graph-D9tSg6Vd.js.map} +1 -1
- package/dist/{improvement-cycle-BIAKVZ3B.js → improvement-cycle-BZ_KfBap.js} +3 -3
- package/dist/{improvement-cycle-BIAKVZ3B.js.map → improvement-cycle-BZ_KfBap.js.map} +1 -1
- package/dist/index.js +7 -7
- package/dist/intelligence.js +3 -3
- package/dist/kernel.js +8 -8
- package/dist/{loop-runner-bin-eB3kQCi8.js → loop-runner-bin-DkU6vtuc.js} +3 -3
- package/dist/{loop-runner-bin-eB3kQCi8.js.map → loop-runner-bin-DkU6vtuc.js.map} +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.js +4 -4
- package/dist/{provision-supervisor-CJ8EkREK.js → provision-supervisor-Cg3fETK-.js} +3 -3
- package/dist/{provision-supervisor-CJ8EkREK.js.map → provision-supervisor-Cg3fETK-.js.map} +1 -1
- package/dist/{runtime-DMRwKO-Y.js → runtime-DZcPHLwa.js} +8 -8
- package/dist/{runtime-DMRwKO-Y.js.map → runtime-DZcPHLwa.js.map} +1 -1
- package/dist/{server-1WLTlddl.js → server-BgPZIHRd.js} +3 -3
- package/dist/{server-1WLTlddl.js.map → server-BgPZIHRd.js.map} +1 -1
- package/dist/{structural-rollout-BAr61WjX.js → structural-rollout-iCePfrcK.js} +2 -2
- package/dist/{structural-rollout-BAr61WjX.js.map → structural-rollout-iCePfrcK.js.map} +1 -1
- package/dist/{supervise-DRDPNM81.js → supervise-CSYu0BeH.js} +5 -309
- package/dist/supervise-CSYu0BeH.js.map +1 -0
- package/dist/{supervisor-WRrw0nlk.js → supervisor-n8DDNGli.js} +368 -31
- package/dist/supervisor-n8DDNGli.js.map +1 -0
- package/dist/testing.js +12 -12
- package/dist/tui/index.js +1 -1
- package/package.json +1 -1
- package/dist/supervise-DRDPNM81.js.map +0 -1
- package/dist/supervisor-WRrw0nlk.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as RetainedInteractiveAdmissionError, d as RetainedRunDispatchBindingError, f as RuntimeRunStateError, l as RetainedInteractiveBindingError, m as ValidationError$1, r as BackendTransportError, u as RetainedRunAdmissionError } from "./errors-DodWX-cb.js";
|
|
1
|
+
import { c as RetainedInteractiveAdmissionError, d as RetainedRunDispatchBindingError, f as RuntimeRunStateError, i as ConfigError, l as RetainedInteractiveBindingError, m as ValidationError$1, r as BackendTransportError, t as AgentEvalError$1, u as RetainedRunAdmissionError } from "./errors-DodWX-cb.js";
|
|
2
2
|
import { a as concreteProfileModel, c as profileModelExecutionSettings, d as agentHarness, l as profileProviderModel, o as enforceTokenLimits, s as profileBridgeWireModel, t as assertExecutableAgentProfile, u as resolveRouterRetryPolicy } from "./model-policy-DKDyr-fc.js";
|
|
3
3
|
import { i as notifyRuntimeHookEvent } from "./runtime-hooks-tXpAarhW.js";
|
|
4
4
|
import { n as assertNoSymlinkDescendant, r as publishExclusiveDurableFile } from "./durable-file-D24y9zg7.js";
|
|
@@ -18213,6 +18213,64 @@ function queueOf(units, budget) {
|
|
|
18213
18213
|
};
|
|
18214
18214
|
}
|
|
18215
18215
|
//#endregion
|
|
18216
|
+
//#region src/runtime/supervise/error-message.ts
|
|
18217
|
+
const maxCauseDepth = 4;
|
|
18218
|
+
const maxMessageLength = 32768;
|
|
18219
|
+
const maxPartLength = 2048;
|
|
18220
|
+
/** A persisted failure must explain its wrappers without exporting credentials or unbounded data. */
|
|
18221
|
+
function errorText(value) {
|
|
18222
|
+
let text;
|
|
18223
|
+
try {
|
|
18224
|
+
text = typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
18225
|
+
} catch {
|
|
18226
|
+
text = "[unprintable rejection]";
|
|
18227
|
+
}
|
|
18228
|
+
return String(defaultRedactor(text)).slice(0, maxMessageLength);
|
|
18229
|
+
}
|
|
18230
|
+
function errorProperty(error, field) {
|
|
18231
|
+
try {
|
|
18232
|
+
const value = error[field];
|
|
18233
|
+
return value === void 0 ? void 0 : errorText(value).slice(0, field === "name" ? 256 : maxMessageLength);
|
|
18234
|
+
} catch {
|
|
18235
|
+
return `[unreadable error ${field}]`;
|
|
18236
|
+
}
|
|
18237
|
+
}
|
|
18238
|
+
function errorHttpStatus(error) {
|
|
18239
|
+
try {
|
|
18240
|
+
const status = Reflect.get(error, "status");
|
|
18241
|
+
return typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 ? status : void 0;
|
|
18242
|
+
} catch {
|
|
18243
|
+
return;
|
|
18244
|
+
}
|
|
18245
|
+
}
|
|
18246
|
+
/** Shared by child settlements, driver attempts, and the final no-winner result. */
|
|
18247
|
+
function errMessage(error) {
|
|
18248
|
+
const parts = [];
|
|
18249
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18250
|
+
let current = error;
|
|
18251
|
+
for (let depth = 0; depth <= maxCauseDepth; depth += 1) try {
|
|
18252
|
+
if (!(current instanceof Error)) {
|
|
18253
|
+
parts.push(errorText(current).slice(0, maxPartLength));
|
|
18254
|
+
break;
|
|
18255
|
+
}
|
|
18256
|
+
if (seen.has(current)) {
|
|
18257
|
+
parts.push("[circular]");
|
|
18258
|
+
break;
|
|
18259
|
+
}
|
|
18260
|
+
seen.add(current);
|
|
18261
|
+
const status = errorHttpStatus(current);
|
|
18262
|
+
const message = (status === void 0 ? "" : `HTTP ${status}: `) + (errorProperty(current, "message") ?? "");
|
|
18263
|
+
parts.push((depth === 0 ? message : `${errorProperty(current, "name")}: ${message}`).slice(0, maxPartLength));
|
|
18264
|
+
current = current.cause;
|
|
18265
|
+
if (current === void 0 || current === null) break;
|
|
18266
|
+
if (depth === maxCauseDepth) parts.push("[cause chain truncated]");
|
|
18267
|
+
} catch {
|
|
18268
|
+
parts.push("[unreadable error cause]");
|
|
18269
|
+
break;
|
|
18270
|
+
}
|
|
18271
|
+
return parts.join(": caused by ").slice(0, maxMessageLength);
|
|
18272
|
+
}
|
|
18273
|
+
//#endregion
|
|
18216
18274
|
//#region src/runtime/retained-interactive-handle.ts
|
|
18217
18275
|
function createRetainedInteractiveRunHandle(environment, inputRef, capabilities, requestedStart) {
|
|
18218
18276
|
const ref = freezeInteractiveRef(inputRef);
|
|
@@ -19585,7 +19643,7 @@ function assertWaitWithinDeadline(spec, deadlineMs) {
|
|
|
19585
19643
|
*/
|
|
19586
19644
|
async function runWait(args) {
|
|
19587
19645
|
const { spec, label, armedAt, resumed, signal, now } = args;
|
|
19588
|
-
const sleep = args.sleep ?? defaultSleep;
|
|
19646
|
+
const sleep = args.sleep ?? defaultSleep$1;
|
|
19589
19647
|
if (signal.aborted) return {
|
|
19590
19648
|
kind: "cancelled",
|
|
19591
19649
|
reason: "aborted before arming"
|
|
@@ -19646,7 +19704,7 @@ function outcome(kind, settled, label, untilMs, armedAt, wokenAt, polls, probeEr
|
|
|
19646
19704
|
}
|
|
19647
19705
|
/** `setTimeout` that resolves early (and clears) when the scope aborts, so a cancelled wait
|
|
19648
19706
|
* releases the event loop immediately instead of holding the process to its deadline. */
|
|
19649
|
-
function defaultSleep(ms, signal) {
|
|
19707
|
+
function defaultSleep$1(ms, signal) {
|
|
19650
19708
|
if (ms <= 0 || signal.aborted) return Promise.resolve();
|
|
19651
19709
|
return new Promise((resolve) => {
|
|
19652
19710
|
const timer = setTimeout(() => {
|
|
@@ -21722,21 +21780,6 @@ function isAbortError(err) {
|
|
|
21722
21780
|
function isInfraError(err) {
|
|
21723
21781
|
return err instanceof ValidationError$1;
|
|
21724
21782
|
}
|
|
21725
|
-
/** The message a settle record carries for a thrown executor, with its cause chain. A wrapper such
|
|
21726
|
-
* as `RetainedExecutionPendingError` has one fixed message, so without the chain a run record says
|
|
21727
|
-
* a child went down and nothing else; across 16 pursuits on 2026-09-11, 143 of 199 children
|
|
21728
|
-
* settled that way and none was diagnosable from the record (#1182). Bounded, because a cause
|
|
21729
|
-
* chain can be cyclic or long and a reason is a line, not a dump. */
|
|
21730
|
-
function errMessage(err) {
|
|
21731
|
-
if (!(err instanceof Error)) return String(err);
|
|
21732
|
-
const parts = [err.message];
|
|
21733
|
-
let cause = err.cause;
|
|
21734
|
-
for (let depth = 0; depth < 4 && cause !== void 0 && cause !== null; depth += 1) {
|
|
21735
|
-
parts.push(cause instanceof Error ? `${cause.name}: ${cause.message}` : String(cause));
|
|
21736
|
-
cause = cause instanceof Error ? cause.cause : void 0;
|
|
21737
|
-
}
|
|
21738
|
-
return parts.join(": caused by ");
|
|
21739
|
-
}
|
|
21740
21783
|
//#endregion
|
|
21741
21784
|
//#region src/runtime/supervise/driver-executor.ts
|
|
21742
21785
|
/**
|
|
@@ -22089,6 +22132,303 @@ function unreportedSpend(total, prior) {
|
|
|
22089
22132
|
};
|
|
22090
22133
|
}
|
|
22091
22134
|
//#endregion
|
|
22135
|
+
//#region src/runtime/supervise/driver-retry.ts
|
|
22136
|
+
/**
|
|
22137
|
+
* Root-driver retry — the root gets the same second chance a worker's transport already has.
|
|
22138
|
+
*
|
|
22139
|
+
* A spawned child that dies is typed into a `down` settlement and the driver may re-spawn it. The
|
|
22140
|
+
* ROOT had no such path: one dropped connection, one SIGKILLed harness process, one upstream 5xx
|
|
22141
|
+
* ended a run of arbitrary length with `reason: 'driver-failed'`, and every live child was torn
|
|
22142
|
+
* down with it (#741). The driver's budget and deadline were usually almost untouched.
|
|
22143
|
+
*
|
|
22144
|
+
* This module supplies the missing arm: run the driver again, on the SAME scope, the SAME
|
|
22145
|
+
* coordination server and the SAME live children, until the budget or the deadline says stop.
|
|
22146
|
+
* Nothing here restarts children or replays work — it re-enters the driver, and the bridge backend
|
|
22147
|
+
* reattaches the harness session because the execution id is bound durably per node.
|
|
22148
|
+
*
|
|
22149
|
+
* Two classifications decide everything, and both are conservative:
|
|
22150
|
+
*
|
|
22151
|
+
* - TERMINAL failures are Runtime's own refusals: a `ValidationError`/`ConfigError` guard, an
|
|
22152
|
+
* exhausted budget, an abort, a client-side transport status (401/404/422). Runtime meant them,
|
|
22153
|
+
* so retrying re-runs a decision rather than recovering from an accident. They fail immediately.
|
|
22154
|
+
* - TRANSIENT failures are everything foreign: a harness process that exited without a reason, a
|
|
22155
|
+
* stream that cut mid-turn, a 5xx, a socket reset. Those are accidents, and they are exactly
|
|
22156
|
+
* what a retry exists for.
|
|
22157
|
+
*
|
|
22158
|
+
* The one loop the budget alone cannot bound is a driver that dies INSTANTLY and repeatedly — a
|
|
22159
|
+
* dead-on-arrival credential, a harness that refuses to start. Spending nothing, it would retry
|
|
22160
|
+
* until the deadline hours later. So progress is measured between attempts, and a run of attempts
|
|
22161
|
+
* that changes nothing stops at `maxConsecutiveFailures`. A failure that made progress resets that
|
|
22162
|
+
* counter: a long run may be rescued many times, a hopeless one gives up in seconds.
|
|
22163
|
+
*
|
|
22164
|
+
* WHAT COUNTS AS PROGRESS is the part this module got wrong first, and the correction is measured.
|
|
22165
|
+
* The original mark read metered spend, settled children, and an accepted submission — the
|
|
22166
|
+
* filesystem and the meter, never the goal. Across 1,422 settled discovery-lab runs (2026-09-01)
|
|
22167
|
+
* that reading retried the runs that had produced NOTHING 629 of 827 times (76.1%) while retrying
|
|
22168
|
+
* the runs that HAD left an artifact 21 of 399 times (5.3%): the loop spent its second chances on
|
|
22169
|
+
* the hopeless runs and measured persistence by burn rate. So when the caller declares a completion
|
|
22170
|
+
* check, spend and settlements alone are NOT progress while that check is unmet; only a delivery —
|
|
22171
|
+
* an accepted submission, a child that passed the check, or the contract turning met — resets the
|
|
22172
|
+
* barren counter. A caller that declares no check reports `contract: 'none'` and keeps the exact
|
|
22173
|
+
* historical reading.
|
|
22174
|
+
*
|
|
22175
|
+
* THE SECOND HALF of the same defect: `budgetStop` used to be consulted only after a failure, and a
|
|
22176
|
+
* driver that RETURNED with the contract unmet ended the run silently — 376 of 376 winning lab runs
|
|
22177
|
+
* ended on this loop's own `stop: 'completed'`, with the completion gate left to label the result
|
|
22178
|
+
* rather than to change it. A completed drive whose contract is unmet is now a first-class moment:
|
|
22179
|
+
* `reprompt.maxReprompts` re-enters the SAME live session with the unmet items, and every re-entry
|
|
22180
|
+
* crosses the same budget, deadline, abort, and attempt bounds a retry crosses.
|
|
22181
|
+
*/
|
|
22182
|
+
/**
|
|
22183
|
+
* The instruction a completed-but-undelivered drive is re-entered with when the caller supplies no
|
|
22184
|
+
* `onUnmetContract`. It states the verdict, names what is owed, reports the ledger, and gives the
|
|
22185
|
+
* three steps — the same shape `depthStrategy` re-prompts a resumed session with, said in the
|
|
22186
|
+
* driver's own terms.
|
|
22187
|
+
*/
|
|
22188
|
+
function defaultUnmetContractSteer(context) {
|
|
22189
|
+
const owed = context.describe?.trim();
|
|
22190
|
+
return [
|
|
22191
|
+
"The completion check has not passed. This run has delivered nothing yet.",
|
|
22192
|
+
owed === void 0 || owed.length === 0 ? "The deliverable this run owes is still missing." : `The deliverable this run owes: ${owed}`,
|
|
22193
|
+
`Workers settled: ${context.progress.settledCount}. Workers that passed the check: ${context.progress.deliveredCount ?? 0}.`,
|
|
22194
|
+
"Do the unfinished work with the tools.",
|
|
22195
|
+
"Verify that the check passes.",
|
|
22196
|
+
"Then submit the result.",
|
|
22197
|
+
"Do not restate work you already did."
|
|
22198
|
+
].join("\n");
|
|
22199
|
+
}
|
|
22200
|
+
const DEFAULT_MAX_CONSECUTIVE_FAILURES = 3;
|
|
22201
|
+
const DEFAULT_MAX_ATTEMPTS = 8;
|
|
22202
|
+
const DEFAULT_INITIAL_BACKOFF_MS = 2e3;
|
|
22203
|
+
const DEFAULT_MAX_BACKOFF_MS = 3e4;
|
|
22204
|
+
/**
|
|
22205
|
+
* Bridge error classes the bridge itself never retries: a request that fails identically on
|
|
22206
|
+
* every attempt, mapped below 5xx on its HTTP path (`parse_error` 400, the other two 501). On the
|
|
22207
|
+
* stream path the same failure arrives with no status at all — a profile that cannot materialize
|
|
22208
|
+
* is a `parse_error` — and the status split alone read it as a bad moment and re-drove it to the
|
|
22209
|
+
* attempt ceiling.
|
|
22210
|
+
*/
|
|
22211
|
+
const DETERMINISTIC_BRIDGE_CODES = /* @__PURE__ */ new Set([
|
|
22212
|
+
"parse_error",
|
|
22213
|
+
"not_configured",
|
|
22214
|
+
"capability_denied"
|
|
22215
|
+
]);
|
|
22216
|
+
/**
|
|
22217
|
+
* Classify one driver failure. Runtime's own typed refusals are decisions and stay terminal;
|
|
22218
|
+
* anything foreign is an accident and is retryable. A `BackendTransportError` is split by status
|
|
22219
|
+
* because the taxonomy already promises consumers may branch on it: a 5xx/429/408 is the upstream
|
|
22220
|
+
* having a bad moment, while a 401/404/422 is a request that will fail identically forever. The
|
|
22221
|
+
* bridge's own never-retry classes are terminal whether or not a status rides with them.
|
|
22222
|
+
*/
|
|
22223
|
+
function classifyDriverFailure(error, signal) {
|
|
22224
|
+
if (signal?.aborted) return "terminal";
|
|
22225
|
+
if (error instanceof Error && errorProperty(error, "name") === "AbortError") return "terminal";
|
|
22226
|
+
if (error instanceof BackendTransportError) {
|
|
22227
|
+
if (error.upstreamCode !== void 0 && DETERMINISTIC_BRIDGE_CODES.has(error.upstreamCode)) return "terminal";
|
|
22228
|
+
const status = error.status;
|
|
22229
|
+
if (status === void 0) return "transient";
|
|
22230
|
+
if (status === 408 || status === 429 || status >= 500) return "transient";
|
|
22231
|
+
return "terminal";
|
|
22232
|
+
}
|
|
22233
|
+
if (error instanceof ValidationError$1 || error instanceof ConfigError || error instanceof RuntimeRunStateError) return "terminal";
|
|
22234
|
+
if (error instanceof AgentEvalError$1) return "terminal";
|
|
22235
|
+
return "transient";
|
|
22236
|
+
}
|
|
22237
|
+
/** The budget's own verdict on whether another attempt may run at all. */
|
|
22238
|
+
function budgetStop(budget, atMs) {
|
|
22239
|
+
if (budget.deadlineMs > 0 && atMs >= budget.deadlineMs) return "deadline";
|
|
22240
|
+
if (budget.tokensLeft <= 0 || budget.iterationsLeft <= 0) return "budget-exhausted";
|
|
22241
|
+
if (budget.usdCapped && budget.usdLeft <= 0) return "budget-exhausted";
|
|
22242
|
+
if (budget.usdCapped && budget.usdKnown === false) return "budget-exhausted";
|
|
22243
|
+
if (Object.values(budget.resources ?? {}).some((resource) => !resource.known || resource.remaining <= 0)) return "budget-exhausted";
|
|
22244
|
+
}
|
|
22245
|
+
function contractOf(mark) {
|
|
22246
|
+
return mark.contract ?? "none";
|
|
22247
|
+
}
|
|
22248
|
+
/**
|
|
22249
|
+
* Did this attempt move the run toward its DELIVERABLE?
|
|
22250
|
+
*
|
|
22251
|
+
* A delivery always counts: an accepted submission, one more child that passed the check, or the
|
|
22252
|
+
* contract turning met. Spend and settlements count only while no declared check is outstanding —
|
|
22253
|
+
* with a check unmet they are the burn-rate reading this module's header measures and rejects.
|
|
22254
|
+
*/
|
|
22255
|
+
function madeProgress(before, after) {
|
|
22256
|
+
if (after.submitted && !before.submitted) return true;
|
|
22257
|
+
if ((after.deliveredCount ?? 0) > (before.deliveredCount ?? 0)) return true;
|
|
22258
|
+
if (contractOf(before) !== "met" && contractOf(after) === "met") return true;
|
|
22259
|
+
if (contractOf(after) === "unmet") return false;
|
|
22260
|
+
return after.poolTokensSpent > before.poolTokensSpent || after.settledCount > before.settledCount;
|
|
22261
|
+
}
|
|
22262
|
+
/** The error a give-up throws: the original cause, re-described with the attempt history so
|
|
22263
|
+
* `driver-failed` carries a diagnosable message instead of one backend's last words. */
|
|
22264
|
+
var DriverAttemptsExhaustedError = class extends RuntimeRunStateError {
|
|
22265
|
+
attempts;
|
|
22266
|
+
stop;
|
|
22267
|
+
constructor(cause, attempts, stop) {
|
|
22268
|
+
const last = attempts[attempts.length - 1];
|
|
22269
|
+
const causeText = cause instanceof Error ? `${errorProperty(cause, "name")}: ${errMessage(cause)}` : errMessage(cause);
|
|
22270
|
+
const firstFailure = attempts.find((attempt) => attempt.error !== void 0)?.error;
|
|
22271
|
+
super(`supervisor driver failed after ${attempts.length} attempt(s) — stopped by ${stop}; ` + (firstFailure !== void 0 && firstFailure !== last?.error ? `first failure: ${errorText(firstFailure)}; ` : "") + `last cause: ${causeText}` + (last?.classification ? ` (classified ${last.classification})` : ""), { cause });
|
|
22272
|
+
this.attempts = Object.freeze([...attempts]);
|
|
22273
|
+
this.stop = stop;
|
|
22274
|
+
}
|
|
22275
|
+
};
|
|
22276
|
+
async function defaultSleep(ms, signal) {
|
|
22277
|
+
if (ms <= 0 || signal.aborted) return;
|
|
22278
|
+
await new Promise((resolve) => {
|
|
22279
|
+
const done = () => {
|
|
22280
|
+
clearTimeout(timer);
|
|
22281
|
+
signal.removeEventListener("abort", done);
|
|
22282
|
+
resolve();
|
|
22283
|
+
};
|
|
22284
|
+
const timer = setTimeout(done, ms);
|
|
22285
|
+
if (typeof timer === "object" && timer !== null && "unref" in timer) timer.unref();
|
|
22286
|
+
signal.addEventListener("abort", done, { once: true });
|
|
22287
|
+
});
|
|
22288
|
+
}
|
|
22289
|
+
/**
|
|
22290
|
+
* Run the driver until it completes WITH ITS CONTRACT MET, or until the budget, the deadline, an
|
|
22291
|
+
* abort, a terminal error, or a ceiling stops it. Transient failures are retried. A drive that
|
|
22292
|
+
* returns with its completion check unmet is re-entered on the same live session with the unmet
|
|
22293
|
+
* items, up to `reprompt.maxReprompts`. Throws `DriverAttemptsExhaustedError` (cause = the last
|
|
22294
|
+
* real failure) when a FAILURE ends the loop; a completed drive returns, met contract or not,
|
|
22295
|
+
* because deciding what an undelivered run is worth belongs to the finalizer, not to this loop.
|
|
22296
|
+
*/
|
|
22297
|
+
async function runDriverWithRetry(run) {
|
|
22298
|
+
const now = run.now ?? Date.now;
|
|
22299
|
+
const sleep = run.sleep ?? defaultSleep;
|
|
22300
|
+
const policy = run.policy ?? {};
|
|
22301
|
+
const retryEnabled = policy.enabled !== false;
|
|
22302
|
+
const maxConsecutive = Math.max(0, policy.maxConsecutiveFailures ?? DEFAULT_MAX_CONSECUTIVE_FAILURES);
|
|
22303
|
+
const maxAttempts = Math.max(1, policy.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
|
|
22304
|
+
const initialBackoff = Math.max(0, policy.initialBackoffMs ?? DEFAULT_INITIAL_BACKOFF_MS);
|
|
22305
|
+
const maxBackoff = Math.max(initialBackoff, policy.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS);
|
|
22306
|
+
const maxReprompts = Math.max(0, run.reprompt?.maxReprompts ?? 0);
|
|
22307
|
+
const attempts = [];
|
|
22308
|
+
let consecutiveBarren = 0;
|
|
22309
|
+
let reprompts = 0;
|
|
22310
|
+
let reentry;
|
|
22311
|
+
const emit = async (record) => {
|
|
22312
|
+
attempts.push(record);
|
|
22313
|
+
await run.onAttempt?.(record);
|
|
22314
|
+
};
|
|
22315
|
+
/**
|
|
22316
|
+
* Decide what a completed-but-undelivered drive does next. Every bound the FAILURE path applies
|
|
22317
|
+
* is applied here too — that is the fix for `budgetStop` having lived only in the catch arm — and
|
|
22318
|
+
* the caller's hook is consulted last, so no hook can talk the loop past a deadline.
|
|
22319
|
+
*/
|
|
22320
|
+
const decideReprompt = async (attempt, after) => {
|
|
22321
|
+
if (reprompts >= maxReprompts) return { refusedBy: "reprompts-exhausted" };
|
|
22322
|
+
if (run.signal.aborted) return { refusedBy: "aborted" };
|
|
22323
|
+
const byBudget = budgetStop(run.budget(), now());
|
|
22324
|
+
if (byBudget === "deadline" || byBudget === "budget-exhausted") return { refusedBy: byBudget };
|
|
22325
|
+
if (attempt >= maxAttempts) return { refusedBy: "max-attempts" };
|
|
22326
|
+
const context = {
|
|
22327
|
+
attempt,
|
|
22328
|
+
reprompts,
|
|
22329
|
+
maxReprompts,
|
|
22330
|
+
progress: after,
|
|
22331
|
+
budget: run.budget(),
|
|
22332
|
+
...run.reprompt?.describe === void 0 ? {} : { describe: run.reprompt.describe }
|
|
22333
|
+
};
|
|
22334
|
+
const decision = await run.reprompt?.onUnmetContract?.(context) ?? { steer: defaultUnmetContractSteer(context) };
|
|
22335
|
+
if (decision === "stop") return { refusedBy: "caller-stop" };
|
|
22336
|
+
const steer = typeof decision.steer === "string" ? decision.steer.trim() : "";
|
|
22337
|
+
if (steer.length === 0) throw new ValidationError$1("runDriverWithRetry: onUnmetContract returned an empty steer — return a non-empty instruction or 'stop'");
|
|
22338
|
+
return { steer };
|
|
22339
|
+
};
|
|
22340
|
+
for (let attempt = 1;; attempt += 1) {
|
|
22341
|
+
const before = run.progress();
|
|
22342
|
+
const startedAt = now();
|
|
22343
|
+
try {
|
|
22344
|
+
await run.drive(attempt, reentry);
|
|
22345
|
+
} catch (error) {
|
|
22346
|
+
const durationMs = now() - startedAt;
|
|
22347
|
+
const classification = classifyDriverFailure(error, run.signal);
|
|
22348
|
+
const progressed = madeProgress(before, run.progress());
|
|
22349
|
+
const stop = (() => {
|
|
22350
|
+
if (classification === "terminal") return "terminal-error";
|
|
22351
|
+
if (!retryEnabled) return "retry-disabled";
|
|
22352
|
+
if (run.signal.aborted) return "aborted";
|
|
22353
|
+
const byBudget = budgetStop(run.budget(), now());
|
|
22354
|
+
if (byBudget) return byBudget;
|
|
22355
|
+
if (attempt >= maxAttempts) return "max-attempts";
|
|
22356
|
+
if (progressed) return void 0;
|
|
22357
|
+
return consecutiveBarren + 1 >= maxConsecutive ? "no-progress" : void 0;
|
|
22358
|
+
})();
|
|
22359
|
+
if (stop !== void 0) {
|
|
22360
|
+
await emit({
|
|
22361
|
+
attempt,
|
|
22362
|
+
durationMs,
|
|
22363
|
+
error: errMessage(error),
|
|
22364
|
+
classification,
|
|
22365
|
+
madeProgress: progressed,
|
|
22366
|
+
stop
|
|
22367
|
+
});
|
|
22368
|
+
throw new DriverAttemptsExhaustedError(error, attempts, stop);
|
|
22369
|
+
}
|
|
22370
|
+
consecutiveBarren = progressed ? 0 : consecutiveBarren + 1;
|
|
22371
|
+
reentry = void 0;
|
|
22372
|
+
const backoff = Math.min(maxBackoff, initialBackoff * 2 ** Math.max(0, consecutiveBarren - 1));
|
|
22373
|
+
await emit({
|
|
22374
|
+
attempt,
|
|
22375
|
+
durationMs,
|
|
22376
|
+
error: errMessage(error),
|
|
22377
|
+
classification,
|
|
22378
|
+
madeProgress: progressed,
|
|
22379
|
+
retryInMs: backoff
|
|
22380
|
+
});
|
|
22381
|
+
await sleep(backoff, run.signal);
|
|
22382
|
+
if (run.signal.aborted) throw new DriverAttemptsExhaustedError(error, attempts, "aborted");
|
|
22383
|
+
const afterWait = budgetStop(run.budget(), now());
|
|
22384
|
+
if (afterWait) throw new DriverAttemptsExhaustedError(error, attempts, afterWait);
|
|
22385
|
+
continue;
|
|
22386
|
+
}
|
|
22387
|
+
const durationMs = now() - startedAt;
|
|
22388
|
+
const after = run.progress();
|
|
22389
|
+
const progressed = madeProgress(before, after);
|
|
22390
|
+
const contract = contractOf(after);
|
|
22391
|
+
const contractField = contract === "none" ? {} : { contract };
|
|
22392
|
+
if (contract === "unmet" && maxReprompts > 0) {
|
|
22393
|
+
const decision = await decideReprompt(attempt, after);
|
|
22394
|
+
if ("steer" in decision) {
|
|
22395
|
+
reprompts += 1;
|
|
22396
|
+
reentry = {
|
|
22397
|
+
reason: "unmet-contract",
|
|
22398
|
+
steer: decision.steer,
|
|
22399
|
+
reprompt: reprompts
|
|
22400
|
+
};
|
|
22401
|
+
await emit({
|
|
22402
|
+
attempt,
|
|
22403
|
+
durationMs,
|
|
22404
|
+
madeProgress: progressed,
|
|
22405
|
+
...contractField,
|
|
22406
|
+
reprompted: true,
|
|
22407
|
+
retryInMs: 0
|
|
22408
|
+
});
|
|
22409
|
+
continue;
|
|
22410
|
+
}
|
|
22411
|
+
await emit({
|
|
22412
|
+
attempt,
|
|
22413
|
+
durationMs,
|
|
22414
|
+
madeProgress: progressed,
|
|
22415
|
+
...contractField,
|
|
22416
|
+
repromptRefusedBy: decision.refusedBy,
|
|
22417
|
+
stop: "completed"
|
|
22418
|
+
});
|
|
22419
|
+
return;
|
|
22420
|
+
}
|
|
22421
|
+
await emit({
|
|
22422
|
+
attempt,
|
|
22423
|
+
durationMs,
|
|
22424
|
+
madeProgress: progressed,
|
|
22425
|
+
...contractField,
|
|
22426
|
+
stop: "completed"
|
|
22427
|
+
});
|
|
22428
|
+
return;
|
|
22429
|
+
}
|
|
22430
|
+
}
|
|
22431
|
+
//#endregion
|
|
22092
22432
|
//#region src/runtime/supervise/finalizer.ts
|
|
22093
22433
|
/**
|
|
22094
22434
|
* `SupervisorFinalizer` — the pluggable last step of a driver run: how the settled-worker ledger
|
|
@@ -22339,20 +22679,17 @@ const defaultMaxDepth = 4;
|
|
|
22339
22679
|
* a stringification that itself throws (circular, hostile `toString`) falls back to the tag.
|
|
22340
22680
|
*/
|
|
22341
22681
|
function describeRejection(error) {
|
|
22342
|
-
if (error instanceof Error)
|
|
22343
|
-
|
|
22344
|
-
|
|
22345
|
-
|
|
22346
|
-
|
|
22347
|
-
|
|
22348
|
-
|
|
22349
|
-
message = typeof error === "string" ? error : JSON.stringify(error) ?? String(error);
|
|
22350
|
-
} catch {
|
|
22351
|
-
message = Object.prototype.toString.call(error);
|
|
22682
|
+
if (error instanceof Error) {
|
|
22683
|
+
const stack = errorProperty(error, "stack");
|
|
22684
|
+
return {
|
|
22685
|
+
name: errorProperty(error, "name") ?? "Error",
|
|
22686
|
+
message: error instanceof DriverAttemptsExhaustedError ? errorProperty(error, "message") ?? "" : errMessage(error),
|
|
22687
|
+
...stack !== void 0 ? { stack } : {}
|
|
22688
|
+
};
|
|
22352
22689
|
}
|
|
22353
22690
|
return {
|
|
22354
22691
|
name: "NonError",
|
|
22355
|
-
message
|
|
22692
|
+
message: errMessage(error)
|
|
22356
22693
|
};
|
|
22357
22694
|
}
|
|
22358
22695
|
/** Create a supervisor that owns one recursive agent execution tree. */
|
|
@@ -22945,6 +23282,6 @@ function isNonEmptySpend(s) {
|
|
|
22945
23282
|
return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false || Object.values(s.resources ?? {}).some((resource) => resource.amount > 0 || !resource.known);
|
|
22946
23283
|
}
|
|
22947
23284
|
//#endregion
|
|
22948
|
-
export {
|
|
23285
|
+
export { bindReusableExecutorExecutionId as $, retainedCreateMaterial as $n, parseCommittedJsonLines as $r, readCodexRolloutSession as $t, waitUntil as A, extractLlmCallEvent as Ai, sleep as An, DEFAULT_LOCAL_HARNESS as Ar, workerTraceEnv as At, readWorkerInteractiveBinding as B, awaitAbortable$1 as Bi, createPushTraceSource as Bn, fullProfileMaterialization as Br, PEER_MAIL_WIRE_KEY as Bt, scopeOwnerExecutorNodeContext as C, detachedSnapshot as Ci, chargedTokens as Cn, sanitizeKnowledgeReadinessReport as Cr, workerTraceAnalysisStore as Ct, pollFor as D, canonicalStreamEventFromSandboxEvent as Di, isAbortError$2 as Dn, captureWorktreeDiff as Dr, spendFromUsageEvents as Dt, isWaitOutcome as E, assertSandboxServedModel as Ei, hasCompleteCacheBreakdown as En, runWorktreeHarness as Er, createBudgetPool as Et, scopeRetainedOwnerResult as F, sandboxEventServedBackend as Fi, withTimeout as Fn, CodexExecutionDiagnosticError as Fr, createActivityLog as Ft, startRetainedInteractiveRun as G, RunCancellationReason as Gn, promptResourceProfileMaterialization as Gr, peerMailVerbNames as Gt, workerInteractiveBindingsDir as H, promptOptionsFromAgentTurnInput as Hi, sandboxSessionTraceSource as Hn, promptControlProfileMaterialization as Hr, createPeerMailbox as Ht, interactiveAdmissionSeamKey as I, sandboxProgressEvents as Ii, zeroSpend as In, AGENT_PROFILE_MATERIALIZATION_AXES as Ir, readWorkerProgress as It, freeSlots as J, runAbortable as Jn, sandboxActProfileMaterialization as Jr, bridgeAdmissionRefusal as Jt, destroyInteractiveEnvironment as K, abortError$1 as Kn, renderProfileMaterializationIssues as Kr, isLiveNodeStatus as Kt, readWorkerInteractiveAdmissions as L, sumSandboxUsage as Li, addResourceSpend as Ln, assertProfileMaterialization as Lr, createInbox as Lt, prepareScopeRetainedOwnerTask as M, mapSandboxEvent as Mi, throwAbort as Mn, harnessSupportsReasoningEffort as Mr, workerTraceSeamKey as Mt, scopeRetainedOwnerContext as N, mapSandboxToolEvent as Ni, throwIfAborted as Nn, localHarnessExecutable as Nr, taskToPrompt as Nt, timerAt as O, createSandboxToolPartState as Oi, promptCacheTokenClasses as On, createWorktree as Or, WORKER_TRACE_PROPAGATION as Ot, scopeRetainedOwnerPriorSpend as P, notifySandboxEventObserver as Pi, unmeteredSpend as Pn, parseCodexTokenUsage as Pr, DEFAULT_STALL_AFTER_MS as Pt, teardownExecutor as Q, startRetainedRunInEnvironment as Qn, isNoEntError as Qr, harnessUsageIsEmpty as Qt, workerInteractiveAdmissionFile as R, decodeHarnessUsage as Ri, resourceTelemetry as Rn, controlProfileMaterialization as Rr, AUTHORITY_MARKERS as Rt, restoreScopeOwnerAcceptedExecution as S, detachedFrozen as Si, addSpend as Sn, sanitizeAgentRuntimeEvent as Sr, parseWorkerToolTraceArtifact as St, createWaitProbes as T, readSandboxOutcome as Ti, deleteBoxSafe as Tn, runSettledCommand as Tr, assertValidBudget as Tt, reconnectRetainedInteractiveRun as U, providerMessageText as Ui, registerRetainedExecutorPreparation as Un, promptModelProfileMaterialization as Ur, isPeerMailEnvelope as Ut, workerInteractiveBindingFile as V, promptFromAgentTurnInput as Vi, decodeToolPart as Vn, profileMaterializationAxes$1 as Vr, claimsAuthority as Vt, recoverRetainedInteractiveRun as W, retainedExecutorSeamKey as Wn, promptOnlyProfileMaterialization as Wr, peerMailTools as Wt, rollingDispatch as X, recoverRetainedRun as Xn, validateProfileMaterialization as Xr, addHarnessUsage as Xt, queueOf as Y, reconnectRetainedRun as Yn, unsupportedProfileDimensions as Yr, bridgeModelRouteRefusal as Yt, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as Z, startRetainedRun as Zn, worktreeCliProfileMaterialization as Zr, createCodexRolloutStoreReader as Zt, createScope as _, runtimeOwnedScopeOwnerRuntime as _i, createAgentEnvironmentProviderRegistry as _n, padSpanId as _r, pendingWaits as _t, pickBestDelivered as a, finalizeRuntimeOwnedPendingExecutor as ai, isTerminalDecision as an, readTraceContextFromEnv as ar, snapshotExecutorConfig as at, meterRuntimeOwnedProviderAttempt as b, executableAgentProfileSnapshot as bi, resolveAgentEnvironmentProvider as bn, createRuntimeEventCollector as br, captureWorkerTraceEvidence as bt, DriverAttemptsExhaustedError as c, knownMaterializationReceipt as ci, probeSandboxCapabilities as cn, buildLoopOtelSpans as cr, createSteerableSandboxSession as ct, runDriverWithRetry as d, recordRuntimeOwnedDriveHarnessProviderEvidence as di, readPromptOptions as dn, createOpenInferenceFileExporter as dr, FileSpawnJournal as dt, prepareJsonlAppend as ei, bridgeRuntimeAttachmentsKey as en, defaultRedactor as er, captureReusableExecutorConfig as et, driverChild as f, runtimeOwnedDriveHarnessProviderEvidence as fi, routerBrain as fn, createOtelExporter as fr, InMemoryResultBlobStore as ft, beginScopeOwnerAttempt as g, runtimeOwnedPendingExecutorMaterialization as gi, DEFAULT_SANDBOX_IDLE_TIMEOUT_SECONDS as gn, loopEventToOtelSpan as gr, materializeTreeView as gt, withDriverExecutor as h, runtimeOwnedExecutorProviderEvidence as hi, observedModelMatchesDeclared as hn, generateSpanId as hr, loadSpawnForest as ht, collectDelivered as i, authoredProfileDigest as ii, defaultSelectWinner as in, mergeTraceEnv as ir, createExecutorRegistry as it, consumeScopeRetainedOwnerResult as j, isSandboxTerminalEvent as ji, stringifySafe as jn, LOCAL_HARNESSES as jr, workerTraceHeaders as jt, validateWaitSpec as k, createSandboxUsageLedger as ki, randomSuffix as kn, removeWorktree as kr, readWorkerTraceContext as kt, classifyDriverFailure as l, newExecutionAttemptId as li, acquireSandbox as ln, buildLoopSpanNodes as lr, createInPlaceCliExecutor as lt, isDriverSpec as m, runtimeOwnedExecutorMaterialization as mi, canonicalObservedModelParts as mn, flatOtelSpan as mr, insideCursorNamespace as mt, createSupervisor as n, attestRuntimeOwnedPendingExecutor as ni, TERMINAL_DECISIONS as nn, resolveRedactor as nr, cliWorktreeExecutor as nt, runFinalizer as o, inheritRuntimeOwnedExecutorAttestation as oi, runAgentRounds as on, traceContextToEnv as or, createWorktreeCliExecutor as ot, driverExecutorFactory as p, runtimeOwnedExecutorExecutionBinding as pi, runBrainLoop as pn, exportEvalRuns as pr, InMemorySpawnJournal as pt, effectiveConcurrency as q, linkAbort as qn, renderUnsupported as qr, isTerminalNodeStatus as qt, bestDelivered as r, attestRuntimeOwnedScopeOwner as ri, createSandboxForSpec as rn, createPropagatingTraceEmitter as rr, createExecutor as rt, runTree as s, knownExecutionBindingReceipt as si, createSandboxLineage as sn, INTELLIGENCE_WIRE_VERSION as sr, DEFAULT_SANDBOX_STEERING_MAX_TURNS as st, createRootHandle as t, writeAllBytes as ti, bridgeStopSignalKey as tn, defaultRedactorIdentityMaterial as tr, cliInPlaceExecutor as tt, defaultUnmetContractSteer as u, providerAttemptEvidence as ui, assertBoxlessPromptOptions as un, buildRuntimeEventOtelSpans as ur, FileResultBlobStore as ut, deriveNodeExecutionIdentity as v, unknownExecutionBindingReceipt as vi, providerAsExecutor as vn, padTraceId as vr, replaySpawnTree as vt, settledToIteration as w, projectSandboxOutcome as wi, cloneSpend as wn, sanitizeRuntimeStreamEvent as wr, contentAddress as wt, recordScopeOwnerMaterialization as x, executableAgentSpecSnapshot as xi, sandboxClientAsProvider as xn, createRuntimeStreamEventCollector as xr, isTraceAnalysisStore as xt, meterRuntimeOwnedAccounting as y, unknownMaterializationReceipt as yi, providerAsSandboxClient as yn, toOtelAttributes as yr, WORKER_TOOL_TRACE_SCHEMA_VERSION as yt, attachWorker as z, abortError$2 as zi, withBudgetResources as zn, defineProfileMaterializationContract as zr, DEFAULT_PEER_MAIL_LIMITS as zt };
|
|
22949
23286
|
|
|
22950
|
-
//# sourceMappingURL=supervisor-
|
|
23287
|
+
//# sourceMappingURL=supervisor-n8DDNGli.js.map
|