@tangle-network/agent-runtime 8.0.0 → 9.0.0

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{activation-xxvLF1-1.d.ts → activation-Cvw_7nrn.d.ts} +2 -2
  3. package/dist/{activation-Ce4zUcu8.js → activation-jAPhmkOb.js} +3 -3
  4. package/dist/{activation-Ce4zUcu8.js.map → activation-jAPhmkOb.js.map} +1 -1
  5. package/dist/agent.d.ts +3 -3
  6. package/dist/agent.js +2 -2
  7. package/dist/agent.js.map +1 -1
  8. package/dist/candidate-execution/index.js +2 -2
  9. package/dist/{continuation-CIyKnS1Q.js → continuation-DDPfLw2w.js} +2 -2
  10. package/dist/{continuation-CIyKnS1Q.js.map → continuation-DDPfLw2w.js.map} +1 -1
  11. package/dist/{coordination-manager-sa_PkISw.js → coordination-manager-T9_VZ_Gh.js} +8 -9
  12. package/dist/coordination-manager-T9_VZ_Gh.js.map +1 -0
  13. package/dist/{delegate-DhTkJIta.js → delegate-BCMyrm5n.js} +2 -2
  14. package/dist/{delegate-DhTkJIta.js.map → delegate-BCMyrm5n.js.map} +1 -1
  15. package/dist/durable.d.ts +33 -2
  16. package/dist/durable.js +75 -14
  17. package/dist/durable.js.map +1 -1
  18. package/dist/{graph-tSIT_eWK.js → graph-CajniLnc.js} +10 -10
  19. package/dist/graph-CajniLnc.js.map +1 -0
  20. package/dist/{graph-registry-czAwYwNj.js → graph-registry-D3cY0BJU.js} +3 -3
  21. package/dist/{graph-registry-czAwYwNj.js.map → graph-registry-D3cY0BJU.js.map} +1 -1
  22. package/dist/{graph-registry-uTIyyy7A.js → graph-registry-DTeb6qhB.js} +1 -1
  23. package/dist/{improve-H08hiIw9.js → improve-Bv419bnu.js} +7 -7
  24. package/dist/{improve-H08hiIw9.js.map → improve-Bv419bnu.js.map} +1 -1
  25. package/dist/index.d.ts +5 -5
  26. package/dist/index.js +13 -13
  27. package/dist/intelligence.d.ts +4 -4
  28. package/dist/intelligence.js +6 -6
  29. package/dist/kernel.d.ts +2 -2
  30. package/dist/kernel.js +15 -15
  31. package/dist/{loop-runner-BGwhcn1p.d.ts → loop-runner-Bd9Ieh5w.d.ts} +2 -2
  32. package/dist/{loop-runner-ChqK8kSz.js → loop-runner-DaMM2vSj.js} +3 -3
  33. package/dist/{loop-runner-ChqK8kSz.js.map → loop-runner-DaMM2vSj.js.map} +1 -1
  34. package/dist/loop-runner-bin.d.ts +1 -1
  35. package/dist/loop-runner-bin.js +1 -1
  36. package/dist/mcp/bin.js +3 -3
  37. package/dist/mcp/index.d.ts +1 -1
  38. package/dist/mcp/index.js +6 -6
  39. package/dist/{model-policy-yxOrDTTj.js → model-policy-CZwhXp8O.js} +7 -2
  40. package/dist/model-policy-CZwhXp8O.js.map +1 -0
  41. package/dist/{prepare-BnF8nGIg.js → prepare-D7WwIddG.js} +2 -2
  42. package/dist/{prepare-BnF8nGIg.js.map → prepare-D7WwIddG.js.map} +1 -1
  43. package/dist/{profile-CD25rTJF.js → profile-BT0X-dm5.js} +2 -2
  44. package/dist/{profile-CD25rTJF.js.map → profile-BT0X-dm5.js.map} +1 -1
  45. package/dist/profiles.d.ts +1 -1
  46. package/dist/profiles.js +1 -1
  47. package/dist/{provision-supervisor-Dx4TXTMM.js → provision-supervisor-mJuBx86X.js} +6 -6
  48. package/dist/{provision-supervisor-Dx4TXTMM.js.map → provision-supervisor-mJuBx86X.js.map} +1 -1
  49. package/dist/{run-cancellation-DYszFJtQ.js → run-cancellation-DZn4OSl8.js} +2 -2
  50. package/dist/{run-cancellation-DYszFJtQ.js.map → run-cancellation-DZn4OSl8.js.map} +1 -1
  51. package/dist/{run-state-DHBoJjaF.js → run-state-ZjIxcjfp.js} +6 -6
  52. package/dist/{run-state-DHBoJjaF.js.map → run-state-ZjIxcjfp.js.map} +1 -1
  53. package/dist/{runtime-CaM5Gbbv.js → runtime-C-G9MAGo.js} +99 -31
  54. package/dist/runtime-C-G9MAGo.js.map +1 -0
  55. package/dist/{search-executor-B9L8W_1O.js → search-executor-D3la0D_r.js} +4 -4
  56. package/dist/{search-executor-B9L8W_1O.js.map → search-executor-D3la0D_r.js.map} +1 -1
  57. package/dist/{server-BlDV8sj_.js → server-CrckVQDt.js} +3 -3
  58. package/dist/{server-BlDV8sj_.js.map → server-CrckVQDt.js.map} +1 -1
  59. package/dist/{settle-record-WWQasnDq.js → settle-record-B95oiypS.js} +3 -3
  60. package/dist/{settle-record-WWQasnDq.js.map → settle-record-B95oiypS.js.map} +1 -1
  61. package/dist/{structural-rollout-C1xxoWcN.js → structural-rollout-U49dEq3i.js} +5 -5
  62. package/dist/{structural-rollout-C1xxoWcN.js.map → structural-rollout-U49dEq3i.js.map} +1 -1
  63. package/dist/{supervise-DWiSgPLB.js → supervise-CSB-Kl6S.js} +16 -16
  64. package/dist/supervise-CSB-Kl6S.js.map +1 -0
  65. package/dist/{supervision-discovery-C9kfBLKy.js → supervision-discovery-DUpm_6nQ.js} +2 -2
  66. package/dist/{supervision-discovery-C9kfBLKy.js.map → supervision-discovery-DUpm_6nQ.js.map} +1 -1
  67. package/dist/{supervisor-Dpeu7rnZ.js → supervisor-K2sskHJV.js} +147 -69
  68. package/dist/{supervisor-Dpeu7rnZ.js.map → supervisor-K2sskHJV.js.map} +1 -1
  69. package/dist/{supervisor-accounting-Bw4MJk-b.js → supervisor-accounting-BB22j3hu.js} +47 -32
  70. package/dist/supervisor-accounting-BB22j3hu.js.map +1 -0
  71. package/dist/testing.d.ts +1 -1
  72. package/dist/testing.js +60 -60
  73. package/dist/{top-web-B3HOAtrZ.js → top-web-DsFGyUlS.js} +5 -5
  74. package/dist/{top-web-B3HOAtrZ.js.map → top-web-DsFGyUlS.js.map} +1 -1
  75. package/dist/tui/bin.js +3 -3
  76. package/dist/tui/index.d.ts +1 -1
  77. package/dist/tui/index.js +2 -2
  78. package/dist/{types-C_qbnw9N.d.ts → types-CwGD-823.d.ts} +43 -32
  79. package/dist/viewer/report-viewer.js +90 -90
  80. package/dist/viewer/runtime-viewer/AgentGraphCanvas-P_PFS2Ko-B7S6Fwwy.js +563 -0
  81. package/dist/viewer/runtime-viewer/latest-events-wofY6ifW-B8_bfLwI.js +17870 -0
  82. package/dist/viewer/styles.css +1637 -7280
  83. package/dist/viewer/workspace-viewer.js +10927 -10523
  84. package/package.json +16 -16
  85. package/dist/coordination-manager-sa_PkISw.js.map +0 -1
  86. package/dist/graph-tSIT_eWK.js.map +0 -1
  87. package/dist/model-policy-yxOrDTTj.js.map +0 -1
  88. package/dist/runtime-CaM5Gbbv.js.map +0 -1
  89. package/dist/supervise-DWiSgPLB.js.map +0 -1
  90. package/dist/supervisor-accounting-Bw4MJk-b.js.map +0 -1
  91. package/dist/viewer/runtime-viewer/AgentGraphCanvas-DGq7_u8--C6yDfIUT.js +0 -8555
  92. package/dist/viewer/runtime-viewer/latest-events-CRq9sGkK-CfoBl1dP.js +0 -9592
  93. package/dist/viewer/runtime-viewer/sandbox-ui-BEziPi7D.css +0 -2
