@tangle-network/agent-runtime 9.0.16 → 10.0.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/CHANGELOG.md +86 -0
- package/dist/{activation-DgT20fzX.js → activation-C_BenzIu.js} +2 -2
- package/dist/{activation-DgT20fzX.js.map → activation-C_BenzIu.js.map} +1 -1
- package/dist/{activation-y6NAn3sW.d.ts → activation-s6dGGify.d.ts} +7 -8
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +3 -3
- package/dist/candidate-execution/index.d.ts +3 -0
- package/dist/candidate-execution/index.js +10 -3
- package/dist/candidate-execution/index.js.map +1 -1
- package/dist/{delegate-Cmu5OF3M.js → delegate-BOren4c7.js} +2 -2
- package/dist/{delegate-Cmu5OF3M.js.map → delegate-BOren4c7.js.map} +1 -1
- package/dist/{coordination-manager-CFtnSLPw.js → driver-control-acknowledgers-ByKwAgCI.js} +1062 -1042
- package/dist/driver-control-acknowledgers-ByKwAgCI.js.map +1 -0
- package/dist/durable.d.ts +5 -5
- package/dist/durable.js +13 -13
- package/dist/durable.js.map +1 -1
- package/dist/{failure-cause-WifbY42M.js → failure-cause-DoCCGLDH.js} +42 -18
- package/dist/failure-cause-DoCCGLDH.js.map +1 -0
- package/dist/{graph-DqtIiS94.js → graph-BXONYT1o.js} +8 -8
- package/dist/{graph-DqtIiS94.js.map → graph-BXONYT1o.js.map} +1 -1
- package/dist/{graph-registry-B_1C7qye.js → graph-registry-DxhlgHdA.js} +1 -1
- package/dist/{graph-registry-BbZN5deo.js → graph-registry-j9t9J0KT.js} +11 -12
- package/dist/{graph-registry-BbZN5deo.js.map → graph-registry-j9t9J0KT.js.map} +1 -1
- package/dist/{improve-B0vNv6e7.js → improve-CS2GIF5O.js} +42 -26
- package/dist/{improve-B0vNv6e7.js.map → improve-CS2GIF5O.js.map} +1 -1
- package/dist/index.d.ts +38 -6
- package/dist/index.js +59 -20
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +93 -63
- package/dist/intelligence.js +166 -73
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +16 -15
- package/dist/{loop-runner-CfMOsISJ.d.ts → loop-runner-C0B3PexH.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/{loop-runner-BvVdDdZC.js → loop-runner-ftyZP4st.js} +2 -2
- package/dist/{loop-runner-BvVdDdZC.js.map → loop-runner-ftyZP4st.js.map} +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +7 -7
- package/dist/mcp/memory-bin.js +1 -1
- package/dist/{model-policy-CZwhXp8O.js → model-policy-CqDuBTq-.js} +12 -2
- package/dist/model-policy-CqDuBTq-.js.map +1 -0
- package/dist/{prepare-Cw4ZaN01.js → prepare-DT-ibRsm.js} +2 -2
- package/dist/{prepare-Cw4ZaN01.js.map → prepare-DT-ibRsm.js.map} +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.js +1 -1
- package/dist/{provision-supervisor-BjKluSKl.js → provision-supervisor-CauovUHn.js} +6 -6
- package/dist/{provision-supervisor-BjKluSKl.js.map → provision-supervisor-CauovUHn.js.map} +1 -1
- package/dist/{run-cancellation-BvGEEwRG.js → run-cancellation-NMNVuYiO.js} +2 -2
- package/dist/{run-cancellation-BvGEEwRG.js.map → run-cancellation-NMNVuYiO.js.map} +1 -1
- package/dist/{run-state-Dd_AjWd6.js → run-state-COyIVOVb.js} +5 -5
- package/dist/{run-state-Dd_AjWd6.js.map → run-state-COyIVOVb.js.map} +1 -1
- package/dist/{runtime-7VEM9muH.js → runtime-DYaRDLKn.js} +191 -24
- package/dist/runtime-DYaRDLKn.js.map +1 -0
- package/dist/{search-executor-Dqtm1fOC.js → search-executor-Drd_N9YO.js} +5 -5
- package/dist/{search-executor-Dqtm1fOC.js.map → search-executor-Drd_N9YO.js.map} +1 -1
- package/dist/{server-B8Kmit_v.js → server-Dk9B1WFf.js} +4 -4
- package/dist/{server-B8Kmit_v.js.map → server-Dk9B1WFf.js.map} +1 -1
- package/dist/{settle-record-BvH2-Ao5.js → settle-record-YdkkHzqw.js} +2 -2
- package/dist/{settle-record-BvH2-Ao5.js.map → settle-record-YdkkHzqw.js.map} +1 -1
- package/dist/{structural-rollout-CYc8PE2N.js → structural-rollout-DbZAkHTq.js} +5 -5
- package/dist/{structural-rollout-CYc8PE2N.js.map → structural-rollout-DbZAkHTq.js.map} +1 -1
- package/dist/{supervise-BayNu7qZ.js → supervise-B5hb0my3.js} +2426 -2336
- package/dist/supervise-B5hb0my3.js.map +1 -0
- package/dist/{supervision-discovery-Ca4QO4rG.js → supervision-discovery-ChkTxilL.js} +3 -3
- package/dist/{supervision-discovery-Ca4QO4rG.js.map → supervision-discovery-ChkTxilL.js.map} +1 -1
- package/dist/{supervisor-Bx21Hy27.js → supervisor-DpwcTrTh.js} +437 -75
- package/dist/supervisor-DpwcTrTh.js.map +1 -0
- package/dist/{supervisor-accounting-StDNW1YT.js → supervisor-accounting-QiXnF-EW.js} +541 -344
- package/dist/supervisor-accounting-QiXnF-EW.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +11 -11
- package/dist/{tool-server-CirrqFlr.js → tool-server-DQCdu3am.js} +2 -2
- package/dist/{tool-server-CirrqFlr.js.map → tool-server-DQCdu3am.js.map} +1 -1
- package/dist/{top-web-Cg7ywIkF.js → top-web-E85Fk8pH.js} +6 -6
- package/dist/{top-web-Cg7ywIkF.js.map → top-web-E85Fk8pH.js.map} +1 -1
- package/dist/tui/bin.js +3 -3
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/{types-_j53efrk.d.ts → types-dv295cpm.d.ts} +9907 -9784
- package/dist/{workspace-streams-BakRr-Pl.js → workspace-streams-C7PGLAUd.js} +3 -3
- package/dist/workspace-streams-C7PGLAUd.js.map +1 -0
- package/package.json +8 -7
- package/dist/coordination-manager-CFtnSLPw.js.map +0 -1
- package/dist/failure-cause-WifbY42M.js.map +0 -1
- package/dist/model-policy-CZwhXp8O.js.map +0 -1
- package/dist/runtime-7VEM9muH.js.map +0 -1
- package/dist/supervise-BayNu7qZ.js.map +0 -1
- package/dist/supervisor-Bx21Hy27.js.map +0 -1
- package/dist/supervisor-accounting-StDNW1YT.js.map +0 -1
- package/dist/workspace-streams-BakRr-Pl.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $r as executableAgentSpecSnapshot, $t as owners, Br as recordRuntimeOwnedProviderDispatchNotStarted, Cn as reconnectRetainedRun, Dr as attestRuntimeOwnedExecutor, Er as attestRuntimeOwnedDeferredExecutor, Fr as knownMaterializationReceipt, G as appendSpawnEvents, Gr as runtimeOwnedExecutorMaterialization, Hr as recordRuntimeOwnedProviderModel, In as environmentGone, Ir as newExecutionAttemptId, J as reenteredWorkers, Jr as runtimeOwnedScopeOwnerControl, L as nestedScopeSeamKey, Ln as WORKER_TRACE_PROPAGATION, M as prepareScopeResume, Mr as finalizeRuntimeOwnedPendingExecutor, Nr as inheritRuntimeOwnedExecutorAttestation, Or as attestRuntimeOwnedPendingExecutor, Pr as knownExecutionBindingReceipt, Qr as executableAgentProfileSnapshot, Qt as bindScopeRetainedOwnerProvider, Rn as workerTraceEnv, Sn as mintRetainedIdentity, Tn as startRetainedRun, Tr as subscriptionUsageLimitSignal, Vn as mergeTraceEnv, Vr as recordRuntimeOwnedProviderIdentityConflict, Wr as runtimeOwnedExecutorExecutionBinding, Wt as scopeRetainedOwnerSettled, X as assertRecursiveReservationPolicy, Xr as unknownExecutionBindingReceipt, Xt as scopeRetainedOwnerCheckpointing, Yr as runtimeOwnedScopeOwnerRuntime, Zr as unknownMaterializationReceipt, _n as describeRetainedNativeStops, _t as unconfirmedTeardowns, ai as assertEventBinding, ar as harnessTranscriptFromLines, bn as RetainedMaterializationTimeoutError, ci as freezeControlRef, cn as nestedDriverTreeRoot, dn as SpawnEventIndex, dt as registerNestedTeardownScope, en as scopeOwnerLiabilities, fi as promptOptionsFromAgentTurnInput, ft as releaseHeldEnvironments, gr as describeToolArgs, gt as startScopeRecoveries, hn as observeModelRequest, hr as createActivityLog, ht as settleManagerWork, ii as RetainedRunProviderContractError, in as ownedTreeRootSpawn, it as hasRetriableTeardowns, j as resolveWorkerSlots, jt as finalizeScopeOwnerMaterialization, li as retainedSessionReplaced, mt as retryUnconfirmedTeardowns, n as terminalAccounting, nt as closeRetainedSlots, oi as awaitAbortable, on as attestNestedDriverTreeOwner, or as harnessTranscriptUnavailable, pn as executorObservation, pt as releaseRetainedEnvironments, q as appendTeardownConfirmation, r as createScope, rn as loadSpawnForest, rr as captureHarnessTranscript, rt as closeScopeAdmission, si as exactSession, sn as driverRuntime, t as isNonEmptySpend, tr as HARNESS_TRANSCRIPT_SETTLE_TIMEOUT_MS, tt as boundRetainedReleases, ui as sameControlCoordinates, un as encodeResultBlob, vn as stopRetainedNativeExecution, vr as isLiveNodeStatus, vt as waitForScopeChildren, wn as recoverRetainedRun, wt as RELEASE_DESTROY_MS, xn as assertRetainedRunReplayMaterial, yn as verifyWorkspaceMarker, zn as workerTraceHeaders, zr as recordRuntimeOwnedProviderAttemptStart } from "./supervisor-accounting-QiXnF-EW.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 { d as abortReason, l as sha256, m as runAbortable, p as linkAbort, u as RunCancellationReason } from "./jsonl-file-BhuxeejY.js";
|
|
4
4
|
import { a as ROOT_DEADLINE_REASON, f as teardownSurfaces, l as isDeadlineAbortReason, o as armDeadlineTimer, t as ACCEPTED_RESULT_GRACE_MS } from "./deadline-CySmJ_0S.js";
|
|
5
5
|
import { C as unreportedSpend, D as addResourceSpend, E as zeroTokenUsage, 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, 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 } from "./util-qsH5cC9S.js";
|
|
6
6
|
import { t as runTaskQueue } from "./task-queue-DbpZAp6C.js";
|
|
7
|
-
import { B as turnFailurePolicy,
|
|
8
|
-
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";
|
|
9
|
-
import { _ as
|
|
7
|
+
import { B as turnFailurePolicy, Ct as sandboxEventServedBackend, D as unavailableResumeAt, Dt as parseCodexUsageRecord, E as unavailablePauseMs, F as executorFailureInfra, H as hashJson, M as contentAddress, N as contentRef, O as unavailableSignalOfFailure, Ot as recordValue, R as runtimeFailureRemediationSchema, S as cappedDoublingMs, St as sandboxEventProviderModels, T as reportedResetAt, U as credentialCommandExit, V as turnRemediationOf, W as isCredentialRefusal, X as createBudgetPool, _ as retainedExecutorContext, _t as createSandboxUsageLedger, b as UNAVAILABLE_CODES, bt as notifySandboxEventObserver, c as DISPATCH_NOT_ADMITTED_CODE, ct as sandboxOutputMarker, f as isProvisioningRefusal, ft as extractTransportEventIdentity, gt as createSandboxTurnEventCollector, ht as canonicalSandboxUsageMode, i as runtimeProviderCode, it as createSandboxToolPartState, l as RetainedExecutionPendingError, lt as sandboxProgressEvents, mt as assertSandboxServedModel, n as runtimeFailureCause, p as isSchemaRejection, s as DISPATCH_EXECUTION_CHANGED_CODE, st as sandboxLeafOutputFromEvents, t as reportedFailureCause, u as TRANSPORT_ERROR_CODES, v as retainedExecutorSeamKey, w as printedStatus, wt as sandboxTerminalUsageField, x as UNAVAILABLE_STATUSES, xt as sameModelId, yt as isSandboxTerminalEvent, z as turnFailureOf } from "./failure-cause-DoCCGLDH.js";
|
|
8
|
+
import { a as errMessage, i as causeChain, l as errorText, n as detachedSnapshot, o as errorHttpStatus, s as errorProperty, t as detachedFrozen, u as defaultRedactor } from "./snapshot-BKI_w3JD.js";
|
|
9
|
+
import { _ as reportedServedModel, a as concreteProfileModel, c as profileModelExecutionSettings, d as assertRouterAutoDeclaration, f as assertRouterAutoResponse, g as observedModelMatchesDeclared, l as profileProviderModel, m as mergeObservedModelIdentity, o as enforceTokenLimits, s as profileBridgeWireModel, t as assertExecutableAgentProfile, u as resolveRouterRetryPolicy, v as agentHarness } from "./model-policy-CqDuBTq-.js";
|
|
10
10
|
import { r as nativeSystemPrompt, t as assertSandboxProfileCompatibility } from "./sandbox-profile-compat-l-SLQnGb.js";
|
|
11
|
-
import {
|
|
11
|
+
import { x as hasControlCharacter } from "./workspace-streams-C7PGLAUd.js";
|
|
12
12
|
import { i as checkVerdictOf, s as isFiniteNumber } from "./continuation-CZaeHEzQ.js";
|
|
13
13
|
import { a as writeAtomicDurableFile, s as fenceRunWrite } from "./durable-file-DstVeHcj.js";
|
|
14
|
-
import { t as PROTOCOL_VERSION } from "./tool-server-
|
|
14
|
+
import { t as PROTOCOL_VERSION } from "./tool-server-DQCdu3am.js";
|
|
15
15
|
import { i as notifyRuntimeHookEvent } from "./runtime-hooks-CsW2pfFk.js";
|
|
16
|
-
import { AGENT_PROFILE_MATERIALIZATION_AXES, AgentExactRunControlRefSchema, AgentRunCancellationRequestSchema, AgentTurnInputSchema, REASONING_EFFORTS, agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalWorkspaceCwd, harnessTypeSchema, mergeProxySecretBindings, nativeReasoningControl, profileMaterializationAxes, profileMaterializationAxes as profileMaterializationAxes$1, renderInputPartsAsText, sha256DigestSchema } from "@tangle-network/agent-interface";
|
|
16
|
+
import { AGENT_PROFILE_MATERIALIZATION_AXES, AgentExactRunControlRefSchema, AgentFileOutputPolicySchema, AgentRetainedFilePublicationSchema, AgentRunCancellationRequestSchema, AgentTurnInputSchema, REASONING_EFFORTS, agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, canonicalWorkspaceCwd, harnessTypeSchema, mergeProxySecretBindings, nativeReasoningControl, profileMaterializationAxes, profileMaterializationAxes as profileMaterializationAxes$1, renderInputPartsAsText, sameAgentRunControlRef, sha256DigestSchema, workspaceCwdPathForBase } from "@tangle-network/agent-interface";
|
|
17
17
|
import { createAgentRunOutcomeTracker } from "@tangle-network/sandbox/runtime";
|
|
18
18
|
import { SDKError, generateIdempotencyKey, isRecord, withRetry } from "@tangle-network/agent-core";
|
|
19
19
|
import { collectAgentFinalMessageText, collectAgentResponseText, isToolBearingEvent } from "@tangle-network/sandbox";
|
|
@@ -57,7 +57,8 @@ function projectSandboxOutcome(outcome) {
|
|
|
57
57
|
failure: reportedFailureCause({
|
|
58
58
|
error: reason,
|
|
59
59
|
errorCode: outcome.errorCode,
|
|
60
|
-
statusCode: outcome.statusCode
|
|
60
|
+
statusCode: outcome.statusCode,
|
|
61
|
+
remediation: turnRemediationOf(outcome)
|
|
61
62
|
})
|
|
62
63
|
};
|
|
63
64
|
return {
|
|
@@ -2281,6 +2282,14 @@ function readOptionalMcpAttachments(ctx, key, who) {
|
|
|
2281
2282
|
if (entries === void 0 || entries.length === 0 || entries.some(([, server]) => server === null || typeof server !== "object")) throw new ValidationError$1(`${who} executor: seam ${JSON.stringify(key)} must be a non-empty map of MCP servers`);
|
|
2282
2283
|
return value;
|
|
2283
2284
|
}
|
|
2285
|
+
/** Narrow the Runtime-owned request env seam: absent sends none; present is a non-empty name map. */
|
|
2286
|
+
function readOptionalRuntimeEnv(ctx, key, who) {
|
|
2287
|
+
const value = ctx.seams[key];
|
|
2288
|
+
if (value === void 0) return void 0;
|
|
2289
|
+
const entries = value !== null && typeof value === "object" && !Array.isArray(value) ? Object.values(value) : [];
|
|
2290
|
+
if (entries.length === 0 || entries.some((secret) => typeof secret !== "string" || !secret)) throw new ValidationError$1(`${who} executor: seam ${JSON.stringify(key)} must map names to values`);
|
|
2291
|
+
return value;
|
|
2292
|
+
}
|
|
2284
2293
|
// src/runtime/supervise/bridge-config.ts
|
|
2285
2294
|
const bridgeSeamKey = "bridge";
|
|
2286
2295
|
/** Internal control seam used by Runtime-owned external supervisors. A completion request stops
|
|
@@ -2291,6 +2300,9 @@ const bridgeStopSignalKey = "__bridge_stop_signal";
|
|
|
2291
2300
|
* them out of its session profile binding. A rebound coordination port therefore cannot move the
|
|
2292
2301
|
* authored profile digest that binds a durable session. */
|
|
2293
2302
|
const bridgeRuntimeAttachmentsKey = "__bridge_runtime_attachments";
|
|
2303
|
+
/** Internal secret seam beside {@link bridgeRuntimeAttachmentsKey}: request `env` the bridge lifts
|
|
2304
|
+
* into memory before it records the run, so a secret-ref attachment header resolves to it. */
|
|
2305
|
+
const bridgeRuntimeEnvKey = "__bridge_runtime_env";
|
|
2294
2306
|
const maxBridgeTimeoutMs = 2147483647;
|
|
2295
2307
|
function isLoopbackBridgeHost(hostname) {
|
|
2296
2308
|
const host = hostname.trim().toLowerCase().replace(/^\[/, "").replace(/\]$/, "");
|
|
@@ -5114,6 +5126,8 @@ var HarnessTurnFailedError = class extends Error {
|
|
|
5114
5126
|
/** The shared HTTP error reader also uses this status for persisted diagnostics. */
|
|
5115
5127
|
status;
|
|
5116
5128
|
failure;
|
|
5129
|
+
/** The producer's quota reset, which `reportedResetAt` holds a capacity pause to. */
|
|
5130
|
+
resetAt;
|
|
5117
5131
|
constructor(runtime, failure) {
|
|
5118
5132
|
super(`${runtime} harness turn ended with a failed outcome` + (failure.errorCode === void 0 ? "" : ` (${failure.errorCode})`) + `: ${failure.error}`);
|
|
5119
5133
|
this.name = "HarnessTurnFailedError";
|
|
@@ -5121,6 +5135,7 @@ var HarnessTurnFailedError = class extends Error {
|
|
|
5121
5135
|
this.reported = failure.error;
|
|
5122
5136
|
if (failure.failure !== void 0) this.failure = failure.failure;
|
|
5123
5137
|
if (failure.errorCode !== void 0) this.errorCode = failure.errorCode;
|
|
5138
|
+
if (failure.resetAt !== void 0) this.resetAt = failure.resetAt;
|
|
5124
5139
|
if (failure.statusCode !== void 0) {
|
|
5125
5140
|
this.statusCode = failure.statusCode;
|
|
5126
5141
|
this.status = failure.statusCode;
|
|
@@ -5527,6 +5542,7 @@ async function* streamBridgeTurn(args, turn) {
|
|
|
5527
5542
|
},
|
|
5528
5543
|
agent_profile: args.profile,
|
|
5529
5544
|
...args.runtimeAttachments === void 0 ? {} : { runtime_attachments: { mcp: args.runtimeAttachments } },
|
|
5545
|
+
...args.runtimeEnv === void 0 ? {} : { env: args.runtimeEnv },
|
|
5530
5546
|
messages: turn.messages
|
|
5531
5547
|
};
|
|
5532
5548
|
ledger.beginTurn();
|
|
@@ -5601,13 +5617,13 @@ async function settleFailedTurn(error, args, signals, activeRun, external) {
|
|
|
5601
5617
|
function observeChunkIdentity(chunk, ledger, args) {
|
|
5602
5618
|
const { seam } = args;
|
|
5603
5619
|
if (chunk.model !== void 0) try {
|
|
5604
|
-
|
|
5620
|
+
const verdict = reportedServedModel(chunk.model, seam.providerModel, seam.model);
|
|
5621
|
+
if (verdict === "conflict") {
|
|
5605
5622
|
args.onProviderIdentityConflict();
|
|
5606
5623
|
throw new ValidationError$1(`bridgeExecutor: bridge reported model ${JSON.stringify(chunk.model)} but the profile requires ${JSON.stringify(seam.providerModel)}`);
|
|
5607
5624
|
}
|
|
5608
|
-
|
|
5609
|
-
if (
|
|
5610
|
-
if (!isWireModel) ledger.observedModel = mergeBridgeObservedModel(ledger.observedModel, chunk.model);
|
|
5625
|
+
if (verdict === "record") args.onProviderModel(chunk.model);
|
|
5626
|
+
if (chunk.model !== seam.model) ledger.observedModel = mergeBridgeObservedModel(ledger.observedModel, chunk.model);
|
|
5611
5627
|
} catch (error) {
|
|
5612
5628
|
args.onProviderIdentityConflict();
|
|
5613
5629
|
throw error;
|
|
@@ -6423,6 +6439,7 @@ const bridgeExecutor = (spec, ctx) => {
|
|
|
6423
6439
|
const base = readSeam(ctx, bridgeSeamKey, "bridge");
|
|
6424
6440
|
const stopSignal = readOptionalAbortSignal(ctx, bridgeStopSignalKey, "bridge");
|
|
6425
6441
|
const runtimeAttachments = readOptionalMcpAttachments(ctx, bridgeRuntimeAttachmentsKey, "bridge");
|
|
6442
|
+
const runtimeEnv = readOptionalRuntimeEnv(ctx, bridgeRuntimeEnvKey, "bridge");
|
|
6426
6443
|
const modelCredential = validateBridgeModelCredential(base.modelCredential, base.bridgeUrl, "bridgeExecutor");
|
|
6427
6444
|
const effectiveProfile = agentProfileSchema.parse(spec.profile);
|
|
6428
6445
|
const model = bridgeProfileModel(effectiveProfile, "bridgeExecutor");
|
|
@@ -6547,6 +6564,7 @@ const bridgeExecutor = (spec, ctx) => {
|
|
|
6547
6564
|
signal,
|
|
6548
6565
|
...stopSignal === void 0 ? {} : { stopSignal },
|
|
6549
6566
|
...runtimeAttachments === void 0 ? {} : { runtimeAttachments },
|
|
6567
|
+
...runtimeEnv === void 0 ? {} : { runtimeEnv },
|
|
6550
6568
|
profile: effectiveProfile,
|
|
6551
6569
|
seam,
|
|
6552
6570
|
sessionId,
|
|
@@ -7390,6 +7408,120 @@ function publicCreateOptions(create) {
|
|
|
7390
7408
|
...secrets === void 0 ? {} : { secretNames: Array.isArray(secrets) ? [...secrets].sort() : Object.keys(secrets).sort() }
|
|
7391
7409
|
};
|
|
7392
7410
|
}
|
|
7411
|
+
// src/runtime/environment-provider/provider-harness-transcript.ts
|
|
7412
|
+
/** Without a trusted port, read the environment and bind it to the exact admitted dispatch. */
|
|
7413
|
+
async function readEnvironmentHarnessTranscript(scope, environment, sourceSignal) {
|
|
7414
|
+
const fallback = await captureHarnessTranscript(environment, scope.profile.harness, sourceSignal);
|
|
7415
|
+
const controlRef = scope.state.workspaceControlRef;
|
|
7416
|
+
if (fallback.status !== "captured" || !scope.node || controlRef?.environmentId !== environment.id) return fallback;
|
|
7417
|
+
return detachedSnapshot({
|
|
7418
|
+
...fallback,
|
|
7419
|
+
artifact: {
|
|
7420
|
+
...fallback.artifact,
|
|
7421
|
+
source: {
|
|
7422
|
+
executionId: scope.state.workspaceExecutionId,
|
|
7423
|
+
controlRef,
|
|
7424
|
+
node: scope.node,
|
|
7425
|
+
environmentId: environment.id,
|
|
7426
|
+
profileDigest: canonicalAgentProfileDigest(scope.createProfile),
|
|
7427
|
+
providerSessionId: controlRef.sessionId,
|
|
7428
|
+
nativeSessionId: null,
|
|
7429
|
+
coverageComplete: false
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
}, "provider environment transcript source");
|
|
7433
|
+
}
|
|
7434
|
+
/** Select the existing reader or trusted host port; Scope alone persists its result. */
|
|
7435
|
+
async function readProviderHarnessTranscript(scope, environment, sourceSignal) {
|
|
7436
|
+
const capture = scope.options.harnessTranscript;
|
|
7437
|
+
if (!capture) return readEnvironmentHarnessTranscript(scope, environment, sourceSignal);
|
|
7438
|
+
const refused = (reason) => ({
|
|
7439
|
+
status: "unavailable",
|
|
7440
|
+
reason: "capture-failed",
|
|
7441
|
+
skipped: [{
|
|
7442
|
+
path: scope.executionId,
|
|
7443
|
+
reason
|
|
7444
|
+
}]
|
|
7445
|
+
});
|
|
7446
|
+
const handle = scope.state.retained;
|
|
7447
|
+
if (!handle) return refused("Native capture requires a retained provider execution");
|
|
7448
|
+
const control = AgentExactRunControlRefSchema.safeParse(handle.controlRef);
|
|
7449
|
+
const expected = scope.state.workspaceControlRef;
|
|
7450
|
+
const harness = agentHarness(scope.createProfile.harness);
|
|
7451
|
+
if (!control.success || !expected || !scope.node || !harness || control.data.provider !== scope.provider.name || environment.provider !== scope.provider.name || control.data.environmentId !== environment.id || control.data.sessionId !== scope.state.providerSessionId || canonicalCandidateDigest(control.data) !== canonicalCandidateDigest(expected)) return refused("Native capture requires the exact admitted provider, session, execution and Scope identity");
|
|
7452
|
+
const signal = AbortSignal.timeout(HARNESS_TRANSCRIPT_SETTLE_TIMEOUT_MS);
|
|
7453
|
+
try {
|
|
7454
|
+
return await runAbortable(async () => {
|
|
7455
|
+
const terminal = await handle.status({ signal });
|
|
7456
|
+
if (![
|
|
7457
|
+
"completed",
|
|
7458
|
+
"failed",
|
|
7459
|
+
"cancelled"
|
|
7460
|
+
].includes(terminal.status ?? "") || canonicalCandidateDigest(terminal.controlRef) !== canonicalCandidateDigest(control.data)) return refused("Native capture requires exact terminal provider proof");
|
|
7461
|
+
const cwd = workspaceCwdPathForBase(scope.options.defaults?.workspace?.cwd, "host", "provider native capture");
|
|
7462
|
+
if (!cwd) return refused("Native capture requires the admitted host working directory");
|
|
7463
|
+
const identity = detachedSnapshot({
|
|
7464
|
+
sessionId: control.data.sessionId,
|
|
7465
|
+
harness,
|
|
7466
|
+
profileDigest: canonicalAgentProfileDigest(scope.createProfile),
|
|
7467
|
+
cwd,
|
|
7468
|
+
node: scope.node,
|
|
7469
|
+
runs: [{
|
|
7470
|
+
runId: control.data.runId,
|
|
7471
|
+
requestDigest: control.data.requestDigest
|
|
7472
|
+
}],
|
|
7473
|
+
controlRef: control.data
|
|
7474
|
+
}, "provider native capture identity");
|
|
7475
|
+
const request = Object.freeze({
|
|
7476
|
+
...identity,
|
|
7477
|
+
signal
|
|
7478
|
+
});
|
|
7479
|
+
const result = await capture(request);
|
|
7480
|
+
if (result.status === "unavailable") return result;
|
|
7481
|
+
const artifact = result.status === "captured" ? result.artifact : void 0;
|
|
7482
|
+
const binding = artifact?.binding;
|
|
7483
|
+
if (!artifact || artifact.harness !== harness || !binding || binding.kind !== "bridge" && binding.kind !== "provider" || binding.controlRef !== void 0 && !sameAgentRunControlRef(binding.controlRef, control.data) || binding.sessionId !== request.sessionId || binding.profileDigest !== request.profileDigest || canonicalCandidateDigest(binding.node ?? null) !== canonicalCandidateDigest(request.node) || canonicalCandidateDigest(binding.runs) !== canonicalCandidateDigest(request.runs)) return refused("Native capture returned a different or unsupported execution binding");
|
|
7484
|
+
return detachedSnapshot({
|
|
7485
|
+
...result,
|
|
7486
|
+
artifact: {
|
|
7487
|
+
...artifact,
|
|
7488
|
+
binding: {
|
|
7489
|
+
...binding,
|
|
7490
|
+
kind: "provider",
|
|
7491
|
+
controlRef: control.data
|
|
7492
|
+
}
|
|
7493
|
+
}
|
|
7494
|
+
}, "provider native capture");
|
|
7495
|
+
}, signal, "Provider native capture stopped");
|
|
7496
|
+
} catch {
|
|
7497
|
+
return refused("Trusted provider native capture failed or exceeded its bound");
|
|
7498
|
+
}
|
|
7499
|
+
}
|
|
7500
|
+
/**
|
|
7501
|
+
* Retain failed capture as evidence debt until an exact repair has been persisted. Custody is owed
|
|
7502
|
+
* only when a later exact repair could succeed: without a retained provider run, Runtime refuses
|
|
7503
|
+
* before any native read and no repair can bind one, so the explicit failure is the whole record.
|
|
7504
|
+
*/
|
|
7505
|
+
async function captureProviderHarnessTranscript(scope, environment, signal) {
|
|
7506
|
+
const repairable = scope.state.retained !== void 0;
|
|
7507
|
+
const capture = await readProviderHarnessTranscript(scope, environment, signal);
|
|
7508
|
+
if (scope.options.harnessTranscript) scope.state.transcriptPreservationRequired = repairable && (capture.status === "unavailable" || (capture.status === "captured" ? capture.coverageComplete !== true || capture.skippedCount > 0 || !!capture.missing?.length : !capture.descriptor.source.coverageComplete || capture.descriptor.skipped.length > 0 || capture.descriptor.missing.length > 0));
|
|
7509
|
+
return capture;
|
|
7510
|
+
}
|
|
7511
|
+
/** A repaired read repays evidence debt only after its exact invocation receipt is durable. */
|
|
7512
|
+
async function persistProviderHarnessTranscript(scope, task, result, retention = scope.retention) {
|
|
7513
|
+
scope.state.transcriptResult = result;
|
|
7514
|
+
try {
|
|
7515
|
+
await retention?.onHarnessTranscript?.(task, scope.state.harnessTranscript, result);
|
|
7516
|
+
if (retention?.onHarnessTranscript) {
|
|
7517
|
+
scope.state.transcriptPersistenceFailed = false;
|
|
7518
|
+
if (!scope.state.sourcePreservationRequired) scope.state.workspaceCleanupPromise = void 0;
|
|
7519
|
+
}
|
|
7520
|
+
} catch (error) {
|
|
7521
|
+
scope.state.transcriptPersistenceFailed = true;
|
|
7522
|
+
throw error;
|
|
7523
|
+
}
|
|
7524
|
+
}
|
|
7393
7525
|
// src/runtime/environment-provider/provider-environment-teardown.ts
|
|
7394
7526
|
/** The environment id the latest durable admission names, when creation got that far. */
|
|
7395
7527
|
function admittedEnvironmentId(retention) {
|
|
@@ -7406,7 +7538,7 @@ async function destroyExecutorEnvironment(scope, cleanupSignal) {
|
|
|
7406
7538
|
const cleanupPromise = attemptDestroy(scope, cleanupSignal);
|
|
7407
7539
|
let cleanupReference;
|
|
7408
7540
|
cleanupReference = cleanupPromise.then((result) => {
|
|
7409
|
-
if (!result.destroyed && state.workspaceCleanupPromise === cleanupReference && !state.
|
|
7541
|
+
if (!result.destroyed && state.workspaceCleanupPromise === cleanupReference && !state.sourcePreservationRequired) state.workspaceCleanupPromise = void 0;
|
|
7410
7542
|
return result;
|
|
7411
7543
|
});
|
|
7412
7544
|
state.workspaceCleanupPromise = cleanupReference;
|
|
@@ -7416,9 +7548,15 @@ async function attemptDestroy(scope, cleanupSignal) {
|
|
|
7416
7548
|
const { state, provider } = scope;
|
|
7417
7549
|
const target = state.environment;
|
|
7418
7550
|
if (target === void 0) return { destroyed: true };
|
|
7419
|
-
|
|
7551
|
+
await state.fileOutput?.settled();
|
|
7552
|
+
if (state.sourcePreservationRequired) return {
|
|
7420
7553
|
destroyed: false,
|
|
7421
|
-
detail: "provider
|
|
7554
|
+
detail: "provider source custody is unresolved; environment preserved",
|
|
7555
|
+
permanent: true
|
|
7556
|
+
};
|
|
7557
|
+
if (state.sourcePreservationRequired) return {
|
|
7558
|
+
destroyed: false,
|
|
7559
|
+
detail: "provider native transcript retention is incomplete; source environment preserved",
|
|
7422
7560
|
permanent: true
|
|
7423
7561
|
};
|
|
7424
7562
|
if (state.destroyed) return { destroyed: true };
|
|
@@ -7441,7 +7579,7 @@ async function attemptDestroy(scope, cleanupSignal) {
|
|
|
7441
7579
|
async function releaseRetainedExecution(scope, signal) {
|
|
7442
7580
|
const { state, provider, retention } = scope;
|
|
7443
7581
|
scope.controller.abort();
|
|
7444
|
-
if (!state.pending) return [];
|
|
7582
|
+
if (!state.pending && !state.transcriptPreservationRequired && !state.transcriptPersistenceFailed) return [];
|
|
7445
7583
|
const environmentId = state.retained?.controlRef.environmentId ?? state.environment?.id ?? admittedEnvironmentId(retention);
|
|
7446
7584
|
if (environmentId === void 0) return [];
|
|
7447
7585
|
const receipt = (destroyed, detail, permanent) => ({
|
|
@@ -7455,7 +7593,7 @@ async function releaseRetainedExecution(scope, signal) {
|
|
|
7455
7593
|
const releasePromise = releaseReceipts(scope, environmentId, signal, receipt);
|
|
7456
7594
|
let releaseReference;
|
|
7457
7595
|
releaseReference = releasePromise.then((receipts) => {
|
|
7458
|
-
if (state.retainedReleasePromise === releaseReference && !receipts.every((entry) => entry.destroyed) && !state.
|
|
7596
|
+
if (state.retainedReleasePromise === releaseReference && !receipts.every((entry) => entry.destroyed) && !state.sourcePreservationRequired) state.retainedReleasePromise = void 0;
|
|
7459
7597
|
return receipts;
|
|
7460
7598
|
});
|
|
7461
7599
|
state.retainedReleasePromise = releaseReference;
|
|
@@ -7493,10 +7631,13 @@ async function releaseReceipts(scope, environmentId, signal, receipt) {
|
|
|
7493
7631
|
*/
|
|
7494
7632
|
async function captureBeforeDestroy(scope, target, signal) {
|
|
7495
7633
|
const { state } = scope;
|
|
7496
|
-
if (state.harnessTranscript.status
|
|
7634
|
+
if ((state.harnessTranscript.status === "unavailable" || state.transcriptPreservationRequired || state.transcriptPersistenceFailed) && !state.releaseReadTried) {
|
|
7497
7635
|
state.releaseReadTried = true;
|
|
7498
|
-
const capture = await
|
|
7499
|
-
if (capture.status
|
|
7636
|
+
const capture = await captureProviderHarnessTranscript(scope, target, signal);
|
|
7637
|
+
if (capture.status !== "unavailable") {
|
|
7638
|
+
state.harnessTranscript = capture;
|
|
7639
|
+
await persistProviderHarnessTranscript(scope, state.transcriptTask, state.transcriptResult);
|
|
7640
|
+
}
|
|
7500
7641
|
}
|
|
7501
7642
|
}
|
|
7502
7643
|
// src/runtime/supervise/host-restart.ts
|
|
@@ -7601,6 +7742,7 @@ function providerFailureEvent(event, sandboxEvent) {
|
|
|
7601
7742
|
const errorCode = failureCode(sandboxEvent.data) ?? failureCode(outcome) ?? failureCode(result);
|
|
7602
7743
|
const statusCode = failureStatusCode(sandboxEvent.data) ?? failureStatusCode(outcome) ?? failureStatusCode(result);
|
|
7603
7744
|
const failure = turnFailureOf(sandboxEvent.data) ?? turnFailureOf(outcome) ?? turnFailureOf(result);
|
|
7745
|
+
const remediation = turnRemediationOf(sandboxEvent.data) ?? turnRemediationOf(outcome) ?? turnRemediationOf(result);
|
|
7604
7746
|
return {
|
|
7605
7747
|
type: "result",
|
|
7606
7748
|
data: {
|
|
@@ -7608,7 +7750,8 @@ function providerFailureEvent(event, sandboxEvent) {
|
|
|
7608
7750
|
...detail ? { error: detail } : {},
|
|
7609
7751
|
...errorCode ? { errorCode } : {},
|
|
7610
7752
|
...statusCode === void 0 ? {} : { statusCode },
|
|
7611
|
-
...failure === void 0 ? {} : { failure }
|
|
7753
|
+
...failure === void 0 ? {} : { failure },
|
|
7754
|
+
...remediation === void 0 ? {} : { remediation }
|
|
7612
7755
|
}
|
|
7613
7756
|
};
|
|
7614
7757
|
}
|
|
@@ -7664,9 +7807,11 @@ function createProviderFailureLedger() {
|
|
|
7664
7807
|
for (const frame of failures) tracker.observe(frame);
|
|
7665
7808
|
const outcome = tracker.finish();
|
|
7666
7809
|
const failure = turnFailureOf(outcome) ?? failures.slice().reverse().map((frame) => turnFailureOf(frame.data)).find((value) => value !== void 0);
|
|
7810
|
+
const remediation = failures.slice().reverse().map((frame) => turnRemediationOf(frame.data)).find((value) => value !== void 0);
|
|
7667
7811
|
return outcome === void 0 ? void 0 : {
|
|
7668
7812
|
...outcome,
|
|
7669
|
-
failure
|
|
7813
|
+
failure,
|
|
7814
|
+
...remediation === void 0 ? {} : { remediation }
|
|
7670
7815
|
};
|
|
7671
7816
|
}
|
|
7672
7817
|
};
|
|
@@ -7680,6 +7825,20 @@ function failureDetail(value) {
|
|
|
7680
7825
|
return typeof value?.detail === "string" ? value.detail : void 0;
|
|
7681
7826
|
}
|
|
7682
7827
|
/** Preserve the Sandbox outcome's numeric HTTP metadata across the provider adapter. */
|
|
7828
|
+
/** The executor envelope of a failed turn: the ledger's outcome as Runtime's retry reads it, quota reset included. */
|
|
7829
|
+
function failedTurnOutcome(outcome) {
|
|
7830
|
+
if (outcome?.status !== "failed") return void 0;
|
|
7831
|
+
const statusCode = failureStatusCode(outcome);
|
|
7832
|
+
return {
|
|
7833
|
+
success: false,
|
|
7834
|
+
...outcome.failure === void 0 ? {} : { failure: outcome.failure },
|
|
7835
|
+
...outcome.error ? { error: outcome.error } : {},
|
|
7836
|
+
...outcome.errorCode ? { errorCode: outcome.errorCode } : {},
|
|
7837
|
+
...statusCode === void 0 ? {} : { statusCode },
|
|
7838
|
+
...outcome.remediation === void 0 ? {} : { remediation: outcome.remediation },
|
|
7839
|
+
...outcome.resetAt ? { resetAt: outcome.resetAt } : {}
|
|
7840
|
+
};
|
|
7841
|
+
}
|
|
7683
7842
|
function failureStatusCode(value) {
|
|
7684
7843
|
const statusCode = recordValue(value)?.statusCode;
|
|
7685
7844
|
return typeof statusCode === "number" && Number.isInteger(statusCode) && statusCode >= 400 && statusCode <= 599 ? statusCode : void 0;
|
|
@@ -7905,6 +8064,7 @@ var RetainedObservation = class {
|
|
|
7905
8064
|
silenceHandledAt;
|
|
7906
8065
|
exactResult;
|
|
7907
8066
|
exactResultSettled = false;
|
|
8067
|
+
exactResultSettledAt = 0;
|
|
7908
8068
|
observedFrames = 0;
|
|
7909
8069
|
framesAfterResult = 0;
|
|
7910
8070
|
exactWakers = /* @__PURE__ */ new Set();
|
|
@@ -8021,7 +8181,10 @@ var RetainedObservation = class {
|
|
|
8021
8181
|
if (this.observedFrames === 0) this.lastObservedAt = Date.now();
|
|
8022
8182
|
const retry = !retried && failed.length > 0 && !exactQuotaRefusal(failed[0]);
|
|
8023
8183
|
if (retry) this.exactResult = void 0;
|
|
8024
|
-
else
|
|
8184
|
+
else {
|
|
8185
|
+
this.exactResultSettled = true;
|
|
8186
|
+
this.exactResultSettledAt = Date.now();
|
|
8187
|
+
}
|
|
8025
8188
|
for (const wake of [...this.exactWakers]) wake();
|
|
8026
8189
|
if (retry) this.readExactResult(true);
|
|
8027
8190
|
};
|
|
@@ -8049,7 +8212,7 @@ var RetainedObservation = class {
|
|
|
8049
8212
|
wake = setImmediate(() => {
|
|
8050
8213
|
const close = () => {
|
|
8051
8214
|
if (!this.exactResultSettled) return;
|
|
8052
|
-
const flowing = this.sawTerminal ? 0 : RETAINED_TAIL_FLOW_MS - (Date.now() - this.lastObservedAt);
|
|
8215
|
+
const flowing = this.sawTerminal ? 0 : RETAINED_TAIL_FLOW_MS - (Date.now() - Math.max(this.lastObservedAt, this.exactResultSettledAt));
|
|
8053
8216
|
if (flowing <= 0) {
|
|
8054
8217
|
wake = setImmediate(() => resolve({ kind: "exact-result" }));
|
|
8055
8218
|
return;
|
|
@@ -8301,6 +8464,7 @@ function retainedDispatchMaterial(args, retention, selectedTurn, signal) {
|
|
|
8301
8464
|
};
|
|
8302
8465
|
return {
|
|
8303
8466
|
material: {
|
|
8467
|
+
...args.options.outputFile === void 0 ? {} : { outputFile: args.options.outputFile },
|
|
8304
8468
|
environment: {
|
|
8305
8469
|
...args.options.defaults,
|
|
8306
8470
|
...restore === void 0 ? {} : { workspace: {
|
|
@@ -8437,10 +8601,11 @@ async function retainedExecution(args, retention, turn, selectedTurn, signal) {
|
|
|
8437
8601
|
}
|
|
8438
8602
|
}
|
|
8439
8603
|
async function providerExecutionSource(args, turn, signal) {
|
|
8440
|
-
const selectedTurn = subscriptionTurnProfile(turn, args.profile);
|
|
8604
|
+
const selectedTurn = subscriptionTurnProfile(turn, args.options.outputFile !== void 0 ? args.createProfile : args.profile);
|
|
8441
8605
|
AgentTurnInputSchema.parse(selectedTurn);
|
|
8442
8606
|
const needsMcp = hasRuntimeMcpAttachments(args.options.defaults);
|
|
8443
8607
|
const capabilities = args.retention || needsMcp ? await args.provider.capabilities() : void 0;
|
|
8608
|
+
if (args.options.outputFile !== void 0 && (capabilities?.retainedControl === void 0 || capabilities.workspace.retainFileOutput !== true)) throw new Error("file output requires a provider with exact retained-file publication support");
|
|
8444
8609
|
assertRuntimeMcpAttachments(args.provider.name, args.options.defaults, capabilities);
|
|
8445
8610
|
if (args.retention !== void 0 && capabilities?.retainedControl !== void 0) return retainedExecution(args, args.retention, turn, selectedTurn, signal);
|
|
8446
8611
|
if (args.recovering) throw new Error(`provider ${args.provider.name} cannot recover retained executions`);
|
|
@@ -8455,6 +8620,83 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
8455
8620
|
retained: false
|
|
8456
8621
|
};
|
|
8457
8622
|
}
|
|
8623
|
+
// src/runtime/environment-provider/provider-file-output.ts
|
|
8624
|
+
/** One invocation's first file transaction. Nothing consults a later node admission or retries
|
|
8625
|
+
* a lost stop acknowledgment. The existing evidence and result writers own its persistence. */
|
|
8626
|
+
var ProviderFileOutput = class {
|
|
8627
|
+
args;
|
|
8628
|
+
pending;
|
|
8629
|
+
output;
|
|
8630
|
+
committed = false;
|
|
8631
|
+
constructor(args) {
|
|
8632
|
+
this.args = args;
|
|
8633
|
+
}
|
|
8634
|
+
get accepted() {
|
|
8635
|
+
return this.output;
|
|
8636
|
+
}
|
|
8637
|
+
get requiresPreservation() {
|
|
8638
|
+
return this.pending !== void 0 && !this.committed;
|
|
8639
|
+
}
|
|
8640
|
+
resultCommitted() {
|
|
8641
|
+
if (this.output) {
|
|
8642
|
+
this.committed = true;
|
|
8643
|
+
this.args.scope.state.fileOutputRequired = false;
|
|
8644
|
+
}
|
|
8645
|
+
}
|
|
8646
|
+
async settled() {
|
|
8647
|
+
await this.pending?.catch(() => void 0);
|
|
8648
|
+
}
|
|
8649
|
+
withSubmission(candidate, accept) {
|
|
8650
|
+
if (this.pending) return Promise.reject(new CheckUnavailableError("file output already reserved by the original submission"));
|
|
8651
|
+
const { args } = this;
|
|
8652
|
+
const handle = args.scope.state.retained;
|
|
8653
|
+
const environment = args.scope.state.environment;
|
|
8654
|
+
const submission = detachedFrozen(candidate);
|
|
8655
|
+
const policy = args.options.outputFile;
|
|
8656
|
+
const work = async () => {
|
|
8657
|
+
if (!handle || !environment || !args.node || !policy || !handle.retainFileOutput || !args.retention?.onEvidence) throw new CheckUnavailableError("file output has no exact retained source or durable evidence writer");
|
|
8658
|
+
const controlRef = detachedFrozen(handle.controlRef);
|
|
8659
|
+
await args.retention.onEvidence({
|
|
8660
|
+
kind: "retained-file-output-pending",
|
|
8661
|
+
invocationId: args.executionId,
|
|
8662
|
+
node: args.node,
|
|
8663
|
+
controlRef,
|
|
8664
|
+
policy,
|
|
8665
|
+
submissionRef: contentAddress(submission),
|
|
8666
|
+
submission
|
|
8667
|
+
});
|
|
8668
|
+
const receipt = await handle.retainFileOutput({
|
|
8669
|
+
controlRef,
|
|
8670
|
+
policy
|
|
8671
|
+
}, { signal: args.signal });
|
|
8672
|
+
if (receipt.status !== "published") throw new CheckUnavailableError(`file output unavailable: ${receipt.reason}`);
|
|
8673
|
+
const publication = AgentRetainedFilePublicationSchema.parse(receipt.publication);
|
|
8674
|
+
if (!sameControlCoordinates(publication.controlRef, controlRef) || !sameControlCoordinates(handle.controlRef, controlRef) || args.scope.state.retained !== handle || args.scope.state.environment !== environment || canonicalCandidateDigest(publication.policy) !== canonicalCandidateDigest(policy)) throw new CheckUnavailableError("file publication does not belong to the original invocation and policy");
|
|
8675
|
+
const output = detachedFrozen({
|
|
8676
|
+
kind: "retained-file-output",
|
|
8677
|
+
version: 1,
|
|
8678
|
+
invocationId: args.executionId,
|
|
8679
|
+
node: args.node,
|
|
8680
|
+
submissionRef: contentAddress(submission),
|
|
8681
|
+
submission,
|
|
8682
|
+
policyDigest: canonicalCandidateDigest(policy),
|
|
8683
|
+
publication
|
|
8684
|
+
});
|
|
8685
|
+
await args.retention.onEvidence(output);
|
|
8686
|
+
args.scope.state.harnessStopped = true;
|
|
8687
|
+
return accept(output, () => {
|
|
8688
|
+
this.output = output;
|
|
8689
|
+
});
|
|
8690
|
+
};
|
|
8691
|
+
this.pending = work().catch((error) => {
|
|
8692
|
+
if (error instanceof CheckUnavailableError) throw error;
|
|
8693
|
+
throw new CheckUnavailableError("the original file transaction could not be verified or committed");
|
|
8694
|
+
});
|
|
8695
|
+
const custody = this.pending.then(() => void 0, () => void 0);
|
|
8696
|
+
args.retention?.onEndOfTurnWork?.(custody);
|
|
8697
|
+
return this.pending;
|
|
8698
|
+
}
|
|
8699
|
+
};
|
|
8458
8700
|
// src/runtime/environment-provider/provider-turn-observer.ts
|
|
8459
8701
|
/** Reads one turn's provider events into archive, text, failures, trace steps, progress and usage. */
|
|
8460
8702
|
var ProviderTurnObserver = class {
|
|
@@ -8473,14 +8715,25 @@ var ProviderTurnObserver = class {
|
|
|
8473
8715
|
this.retained = retained;
|
|
8474
8716
|
this.turnModel = turnModel;
|
|
8475
8717
|
}
|
|
8476
|
-
/** The platform's `effectiveBackend` (on `execution.started` and the terminal event) is the
|
|
8477
|
-
* provider evidence; a model other than the declared one is an identity conflict
|
|
8718
|
+
/** The platform's `effectiveBackend` (on `execution.started` and the terminal event) is the
|
|
8719
|
+
* attempt's provider evidence; a model other than the declared one is an identity conflict
|
|
8720
|
+
* (the leaf's rule). Without one, a CLI Bridge provider's `provider_models` are judged by the
|
|
8721
|
+
* bridge path's rule. */
|
|
8478
8722
|
recordServedModel(sandboxEvent) {
|
|
8479
|
-
const
|
|
8480
|
-
if (served?.model === void 0) return;
|
|
8723
|
+
const executor = this.args.scope.executor();
|
|
8481
8724
|
const declared = this.turnModel ?? concreteProfileModel(this.args.profile);
|
|
8482
|
-
|
|
8483
|
-
|
|
8725
|
+
const served = sandboxEventServedBackend(sandboxEvent);
|
|
8726
|
+
if (served?.model === void 0) {
|
|
8727
|
+
if (declared === void 0) return;
|
|
8728
|
+
for (const model of sandboxEventProviderModels(sandboxEvent)) {
|
|
8729
|
+
const verdict = reportedServedModel(model, declared);
|
|
8730
|
+
if (verdict === "conflict") recordRuntimeOwnedProviderIdentityConflict(executor);
|
|
8731
|
+
else if (verdict === "record") recordRuntimeOwnedProviderModel(executor, model);
|
|
8732
|
+
}
|
|
8733
|
+
return;
|
|
8734
|
+
}
|
|
8735
|
+
if (declared !== void 0 && !sameModelId(served.model, declared, [served.provider])) recordRuntimeOwnedProviderIdentityConflict(executor);
|
|
8736
|
+
else recordRuntimeOwnedProviderModel(executor, served.model);
|
|
8484
8737
|
}
|
|
8485
8738
|
async *consume(events) {
|
|
8486
8739
|
const toolParts = createSandboxToolPartState();
|
|
@@ -8916,6 +9169,7 @@ var ProviderTurnSettlement = class {
|
|
|
8916
9169
|
/** The artifact this turn settled with. Its presence separates "the work finished and the
|
|
8917
9170
|
* resource would not release" from "the work never finished". */
|
|
8918
9171
|
settled;
|
|
9172
|
+
commitStarted = false;
|
|
8919
9173
|
/** The body's own failure, held so a throwing teardown `finally` cannot mask it. */
|
|
8920
9174
|
failure;
|
|
8921
9175
|
failed = false;
|
|
@@ -8949,11 +9203,13 @@ var ProviderTurnSettlement = class {
|
|
|
8949
9203
|
/** Read the provider transcript while its environment is still available. */
|
|
8950
9204
|
async readLiveTranscript() {
|
|
8951
9205
|
const { args } = this;
|
|
8952
|
-
args.scope.state.harnessTranscript = await
|
|
9206
|
+
args.scope.state.harnessTranscript = await captureProviderHarnessTranscript(args.scope, this.environment, args.signal);
|
|
8953
9207
|
}
|
|
8954
9208
|
/** Commit the consumed turn, validator verdict and measured spend. */
|
|
8955
9209
|
async *settle() {
|
|
8956
9210
|
const { args, usage } = this;
|
|
9211
|
+
const file = args.scope.state.fileOutput;
|
|
9212
|
+
await file?.settled();
|
|
8957
9213
|
yield* usage.settleTurn();
|
|
8958
9214
|
yield* usage.settleUnpricedWork();
|
|
8959
9215
|
if ((args.options.requireTerminalEvent ?? true) && !this.observer.terminal) throw new ValidationError(`providerAsExecutor(${args.provider.name}): stream ended without a terminal result/done/status event`);
|
|
@@ -8977,16 +9233,10 @@ var ProviderTurnSettlement = class {
|
|
|
8977
9233
|
});
|
|
8978
9234
|
const settledResult = result;
|
|
8979
9235
|
const jsonOutput = args.options.outputFormat === "json";
|
|
8980
|
-
if (jsonOutput) await args.retention?.onEvidence?.(settledResult);
|
|
8981
|
-
|
|
8982
|
-
const
|
|
8983
|
-
const nativeFailure = outcome
|
|
8984
|
-
success: false,
|
|
8985
|
-
...outcome.failure === void 0 ? {} : { failure: outcome.failure },
|
|
8986
|
-
...outcome.error ? { error: outcome.error } : {},
|
|
8987
|
-
...outcome.errorCode ? { errorCode: outcome.errorCode } : {},
|
|
8988
|
-
...statusCode === void 0 ? {} : { statusCode }
|
|
8989
|
-
} : void 0;
|
|
9236
|
+
if (jsonOutput || file) await args.retention?.onEvidence?.(settledResult);
|
|
9237
|
+
if (file && !file.accepted) throw new CheckUnavailableError("file output has no independently accepted submission; candidate custody remains held");
|
|
9238
|
+
const output = file?.accepted ? { out: file.accepted } : jsonOutput && outcome?.status !== "failed" ? jsonResultFromEvents(result.events) : { out: settledResult };
|
|
9239
|
+
const nativeFailure = failedTurnOutcome(outcome);
|
|
8990
9240
|
const settled = {
|
|
8991
9241
|
...jsonOutput ? { outputFormat: "json" } : {},
|
|
8992
9242
|
...nativeFailure ? { outcome: nativeFailure } : {},
|
|
@@ -8995,7 +9245,6 @@ var ProviderTurnSettlement = class {
|
|
|
8995
9245
|
...verdict ? { verdict } : {},
|
|
8996
9246
|
spent: executionSpent
|
|
8997
9247
|
};
|
|
8998
|
-
this.settled = settled;
|
|
8999
9248
|
if (args.mayContinue && this.retained && nativeFailure) {
|
|
9000
9249
|
const transport = nativeFailure.failure === void 0 ? nativeFailure.errorCode : nativeFailure.failure.kind === "infra" ? nativeFailure.failure.code : void 0;
|
|
9001
9250
|
const signal = unavailableSignalOfFailure({
|
|
@@ -9008,23 +9257,67 @@ var ProviderTurnSettlement = class {
|
|
|
9008
9257
|
...nativeFailure.failure ? { failure: nativeFailure.failure } : {}
|
|
9009
9258
|
};
|
|
9010
9259
|
}
|
|
9011
|
-
|
|
9260
|
+
await this.commit(settled);
|
|
9261
|
+
}
|
|
9262
|
+
/** Commit the result durably once; its transcript persists after it. A persistence throw
|
|
9263
|
+
* reaches `fail`, which reports the committed turn as pending and keeps the source. */
|
|
9264
|
+
async commit(settled) {
|
|
9265
|
+
const { args } = this;
|
|
9266
|
+
this.commitStarted = true;
|
|
9267
|
+
if (this.retained) {
|
|
9268
|
+
await args.retention?.onResult(settled);
|
|
9269
|
+
args.scope.state.artifact = settled;
|
|
9270
|
+
}
|
|
9271
|
+
args.scope.state.fileOutput?.resultCommitted();
|
|
9272
|
+
this.settled = settled;
|
|
9273
|
+
if (this.retained) await persistProviderHarnessTranscript(args.scope, args.task, settled, args.retention);
|
|
9012
9274
|
args.scope.state.pending = false;
|
|
9013
9275
|
args.scope.state.artifact = settled;
|
|
9014
9276
|
}
|
|
9015
9277
|
/** Record the turn's failure, then capture what evidence its environment still holds. */
|
|
9016
|
-
async *fail(
|
|
9278
|
+
async *fail(cause) {
|
|
9279
|
+
let error = cause;
|
|
9017
9280
|
const { args } = this;
|
|
9281
|
+
const file = args.scope.state.fileOutput;
|
|
9282
|
+
await file?.settled();
|
|
9283
|
+
if (file?.accepted && !this.commitStarted) {
|
|
9284
|
+
yield* this.usage.settleTurn();
|
|
9285
|
+
await this.readLiveTranscript();
|
|
9286
|
+
const settled = {
|
|
9287
|
+
out: file.accepted,
|
|
9288
|
+
outRef: contentRef(`provider:${args.provider.name}`, file.accepted),
|
|
9289
|
+
outcome: {
|
|
9290
|
+
success: false,
|
|
9291
|
+
error: errorText(error)
|
|
9292
|
+
},
|
|
9293
|
+
spent: this.usage.spend(this.started)
|
|
9294
|
+
};
|
|
9295
|
+
await args.retention?.onEvidence?.({
|
|
9296
|
+
nativeFailure: errorText(error),
|
|
9297
|
+
invocationId: args.executionId
|
|
9298
|
+
});
|
|
9299
|
+
try {
|
|
9300
|
+
await this.commit(settled);
|
|
9301
|
+
return;
|
|
9302
|
+
} catch (persistence) {
|
|
9303
|
+
error = persistence;
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9018
9306
|
yield* this.usage.settleTurn();
|
|
9019
9307
|
this.failure = this.retained && !retainedSessionReplaced(error) ? new RetainedExecutionPendingError(error) : error;
|
|
9020
9308
|
this.failed = true;
|
|
9021
9309
|
await this.stopEndedHarness();
|
|
9022
|
-
args.scope.state.settleTranscript();
|
|
9023
9310
|
await this.readLiveTranscript();
|
|
9311
|
+
if (this.retained) try {
|
|
9312
|
+
await persistProviderHarnessTranscript(this.args.scope, this.args.task, this.settled, this.args.retention);
|
|
9313
|
+
} catch (error) {
|
|
9314
|
+
if (this.failure instanceof Error && this.failure.cause === void 0) this.failure.cause = error;
|
|
9315
|
+
}
|
|
9024
9316
|
}
|
|
9025
9317
|
/** Stop the harness when required, then settle its environment's custody. */
|
|
9026
9318
|
async release() {
|
|
9027
9319
|
const { args } = this;
|
|
9320
|
+
await args.scope.state.fileOutput?.settled();
|
|
9028
9321
|
await this.stopEndedHarness();
|
|
9029
9322
|
const held = this.retained && this.settled !== void 0 && !this.failed && this.unavailable === void 0 && args.retention?.preserveEnvironment !== true && args.retention?.holdOnSettle?.(this.settled.spent) === true;
|
|
9030
9323
|
if (held) args.scope.state.holdingForContinuation = true;
|
|
@@ -9279,6 +9572,7 @@ async function* streamProviderExecutor(args) {
|
|
|
9279
9572
|
const source = await providerExecutionSource(args, turn, args.signal);
|
|
9280
9573
|
const environment = source.environment;
|
|
9281
9574
|
await args.onEnvironment(environment);
|
|
9575
|
+
args.scope.state.fileOutput = args.options.outputFile !== void 0 ? new ProviderFileOutput(args) : void 0;
|
|
9282
9576
|
const usage = new ProviderUsageAccount(args, turn.model);
|
|
9283
9577
|
const observer = new ProviderTurnObserver(args, usage, source.retained, turn.model);
|
|
9284
9578
|
const settlement = new ProviderTurnSettlement(args, environment, source.retained, observer, usage, started);
|
|
@@ -9416,7 +9710,10 @@ async function* runProviderExecution(scope, task, signal, recovering = false) {
|
|
|
9416
9710
|
let refusalsInARow = 0;
|
|
9417
9711
|
for (let attempt = 1;; attempt += 1) {
|
|
9418
9712
|
const continued = attempt > 1;
|
|
9713
|
+
state.transcriptTask = invocation.task;
|
|
9714
|
+
state.transcriptResult = void 0;
|
|
9419
9715
|
if (continued && state.environment !== void 0) {
|
|
9716
|
+
state.harnessTranscript = harnessTranscriptUnavailable("capture-did-not-run");
|
|
9420
9717
|
state.resetWorkspace(state.environment, invocation.executionId);
|
|
9421
9718
|
state.workspaceControlRef = void 0;
|
|
9422
9719
|
state.providerSessionId = null;
|
|
@@ -9439,7 +9736,7 @@ async function pauseForContinuation(scope, invocation, ended, attempt, refusalsB
|
|
|
9439
9736
|
const { state, options, provider } = scope;
|
|
9440
9737
|
const refusal = ended.unavailable;
|
|
9441
9738
|
const continueInvocation = invocation.retention?.continueInvocation;
|
|
9442
|
-
if (refusal === void 0 || continueInvocation === void 0 || state.
|
|
9739
|
+
if (refusal === void 0 || continueInvocation === void 0 || state.sourcePreservationRequired) return;
|
|
9443
9740
|
const refusalsInARow = ended.madeProgress ? 1 : refusalsBefore + 1;
|
|
9444
9741
|
const now = Date.now();
|
|
9445
9742
|
const reset = unavailableResumeAt(reportedResetAt(refusal, now), now);
|
|
@@ -9471,6 +9768,9 @@ async function pauseForContinuation(scope, invocation, ended, attempt, refusalsB
|
|
|
9471
9768
|
var ProviderExecutorState = class {
|
|
9472
9769
|
callerSignal;
|
|
9473
9770
|
workspaceExecutionId;
|
|
9771
|
+
fileOutput;
|
|
9772
|
+
/** Reconstructed from the frozen file policy too: process loss cannot erase capture debt. */
|
|
9773
|
+
fileOutputRequired = false;
|
|
9474
9774
|
environment;
|
|
9475
9775
|
artifact;
|
|
9476
9776
|
retained;
|
|
@@ -9496,6 +9796,18 @@ var ProviderExecutorState = class {
|
|
|
9496
9796
|
retainedReleasePromise;
|
|
9497
9797
|
releaseReadTried = false;
|
|
9498
9798
|
workspacePreservationRequired = false;
|
|
9799
|
+
/** Configured native capture did not retain complete evidence; native stop cannot clear it. */
|
|
9800
|
+
transcriptPreservationRequired = false;
|
|
9801
|
+
/** A capture existed but its durable writer failed. A later read alone cannot repay this debt. */
|
|
9802
|
+
transcriptPersistenceFailed = false;
|
|
9803
|
+
/** Any open workspace, file-output or transcript custody debt keeps the source environment. */
|
|
9804
|
+
get sourcePreservationRequired() {
|
|
9805
|
+
return this.workspacePreservationRequired || this.fileOutputRequired || this.fileOutput?.requiresPreservation === true || this.transcriptPreservationRequired || this.transcriptPersistenceFailed;
|
|
9806
|
+
}
|
|
9807
|
+
/** Exact current invocation input for a capture recovered during retained release. */
|
|
9808
|
+
transcriptTask;
|
|
9809
|
+
/** This invocation's result, independent of the prior result kept across a continuation. */
|
|
9810
|
+
transcriptResult;
|
|
9499
9811
|
workspaceRunActive = false;
|
|
9500
9812
|
providerSessionId = null;
|
|
9501
9813
|
workspaceControlRef;
|
|
@@ -9519,6 +9831,8 @@ var ProviderExecutorState = class {
|
|
|
9519
9831
|
this.workspaceCleanupPromise = void 0;
|
|
9520
9832
|
this.retainedReleasePromise = void 0;
|
|
9521
9833
|
this.workspacePreservationRequired = false;
|
|
9834
|
+
this.transcriptPreservationRequired = false;
|
|
9835
|
+
this.transcriptPersistenceFailed = false;
|
|
9522
9836
|
this.destroyed = false;
|
|
9523
9837
|
}
|
|
9524
9838
|
resetWorkspace(next, invocationId = this.workspaceExecutionId) {
|
|
@@ -9529,12 +9843,13 @@ var ProviderExecutorState = class {
|
|
|
9529
9843
|
}
|
|
9530
9844
|
};
|
|
9531
9845
|
// src/runtime/environment-provider/provider-materialization.ts
|
|
9532
|
-
function providerMaterialization(provider, createProfile, node, executionId, retention, options, placement) {
|
|
9846
|
+
function providerMaterialization(provider, authoredProfile, createProfile, node, executionId, retention, options, placement) {
|
|
9533
9847
|
const attemptId = node?.attemptId ?? newExecutionAttemptId(executionId);
|
|
9534
9848
|
const providerModel = concreteProfileModel(createProfile);
|
|
9535
9849
|
const tokenLimits = enforceTokenLimits(profileModelExecutionSettings(createProfile, `providerAsExecutor(${provider.name})`, "provider").tokenLimits, "provider", `providerAsExecutor(${provider.name})`);
|
|
9536
9850
|
return {
|
|
9537
9851
|
plannedDeclaration: {
|
|
9852
|
+
...authoredProfile.outputFile === void 0 ? {} : { authoredProfile },
|
|
9538
9853
|
effectiveProfile: createProfile,
|
|
9539
9854
|
backend: provider.name,
|
|
9540
9855
|
model: providerModel ? {
|
|
@@ -9555,6 +9870,7 @@ function providerMaterialization(provider, createProfile, node, executionId, ret
|
|
|
9555
9870
|
destroyOnSettle: retention?.preserveEnvironment ? false : options.destroyOnSettle ?? true,
|
|
9556
9871
|
requireTerminalEvent: options.requireTerminalEvent ?? true,
|
|
9557
9872
|
...options.outputFormat === void 0 ? {} : { outputFormat: options.outputFormat },
|
|
9873
|
+
...options.outputFile === void 0 ? {} : { outputFile: options.outputFile },
|
|
9558
9874
|
tokenLimits,
|
|
9559
9875
|
...placement ? { placement } : {}
|
|
9560
9876
|
}
|
|
@@ -9585,7 +9901,7 @@ function createProviderNativeControl(provider, retention, managerStop, state) {
|
|
|
9585
9901
|
const cancelRetainedOnManagerStop = (handle) => {
|
|
9586
9902
|
if (managerStop === void 0) return;
|
|
9587
9903
|
const cancel = () => {
|
|
9588
|
-
if (state.retained !== handle || !state.workspaceRunActive) return;
|
|
9904
|
+
if (state.retained !== handle || !state.workspaceRunActive || state.harnessStopped) return;
|
|
9589
9905
|
handle.cancel({
|
|
9590
9906
|
operationId: `manager-stop:${randomUUID()}`,
|
|
9591
9907
|
reason: String(managerStop.reason ?? "the manager stopped")
|
|
@@ -9627,6 +9943,7 @@ function createProviderNativeControl(provider, retention, managerStop, state) {
|
|
|
9627
9943
|
* release records what it kept.
|
|
9628
9944
|
*/
|
|
9629
9945
|
const withoutRunningHarness = (release) => async (signal) => {
|
|
9946
|
+
if (state.harnessStopped) return release(signal);
|
|
9630
9947
|
const stop = await awaitAbortable(stopNativeExecution(), signal).catch(() => void 0);
|
|
9631
9948
|
const stopped = stop === void 0 ? "native stop unconfirmed: no exact dispatch or cleanup interrupted" : describeRetainedNativeStops([stop]);
|
|
9632
9949
|
const environmentId = (state.retained?.controlRef ?? admittedControlRef(retention))?.environmentId ?? admittedEnvironmentId(retention);
|
|
@@ -9660,14 +9977,33 @@ function admittedControlRef(retention) {
|
|
|
9660
9977
|
const NATIVE_STOP_TIMEOUT_MS = 3e4;
|
|
9661
9978
|
// src/runtime/environment-provider/provider-executor-lifecycle.ts
|
|
9662
9979
|
function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
9980
|
+
options = {
|
|
9981
|
+
...options,
|
|
9982
|
+
...providerOutputOptions(profile, options)
|
|
9983
|
+
};
|
|
9663
9984
|
const node = detachedSnapshot(ctx.node, "provider executor node");
|
|
9664
9985
|
const retention = retainedExecutorContext(ctx);
|
|
9665
|
-
if (options.outputFormat !== void 0 && (options.outputFormat !== "json" || retention?.onEvidence === void 0 || options.requireTerminalEvent === false)) throw new ValidationError("providerAsExecutor:
|
|
9986
|
+
if ((options.outputFormat !== void 0 || options.outputFile !== void 0) && (options.outputFormat !== void 0 && options.outputFormat !== "json" || retention?.onEvidence === void 0 || options.requireTerminalEvent === false)) throw new ValidationError("providerAsExecutor: structured output requires Runtime-owned durable evidence and a native terminal receipt");
|
|
9987
|
+
if (options.outputFormat !== void 0 && options.outputFile !== void 0) throw new ValidationError("providerAsExecutor: file output is selected by outputFile alone and excludes JSON output");
|
|
9988
|
+
if (options.outputFile !== void 0) {
|
|
9989
|
+
const policy = AgentFileOutputPolicySchema.parse(options.outputFile);
|
|
9990
|
+
options = {
|
|
9991
|
+
...options,
|
|
9992
|
+
outputFile: policy,
|
|
9993
|
+
defaults: {
|
|
9994
|
+
...options.defaults,
|
|
9995
|
+
retain: { paths: [.../* @__PURE__ */ new Set([...options.defaults?.retain?.paths ?? [], policy.path])] }
|
|
9996
|
+
}
|
|
9997
|
+
};
|
|
9998
|
+
if (!node || options.validator) throw new ValidationError("providerAsExecutor: file output requires a Runtime node and a completion check over retained bytes, not a live-box validator");
|
|
9999
|
+
}
|
|
9666
10000
|
const managerStop = readOptionalAbortSignal(ctx, bridgeStopSignalKey, "provider");
|
|
9667
|
-
const
|
|
9668
|
-
|
|
10001
|
+
const { outputFile: _outputFile, ...nativeProfile } = profile;
|
|
10002
|
+
const createProfile = options.profileForCreate?.(nativeProfile) ?? nativeProfile;
|
|
10003
|
+
if (placement && canonicalAgentProfileDigest(createProfile) !== canonicalAgentProfileDigest(nativeProfile)) throw new ValidationError("provider placement: profileForCreate cannot change the selected profile");
|
|
9669
10004
|
const executionId = retention?.executionId ?? node?.nodeId ?? `provider-run-${randomUUID()}`;
|
|
9670
10005
|
const state = new ProviderExecutorState(ctx.signal, executionId);
|
|
10006
|
+
state.fileOutputRequired = options.outputFile !== void 0;
|
|
9671
10007
|
state.pending = admittedEnvironmentId(retention) !== void 0;
|
|
9672
10008
|
state.workspaceControlRef = admittedControlRef(retention);
|
|
9673
10009
|
state.providerSessionId = state.workspaceControlRef?.sessionId ?? null;
|
|
@@ -9685,7 +10021,7 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
9685
10021
|
controller: new AbortController(),
|
|
9686
10022
|
nativeControl: createProviderNativeControl(provider, retention, managerStop, state),
|
|
9687
10023
|
trace: createPushTraceSource({ runId: executionId }),
|
|
9688
|
-
materialization: providerMaterialization(provider, createProfile, node, executionId, retention, options, placement),
|
|
10024
|
+
materialization: providerMaterialization(provider, profile, createProfile, node, executionId, retention, options, placement),
|
|
9689
10025
|
continuationTask: LEAF_CONTINUATION_TASK,
|
|
9690
10026
|
executor: () => executor
|
|
9691
10027
|
};
|
|
@@ -9693,6 +10029,11 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
9693
10029
|
const run = (task, signal, recovering = false) => runProviderExecution(scope, task, signal, recovering);
|
|
9694
10030
|
executor = {
|
|
9695
10031
|
runtime: options.runtime ?? provider.name,
|
|
10032
|
+
...options.outputFile !== void 0 ? { withFileOutput: (submission, accept) => {
|
|
10033
|
+
const current = state.fileOutput;
|
|
10034
|
+
if (!current) return Promise.reject(new ValidationError("file output has no active retained invocation"));
|
|
10035
|
+
return current.withSubmission(submission, accept);
|
|
10036
|
+
} } : {},
|
|
9696
10037
|
execute: run,
|
|
9697
10038
|
recover: (task, signal) => run(task, signal, true),
|
|
9698
10039
|
cancel: (request) => cancelExecution(scope, request),
|
|
@@ -9758,7 +10099,7 @@ function heldEnvironments(scope) {
|
|
|
9758
10099
|
if (state.destroyed) return [];
|
|
9759
10100
|
const environmentId = state.environment?.id ?? state.retained?.controlRef.environmentId ?? admittedEnvironmentId(scope.retention);
|
|
9760
10101
|
if (environmentId === void 0) return [];
|
|
9761
|
-
const preserved = state.
|
|
10102
|
+
const preserved = state.sourcePreservationRequired;
|
|
9762
10103
|
return [{
|
|
9763
10104
|
provider: scope.provider.name,
|
|
9764
10105
|
environmentId,
|
|
@@ -9790,6 +10131,16 @@ function heldForContinuation(scope) {
|
|
|
9790
10131
|
* infrastructure (discovery-lab AGENTS.md). */
|
|
9791
10132
|
const LEAF_CONTINUATION_TASK = "Your previous turn was interrupted before it finished. This is the same task in the same session: your conversation so far and the files in your workspace are where you left them. Continue from where you stopped. Do not start over.";
|
|
9792
10133
|
// src/runtime/environment-provider/provider-executor-admission.ts
|
|
10134
|
+
/** Resolve the authored per-profile output policy before a provider executor is constructed.
|
|
10135
|
+
* Backend-wide output remains the default for profiles that do not select a file. */
|
|
10136
|
+
function providerOutputOptions(profile, defaults) {
|
|
10137
|
+
if (profile.outputFile === void 0) return {};
|
|
10138
|
+
if (defaults.outputFile !== void 0 && canonicalCandidateDigest(defaults.outputFile) !== canonicalCandidateDigest(profile.outputFile)) throw new ValidationError("profile outputFile conflicts with the provider output policy");
|
|
10139
|
+
return {
|
|
10140
|
+
outputFormat: void 0,
|
|
10141
|
+
outputFile: detachedSnapshot(profile.outputFile, "profile outputFile")
|
|
10142
|
+
};
|
|
10143
|
+
}
|
|
9793
10144
|
/** Adapt an environment provider into an `ExecutorFactory` for `createExecutor`.
|
|
9794
10145
|
*
|
|
9795
10146
|
* `createExecutor({ backend: 'provider', provider })` is the composition most callers want; it
|
|
@@ -9801,6 +10152,10 @@ const LEAF_CONTINUATION_TASK = "Your previous turn was interrupted before it fin
|
|
|
9801
10152
|
*
|
|
9802
10153
|
* @experimental */
|
|
9803
10154
|
function providerAsExecutor(provider, options = {}) {
|
|
10155
|
+
if (options.outputFile !== void 0) options = {
|
|
10156
|
+
...options,
|
|
10157
|
+
outputFile: detachedSnapshot(options.outputFile, "file output policy")
|
|
10158
|
+
};
|
|
9804
10159
|
const captured = options.placements === void 0 ? options : {
|
|
9805
10160
|
...options,
|
|
9806
10161
|
placements: detachedSnapshot(options.placements, "provider placements"),
|
|
@@ -14164,8 +14519,11 @@ function snapshotExecutorConfig(config, mode = "execution") {
|
|
|
14164
14519
|
});
|
|
14165
14520
|
}
|
|
14166
14521
|
case "provider": {
|
|
14167
|
-
if (config.
|
|
14168
|
-
|
|
14522
|
+
if (config.outputFile !== void 0 && config.shared !== void 0) throw new ValidationError$1("createExecutor(provider): file output requires a dedicated retained environment");
|
|
14523
|
+
if ((config.outputFormat ?? config.outputFile) !== void 0 && config.steering !== void 0) throw new ValidationError$1("createExecutor(provider): JSON output is not supported with steering");
|
|
14524
|
+
if (config.harnessTranscript !== void 0 && config.steering !== void 0) throw new ValidationError$1("createExecutor(provider): native capture is not supported with steering");
|
|
14525
|
+
const { provider, registry, profileForCreate, taskToTurn, validator, harnessTranscript, shared, ...decisionData } = config;
|
|
14526
|
+
if (harnessTranscript !== void 0 && typeof harnessTranscript !== "function") throw new ValidationError$1("createExecutor provider: harnessTranscript must be a capture function");
|
|
14169
14527
|
if (shared !== void 0 && (decisionData.steering !== void 0 || decisionData.placements !== void 0)) throw new ValidationError$1("createExecutor(provider): shared placement cannot combine with steering or placements");
|
|
14170
14528
|
const snapshot = detachedSnapshot(decisionData, "createExecutor provider config");
|
|
14171
14529
|
const resolvedProvider = mode === "control" && typeof provider === "string" ? registry?.get(provider) ?? provider : resolveAgentEnvironmentProvider(provider, registry);
|
|
@@ -14175,6 +14533,7 @@ function snapshotExecutorConfig(config, mode = "execution") {
|
|
|
14175
14533
|
...profileForCreate === void 0 ? {} : { profileForCreate },
|
|
14176
14534
|
...taskToTurn === void 0 ? {} : { taskToTurn },
|
|
14177
14535
|
...validator === void 0 ? {} : { validator },
|
|
14536
|
+
...harnessTranscript === void 0 ? {} : { harnessTranscript },
|
|
14178
14537
|
...shared === void 0 ? {} : { shared }
|
|
14179
14538
|
});
|
|
14180
14539
|
}
|
|
@@ -14294,6 +14653,7 @@ function createExecutor(config) {
|
|
|
14294
14653
|
const captured = snapshotExecutorConfig(config);
|
|
14295
14654
|
return (rawSpec, ctx) => {
|
|
14296
14655
|
const spec = executableAgentSpecSnapshot(rawSpec, `createExecutor(${captured.backend})`);
|
|
14656
|
+
if (spec.profile.outputFile !== void 0 && captured.backend !== "provider") throw new ValidationError$1("profile outputFile requires a retained provider backend");
|
|
14297
14657
|
const { backend, ...seamData } = captured;
|
|
14298
14658
|
const seam = Object.freeze(seamData);
|
|
14299
14659
|
const seamed = {
|
|
@@ -14311,7 +14671,12 @@ function createExecutor(config) {
|
|
|
14311
14671
|
case "cli-worktree": return cliWorktreeExecutor(spec, seamed);
|
|
14312
14672
|
case "cli-in-place": return cliInPlaceExecutor(spec, seamed);
|
|
14313
14673
|
case "provider": {
|
|
14314
|
-
const
|
|
14674
|
+
const declared = readSeam(seamed, providerSeamKey, "provider");
|
|
14675
|
+
const originalSeam = {
|
|
14676
|
+
...declared,
|
|
14677
|
+
...providerOutputOptions(spec.profile, declared)
|
|
14678
|
+
};
|
|
14679
|
+
if (originalSeam.outputFile !== void 0 && (originalSeam.steering !== void 0 || originalSeam.shared !== void 0)) throw new ValidationError$1("profile outputFile requires a dedicated retained provider without steering");
|
|
14315
14680
|
const selected = originalSeam.steering ? selectProviderPlacement(spec.profile, originalSeam) : void 0;
|
|
14316
14681
|
const providerSeam = selected?.options ?? originalSeam;
|
|
14317
14682
|
const provider = resolveAgentEnvironmentProvider(providerSeam.provider, providerSeam.registry);
|
|
@@ -15294,7 +15659,7 @@ function unconfirmedRecord(node) {
|
|
|
15294
15659
|
}
|
|
15295
15660
|
/**
|
|
15296
15661
|
* Retry every unconfirmed teardown in the settled tree until each executor confirms destruction
|
|
15297
|
-
* or `windowMs` passes, and return what is still unconfirmed.
|
|
15662
|
+
* or `windowMs` from `opensAt` passes, and return what is still unconfirmed.
|
|
15298
15663
|
*
|
|
15299
15664
|
* Settled children are evidence about an EXECUTOR, not a cause of run failure, so the barrier
|
|
15300
15665
|
* never fails the run over them; it asks again and then NAMES what it could not confirm. Backoff
|
|
@@ -15305,15 +15670,15 @@ function unconfirmedRecord(node) {
|
|
|
15305
15670
|
* failed is released again; otherwise it is kept for a resume and not retried. The window is wall
|
|
15306
15671
|
* clock, like the timers that pace it, so an injected `now` cannot stall it.
|
|
15307
15672
|
*/
|
|
15308
|
-
async function confirmSettledTeardowns(scope, windowMs, release) {
|
|
15309
|
-
const closesAt =
|
|
15673
|
+
async function confirmSettledTeardowns(scope, windowMs, release, opensAt) {
|
|
15674
|
+
const closesAt = opensAt + windowMs;
|
|
15310
15675
|
const maxDelayMs = windowMs / 10;
|
|
15311
15676
|
let delayMs = windowMs / 300;
|
|
15312
15677
|
let releasing;
|
|
15313
15678
|
let failure;
|
|
15314
15679
|
while (failure === void 0 && hasRetriableTeardowns(scope, release)) {
|
|
15315
15680
|
if (closesAt - Date.now() <= 0) break;
|
|
15316
|
-
await
|
|
15681
|
+
await pausable(Math.min(delayMs, closesAt - Date.now())).elapsed;
|
|
15317
15682
|
delayMs = Math.min(delayMs * 2, maxDelayMs);
|
|
15318
15683
|
if (release && releasing === void 0) releasing = releaseRetainedEnvironments(scope).finally(() => {
|
|
15319
15684
|
releasing = void 0;
|
|
@@ -15332,10 +15697,6 @@ async function confirmSettledTeardowns(scope, windowMs, release) {
|
|
|
15332
15697
|
if (failure !== void 0) throw failure.error;
|
|
15333
15698
|
return unconfirmedTeardowns(scope);
|
|
15334
15699
|
}
|
|
15335
|
-
/** A wall-clock wait that keeps the process alive until it ends. */
|
|
15336
|
-
function pause(ms) {
|
|
15337
|
-
return pausable(ms).elapsed;
|
|
15338
|
-
}
|
|
15339
15700
|
/** A wall-clock wait that can be cancelled, so a wait that lost a race holds no timer open. */
|
|
15340
15701
|
function pausable(ms) {
|
|
15341
15702
|
if (ms <= 0) return {
|
|
@@ -15756,11 +16117,12 @@ async function joinRunChildren(join, settleGraceMs) {
|
|
|
15756
16117
|
await drainLiveChildren(scope, join.controller, settleGraceMs);
|
|
15757
16118
|
await releaseHeldEnvironments(scope);
|
|
15758
16119
|
join.teardownUnconfirmed = unconfirmedTeardowns(scope);
|
|
15759
|
-
await settleManagerWork(scope);
|
|
15760
|
-
join.teardownUnconfirmed = unconfirmedTeardowns(scope);
|
|
15761
|
-
if (!persistence.failed && join.retainedAtSettlement === "release") join.teardownUnconfirmed = await releaseRetainedEnvironments(scope);
|
|
15762
16120
|
const releasing = !persistence.failed && join.retainedAtSettlement === "release";
|
|
15763
|
-
|
|
16121
|
+
const clock = { windowMs: Math.max(join.opts.teardownConfirmMs ?? 0, RELEASE_DESTROY_MS) };
|
|
16122
|
+
if (releasing) boundRetainedReleases(scope, clock);
|
|
16123
|
+
await Promise.all([settleManagerWork(scope), releasing ? releaseRetainedEnvironments(scope) : void 0]);
|
|
16124
|
+
join.teardownUnconfirmed = unconfirmedTeardowns(scope);
|
|
16125
|
+
await confirmRetriableTeardowns(join, releasing, clock.startedAt ?? Date.now());
|
|
15764
16126
|
join.teardownUnconfirmed = await unrecoveredRetainedChildren(join);
|
|
15765
16127
|
for (const node of join.teardownUnconfirmed) await join.opts.journal.appendEvent(join.opts.runId, {
|
|
15766
16128
|
kind: "teardown-unconfirmed",
|
|
@@ -15882,10 +16244,10 @@ async function unrecoveredRetainedChildren(join) {
|
|
|
15882
16244
|
* settles over it leaves the sandbox running: cancelling 20 Discovery lanes
|
|
15883
16245
|
* left 2 workers running. Ask again until confirmed or out of time.
|
|
15884
16246
|
*/
|
|
15885
|
-
async function confirmRetriableTeardowns(join, releasing) {
|
|
16247
|
+
async function confirmRetriableTeardowns(join, releasing, opensAt) {
|
|
15886
16248
|
const { opts, scope } = join;
|
|
15887
|
-
const confirmWindowMs = opts.teardownConfirmMs ??
|
|
15888
|
-
if (!(join.teardownUnconfirmed.length > 0 && confirmWindowMs >
|
|
16249
|
+
const confirmWindowMs = opts.teardownConfirmMs ?? 9e4;
|
|
16250
|
+
if (!(join.teardownUnconfirmed.length > 0 && opensAt + confirmWindowMs > Date.now() && hasRetriableTeardowns(scope, releasing))) return;
|
|
15889
16251
|
const pending = join.teardownUnconfirmed;
|
|
15890
16252
|
for (const node of pending) await opts.journal.appendEvent(opts.runId, {
|
|
15891
16253
|
kind: "teardown-pending",
|
|
@@ -15893,7 +16255,7 @@ async function confirmRetriableTeardowns(join, releasing) {
|
|
|
15893
16255
|
seq: join.teardownSeq++,
|
|
15894
16256
|
at: new Date(join.now()).toISOString()
|
|
15895
16257
|
});
|
|
15896
|
-
join.teardownUnconfirmed = await confirmSettledTeardowns(scope, confirmWindowMs, releasing);
|
|
16258
|
+
join.teardownUnconfirmed = await confirmSettledTeardowns(scope, confirmWindowMs, releasing, opensAt);
|
|
15897
16259
|
const still = new Set(join.teardownUnconfirmed.map((node) => node.id));
|
|
15898
16260
|
for (const node of pending) {
|
|
15899
16261
|
if (still.has(node.id)) continue;
|
|
@@ -16298,6 +16660,6 @@ async function noWinner(settled, rejection) {
|
|
|
16298
16660
|
reason: "no-result-selected"
|
|
16299
16661
|
};
|
|
16300
16662
|
}
|
|
16301
|
-
export {
|
|
16663
|
+
export { failPendingAfter as $, worktreeCliProfileMaterialization as $t, readPromptOptions as A, readCodexRolloutSession as At, toolResultText as B, terminateProcessTreeAndConfirm as Bt, captureReusableExecutorConfig as C, bridgeAdmissionRefusal as Ct, createSteerableSandboxSession as D, addHarnessUsage as Dt, DEFAULT_SANDBOX_STEERING_MAX_TURNS as E, ROUTER_PRICE_SOURCE as Et, defaultSelectWinner as F, defaultRunCommand as Ft, providerAsExecutor as G, fullProfileMaterialization as Gt, routerBrain as H, assertProfileMaterializes as Ht, codeModeArguments as I, runSettledCommand as It, providerAsSandboxClient as J, promptModelProfileMaterialization as Jt, providerOutputOptions as K, profileMaterializationAxes$1 as Kt, codeModeModelOutput as L, runWorktreeHarness as Lt, createSandboxLineage as M, bridgeRuntimeAttachmentsKey as Mt, acquireSandbox as N, bridgeRuntimeEnvKey as Nt, runAgentRounds as O, createCodexRolloutStoreReader as Ot, TERMINAL_DECISIONS as P, bridgeStopSignalKey as Pt, createInbox as Q, unsupportedProfileDimensions as Qt, createCodeModeTools as R, LOCAL_HARNESSES as Rt, bindReusableExecutorExecutionId as S, verdictFromJudgeScore as St, snapshotExecutorConfig as T, priceTokens as Tt, createAgentEnvironmentProviderRegistry as U, controlProfileMaterialization as Ut, createRouterTranscript as V, assertProfileMaterialization as Vt, resolveAgentEnvironmentProvider as W, defineProfileMaterializationContract as Wt, createInPlaceCliExecutor as X, sandboxActProfileMaterialization as Xt, createWorktreeCliExecutor as Y, renderUnsupported as Yt, INBOX_RECEIPT_KEY as Z, sandboxProfileMaterialization as Zt, isDriverSpec as _, preflightPublicCoordination as _t, assertRunParking as a, isPeerMailEnvelope as at, InMemorySpawnJournal as b, gateOnDeliverable as bt, readRunParking as c, taskToPrompt$1 as ct, bestDelivered as d, abandonablePending as dt, projectSandboxOutcome as en, AUTHORITY_MARKERS as et, runFinalizer as f, classifyDriverFailure as ft, driverExecutorFactory as g, upstreamUnavailableSignal as gt, driverChild as h, undispatchedCredentialExit as ht, RunParkedError as i, createPeerMailbox as it, createSandboxForSpec as j, createPushTraceSource as jt, assertBoxlessPromptOptions as k, harnessUsageIsEmpty as kt, sleepScopeWait as l, DriverAttemptsExhaustedError as lt, createRootHandle as m, transientFailureKind as mt, createSupervisor as n, PEER_MAIL_WIRE_KEY as nt, bindScopeParkingDrain as o, peerMailTools as ot, runTree as p, summarizeDriverAttempts as pt, LEAF_CONTINUATION_TASK as q, promptControlProfileMaterialization as qt, assertResumeLimits as r, claimsAuthority as rt, isRunParked as s, peerMailVerbNames as st, DEFAULT_MAX_DEPTH as t, readSandboxOutcome as tn, DEFAULT_PEER_MAIL_LIMITS as tt, withRunParking as u, HarnessTurnFailedError as ut, withDriverExecutor as v, CheckUnavailableError as vt, createExecutor as w, bridgeModelRouteRefusal as wt, createExecutorRegistry as x, mapExecutorResult as xt, InMemoryResultBlobStore as y, gateFactoryOnDeliverable as yt, runCodeMode as z, harnessInvocation as zt };
|
|
16302
16664
|
|
|
16303
|
-
//# sourceMappingURL=supervisor-
|
|
16665
|
+
//# sourceMappingURL=supervisor-DpwcTrTh.js.map
|