@@ -1,14 +1,14 @@
1
- import { $n as harnessTranscriptFromLines, $r as awaitAbortable, $t as ownedTreeRootSpawn, An as environmentGone, Bt as scopeRetainedOwnerSettled, Dr as knownExecutionBindingReceipt, Er as inheritRuntimeOwnedExecutorAttestation, Fn as mergeTraceEnv, Fr as recordRuntimeOwnedProviderModel, G as appendSpawnEvents, Gr as executableAgentProfileSnapshot, Hr as runtimeOwnedScopeOwnerRuntime, J as reenteredWorkers, Jt as bindScopeRetainedOwnerProvider, Kr as executableAgentSpecSnapshot, Kt as scopeRetainedOwnerCheckpointing, L as nestedScopeSeamKey, Lr as runtimeOwnedExecutorExecutionBinding, M as prepareScopeResume, Mn as workerTraceEnv, Mr as recordRuntimeOwnedProviderAttemptStart, Nn as workerTraceHeaders, Nr as recordRuntimeOwnedProviderDispatchNotStarted, Or as knownMaterializationReceipt, Pr as recordRuntimeOwnedProviderIdentityConflict, Qr as assertEventBinding, Qt as loadSpawnForest, Rr as runtimeOwnedExecutorMaterialization, Tr as finalizeRuntimeOwnedPendingExecutor, Ur as unknownExecutionBindingReceipt, Vr as runtimeOwnedScopeOwnerControl, Wr as unknownMaterializationReceipt, X as assertRecursiveReservationPolicy, Yn as HARNESS_TRANSCRIPT_SETTLE_TIMEOUT_MS, Zn as captureHarnessTranscript, Zr as RetainedRunProviderContractError, _n as reconnectRetainedRun, _t as waitForScopeChildren, ai as abortReason, an as encodeResultBlob, br as attestRuntimeOwnedExecutor, cn as executorObservation, cr as createActivityLog, dn as describeRetainedNativeStops, dr as isLiveNodeStatus, dt as releaseHeldEnvironments, ei as exactSession, er as harnessTranscriptUnavailable, fn as stopRetainedNativeExecution, ft as releaseRetainedEnvironments, gn as mintRetainedIdentity, gt as unconfirmedTeardowns, hn as assertRetainedRunReplayMaterial, ht as startScopeRecoveries, ii as RunCancellationReason, j as resolveWorkerSlots, jn as WORKER_TRACE_PROPAGATION, kr as newExecutionAttemptId, kt as finalizeScopeOwnerMaterialization, lr as describeToolArgs, mn as RetainedMaterializationTimeoutError, mt as settleManagerWork, n as terminalAccounting, ni as retainedSessionReplaced, nn as driverRuntime, nt as closeScopeAdmission, oi as linkAbort, on as SpawnEventIndex, pn as verifyWorkspaceMarker, pt as retryUnconfirmedTeardowns, q as appendTeardownConfirmation, r as createScope, ri as sameControlCoordinates, rn as nestedDriverTreeRoot, rt as hasRetriableTeardowns, si as runAbortable, t as isNonEmptySpend, ti as freezeControlRef, tn as attestNestedDriverTreeOwner, tt as closeRetainedSlots, ui as promptOptionsFromAgentTurnInput, un as observeModelRequest, ut as registerNestedTeardownScope, vn as recoverRetainedRun, vr as subscriptionUsageLimitSignal, xr as attestRuntimeOwnedPendingExecutor, yn as startRetainedRun, yr as attestRuntimeOwnedDeferredExecutor } from "./supervisor-accounting-Bw4MJk-b.js";
1
+ import { $r as assertEventBinding, $t as loadSpawnForest, Ar as newExecutionAttemptId, Bt as scopeRetainedOwnerSettled, Dr as inheritRuntimeOwnedExecutorAttestation, Er as finalizeRuntimeOwnedPendingExecutor, Fr as recordRuntimeOwnedProviderIdentityConflict, G as appendSpawnEvents, Gr as unknownMaterializationReceipt, Hr as runtimeOwnedScopeOwnerControl, In as mergeTraceEnv, Ir as recordRuntimeOwnedProviderModel, J as reenteredWorkers, Jt as bindScopeRetainedOwnerProvider, Kr as executableAgentProfileSnapshot, Kt as scopeRetainedOwnerCheckpointing, L as nestedScopeSeamKey, M as prepareScopeResume, Mn as WORKER_TRACE_PROPAGATION, Nn as workerTraceEnv, Nr as recordRuntimeOwnedProviderAttemptStart, Or as knownExecutionBindingReceipt, Pn as workerTraceHeaders, Pr as recordRuntimeOwnedProviderDispatchNotStarted, Qn as captureHarnessTranscript, Qr as RetainedRunProviderContractError, Rr as runtimeOwnedExecutorExecutionBinding, Sr as attestRuntimeOwnedPendingExecutor, Ur as runtimeOwnedScopeOwnerRuntime, Wr as unknownExecutionBindingReceipt, X as assertRecursiveReservationPolicy, Xn as HARNESS_TRANSCRIPT_SETTLE_TIMEOUT_MS, Xt as scopeOwnerLiabilities, Yt as owners, _n as mintRetainedIdentity, _t as waitForScopeChildren, ai as RunCancellationReason, bn as startRetainedRun, br as attestRuntimeOwnedDeferredExecutor, ci as runAbortable, di as promptOptionsFromAgentTurnInput, dn as observeModelRequest, dt as releaseHeldEnvironments, ei as awaitAbortable, en as ownedTreeRootSpawn, er as harnessTranscriptFromLines, fn as describeRetainedNativeStops, fr as isLiveNodeStatus, ft as releaseRetainedEnvironments, gn as assertRetainedRunReplayMaterial, gt as unconfirmedTeardowns, hn as RetainedMaterializationTimeoutError, ht as startScopeRecoveries, ii as sameControlCoordinates, in as nestedDriverTreeRoot, j as resolveWorkerSlots, jn as environmentGone, kr as knownMaterializationReceipt, kt as finalizeScopeOwnerMaterialization, ln as executorObservation, lr as createActivityLog, mn as verifyWorkspaceMarker, mt as settleManagerWork, n as terminalAccounting, ni as freezeControlRef, nn as attestNestedDriverTreeOwner, nt as closeScopeAdmission, oi as abortReason, on as encodeResultBlob, pn as stopRetainedNativeExecution, pt as retryUnconfirmedTeardowns, q as appendTeardownConfirmation, qr as executableAgentSpecSnapshot, r as createScope, ri as retainedSessionReplaced, rn as driverRuntime, rt as hasRetriableTeardowns, si as linkAbort, sn as SpawnEventIndex, t as isNonEmptySpend, ti as exactSession, tr as harnessTranscriptUnavailable, tt as closeRetainedSlots, ur as describeToolArgs, ut as registerNestedTeardownScope, vn as reconnectRetainedRun, xr as attestRuntimeOwnedExecutor, yn as recoverRetainedRun, yr as subscriptionUsageLimitSignal, zr as runtimeOwnedExecutorMaterialization } from "./supervisor-accounting-BB22j3hu.js";
2
2
  import { f as RuntimeRunStateError, i as ConfigError, m as ValidationError$1, r as BackendTransportError, t as AgentEvalError } from "./errors-DG8yufqX.js";
3
3
  import { C as unreportedSpend, D as addResourceSpend, E as zeroTokenUsage, F as ROOT_DEADLINE_REASON, H as teardownSurfaces, I as armDeadlineTimer, S as unmeteredSpend, T as zeroSpend, _ as roundBoxMinutes, b as throwAbort, c as errorMessage, d as isAbortError, f as isAsyncIterable, g as randomUuid, h as randomSuffix, j as ACCEPTED_RESULT_GRACE_MS, m as promptCacheTokenClasses, n as addSpend, o as cloneTokenUsage, p as mapWithConcurrency, r as addTokenUsage, s as deleteBoxSafe, v as sleep, w as withTimeout, x as throwIfAborted, y as stringifySafe, z as isDeadlineAbortReason } from "./util-fcckrkKp.js";
4
4
  import { t as runTaskQueue } from "./task-queue-DbpZAp6C.js";
5
5
  import { B as hashJson, D as unavailableResumeAt, E as unavailablePauseMs, F as executorFailureInfra, H as isCredentialRefusal, J as createBudgetPool, M as contentAddress, N as contentRef, O as unavailableSignalOfFailure, R as turnFailureOf, T as reportedResetAt, Tt as recordValue, V as credentialCommandExit, _t as isSandboxTerminalEvent, a as runtimeProviderCode, at as sandboxLeafOutputFromEvents, b as UNAVAILABLE_CODES, bt as sandboxEventServedBackend, c as DISPATCH_EXECUTION_CHANGED_CODE, d as TRANSPORT_ERROR_CODES, ft as assertSandboxServedModel, ht as createSandboxUsageLedger, i as runtimeFailureRemediationSchema, l as DISPATCH_NOT_ADMITTED_CODE, m as isSchemaRejection, mt as createSandboxTurnEventCollector, n as runtimeFailureCause, nt as createSandboxToolPartState, ot as sandboxOutputMarker, p as isProvisioningRefusal, pt as canonicalSandboxUsageMode, st as sandboxProgressEvents, t as reportedFailureCause, u as RetainedExecutionPendingError, ut as extractTransportEventIdentity, v as retainedExecutorContext, vt as notifySandboxEventObserver, w as printedStatus, wt as parseCodexUsageRecord, x as UNAVAILABLE_STATUSES, xt as sandboxTerminalUsageField, y as retainedExecutorSeamKey, yt as sameModelId, z as turnFailurePolicy } from "./failure-cause-CVB-YE88.js";
6
6
  import { a as errMessage, i as causeChain, l as errorText, n as detachedSnapshot, o as errorHttpStatus, s as errorProperty, u as defaultRedactor } from "./snapshot-BKI_w3JD.js";
7
- import { _ as agentHarness, a as concreteProfileModel, c as profileModelExecutionSettings, d as assertRouterAutoDeclaration, f as assertRouterAutoResponse, g as observedModelMatchesDeclared, h as observedModelHasSnapshot, l as profileProviderModel, m as mergeObservedModelIdentity, o as enforceTokenLimits, s as profileBridgeWireModel, t as assertExecutableAgentProfile, u as resolveRouterRetryPolicy } from "./model-policy-yxOrDTTj.js";
7
+ import { _ as agentHarness, a as concreteProfileModel, c as profileModelExecutionSettings, d as assertRouterAutoDeclaration, f as assertRouterAutoResponse, g as observedModelMatchesDeclared, h as observedModelHasSnapshot, l as profileProviderModel, m as mergeObservedModelIdentity, o as enforceTokenLimits, s as profileBridgeWireModel, t as assertExecutableAgentProfile, u as resolveRouterRetryPolicy } from "./model-policy-CZwhXp8O.js";
8
8
  import { r as nativeSystemPrompt, t as assertSandboxProfileCompatibility } from "./sandbox-profile-compat-l-SLQnGb.js";
9
9
  import { l as sha256 } from "./jsonl-file-DsxVI0E_.js";
10
10
  import { V as hasControlCharacter } from "./workspace-streams-DA9R3j-p.js";
11
- import { i as checkVerdictOf, s as isFiniteNumber } from "./continuation-CIyKnS1Q.js";
11
+ import { i as checkVerdictOf, s as isFiniteNumber } from "./continuation-DDPfLw2w.js";
12
12
  import { a as writeAtomicDurableFile, s as fenceRunWrite } from "./durable-file-DstVeHcj.js";
13
13
  import { t as PROTOCOL_VERSION } from "./tool-server-DYwRbi0I.js";
14
14
  import { i as notifyRuntimeHookEvent } from "./runtime-hooks-CsW2pfFk.js";
@@ -14985,9 +14985,11 @@ var RunParkedError = class extends Error {
14985
14985
  }
14986
14986
  };
14987
14987
  const DEFAULT_PARK_AFTER_MS = 6e4;
14988
+ /** A seat reset nearer than this is slept through in place; requeueing costs more than it frees. */
14989
+ const SEAT_PARK_MIN_MS = 3e5;
14988
14990
  const parkingContext = new AsyncLocalStorage();
14989
14991
  const parkingDrains = /* @__PURE__ */ new WeakMap();
14990
- /** Drain committed child work through the existing manager ledger before testing root idleness. */
14992
+ /** Drain committed child work through the existing manager ledger before testing idleness. */
14991
14993
  function bindScopeParkingDrain(scope, drain, idle) {
14992
14994
  parkingDrains.set(scope, {
14993
14995
  drain,
@@ -14997,96 +14999,168 @@ function bindScopeParkingDrain(scope, drain, idle) {
14997
14999
  /** Validate at intake, before any execution or ownership acquisition. */
14998
15000
  function assertRunParking(policy, durable) {
14999
15001
  if (policy === void 0) return;
15000
- if (!durable) throw new ValidationError$1("supervise: parking requires runDir");
15002
+ if (!durable) throw new ValidationError$1("supervise: parking requires runDir or a SQL runContext");
15001
15003
  if (policy === null || typeof policy !== "object" || policy.afterMs !== void 0 && (!Number.isFinite(policy.afterMs) || policy.afterMs < 0)) throw new ValidationError$1("supervise: parking.afterMs must be a nonnegative finite number");
15002
15004
  }
15003
- /** Scope the handoff to one execution, preserving the original wake time on an early re-entry. */
15005
+ /** Whether this error is the current run's own park, which every scope of the run propagates. */
15006
+ function isRunParked(error, scope) {
15007
+ return error instanceof RunParkedError && (error.runId === scope.view.root || error.runId === parkingContext.getStore()?.runId);
15008
+ }
15009
+ /**
15010
+ * Scope the handoff to one execution, preserving the original wake time on an early re-entry.
15011
+ * The journal's `run-parked` event is the durable record; `parking.json` is its runDir projection.
15012
+ */
15004
15013
  async function withRunParking(policy, runDir, runId, journal, now, signal, run) {
15005
- if (policy === void 0 || runDir === void 0) return run();
15014
+ if (policy === void 0) return parkingContext.exit(run);
15006
15015
  const events = await journal.loadTree(runId) ?? [];
15007
15016
  const previous = [...events].reverse().find((event) => event.kind === "run-parked");
15008
15017
  const transition = [...events].reverse().find((event) => event.id === runId && (event.kind === "run-parked" || event.kind === "root-reentered" || event.kind === "reopened"));
15009
15018
  const current = transition?.kind === "run-parked" ? transition : void 0;
15010
15019
  if (current !== void 0 && Date.parse(current.wakeAt) > now() && !signal?.aborted) {
15011
- await writeParkingProjection(runDir, runId, current);
15020
+ if (runDir !== void 0) await writeParkingProjection(runDir, runId, current);
15012
15021
  throw new RunParkedError(runId, parkingRecordOf(current));
15013
15022
  }
15014
- if (previous !== void 0) await writeAtomicDurableFile(resolve(runDir, "parking.json"), JSON.stringify({
15015
- status: "resuming",
15016
- runId,
15017
- ...parkingRecordOf(previous),
15018
- resumedAt: new Date(now()).toISOString()
15019
- }));
15023
+ if (previous !== void 0 && runDir !== void 0) await writeParkingProjection(runDir, runId, previous, now());
15024
+ let park;
15025
+ const parked = new Promise((_, reject) => {
15026
+ park = reject;
15027
+ });
15028
+ parked.catch(() => void 0);
15020
15029
  return parkingContext.run({
15021
15030
  runDir,
15022
15031
  runId,
15023
15032
  journal,
15024
15033
  now,
15025
- afterMs: policy.afterMs ?? DEFAULT_PARK_AFTER_MS
15034
+ afterMs: policy.afterMs ?? DEFAULT_PARK_AFTER_MS,
15035
+ waits: /* @__PURE__ */ new Map(),
15036
+ parked,
15037
+ park,
15038
+ handingOff: false
15026
15039
  }, run);
15027
15040
  }
15041
+ /** Run the root execution so a park decided by any of the run's waits rejects it at once. */
15042
+ function raceRunParking(runId, scope, seal, run) {
15043
+ const context = parkingContext.getStore();
15044
+ if (context === void 0 || context.runId !== runId) return run();
15045
+ context.root = {
15046
+ scope,
15047
+ seal
15048
+ };
15049
+ const running = run();
15050
+ running.catch(() => void 0);
15051
+ return Promise.race([running, context.parked]);
15052
+ }
15028
15053
  /**
15029
- * Sleep through the existing wait path. A root with no live descendants may hand off after its
15030
- * idle threshold; children and roots with active work keep their normal wait. No timer survives
15031
- * the handoff, and no provider work is cancelled or terminal settlement written for parking.
15054
+ * Sleep through the existing wait path. The run may hand off once every live node is waiting
15055
+ * here: the root on its own wait, any node on a seat reset at least SEAT_PARK_MIN_MS away. A run
15056
+ * with other active work keeps its normal wait. No timer survives the handoff, and no provider
15057
+ * work is cancelled or terminal settlement written for parking.
15032
15058
  */
15033
15059
  async function sleepScopeWait(scope, ms, signal, reason) {
15034
15060
  if (ms <= 0 || signal.aborted) return;
15035
15061
  const context = parkingContext.getStore();
15036
- const onlyRootWait = () => context !== void 0 && scope.view.root === context.runId && parkingDrains.get(scope)?.idle() !== false && scope.workerCapacity.unconfirmed.length === 0 && !(scope.observeTree?.() ?? scope.view).nodes.some((node) => node.id !== context.runId && isLiveNodeStatus(node.status));
15037
- if (context === void 0 || scope.view.root !== context.runId || ms <= context.afterMs) return sleep(ms, signal, false);
15062
+ const node = scope.view.root;
15063
+ if (context === void 0 || node !== context.runId && reason !== "seat-wait") return sleep(ms, signal, false);
15064
+ const floor = reason === "seat-wait" ? Math.max(context.afterMs, SEAT_PARK_MIN_MS) : context.afterMs;
15038
15065
  const since = context.now();
15039
- const deadline = scope.budget.deadlineMs;
15040
- const wakeAt = Math.min(since + ms, deadline > 0 ? deadline : Number.POSITIVE_INFINITY);
15041
- if (wakeAt - since <= context.afterMs) return sleep(ms, signal, false);
15042
- let idleSince = onlyRootWait() ? since : void 0;
15043
- for (;;) {
15044
- const remaining = Math.max(0, wakeAt - context.now());
15045
- if (remaining <= context.afterMs) return sleep(remaining, signal, false);
15046
- const checkMs = context.afterMs || (idleSince === void 0 ? DEFAULT_PARK_AFTER_MS : 0);
15047
- await sleep(Math.min(checkMs, remaining), signal, false);
15048
- if (signal.aborted) return;
15049
- await parkingDrains.get(scope)?.drain();
15050
- if (!onlyRootWait()) {
15051
- idleSince = void 0;
15052
- continue;
15053
- }
15054
- if (idleSince === void 0) {
15055
- idleSince = context.now();
15056
- continue;
15057
- }
15058
- if (context.now() - idleSince < context.afterMs) continue;
15059
- const events = await context.journal.loadTree(context.runId) ?? [];
15060
- if (signal.aborted) return;
15061
- const ownerEvents = events.filter((event) => event.id === context.runId);
15062
- const input = [...ownerEvents].reverse().find((event) => event.kind === "execution-input");
15063
- const invocation = input === void 0 ? [] : ownerEvents.slice(ownerEvents.indexOf(input));
15064
- if (invocation.some((event) => event.kind === "execution-admitted") && !invocation.some((event) => event.kind === "execution-result" || event.kind === "execution-abandoned" && event.outcome === "stopped") || !onlyRootWait()) {
15065
- idleSince = void 0;
15066
- continue;
15066
+ const deadline = Math.min(deadlineOf(scope), context.root ? deadlineOf(context.root.scope) : Number.POSITIVE_INFINITY);
15067
+ const wakeAt = Math.min(since + ms, deadline);
15068
+ if (wakeAt - since <= floor) return sleep(ms, signal, false);
15069
+ context.waits.set(node, {
15070
+ scope,
15071
+ wakeAt,
15072
+ floor,
15073
+ reason: wakeAt === deadline && wakeAt < since + ms ? "deadline" : reason
15074
+ });
15075
+ try {
15076
+ let idleSince = runIdle(context) ? since : void 0;
15077
+ for (;;) {
15078
+ const remaining = Math.max(0, wakeAt - context.now());
15079
+ if (remaining <= floor) return await Promise.race([sleep(remaining, signal, false), context.parked]);
15080
+ const checkMs = context.afterMs || (idleSince === void 0 ? DEFAULT_PARK_AFTER_MS : 0);
15081
+ await Promise.race([sleep(Math.min(checkMs, remaining), signal, false), context.parked]);
15082
+ if (signal.aborted) return;
15083
+ for (const held of heldScopes(context)) await parkingDrains.get(held)?.drain();
15084
+ if (!runIdle(context)) {
15085
+ idleSince = void 0;
15086
+ continue;
15087
+ }
15088
+ if (idleSince === void 0) {
15089
+ idleSince = context.now();
15090
+ continue;
15091
+ }
15092
+ if (context.now() - idleSince < context.afterMs) continue;
15093
+ const events = await context.journal.loadTree(context.runId) ?? [];
15094
+ if (signal.aborted) return;
15095
+ if (await invocationUnresolved(context, events) || !runIdle(context)) {
15096
+ idleSince = void 0;
15097
+ continue;
15098
+ }
15099
+ const at = context.now();
15100
+ const waits = [...context.waits.values()];
15101
+ if (waits.some((wait) => wait.wakeAt - at <= wait.floor)) continue;
15102
+ await parkRun(context, waits, idleSince, events);
15067
15103
  }
15068
- const parking = {
15069
- reason: deadline > 0 && wakeAt === deadline ? "deadline" : reason,
15070
- since: new Date(idleSince).toISOString(),
15071
- wakeAt: new Date(wakeAt).toISOString()
15072
- };
15073
- closeScopeAdmission(scope);
15074
- await context.journal.appendEvent(context.runId, {
15075
- kind: "run-parked",
15076
- id: context.runId,
15077
- ...parking,
15078
- seq: events.filter((event) => event.kind === "run-parked").length,
15079
- at: new Date(context.now()).toISOString()
15080
- });
15081
- await writeParkingProjection(context.runDir, context.runId, parking);
15082
- throw new RunParkedError(context.runId, parking);
15104
+ } finally {
15105
+ context.waits.delete(node);
15106
+ }
15107
+ }
15108
+ async function parkRun(context, waits, idleSince, events) {
15109
+ if (context.handingOff) return context.parked;
15110
+ context.handingOff = true;
15111
+ const root = context.root;
15112
+ const earliest = waits.reduce((first, wait) => wait.wakeAt < first.wakeAt ? wait : first);
15113
+ const parking = {
15114
+ reason: earliest.reason,
15115
+ since: new Date(idleSince).toISOString(),
15116
+ wakeAt: new Date(earliest.wakeAt).toISOString()
15117
+ };
15118
+ for (const held of heldScopes(context)) closeScopeAdmission(held);
15119
+ await context.journal.appendEvent(context.runId, {
15120
+ kind: "run-parked",
15121
+ id: context.runId,
15122
+ ...parking,
15123
+ seq: events.filter((event) => event.kind === "run-parked").length,
15124
+ at: new Date(context.now()).toISOString()
15125
+ });
15126
+ if (context.runDir !== void 0) await writeParkingProjection(context.runDir, context.runId, parking);
15127
+ const error = new RunParkedError(context.runId, parking);
15128
+ if (waits.some((wait) => wait.scope !== root.scope)) root.seal(error);
15129
+ context.park(error);
15130
+ throw error;
15131
+ }
15132
+ function heldScopes(context) {
15133
+ const scopes = new Set([...context.waits.values()].map((wait) => wait.scope));
15134
+ if (context.root) scopes.add(context.root.scope);
15135
+ return [...scopes];
15136
+ }
15137
+ /** Every live node is in a parkable wait, and no scope holds open work or unconfirmed capacity. */
15138
+ function runIdle(context) {
15139
+ const root = context.root;
15140
+ if (root === void 0) return false;
15141
+ if (heldScopes(context).some((held) => parkingDrains.get(held)?.idle() === false || held.workerCapacity.unconfirmed.length > 0)) return false;
15142
+ return !(root.scope.observeTree?.() ?? root.scope.view).nodes.some((node) => node.id !== context.runId && isLiveNodeStatus(node.status) && !context.waits.has(node.id));
15143
+ }
15144
+ /** The owners' own receipts decide: an admitted invocation without its result may still compute. */
15145
+ async function invocationUnresolved(context, rootEvents) {
15146
+ for (const held of heldScopes(context)) {
15147
+ const rootId = owners.get(held)?.args.rootId;
15148
+ if (rootId === void 0) continue;
15149
+ const events = rootId === context.runId ? rootEvents : await context.journal.loadTree(rootId);
15150
+ if (scopeOwnerLiabilities(held, events ?? []).invocationUnsettled) return true;
15083
15151
  }
15152
+ return false;
15153
+ }
15154
+ function deadlineOf(scope) {
15155
+ const deadline = scope.budget.deadlineMs;
15156
+ return deadline > 0 ? deadline : Number.POSITIVE_INFINITY;
15084
15157
  }
15085
- async function writeParkingProjection(runDir, runId, parking) {
15158
+ async function writeParkingProjection(runDir, runId, parking, resumedAt) {
15086
15159
  await writeAtomicDurableFile(resolve(runDir, "parking.json"), JSON.stringify({
15087
- status: "parked",
15160
+ status: resumedAt === void 0 ? "parked" : "resuming",
15088
15161
  runId,
15089
- ...parkingRecordOf(parking)
15162
+ ...parkingRecordOf(parking),
15163
+ ...resumedAt === void 0 ? {} : { resumedAt: new Date(resumedAt).toISOString() }
15090
15164
  }));
15091
15165
  }
15092
15166
  function parkingRecordOf(record) {
@@ -15524,6 +15598,10 @@ function guardRunPersistence(journal, blobs, interrupt) {
15524
15598
  },
15525
15599
  assertAvailable() {
15526
15600
  if (failure !== void 0) throw failure;
15601
+ },
15602
+ /** Refuse every later write with `error`, without interrupting the retained executions. */
15603
+ seal(error) {
15604
+ failure ??= error;
15527
15605
  }
15528
15606
  };
15529
15607
  }
@@ -16003,7 +16081,7 @@ async function executeRoot(root) {
16003
16081
  ok: true,
16004
16082
  out: await runAbortable(() => {
16005
16083
  rootStarted = true;
16006
- return root.run();
16084
+ return raceRunParking(opts.runId, scope, persistence.seal, root.run);
16007
16085
  }, controller.signal, "supervisor aborted")
16008
16086
  };
16009
16087
  } catch (error) {
@@ -16136,6 +16214,6 @@ async function noWinner(settled, rejection) {
16136
16214
  reason: "no-result-selected"
16137
16215
  };
16138
16216
  }
16139
- export { DEFAULT_PEER_MAIL_LIMITS as $, createSandboxForSpec as A, bridgeRuntimeAttachmentsKey as At, createRouterTranscript as B, controlProfileMaterialization as Bt, createExecutor as C, priceTokens as Ct, runAgentRounds as D, harnessUsageIsEmpty as Dt, createSteerableSandboxSession as E, createCodexRolloutStoreReader as Et, codeModeArguments as F, LOCAL_HARNESSES as Ft, LEAF_CONTINUATION_TASK as G, promptModelProfileMaterialization as Gt, createAgentEnvironmentProviderRegistry as H, fullProfileMaterialization as Ht, codeModeModelOutput as I, harnessInvocation as It, createInPlaceCliExecutor as J, sandboxProfileMaterialization as Jt, providerAsSandboxClient as K, renderUnsupported as Kt, createCodeModeTools as L, terminateProcessTreeAndConfirm as Lt, acquireSandbox as M, defaultRunCommand as Mt, TERMINAL_DECISIONS as N, runSettledCommand as Nt, assertBoxlessPromptOptions as O, readCodexRolloutSession as Ot, defaultSelectWinner as P, runWorktreeHarness as Pt, AUTHORITY_MARKERS as Q, readSandboxOutcome as Qt, runCodeMode as R, assertProfileMaterialization as Rt, captureReusableExecutorConfig as S, bridgeModelRouteRefusal as St, DEFAULT_SANDBOX_STEERING_MAX_TURNS as T, addHarnessUsage as Tt, resolveAgentEnvironmentProvider as U, profileMaterializationAxes$1 as Ut, routerBrain as V, defineProfileMaterializationContract as Vt, providerAsExecutor as W, promptControlProfileMaterialization as Wt, createInbox as X, worktreeCliProfileMaterialization as Xt, INBOX_RECEIPT_KEY as Y, unsupportedProfileDimensions as Yt, failPendingAfter as Z, projectSandboxOutcome as Zt, withDriverExecutor as _, gateFactoryOnDeliverable as _t, assertRunParking as a, peerMailVerbNames as at, createExecutorRegistry as b, verdictFromJudgeScore as bt, sleepScopeWait as c, HarnessTurnFailedError as ct, runFinalizer as d, summarizeDriverAttempts as dt, PEER_MAIL_WIRE_KEY as et, runTree as f, transientFailureKind as ft, isDriverSpec as g, CheckUnavailableError as gt, driverExecutorFactory as h, preflightPublicCoordination as ht, RunParkedError as i, peerMailTools as it, createSandboxLineage as j, bridgeStopSignalKey as jt, readPromptOptions as k, createPushTraceSource as kt, withRunParking as l, abandonablePending as lt, driverChild as m, upstreamUnavailableSignal as mt, createSupervisor as n, createPeerMailbox as nt, bindScopeParkingDrain as o, taskToPrompt$1 as ot, createRootHandle as p, undispatchedCredentialExit as pt, createWorktreeCliExecutor as q, sandboxActProfileMaterialization as qt, assertResumeLimits as r, isPeerMailEnvelope as rt, readRunParking as s, DriverAttemptsExhaustedError as st, DEFAULT_MAX_DEPTH as t, claimsAuthority as tt, bestDelivered as u, classifyDriverFailure as ut, InMemoryResultBlobStore as v, gateOnDeliverable as vt, snapshotExecutorConfig as w, ROUTER_PRICE_SOURCE as wt, bindReusableExecutorExecutionId as x, bridgeAdmissionRefusal as xt, InMemorySpawnJournal as y, mapExecutorResult as yt, toolResultText as z, assertProfileMaterializes as zt };
16217
+ export { AUTHORITY_MARKERS as $, readSandboxOutcome as $t, readPromptOptions as A, createPushTraceSource as At, toolResultText as B, assertProfileMaterializes as Bt, captureReusableExecutorConfig as C, bridgeModelRouteRefusal as Ct, createSteerableSandboxSession as D, createCodexRolloutStoreReader as Dt, DEFAULT_SANDBOX_STEERING_MAX_TURNS as E, addHarnessUsage as Et, defaultSelectWinner as F, runWorktreeHarness as Ft, providerAsExecutor as G, promptControlProfileMaterialization as Gt, routerBrain as H, defineProfileMaterializationContract as Ht, codeModeArguments as I, LOCAL_HARNESSES as It, createWorktreeCliExecutor as J, sandboxActProfileMaterialization as Jt, LEAF_CONTINUATION_TASK as K, promptModelProfileMaterialization as Kt, codeModeModelOutput as L, harnessInvocation as Lt, createSandboxLineage as M, bridgeStopSignalKey as Mt, acquireSandbox as N, defaultRunCommand as Nt, runAgentRounds as O, harnessUsageIsEmpty as Ot, TERMINAL_DECISIONS as P, runSettledCommand as Pt, failPendingAfter as Q, projectSandboxOutcome as Qt, createCodeModeTools as R, terminateProcessTreeAndConfirm as Rt, bindReusableExecutorExecutionId as S, bridgeAdmissionRefusal as St, snapshotExecutorConfig as T, ROUTER_PRICE_SOURCE as Tt, createAgentEnvironmentProviderRegistry as U, fullProfileMaterialization as Ut, createRouterTranscript as V, controlProfileMaterialization as Vt, resolveAgentEnvironmentProvider as W, profileMaterializationAxes$1 as Wt, INBOX_RECEIPT_KEY as X, unsupportedProfileDimensions as Xt, createInPlaceCliExecutor as Y, sandboxProfileMaterialization as Yt, createInbox as Z, worktreeCliProfileMaterialization as Zt, isDriverSpec as _, CheckUnavailableError as _t, assertRunParking as a, peerMailTools as at, InMemorySpawnJournal as b, mapExecutorResult as bt, readRunParking as c, DriverAttemptsExhaustedError as ct, bestDelivered as d, classifyDriverFailure as dt, DEFAULT_PEER_MAIL_LIMITS as et, runFinalizer as f, summarizeDriverAttempts as ft, driverExecutorFactory as g, preflightPublicCoordination as gt, driverChild as h, upstreamUnavailableSignal as ht, RunParkedError as i, isPeerMailEnvelope as it, createSandboxForSpec as j, bridgeRuntimeAttachmentsKey as jt, assertBoxlessPromptOptions as k, readCodexRolloutSession as kt, sleepScopeWait as l, HarnessTurnFailedError as lt, createRootHandle as m, undispatchedCredentialExit as mt, createSupervisor as n, claimsAuthority as nt, bindScopeParkingDrain as o, peerMailVerbNames as ot, runTree as p, transientFailureKind as pt, providerAsSandboxClient as q, renderUnsupported as qt, assertResumeLimits as r, createPeerMailbox as rt, isRunParked as s, taskToPrompt$1 as st, DEFAULT_MAX_DEPTH as t, PEER_MAIL_WIRE_KEY as tt, withRunParking as u, abandonablePending as ut, withDriverExecutor as v, gateFactoryOnDeliverable as vt, createExecutor as w, priceTokens as wt, createExecutorRegistry as x, verdictFromJudgeScore as xt, InMemoryResultBlobStore as y, gateOnDeliverable as yt, runCodeMode as z, assertProfileMaterialization as zt };
16140
16218
 
16141
- //# sourceMappingURL=supervisor-Dpeu7rnZ.js.map
16219
+ //# sourceMappingURL=supervisor-K2sskHJV.js.map