@tangle-network/agent-runtime 0.229.0 → 0.232.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.
- package/dist/{activation-o9SrkJqs.js → activation-BXjgjus6.js} +2 -2
- package/dist/{activation-o9SrkJqs.js.map → activation-BXjgjus6.js.map} +1 -1
- package/dist/{activation-DFSQ90A8.d.ts → activation-LJ33ygpS.d.ts} +2 -2
- package/dist/agent.d.ts +2 -2
- package/dist/agent.js +2 -2
- package/dist/{coordination-driver-C6rde-Rv.js → coordination-driver-hXWuo-1n.js} +16 -14
- package/dist/{coordination-driver-C6rde-Rv.js.map → coordination-driver-hXWuo-1n.js.map} +1 -1
- package/dist/{delegate-Cmd-qlWH.js → delegate-B8b6oHnj.js} +2 -2
- package/dist/{delegate-Cmd-qlWH.js.map → delegate-B8b6oHnj.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +9 -3
- package/dist/durable.js.map +1 -1
- package/dist/{graph-BK05MhFv.js → graph-Ce7g744w.js} +3 -3
- package/dist/{graph-BK05MhFv.js.map → graph-Ce7g744w.js.map} +1 -1
- package/dist/{improvement-cycle-DHl4SxbQ.js → improvement-cycle-CGAPVMst.js} +3 -3
- package/dist/{improvement-cycle-DHl4SxbQ.js.map → improvement-cycle-CGAPVMst.js.map} +1 -1
- package/dist/{index-B6xSpuPo.d.ts → index-BnEWL76W.d.ts} +33 -22
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -7
- package/dist/intelligence.d.ts +3 -3
- package/dist/intelligence.js +3 -3
- package/dist/kernel.d.ts +4 -4
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-D5hutINM.d.ts → loop-runner-bin-BdobVmHx.d.ts} +3 -3
- package/dist/{loop-runner-bin-CU2bdlr1.js → loop-runner-bin-Q47flacp.js} +3 -3
- package/dist/{loop-runner-bin-CU2bdlr1.js.map → loop-runner-bin-Q47flacp.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +6 -6
- package/dist/mcp/memory-bin.js +1 -1
- package/dist/{memory-server-BR310Weg.js → memory-server-Cn8LbAxO.js} +2 -2
- package/dist/{memory-server-BR310Weg.js.map → memory-server-Cn8LbAxO.js.map} +1 -1
- package/dist/{openai-tools-HhRT1L1W.d.ts → openai-tools-Dl5AKEtq.d.ts} +2 -2
- package/dist/profiles.d.ts +2 -2
- package/dist/{provision-supervisor-C2rRWXG6.js → provision-supervisor-BXnC4uwd.js} +3 -3
- package/dist/{provision-supervisor-C2rRWXG6.js.map → provision-supervisor-BXnC4uwd.js.map} +1 -1
- package/dist/{runtime-BBcrtrkj.js → runtime-CcMvprwa.js} +8 -8
- package/dist/{runtime-BBcrtrkj.js.map → runtime-CcMvprwa.js.map} +1 -1
- package/dist/{server-CWIl-a3C.js → server-ClTO4X79.js} +4 -4
- package/dist/{server-CWIl-a3C.js.map → server-ClTO4X79.js.map} +1 -1
- package/dist/stream-agent-turn-nAvemLZR.d.ts +2049 -0
- package/dist/{structural-rollout-zl02ztZ4.js → structural-rollout-C9z5pjxN.js} +2 -2
- package/dist/{structural-rollout-zl02ztZ4.js.map → structural-rollout-C9z5pjxN.js.map} +1 -1
- package/dist/{substrate-sWW5cDIe.d.ts → substrate-ijm9h_79.d.ts} +2 -2
- package/dist/{supervise-DbNMYx7z.js → supervise-CLkM45VY.js} +144 -28
- package/dist/supervise-CLkM45VY.js.map +1 -0
- package/dist/{supervisor-DAHG98Rs.js → supervisor-BVAM5glY.js} +609 -262
- package/dist/supervisor-BVAM5glY.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +12 -12
- package/dist/{tool-server-BJbCPhoW.js → tool-server-x9NEhvHZ.js} +2 -2
- package/dist/tool-server-x9NEhvHZ.js.map +1 -0
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{stream-agent-turn-jPdnzI_5.d.ts → types-C8Fj6hNL.d.ts} +4103 -4746
- package/package.json +4 -4
- package/dist/supervise-DbNMYx7z.js.map +0 -1
- package/dist/supervisor-DAHG98Rs.js.map +0 -1
- package/dist/tool-server-BJbCPhoW.js.map +0 -1
- package/dist/types-Ba5mJkyd.d.ts +0 -1293
|
@@ -5754,7 +5754,18 @@ function generateTraceId() {
|
|
|
5754
5754
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
5755
5755
|
}
|
|
5756
5756
|
//#endregion
|
|
5757
|
-
//#region src/
|
|
5757
|
+
//#region src/durable/content-address.ts
|
|
5758
|
+
/** Stable content address shared by result and trace artifacts. */
|
|
5759
|
+
function contentAddress(artifact) {
|
|
5760
|
+
return `sha256:${createHash("sha256").update(stableStringify(artifact), "utf-8").digest("hex")}`;
|
|
5761
|
+
}
|
|
5762
|
+
function stableStringify(value) {
|
|
5763
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
5764
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
5765
|
+
return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(",")}}`;
|
|
5766
|
+
}
|
|
5767
|
+
//#endregion
|
|
5768
|
+
//#region src/runtime/harness-transcript.ts
|
|
5758
5769
|
/**
|
|
5759
5770
|
* Read a sandbox child's own harness transcript out of its environment before the
|
|
5760
5771
|
* environment is destroyed, and persist it beside the tool-span `trace` receipt.
|
|
@@ -5777,9 +5788,11 @@ function generateTraceId() {
|
|
|
5777
5788
|
* `exec`. An environment with `read` but no `exec` cannot be enumerated and is also
|
|
5778
5789
|
* reported, not guessed at.
|
|
5779
5790
|
*
|
|
5780
|
-
* Storage is NOT
|
|
5781
|
-
*
|
|
5782
|
-
*
|
|
5791
|
+
* Storage is NOT the executor's business. The executor holds the in-memory capture and hands it
|
|
5792
|
+
* to the scope through `Executor.harnessTranscript()`; the scope persists it under its own
|
|
5793
|
+
* content ref with `persistHarnessTranscript` and settles the receipt. No provider or destroy
|
|
5794
|
+
* site learns about storage, the result blob never carries the files, and replay rehydrates a
|
|
5795
|
+
* pointer — the bytes are read only by `harnessTranscriptArtifact`, when someone opens them.
|
|
5783
5796
|
*
|
|
5784
5797
|
* Credentials are excluded by construction: enumeration lists only the transcript globs
|
|
5785
5798
|
* for the harness, and any path matching DENY is dropped even if a producer moved a
|
|
@@ -5805,9 +5818,15 @@ const HARNESS_ROOTS = Object.freeze({
|
|
|
5805
5818
|
*/
|
|
5806
5819
|
const DENY = /(^|\/)(auth\.json|\.credentials\.json|credentials|\.netrc|\.env(\..*)?|secrets?(\.|$)|.*\.(pem|key|p12|pfx)|id_[a-z0-9_]+)$/iu;
|
|
5807
5820
|
/**
|
|
5808
|
-
* Bounds per file and in total.
|
|
5809
|
-
*
|
|
5810
|
-
*
|
|
5821
|
+
* Bounds per file and in total, PER CHILD. They multiply by fleet width, and the next person
|
|
5822
|
+
* sizing a fleet must find that here: a 132-child pursuit (mech-interp-foundations-astra-20260911f,
|
|
5823
|
+
* the widest retained on one operator host) at the ceiling is 132 x 16 MiB = 2.1 GiB of transcript
|
|
5824
|
+
* for one run (#1248).
|
|
5825
|
+
*
|
|
5826
|
+
* That figure is a DISK number, not a replay number. The artifact is persisted under its own
|
|
5827
|
+
* content ref in the `ResultBlobStore` and the settlement carries only the receipt, so replay and
|
|
5828
|
+
* resume rehydrate a ref, never the files; nothing pays for a transcript until someone opens it.
|
|
5829
|
+
* The bound is enforced exactly, after each read, so a child settles at or under MAX_TOTAL_BYTES.
|
|
5811
5830
|
*/
|
|
5812
5831
|
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
5813
5832
|
const MAX_TOTAL_BYTES = 16 * 1024 * 1024;
|
|
@@ -5818,17 +5837,53 @@ function unavailable$2(reason) {
|
|
|
5818
5837
|
reason
|
|
5819
5838
|
});
|
|
5820
5839
|
}
|
|
5840
|
+
/** The one place an absent transcript is spelled, so every settlement reads the same — the
|
|
5841
|
+
* settle path needs it for the reasons only IT can know (an executor that offers no transcript,
|
|
5842
|
+
* a child that never started), which the capture itself never sees. */
|
|
5843
|
+
function harnessTranscriptUnavailable(reason) {
|
|
5844
|
+
return unavailable$2(reason);
|
|
5845
|
+
}
|
|
5821
5846
|
/**
|
|
5822
5847
|
* Enumerate candidate transcript paths inside the environment.
|
|
5823
5848
|
*
|
|
5824
|
-
* `find` is given the roots and prints one path per
|
|
5825
|
-
* a child that never used a harness has no directory for it.
|
|
5849
|
+
* `find` is given the roots and prints one `size<TAB>path` line per file. A missing root is not
|
|
5850
|
+
* an error: a child that never used a harness has no directory for it. A line with no size (an
|
|
5851
|
+
* environment whose `find` lacks `-printf`) is read and bounded after the read, as before.
|
|
5852
|
+
*
|
|
5853
|
+
* Two omissions used to be silent, so `skippedCount` could read 0 on an incomplete capture: a
|
|
5854
|
+
* `-size` filter dropped oversized files before they were ever listed, and `head` cut the listing
|
|
5855
|
+
* at MAX_FILES with nothing saying so. Both are reported now: an oversized file is skipped by its
|
|
5856
|
+
* listed size WITHOUT being read, and a listing that overflows carries one
|
|
5857
|
+
* `enumeration-truncated` entry naming the bound.
|
|
5826
5858
|
*/
|
|
5827
5859
|
async function enumerate(environment, roots, signal) {
|
|
5828
5860
|
if (!environment.exec) return void 0;
|
|
5829
|
-
const command = `find ${roots.map((r) => `"$HOME/${r}"`).join(" ")} -type f -
|
|
5861
|
+
const command = `find ${roots.map((r) => `"$HOME/${r}"`).join(" ")} -type f -printf '%s\\t%p\\n' 2>/dev/null | head -1001`;
|
|
5830
5862
|
try {
|
|
5831
|
-
|
|
5863
|
+
const lines = ((await environment.exec(command, signal ? { signal } : void 0)).stdout ?? "").split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
5864
|
+
const omitted = [];
|
|
5865
|
+
const paths = [];
|
|
5866
|
+
for (const line of lines.slice(0, MAX_FILES)) {
|
|
5867
|
+
const tab = line.indexOf(" ");
|
|
5868
|
+
const path = tab === -1 ? line : line.slice(tab + 1);
|
|
5869
|
+
const size = tab === -1 ? void 0 : Number(line.slice(0, tab));
|
|
5870
|
+
if (size !== void 0 && Number.isFinite(size) && size > MAX_FILE_BYTES) {
|
|
5871
|
+
omitted.push({
|
|
5872
|
+
path,
|
|
5873
|
+
reason: "file-exceeds-byte-bound"
|
|
5874
|
+
});
|
|
5875
|
+
continue;
|
|
5876
|
+
}
|
|
5877
|
+
paths.push(path);
|
|
5878
|
+
}
|
|
5879
|
+
if (lines.length > MAX_FILES) omitted.push({
|
|
5880
|
+
path: roots.join(" "),
|
|
5881
|
+
reason: `enumeration-truncated-at-${MAX_FILES}`
|
|
5882
|
+
});
|
|
5883
|
+
return {
|
|
5884
|
+
paths,
|
|
5885
|
+
omitted
|
|
5886
|
+
};
|
|
5832
5887
|
} catch {
|
|
5833
5888
|
return;
|
|
5834
5889
|
}
|
|
@@ -5841,16 +5896,17 @@ async function enumerate(environment, roots, signal) {
|
|
|
5841
5896
|
* must not fail because evidence could not be collected, and every failure mode is a named
|
|
5842
5897
|
* `reason` the settled receipt carries instead of an empty artifact that reads as coverage.
|
|
5843
5898
|
*/
|
|
5844
|
-
async function
|
|
5899
|
+
async function captureHarnessTranscript(environment, harness, signal) {
|
|
5845
5900
|
if (!environment?.read) return unavailable$2("unsupported-environment");
|
|
5846
5901
|
if (harness === void 0) return unavailable$2("unknown-harness");
|
|
5847
5902
|
const roots = HARNESS_ROOTS[harness];
|
|
5848
5903
|
if (!roots) return unavailable$2("unknown-harness");
|
|
5849
|
-
const
|
|
5850
|
-
if (
|
|
5851
|
-
|
|
5904
|
+
const enumerated = await enumerate(environment, roots, signal);
|
|
5905
|
+
if (enumerated === void 0) return unavailable$2("enumeration-failed");
|
|
5906
|
+
const { paths } = enumerated;
|
|
5907
|
+
if (paths.length === 0 && enumerated.omitted.length === 0) return unavailable$2("no-transcript");
|
|
5852
5908
|
const files = [];
|
|
5853
|
-
const skipped = [];
|
|
5909
|
+
const skipped = [...enumerated.omitted];
|
|
5854
5910
|
let total = 0;
|
|
5855
5911
|
for (const path of paths) {
|
|
5856
5912
|
if (signal?.aborted) {
|
|
@@ -5884,6 +5940,13 @@ async function captureNativeSessionEvidence(environment, harness, signal) {
|
|
|
5884
5940
|
});
|
|
5885
5941
|
continue;
|
|
5886
5942
|
}
|
|
5943
|
+
if (total + bytes > MAX_TOTAL_BYTES) {
|
|
5944
|
+
skipped.push({
|
|
5945
|
+
path,
|
|
5946
|
+
reason: "total-byte-budget-exhausted"
|
|
5947
|
+
});
|
|
5948
|
+
continue;
|
|
5949
|
+
}
|
|
5887
5950
|
files.push(Object.freeze({
|
|
5888
5951
|
path,
|
|
5889
5952
|
bytes,
|
|
@@ -5897,7 +5960,11 @@ async function captureNativeSessionEvidence(environment, harness, signal) {
|
|
|
5897
5960
|
});
|
|
5898
5961
|
}
|
|
5899
5962
|
}
|
|
5900
|
-
if (files.length === 0) return
|
|
5963
|
+
if (files.length === 0) return Object.freeze({
|
|
5964
|
+
status: "unavailable",
|
|
5965
|
+
reason: "nothing-carried",
|
|
5966
|
+
skipped: Object.freeze(skipped)
|
|
5967
|
+
});
|
|
5901
5968
|
const artifact = Object.freeze({
|
|
5902
5969
|
schemaVersion: 1,
|
|
5903
5970
|
harness,
|
|
@@ -5905,13 +5972,54 @@ async function captureNativeSessionEvidence(environment, harness, signal) {
|
|
|
5905
5972
|
skipped: Object.freeze(skipped)
|
|
5906
5973
|
});
|
|
5907
5974
|
return Object.freeze({
|
|
5908
|
-
status: "
|
|
5975
|
+
status: "captured",
|
|
5909
5976
|
artifact,
|
|
5910
5977
|
fileCount: files.length,
|
|
5911
5978
|
totalBytes: total,
|
|
5912
5979
|
skippedCount: skipped.length
|
|
5913
5980
|
});
|
|
5914
5981
|
}
|
|
5982
|
+
/**
|
|
5983
|
+
* Persist a capture under its own content ref and return the receipt a settlement carries.
|
|
5984
|
+
*
|
|
5985
|
+
* The scope calls this, not the executor: storage stays out of every provider and destroy site,
|
|
5986
|
+
* exactly as the tool-span trace is persisted by `captureWorkerTraceEvidence` and not by the
|
|
5987
|
+
* source that collected it. A capture that is already unavailable passes through untouched.
|
|
5988
|
+
*/
|
|
5989
|
+
async function persistHarnessTranscript(capture, blobs) {
|
|
5990
|
+
if (capture.status !== "captured") return capture;
|
|
5991
|
+
const transcriptRef = contentAddress(capture.artifact);
|
|
5992
|
+
try {
|
|
5993
|
+
await blobs.put(transcriptRef, capture.artifact);
|
|
5994
|
+
} catch {
|
|
5995
|
+
return unavailable$2("transcript-persistence-failed");
|
|
5996
|
+
}
|
|
5997
|
+
return Object.freeze({
|
|
5998
|
+
status: "available",
|
|
5999
|
+
transcriptRef,
|
|
6000
|
+
harness: capture.artifact.harness,
|
|
6001
|
+
fileCount: capture.fileCount,
|
|
6002
|
+
totalBytes: capture.totalBytes,
|
|
6003
|
+
skippedCount: capture.skippedCount
|
|
6004
|
+
});
|
|
6005
|
+
}
|
|
6006
|
+
/**
|
|
6007
|
+
* Rehydrate the exact persisted transcript a receipt points at, or `undefined` when the receipt
|
|
6008
|
+
* says there is none. Throws only when the receipt claims a blob the store does not hold — that
|
|
6009
|
+
* is corruption, not absence, and must not read as "no transcript".
|
|
6010
|
+
*/
|
|
6011
|
+
async function harnessTranscriptArtifact(evidence, blobs) {
|
|
6012
|
+
if (evidence.status !== "available") return void 0;
|
|
6013
|
+
const raw = await blobs.get(evidence.transcriptRef);
|
|
6014
|
+
if (!isHarnessTranscriptArtifact(raw)) throw new ValidationError$1(`harnessTranscriptArtifact: blob store has no transcript artifact for '${evidence.transcriptRef}'`);
|
|
6015
|
+
return raw;
|
|
6016
|
+
}
|
|
6017
|
+
/** Every entry, not just the arrays: a blob with `files: [null]` is corruption, not a transcript. */
|
|
6018
|
+
function isHarnessTranscriptArtifact(value) {
|
|
6019
|
+
if (value === null || typeof value !== "object") return false;
|
|
6020
|
+
const artifact = value;
|
|
6021
|
+
return artifact.schemaVersion === 1 && typeof artifact.harness === "string" && Array.isArray(artifact.files) && artifact.files.every((file) => file !== null && typeof file === "object" && typeof file.path === "string" && typeof file.content === "string" && Number.isSafeInteger(file.bytes) && file.bytes >= 0) && Array.isArray(artifact.skipped) && artifact.skipped.every((entry) => entry !== null && typeof entry === "object" && typeof entry.path === "string" && typeof entry.reason === "string");
|
|
6022
|
+
}
|
|
5915
6023
|
//#endregion
|
|
5916
6024
|
//#region src/runtime/provider-placement.ts
|
|
5917
6025
|
const placementMetadataKey = "runtimeProviderPlacement";
|
|
@@ -6618,7 +6726,14 @@ async function startRetainedRun(options) {
|
|
|
6618
6726
|
assertRequestedInteractionCapabilities(options.provider.name, options.turn.interactions, providerCapabilities);
|
|
6619
6727
|
options.environment.signal?.throwIfAborted();
|
|
6620
6728
|
options.turn.signal?.throwIfAborted();
|
|
6621
|
-
|
|
6729
|
+
let environment;
|
|
6730
|
+
if (options.existingEnvironmentId !== void 0) {
|
|
6731
|
+
assertStableText(options.existingEnvironmentId, "retained environment id");
|
|
6732
|
+
const existing = await options.provider.get(options.existingEnvironmentId);
|
|
6733
|
+
if (!existing || existing.id !== options.existingEnvironmentId || existing.provider !== options.provider.name) throw new Error("retained provider environment is unavailable or has another identity");
|
|
6734
|
+
await assertRetainedEnvironmentOwnership(options.provider, existing.id, options.environment.idempotencyKey);
|
|
6735
|
+
environment = existing;
|
|
6736
|
+
} else environment = await options.provider.create({
|
|
6622
6737
|
...options.environment,
|
|
6623
6738
|
metadata: retainedEnvironmentMetadata(options.environment.metadata, options.environment.idempotencyKey)
|
|
6624
6739
|
});
|
|
@@ -6627,6 +6742,7 @@ async function startRetainedRun(options) {
|
|
|
6627
6742
|
capabilities = retainedCapabilitiesForEnvironment(options.provider.name, providerCapabilities, environment);
|
|
6628
6743
|
assertRequestedInteractionCapabilities(options.provider.name, options.turn.interactions, capabilities);
|
|
6629
6744
|
} catch (error) {
|
|
6745
|
+
if (options.existingEnvironmentId !== void 0) throw error;
|
|
6630
6746
|
try {
|
|
6631
6747
|
await environment.destroy?.();
|
|
6632
6748
|
} catch (cleanupError) {
|
|
@@ -6635,6 +6751,7 @@ async function startRetainedRun(options) {
|
|
|
6635
6751
|
throw error;
|
|
6636
6752
|
}
|
|
6637
6753
|
if (!environment.dispatch || !environment.session) {
|
|
6754
|
+
if (options.existingEnvironmentId !== void 0) throw new Error(`provider "${options.provider.name}" does not expose detached session control`);
|
|
6638
6755
|
try {
|
|
6639
6756
|
await environment.destroy?.();
|
|
6640
6757
|
} catch (cleanupError) {
|
|
@@ -6652,7 +6769,8 @@ async function startRetainedRun(options) {
|
|
|
6652
6769
|
identity,
|
|
6653
6770
|
onAdmission: options.onAdmission,
|
|
6654
6771
|
capabilities,
|
|
6655
|
-
now: options.now
|
|
6772
|
+
now: options.now,
|
|
6773
|
+
preserveEnvironment: options.existingEnvironmentId !== void 0
|
|
6656
6774
|
});
|
|
6657
6775
|
}
|
|
6658
6776
|
/**
|
|
@@ -6693,7 +6811,8 @@ async function startRetainedRunInEnvironment(options) {
|
|
|
6693
6811
|
identity,
|
|
6694
6812
|
onAdmission: options.onAdmission,
|
|
6695
6813
|
capabilities,
|
|
6696
|
-
now: options.now
|
|
6814
|
+
now: options.now,
|
|
6815
|
+
preserveEnvironment: true
|
|
6697
6816
|
});
|
|
6698
6817
|
}
|
|
6699
6818
|
async function assertRetainedEnvironmentOwnership(provider, environmentId, idempotencyKey) {
|
|
@@ -6714,7 +6833,7 @@ async function dispatchRetainedRun(options) {
|
|
|
6714
6833
|
executionId: identity.executionId
|
|
6715
6834
|
});
|
|
6716
6835
|
const destroyIfCreated = async (cause) => {
|
|
6717
|
-
if (environment.creation !== "created") throw cause;
|
|
6836
|
+
if (options.preserveEnvironment || environment.creation !== "created") throw cause;
|
|
6718
6837
|
try {
|
|
6719
6838
|
await environment.destroy?.();
|
|
6720
6839
|
} catch (cleanupError) {
|
|
@@ -6851,6 +6970,7 @@ function retainedRunIntent(options, identity, contextTransfer) {
|
|
|
6851
6970
|
kind: "retained-run-intent.v1",
|
|
6852
6971
|
provider: options.provider.name,
|
|
6853
6972
|
idempotencyKey: options.environment.idempotencyKey,
|
|
6973
|
+
...options.existingEnvironmentId === void 0 ? {} : { existingEnvironmentId: options.existingEnvironmentId },
|
|
6854
6974
|
turnId: options.turn.turnId,
|
|
6855
6975
|
sessionId: identity.sessionId,
|
|
6856
6976
|
executionId: identity.executionId,
|
|
@@ -7545,18 +7665,20 @@ function providerAsExecutor(provider, options = {}) {
|
|
|
7545
7665
|
};
|
|
7546
7666
|
}
|
|
7547
7667
|
function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
7548
|
-
const controller =
|
|
7668
|
+
const controller = new AbortController();
|
|
7669
|
+
const node = ctx.node === void 0 ? void 0 : detachedSnapshot(ctx.node, "provider executor node");
|
|
7549
7670
|
let environment;
|
|
7550
7671
|
let artifact;
|
|
7551
7672
|
let retained;
|
|
7552
7673
|
let pending = false;
|
|
7674
|
+
let harnessTranscript = harnessTranscriptUnavailable("execution-never-started");
|
|
7553
7675
|
const retention = retainedExecutorContext(ctx);
|
|
7554
7676
|
let destroyed = false;
|
|
7555
7677
|
const runtime = options.runtime ?? provider.name;
|
|
7556
7678
|
const createProfile = options.profileForCreate?.(profile) ?? profile;
|
|
7557
7679
|
if (placement && canonicalAgentProfileDigest(createProfile) !== canonicalAgentProfileDigest(profile)) throw new ValidationError("provider placement: profileForCreate cannot change the selected profile");
|
|
7558
|
-
const executionId = retention?.executionId ??
|
|
7559
|
-
const attemptId =
|
|
7680
|
+
const executionId = retention?.executionId ?? node?.nodeId ?? `provider-run-${randomUUID()}`;
|
|
7681
|
+
const attemptId = node?.attemptId ?? newExecutionAttemptId(executionId);
|
|
7560
7682
|
const trace = createPushTraceSource({ runId: executionId });
|
|
7561
7683
|
const providerModel = concreteProfileModel(createProfile);
|
|
7562
7684
|
const tokenLimits = enforceTokenLimits(profileModelExecutionSettings(createProfile, `providerAsExecutor(${provider.name})`).tokenLimits, "provider", `providerAsExecutor(${provider.name})`);
|
|
@@ -7578,7 +7700,7 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
7578
7700
|
plan: {
|
|
7579
7701
|
kind: "agent-environment",
|
|
7580
7702
|
provider: provider.name,
|
|
7581
|
-
destroyOnSettle: options.destroyOnSettle ?? true,
|
|
7703
|
+
destroyOnSettle: retention?.preserveEnvironment ? false : options.destroyOnSettle ?? true,
|
|
7582
7704
|
requireTerminalEvent: options.requireTerminalEvent ?? true,
|
|
7583
7705
|
tokenLimits,
|
|
7584
7706
|
...placement ? { placement } : {}
|
|
@@ -7603,42 +7725,51 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
7603
7725
|
}
|
|
7604
7726
|
};
|
|
7605
7727
|
let executor;
|
|
7606
|
-
const run = (task, signal, recovering = false)
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
execution
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7728
|
+
const run = async function* (task, signal, recovering = false) {
|
|
7729
|
+
const linked = linkAbort(ctx.signal, signal, controller.signal);
|
|
7730
|
+
try {
|
|
7731
|
+
yield* streamProviderExecutor({
|
|
7732
|
+
provider,
|
|
7733
|
+
profile,
|
|
7734
|
+
createProfile,
|
|
7735
|
+
task,
|
|
7736
|
+
signal: linked.signal,
|
|
7737
|
+
...node === void 0 ? {} : { node },
|
|
7738
|
+
options,
|
|
7739
|
+
retention,
|
|
7740
|
+
executionId,
|
|
7741
|
+
trace,
|
|
7742
|
+
recovering,
|
|
7743
|
+
onRetained: (handle) => {
|
|
7744
|
+
retained = handle;
|
|
7745
|
+
},
|
|
7746
|
+
onPending: (value) => {
|
|
7747
|
+
pending = value;
|
|
7748
|
+
},
|
|
7749
|
+
onEnvironment: (env) => {
|
|
7750
|
+
environment = env;
|
|
7751
|
+
if (harnessTranscript.status === "unavailable" && harnessTranscript.reason === "execution-never-started") harnessTranscript = harnessTranscriptUnavailable("capture-did-not-run");
|
|
7752
|
+
finalizeRuntimeOwnedPendingExecutor(executor, {
|
|
7753
|
+
...plannedDeclaration,
|
|
7754
|
+
execution: {
|
|
7755
|
+
kind: "environment",
|
|
7756
|
+
id: env.id
|
|
7757
|
+
}
|
|
7758
|
+
}, plannedBinding);
|
|
7759
|
+
},
|
|
7760
|
+
onArtifact: (next) => {
|
|
7761
|
+
artifact = next;
|
|
7762
|
+
},
|
|
7763
|
+
onHarnessTranscript: (next) => {
|
|
7764
|
+
harnessTranscript = next;
|
|
7765
|
+
},
|
|
7766
|
+
onDestroyed: () => {
|
|
7767
|
+
destroyed = true;
|
|
7768
|
+
}
|
|
7769
|
+
});
|
|
7770
|
+
} finally {
|
|
7771
|
+
linked.release();
|
|
7772
|
+
}
|
|
7642
7773
|
};
|
|
7643
7774
|
executor = {
|
|
7644
7775
|
runtime,
|
|
@@ -7717,7 +7848,8 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
7717
7848
|
if (!artifact) throw new ValidationError(`providerAsExecutor(${provider.name}): resultArtifact() read before stream drained`);
|
|
7718
7849
|
return artifact;
|
|
7719
7850
|
},
|
|
7720
|
-
traceSource: () => trace.source
|
|
7851
|
+
traceSource: () => trace.source,
|
|
7852
|
+
harnessTranscript: () => harnessTranscript
|
|
7721
7853
|
};
|
|
7722
7854
|
return attestRuntimeOwnedPendingExecutor(executor, runtime, plannedDeclaration, plannedBinding);
|
|
7723
7855
|
}
|
|
@@ -7730,7 +7862,7 @@ function admittedEnvironmentId(retention) {
|
|
|
7730
7862
|
}
|
|
7731
7863
|
async function* streamProviderExecutor(args) {
|
|
7732
7864
|
const started = Date.now();
|
|
7733
|
-
const linked =
|
|
7865
|
+
const linked = args.signal;
|
|
7734
7866
|
const defaultTurn = taskToTurnInput(args.task, linked);
|
|
7735
7867
|
let turn = providerTurnWithDefaults(providerTurnDefaults(args.options.promptOptions, `providerAsExecutor(${args.provider.name})`), args.options.taskToTurn?.(args.task, args.profile, defaultTurn) ?? defaultTurn, linked);
|
|
7736
7868
|
if (args.options.defaults?.metadata?.runtimeProviderPlacement !== void 0) {
|
|
@@ -7814,10 +7946,10 @@ async function* streamProviderExecutor(args) {
|
|
|
7814
7946
|
}
|
|
7815
7947
|
if ((args.options.requireTerminalEvent ?? true) && !terminal) throw new ValidationError(`providerAsExecutor(${args.provider.name}): stream ended without a terminal result/done/status event`);
|
|
7816
7948
|
yield { kind: "iteration" };
|
|
7817
|
-
const
|
|
7949
|
+
const harnessTranscript = await captureHarnessTranscript(environment, args.profile.harness, linked);
|
|
7950
|
+
args.onHarnessTranscript(harnessTranscript);
|
|
7818
7951
|
const result = {
|
|
7819
7952
|
...resultFromEvents(archive.events(), text),
|
|
7820
|
-
nativeSession,
|
|
7821
7953
|
...archive.superseded > 0 ? { supersededPartUpdates: archive.superseded } : {},
|
|
7822
7954
|
...explicitFailure ? { outcome: outcomeTracker.finish() } : {}
|
|
7823
7955
|
};
|
|
@@ -7832,6 +7964,7 @@ async function* streamProviderExecutor(args) {
|
|
|
7832
7964
|
};
|
|
7833
7965
|
const verdict = await args.options.validator?.validate(result, {
|
|
7834
7966
|
iteration: 0,
|
|
7967
|
+
...args.node === void 0 ? {} : { node: args.node },
|
|
7835
7968
|
box: environmentAsSandboxInstance(environment, { requireTerminalEvent: args.options.requireTerminalEvent ?? true }),
|
|
7836
7969
|
signal: linked
|
|
7837
7970
|
});
|
|
@@ -7851,8 +7984,9 @@ async function* streamProviderExecutor(args) {
|
|
|
7851
7984
|
} catch (error) {
|
|
7852
7985
|
failure = source.retained ? new RetainedExecutionPendingError(error) : error;
|
|
7853
7986
|
failed = true;
|
|
7987
|
+
args.onHarnessTranscript(await captureHarnessTranscript(environment, args.profile.harness, linked));
|
|
7854
7988
|
} finally {
|
|
7855
|
-
if ((!source.retained || settled !== void 0 && !failed) && (args.options.destroyOnSettle ?? true)) try {
|
|
7989
|
+
if ((!source.retained || settled !== void 0 && !failed) && !(source.retained && args.retention?.preserveEnvironment) && (args.options.destroyOnSettle ?? true)) try {
|
|
7856
7990
|
await environment.destroy?.();
|
|
7857
7991
|
args.onDestroyed();
|
|
7858
7992
|
} catch (error) {
|
|
@@ -7943,16 +8077,26 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
7943
8077
|
admitted = true;
|
|
7944
8078
|
args.onPending(true);
|
|
7945
8079
|
};
|
|
8080
|
+
const priorSession = retention.priorSession;
|
|
8081
|
+
const environmentKey = priorSession?.idempotencyKey ?? `runtime:${args.executionId}`;
|
|
8082
|
+
const turnId = `${args.executionId}:turn:0`;
|
|
7946
8083
|
const material = {
|
|
7947
8084
|
environment: {
|
|
7948
8085
|
...args.options.defaults,
|
|
7949
8086
|
profile: args.createProfile,
|
|
7950
|
-
idempotencyKey:
|
|
8087
|
+
idempotencyKey: environmentKey,
|
|
7951
8088
|
signal
|
|
7952
8089
|
},
|
|
7953
8090
|
turn: {
|
|
7954
8091
|
...turn,
|
|
7955
|
-
turnId
|
|
8092
|
+
turnId
|
|
8093
|
+
},
|
|
8094
|
+
...priorSession === void 0 ? {} : {
|
|
8095
|
+
existingEnvironmentId: priorSession.environmentId,
|
|
8096
|
+
identity: {
|
|
8097
|
+
sessionId: priorSession.sessionId,
|
|
8098
|
+
executionId: mintRetainedIdentity(environmentKey, turnId).executionId
|
|
8099
|
+
}
|
|
7956
8100
|
}
|
|
7957
8101
|
};
|
|
7958
8102
|
try {
|
|
@@ -7973,7 +8117,12 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
7973
8117
|
if (!reconnected) throw new Error("retained provider environment is unavailable");
|
|
7974
8118
|
handle = reconnected;
|
|
7975
8119
|
} else if (args.recovering && environmentAdmission?.phase === "environment") {
|
|
7976
|
-
let recovered = await recoverRetainedRun({
|
|
8120
|
+
let recovered = material.existingEnvironmentId !== void 0 && intent?.phase === "intent" ? await recoverRetainedRun({
|
|
8121
|
+
provider: args.provider,
|
|
8122
|
+
admission: intent,
|
|
8123
|
+
replay: material,
|
|
8124
|
+
onAdmission
|
|
8125
|
+
}) : await recoverRetainedRun({
|
|
7977
8126
|
provider: args.provider,
|
|
7978
8127
|
environmentId: environmentAdmission.environmentId,
|
|
7979
8128
|
sessionId: environmentAdmission.sessionId,
|
|
@@ -8016,34 +8165,53 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
8016
8165
|
if (!environment) throw new Error("retained provider environment is unavailable");
|
|
8017
8166
|
const session = exactSession(environment, handle.controlRef).session;
|
|
8018
8167
|
async function* events() {
|
|
8019
|
-
let iterator;
|
|
8020
8168
|
let observationFailure;
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8169
|
+
let lastReplayPosition;
|
|
8170
|
+
let sawTerminal = false;
|
|
8171
|
+
const drain = async function* (open) {
|
|
8172
|
+
let iterator;
|
|
8173
|
+
let failed = false;
|
|
8174
|
+
try {
|
|
8175
|
+
iterator = open()[Symbol.asyncIterator]();
|
|
8176
|
+
} catch (error) {
|
|
8177
|
+
if (signal.aborted) throw error;
|
|
8178
|
+
observationFailure = { error };
|
|
8179
|
+
return false;
|
|
8180
|
+
}
|
|
8181
|
+
try {
|
|
8182
|
+
while (true) {
|
|
8183
|
+
let next;
|
|
8184
|
+
try {
|
|
8185
|
+
next = await awaitAbortable$1(Promise.resolve().then(() => iterator.next()), signal);
|
|
8186
|
+
} catch (error) {
|
|
8187
|
+
if (signal.aborted) throw error;
|
|
8188
|
+
observationFailure = { error };
|
|
8189
|
+
failed = true;
|
|
8190
|
+
break;
|
|
8191
|
+
}
|
|
8192
|
+
if (next.done) break;
|
|
8193
|
+
assertEventBinding(next.value, handle.controlRef);
|
|
8194
|
+
if (next.value.id !== void 0) lastReplayPosition = next.value.id;
|
|
8195
|
+
if (isTerminalEnvironmentEvent(next.value)) sawTerminal = true;
|
|
8196
|
+
yield next.value;
|
|
8039
8197
|
}
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8198
|
+
} finally {
|
|
8199
|
+
if (signal.aborted || failed) Promise.resolve().then(() => iterator?.return?.()).catch(() => void 0);
|
|
8200
|
+
else await iterator?.return?.();
|
|
8043
8201
|
}
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8202
|
+
return !failed;
|
|
8203
|
+
};
|
|
8204
|
+
if (!(yield* drain(() => session.events({
|
|
8205
|
+
executionId: handle.controlRef.executionId,
|
|
8206
|
+
signal
|
|
8207
|
+
}))) && !sawTerminal && lastReplayPosition !== void 0) {
|
|
8208
|
+
const firstFailure = observationFailure;
|
|
8209
|
+
observationFailure = void 0;
|
|
8210
|
+
if (!(yield* drain(() => session.events({
|
|
8211
|
+
executionId: handle.controlRef.executionId,
|
|
8212
|
+
since: lastReplayPosition,
|
|
8213
|
+
signal
|
|
8214
|
+
})))) observationFailure = firstFailure;
|
|
8047
8215
|
}
|
|
8048
8216
|
let result;
|
|
8049
8217
|
try {
|
|
@@ -15021,17 +15189,6 @@ function describeLeakedReservation(leak) {
|
|
|
15021
15189
|
return parts.join(", ");
|
|
15022
15190
|
}
|
|
15023
15191
|
//#endregion
|
|
15024
|
-
//#region src/durable/content-address.ts
|
|
15025
|
-
/** Stable content address shared by result and trace artifacts. */
|
|
15026
|
-
function contentAddress(artifact) {
|
|
15027
|
-
return `sha256:${createHash("sha256").update(stableStringify(artifact), "utf-8").digest("hex")}`;
|
|
15028
|
-
}
|
|
15029
|
-
function stableStringify(value) {
|
|
15030
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
15031
|
-
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
15032
|
-
return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(",")}}`;
|
|
15033
|
-
}
|
|
15034
|
-
//#endregion
|
|
15035
15192
|
//#region src/runtime/supervise/trace-evidence.ts
|
|
15036
15193
|
/**
|
|
15037
15194
|
* Durable structured tool evidence for supervised workers.
|
|
@@ -15151,27 +15308,6 @@ function runtimeOwnedNestedDriverTreeRoot(owner, parentTreeRoot, driverNodeId) {
|
|
|
15151
15308
|
//#endregion
|
|
15152
15309
|
//#region src/durable/spawn-journal.ts
|
|
15153
15310
|
/**
|
|
15154
|
-
*
|
|
15155
|
-
* Event-sourced spawn journal for the recursive execution atom (build steps 3 + 7).
|
|
15156
|
-
*
|
|
15157
|
-
* The supervision tree is journaled as an append-only event log: every `spawned`,
|
|
15158
|
-
* `settled`, and `cancelled` is recorded AFTER it is observed-committed (never
|
|
15159
|
-
* speculative), mirroring `ConversationJournal`'s begin/append/load shape. The log
|
|
15160
|
-
* holds only the THIN decision record — ids, parentage, budget, the spend a decision
|
|
15161
|
-
* consumed, and a content-addressed `outRef`. The payloads the driver branched on
|
|
15162
|
-
* (the `out` artifacts) live in a separate `ResultBlobStore`, keyed by `outRef`, so
|
|
15163
|
-
* the journal stays small (decisions) and replay rehydrates the exact `Settled` from
|
|
15164
|
-
* the blob store (evidence). This is the decision/payload split the replay argument
|
|
15165
|
-
* rests on (B1/B2).
|
|
15166
|
-
*
|
|
15167
|
-
* Replay determinism (B2): `seq` is the monotonic cursor order `scope.next()` yielded
|
|
15168
|
-
* each settlement — NOT wall-clock. `replaySpawnTree` sorts strictly by `seq` before
|
|
15169
|
-
* touching the blob store, so the order in which rehydration `get`s resolve can never
|
|
15170
|
-
* reorder the replayed `Settled[]`; the result is identical regardless of blob latency.
|
|
15171
|
-
*
|
|
15172
|
-
* @stable
|
|
15173
|
-
*/
|
|
15174
|
-
/**
|
|
15175
15311
|
* Mint the content-addressed `outRef` for a result artifact: `sha256:<hex>` over a
|
|
15176
15312
|
* stable JSON encoding. Producers call this to derive the `outRef` they journal and
|
|
15177
15313
|
* `put`; the FS/in-mem stores re-derive it on `put` to verify the supplied ref
|
|
@@ -15284,14 +15420,17 @@ var InMemorySpawnJournal = class {
|
|
|
15284
15420
|
}
|
|
15285
15421
|
this.trees.set(root, {
|
|
15286
15422
|
begunAt: at,
|
|
15287
|
-
events: []
|
|
15423
|
+
events: [],
|
|
15424
|
+
index: new SpawnEventIndex(root)
|
|
15288
15425
|
});
|
|
15289
15426
|
}
|
|
15290
15427
|
async appendEvent(root, ev) {
|
|
15291
15428
|
const tree = this.trees.get(root);
|
|
15292
15429
|
if (!tree) throw new Error(`appendEvent called for unknown spawn tree '${root}'; call beginTree first`);
|
|
15293
|
-
|
|
15294
|
-
tree.
|
|
15430
|
+
const event = detachedSnapshot(ev, "spawn event");
|
|
15431
|
+
tree.index.assert(event);
|
|
15432
|
+
tree.events.push(event);
|
|
15433
|
+
tree.index.add(event);
|
|
15295
15434
|
}
|
|
15296
15435
|
};
|
|
15297
15436
|
/**
|
|
@@ -15306,6 +15445,7 @@ var InMemorySpawnJournal = class {
|
|
|
15306
15445
|
var FileSpawnJournal = class {
|
|
15307
15446
|
path;
|
|
15308
15447
|
appendTail = Promise.resolve();
|
|
15448
|
+
appendIndex;
|
|
15309
15449
|
constructor(path) {
|
|
15310
15450
|
this.path = path;
|
|
15311
15451
|
}
|
|
@@ -15320,12 +15460,14 @@ var FileSpawnJournal = class {
|
|
|
15320
15460
|
}
|
|
15321
15461
|
let begun = false;
|
|
15322
15462
|
const events = [];
|
|
15463
|
+
const index = new SpawnEventIndex(root);
|
|
15323
15464
|
for (const record of parseCommittedJsonLines(text, this.path)) {
|
|
15324
15465
|
if (record.root !== root) continue;
|
|
15325
15466
|
if (record.kind === "begin") begun = true;
|
|
15326
15467
|
else {
|
|
15327
15468
|
if (!begun) throw new Error(`spawn journal corrupted: event for tree '${root}' precedes its begin record`);
|
|
15328
|
-
|
|
15469
|
+
index.assert(record.event);
|
|
15470
|
+
index.add(record.event);
|
|
15329
15471
|
events.push(record.event);
|
|
15330
15472
|
}
|
|
15331
15473
|
}
|
|
@@ -15333,41 +15475,73 @@ var FileSpawnJournal = class {
|
|
|
15333
15475
|
}
|
|
15334
15476
|
async beginTree(root, at) {
|
|
15335
15477
|
return this.serializeAppend(async () => {
|
|
15336
|
-
const
|
|
15478
|
+
const state = await this.validationIndex();
|
|
15479
|
+
const existing = state.trees.get(root);
|
|
15337
15480
|
if (existing) {
|
|
15338
|
-
if (existing !== at) throw new Error(`spawn tree '${root}' already begun in ${this.path} at ${existing}; refusing to overwrite with ${at}`);
|
|
15481
|
+
if (existing.begunAt !== at) throw new Error(`spawn tree '${root}' already begun in ${this.path} at ${existing.begunAt}; refusing to overwrite with ${at}`);
|
|
15339
15482
|
return;
|
|
15340
15483
|
}
|
|
15341
|
-
await this.writeRecord({
|
|
15484
|
+
state.stamp = await this.writeRecord({
|
|
15342
15485
|
kind: "begin",
|
|
15343
15486
|
root,
|
|
15344
15487
|
at
|
|
15345
15488
|
});
|
|
15489
|
+
state.trees.set(root, {
|
|
15490
|
+
begunAt: at,
|
|
15491
|
+
index: new SpawnEventIndex(root)
|
|
15492
|
+
});
|
|
15346
15493
|
});
|
|
15347
15494
|
}
|
|
15348
15495
|
async appendEvent(root, ev) {
|
|
15349
15496
|
const event = detachedSnapshot(ev, "spawn event");
|
|
15350
15497
|
return this.serializeAppend(async () => {
|
|
15351
|
-
const
|
|
15352
|
-
|
|
15353
|
-
|
|
15354
|
-
|
|
15498
|
+
const state = await this.validationIndex();
|
|
15499
|
+
const tree = state.trees.get(root);
|
|
15500
|
+
if (tree === void 0) throw new Error(`appendEvent called for unknown spawn tree '${root}'; call beginTree first`);
|
|
15501
|
+
tree.index.assert(event);
|
|
15502
|
+
state.stamp = await this.writeRecord({
|
|
15355
15503
|
kind: "event",
|
|
15356
15504
|
root,
|
|
15357
15505
|
event
|
|
15358
15506
|
});
|
|
15507
|
+
tree.index.add(event);
|
|
15359
15508
|
});
|
|
15360
15509
|
}
|
|
15361
|
-
async
|
|
15510
|
+
async validationIndex() {
|
|
15511
|
+
const fs = await import("node:fs/promises");
|
|
15512
|
+
const stamp = await this.fileStamp();
|
|
15513
|
+
if (this.appendIndex && this.appendIndex.stamp === stamp) return this.appendIndex;
|
|
15514
|
+
this.appendIndex = void 0;
|
|
15515
|
+
const trees = /* @__PURE__ */ new Map();
|
|
15516
|
+
if (stamp !== void 0) {
|
|
15517
|
+
const text = await fs.readFile(this.path, "utf8");
|
|
15518
|
+
if (await this.fileStamp() !== stamp) throw new Error("spawn journal changed while rebuilding its append index");
|
|
15519
|
+
for (const record of parseCommittedJsonLines(text, this.path)) if (record.kind === "begin") {
|
|
15520
|
+
if (!trees.has(record.root)) trees.set(record.root, {
|
|
15521
|
+
begunAt: record.at,
|
|
15522
|
+
index: new SpawnEventIndex(record.root)
|
|
15523
|
+
});
|
|
15524
|
+
} else {
|
|
15525
|
+
const tree = trees.get(record.root);
|
|
15526
|
+
if (!tree) throw new Error(`spawn journal corrupted: event for tree '${record.root}' precedes its begin record`);
|
|
15527
|
+
tree.index.assert(record.event);
|
|
15528
|
+
tree.index.add(record.event);
|
|
15529
|
+
}
|
|
15530
|
+
}
|
|
15531
|
+
this.appendIndex = {
|
|
15532
|
+
stamp,
|
|
15533
|
+
trees
|
|
15534
|
+
};
|
|
15535
|
+
return this.appendIndex;
|
|
15536
|
+
}
|
|
15537
|
+
async fileStamp() {
|
|
15362
15538
|
const fs = await import("node:fs/promises");
|
|
15363
|
-
let text;
|
|
15364
15539
|
try {
|
|
15365
|
-
|
|
15366
|
-
} catch (
|
|
15367
|
-
if (isNoEntError(
|
|
15368
|
-
throw
|
|
15540
|
+
return journalFileStamp(await fs.stat(this.path, { bigint: true }));
|
|
15541
|
+
} catch (error) {
|
|
15542
|
+
if (isNoEntError(error)) return void 0;
|
|
15543
|
+
throw error;
|
|
15369
15544
|
}
|
|
15370
|
-
for (const record of parseCommittedJsonLines(text, this.path)) if (record.root === root && record.kind === "begin") return record.at;
|
|
15371
15545
|
}
|
|
15372
15546
|
async serializeAppend(operation) {
|
|
15373
15547
|
const append = this.appendTail.then(operation);
|
|
@@ -15377,17 +15551,29 @@ var FileSpawnJournal = class {
|
|
|
15377
15551
|
async writeRecord(record) {
|
|
15378
15552
|
const fs = await import("node:fs/promises");
|
|
15379
15553
|
const path = await import("node:path");
|
|
15380
|
-
await fs.mkdir(path.dirname(this.path), { recursive: true });
|
|
15381
|
-
const needsSeparator = await prepareJsonlAppend(this.path);
|
|
15382
|
-
const fh = await fs.open(this.path, "a");
|
|
15383
15554
|
try {
|
|
15384
|
-
await
|
|
15385
|
-
await
|
|
15386
|
-
|
|
15387
|
-
|
|
15555
|
+
await fs.mkdir(path.dirname(this.path), { recursive: true });
|
|
15556
|
+
const needsSeparator = await prepareJsonlAppend(this.path);
|
|
15557
|
+
const fh = await fs.open(this.path, "a");
|
|
15558
|
+
try {
|
|
15559
|
+
await writeAllBytes(fh, `${needsSeparator ? "\n" : ""}${JSON.stringify(record)}\n`);
|
|
15560
|
+
await fh.sync();
|
|
15561
|
+
const stamp = journalFileStamp(await fh.stat({ bigint: true }));
|
|
15562
|
+
if (await this.fileStamp() !== stamp) throw new Error("spawn journal changed while acknowledging its append");
|
|
15563
|
+
return stamp;
|
|
15564
|
+
} finally {
|
|
15565
|
+
await fh.close();
|
|
15566
|
+
}
|
|
15567
|
+
} catch (error) {
|
|
15568
|
+
this.appendIndex = void 0;
|
|
15569
|
+
throw error;
|
|
15388
15570
|
}
|
|
15389
15571
|
}
|
|
15390
15572
|
};
|
|
15573
|
+
/** Detect replacement, truncation, and same-size edits; this is not a cross-process write lock. */
|
|
15574
|
+
function journalFileStamp(stat) {
|
|
15575
|
+
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
15576
|
+
}
|
|
15391
15577
|
/**
|
|
15392
15578
|
* Load every journal tree owned by one recursive supervision run and flatten its nodes/events.
|
|
15393
15579
|
*
|
|
@@ -15654,79 +15840,104 @@ function servedIdentityParts(model) {
|
|
|
15654
15840
|
snapshot
|
|
15655
15841
|
};
|
|
15656
15842
|
}
|
|
15657
|
-
/**
|
|
15658
|
-
|
|
15659
|
-
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15672
|
-
if (
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
15686
|
-
|
|
15687
|
-
|
|
15688
|
-
|
|
15689
|
-
|
|
15690
|
-
|
|
15691
|
-
|
|
15692
|
-
|
|
15693
|
-
|
|
15694
|
-
|
|
15695
|
-
|
|
15696
|
-
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
|
|
15702
|
-
|
|
15703
|
-
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
|
|
15707
|
-
|
|
15708
|
-
|
|
15709
|
-
|
|
15710
|
-
|
|
15711
|
-
|
|
15712
|
-
|
|
15713
|
-
|
|
15714
|
-
|
|
15715
|
-
|
|
15716
|
-
|
|
15717
|
-
|
|
15718
|
-
|
|
15719
|
-
|
|
15720
|
-
|
|
15721
|
-
if (
|
|
15722
|
-
|
|
15723
|
-
|
|
15724
|
-
|
|
15725
|
-
|
|
15843
|
+
/** One validation implementation for memory, durable append, and cold replay. */
|
|
15844
|
+
var SpawnEventIndex = class {
|
|
15845
|
+
root;
|
|
15846
|
+
nodes = /* @__PURE__ */ new Map();
|
|
15847
|
+
cursors = /* @__PURE__ */ new Set();
|
|
15848
|
+
constructor(root) {
|
|
15849
|
+
this.root = root;
|
|
15850
|
+
}
|
|
15851
|
+
assert(event) {
|
|
15852
|
+
const node = this.nodes.get(event.id);
|
|
15853
|
+
this.assertRetained(node, event);
|
|
15854
|
+
if (event.kind === "materialized") {
|
|
15855
|
+
if (node?.materialized) throw new Error(`spawn journal corrupted: duplicate materialization receipt for node '${event.id}' in tree '${this.root}'`);
|
|
15856
|
+
if (!node?.spawned) throw new Error(`spawn journal corrupted: materialization for node '${event.id}' precedes its spawn in tree '${this.root}'`);
|
|
15857
|
+
}
|
|
15858
|
+
if (event.kind === "execution-bound") {
|
|
15859
|
+
if (node?.bindings.has(event.binding.attemptId)) throw new Error(`spawn journal corrupted: duplicate execution binding for node '${event.id}' attempt '${event.binding.attemptId}' in tree '${this.root}'`);
|
|
15860
|
+
if (!node?.materialized) throw new Error(`spawn journal corrupted: execution binding for node '${event.id}' precedes materialization in tree '${this.root}'`);
|
|
15861
|
+
}
|
|
15862
|
+
if (!outsideCursorNamespace(event) && this.cursors.has(event.seq)) throw new Error(`spawn journal corrupted: duplicate cursor seq ${event.seq} in tree '${this.root}'; the cursor order replay relies on is not unique`);
|
|
15863
|
+
}
|
|
15864
|
+
/** Called only after validation and, for the file writer, a successful durable append. */
|
|
15865
|
+
add(event) {
|
|
15866
|
+
if (!outsideCursorNamespace(event)) this.cursors.add(event.seq);
|
|
15867
|
+
if (event.kind !== "spawned" && event.kind !== "materialized" && event.kind !== "execution-bound" && event.kind !== "execution-input" && event.kind !== "execution-admitted" && event.kind !== "execution-result" && !closesCursorSlot(event)) return;
|
|
15868
|
+
let node = this.nodes.get(event.id);
|
|
15869
|
+
if (!node) {
|
|
15870
|
+
node = {
|
|
15871
|
+
spawned: false,
|
|
15872
|
+
closed: false,
|
|
15873
|
+
materialized: false,
|
|
15874
|
+
bindings: /* @__PURE__ */ new Set(),
|
|
15875
|
+
inputs: /* @__PURE__ */ new Set(),
|
|
15876
|
+
input: false,
|
|
15877
|
+
result: false,
|
|
15878
|
+
admissions: /* @__PURE__ */ new Map()
|
|
15879
|
+
};
|
|
15880
|
+
this.nodes.set(event.id, node);
|
|
15881
|
+
}
|
|
15882
|
+
if (event.kind === "spawned") node.spawned = true;
|
|
15883
|
+
else if (event.kind === "materialized") node.materialized = true;
|
|
15884
|
+
else if (event.kind === "execution-bound") node.bindings.add(event.binding.attemptId);
|
|
15885
|
+
else if (event.kind === "execution-input") {
|
|
15886
|
+
node.inputs.add(event.seq);
|
|
15887
|
+
node.input = true;
|
|
15888
|
+
node.result = false;
|
|
15889
|
+
node.admissions.clear();
|
|
15890
|
+
} else if (event.kind === "execution-admitted") node.admissions.set(event.admission.phase, event.admission);
|
|
15891
|
+
else if (event.kind === "execution-result") node.result = true;
|
|
15892
|
+
if (closesCursorSlot(event)) node.closed = true;
|
|
15893
|
+
}
|
|
15894
|
+
assertRetained(node, event) {
|
|
15895
|
+
if (event.kind !== "execution-input" && event.kind !== "execution-admitted" && event.kind !== "execution-result") return;
|
|
15896
|
+
function fail(reason) {
|
|
15897
|
+
throw new Error(`spawn journal corrupted: retained execution '${event.id}' ${reason}`);
|
|
15898
|
+
}
|
|
15899
|
+
if (!node?.spawned) fail("precedes its spawn");
|
|
15900
|
+
if (node.closed) fail("follows its terminal settlement");
|
|
15901
|
+
if (event.kind === "execution-input") {
|
|
15902
|
+
if (!/^sha256:[0-9a-f]{64}$/.test(event.taskRef)) fail("has an invalid task reference");
|
|
15903
|
+
if (node.inputs.has(event.seq)) fail("has duplicate input sequence");
|
|
15904
|
+
if (node.input && !node.result) fail("input replaces an unfinished invocation");
|
|
15905
|
+
return;
|
|
15906
|
+
}
|
|
15907
|
+
if (event.kind === "execution-result") {
|
|
15908
|
+
if (node.result) fail("has duplicate result");
|
|
15909
|
+
if (!node.admissions.has("dispatched")) fail("result precedes dispatch");
|
|
15910
|
+
if (!/^sha256:[0-9a-f]{64}$/.test(event.outRef)) fail("has an invalid result reference");
|
|
15911
|
+
assertValidSpend(event.spent, "retained execution result");
|
|
15912
|
+
executorFailureReason(event);
|
|
15913
|
+
return;
|
|
15914
|
+
}
|
|
15915
|
+
const admission = event.admission;
|
|
15916
|
+
if (!admission || ![
|
|
15917
|
+
"intent",
|
|
15918
|
+
"environment",
|
|
15919
|
+
"dispatched"
|
|
15920
|
+
].includes(admission.phase)) fail("has an invalid admission phase");
|
|
15921
|
+
if (node.admissions.has(admission.phase)) fail("has duplicate admission phase");
|
|
15922
|
+
if (node.result) fail("admission follows result");
|
|
15923
|
+
if (!node.input) fail("admission precedes input");
|
|
15924
|
+
if (admission.phase === "intent") {
|
|
15925
|
+
if (node.admissions.size !== 0) fail("intent follows another admission");
|
|
15926
|
+
return;
|
|
15927
|
+
}
|
|
15928
|
+
const intent = node.admissions.get("intent");
|
|
15929
|
+
if (intent?.phase !== "intent") fail("admission precedes intent");
|
|
15930
|
+
if (admission.idempotencyKey !== intent.idempotencyKey || admission.turnId !== intent.turnId) fail("changes its admitted request identity");
|
|
15931
|
+
if (admission.phase === "environment") {
|
|
15932
|
+
if (admission.provider !== intent.provider || admission.sessionId !== intent.sessionId || admission.executionId !== intent.executionId) fail("changes its admitted execution identity");
|
|
15933
|
+
return;
|
|
15934
|
+
}
|
|
15935
|
+
const environment = node.admissions.get("environment");
|
|
15936
|
+
if (environment?.phase !== "environment") fail("dispatch precedes environment");
|
|
15937
|
+
const control = admission.controlRef;
|
|
15938
|
+
if (!control || control.provider !== intent.provider || control.environmentId !== environment.environmentId || control.sessionId !== intent.sessionId || control.executionId !== intent.executionId) fail("dispatch changes its admitted execution identity");
|
|
15726
15939
|
}
|
|
15727
|
-
|
|
15728
|
-
if (events.some((e) => !outsideCursorNamespace(e) && e.seq === ev.seq)) throw new Error(`spawn journal corrupted: duplicate cursor seq ${ev.seq} in tree '${root}'; the cursor order replay relies on is not unique`);
|
|
15729
|
-
}
|
|
15940
|
+
};
|
|
15730
15941
|
/**
|
|
15731
15942
|
* The records that CLOSE a node's cursor slot: a settlement, a cancellation, or a wait being
|
|
15732
15943
|
* woken. The complement question to {@link outsideCursorNamespace}, and the one a resume needs —
|
|
@@ -15886,6 +16097,7 @@ async function replaySpawnTree(journal, blobs, root) {
|
|
|
15886
16097
|
...ev.providerModel === void 0 ? {} : { providerModel: copyProviderModelEvidence(ev.providerModel) },
|
|
15887
16098
|
...budgetViolationOf(ev),
|
|
15888
16099
|
trace,
|
|
16100
|
+
...ev.harnessTranscript === void 0 ? {} : { harnessTranscript: ev.harnessTranscript },
|
|
15889
16101
|
...settlementTime(ev.at),
|
|
15890
16102
|
seq: ev.seq
|
|
15891
16103
|
});
|
|
@@ -15906,6 +16118,7 @@ async function replaySpawnTree(journal, blobs, root) {
|
|
|
15906
16118
|
...ev.providerModel === void 0 ? {} : { providerModel: copyProviderModelEvidence(ev.providerModel) },
|
|
15907
16119
|
...budgetViolationOf(ev),
|
|
15908
16120
|
trace,
|
|
16121
|
+
...ev.harnessTranscript === void 0 ? {} : { harnessTranscript: ev.harnessTranscript },
|
|
15909
16122
|
...settlementTime(ev.at),
|
|
15910
16123
|
seq: ev.seq
|
|
15911
16124
|
});
|
|
@@ -19874,8 +20087,13 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
19874
20087
|
const taskEvent = [...events].reverse().find((event) => event.kind === "execution-input");
|
|
19875
20088
|
const start = taskEvent === void 0 ? 0 : events.indexOf(taskEvent);
|
|
19876
20089
|
const attempt = events.slice(start);
|
|
20090
|
+
const beforeInput = taskEvent === void 0 ? [] : events.slice(0, start);
|
|
20091
|
+
const priorInput = [...beforeInput].reverse().find((event) => event.kind === "execution-input");
|
|
20092
|
+
const priorAttempt = priorInput === void 0 ? [] : beforeInput.slice(beforeInput.indexOf(priorInput));
|
|
19877
20093
|
const admissions = attempt.flatMap((event) => event.kind === "execution-admitted" ? [event.admission] : []);
|
|
19878
20094
|
const acceptedRef = [...attempt].reverse().find((event) => event.kind === "execution-result");
|
|
20095
|
+
const priorResult = [...priorAttempt].reverse().find((event) => event.kind === "execution-result");
|
|
20096
|
+
const priorSession = priorResult?.kind === "execution-result" ? priorAttempt.slice(0, priorAttempt.indexOf(priorResult)).reverse().flatMap((event) => event.kind === "execution-admitted" && event.admission.phase === "environment" ? [event.admission] : [])[0] : void 0;
|
|
19879
20097
|
let sequence = Math.max(0, ...events.map((event) => "seq" in event ? event.seq : 0));
|
|
19880
20098
|
const state = {
|
|
19881
20099
|
args,
|
|
@@ -19886,11 +20104,16 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
19886
20104
|
inputSequence: taskEvent.seq
|
|
19887
20105
|
} : {},
|
|
19888
20106
|
...acceptedRef?.kind === "execution-result" ? { acceptedRef } : {},
|
|
20107
|
+
...priorSession ? { priorSession } : {},
|
|
19889
20108
|
context: {
|
|
19890
20109
|
get executionId() {
|
|
19891
20110
|
if (state.inputSequence === void 0) throw new ValidationError$1("retained owner input was not committed");
|
|
19892
20111
|
return `${args.nodeId}:input:${state.inputSequence}`;
|
|
19893
20112
|
},
|
|
20113
|
+
get priorSession() {
|
|
20114
|
+
return state.priorSession;
|
|
20115
|
+
},
|
|
20116
|
+
preserveEnvironment: true,
|
|
19894
20117
|
admissions,
|
|
19895
20118
|
onAdmission: async (admission) => {
|
|
19896
20119
|
scope.signal.throwIfAborted();
|
|
@@ -19938,6 +20161,56 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
19938
20161
|
function scopeRetainedOwnerContext(scope) {
|
|
19939
20162
|
return owners.get(scope)?.context;
|
|
19940
20163
|
}
|
|
20164
|
+
/** Bind cleanup before replay can return an already accepted owner result. */
|
|
20165
|
+
function bindScopeRetainedOwnerProvider(scope, provider) {
|
|
20166
|
+
const state = owners.get(scope);
|
|
20167
|
+
if (state) state.provider = provider;
|
|
20168
|
+
}
|
|
20169
|
+
/** The existing scope settlement barrier releases the owner's environment after all its turns. */
|
|
20170
|
+
async function releaseScopeRetainedOwnerEnvironment(scope) {
|
|
20171
|
+
const state = owners.get(scope);
|
|
20172
|
+
if (!state?.provider) return [];
|
|
20173
|
+
const { provider, args } = state;
|
|
20174
|
+
const events = await args.journal.loadTree(args.rootId) ?? [];
|
|
20175
|
+
const released = new Set(events.flatMap((event) => event.kind === "environment-teardown" && event.id === args.nodeId && event.provider === provider.name && event.destroyed ? [event.environmentId] : []));
|
|
20176
|
+
const environments = new Set(events.flatMap((event) => event.id === args.nodeId && event.kind === "execution-admitted" && event.admission.phase === "environment" ? [event.admission.environmentId] : []));
|
|
20177
|
+
let unconfirmed = false;
|
|
20178
|
+
for (const environmentId of environments) {
|
|
20179
|
+
if (released.has(environmentId)) continue;
|
|
20180
|
+
let destroyed = false;
|
|
20181
|
+
let detail;
|
|
20182
|
+
try {
|
|
20183
|
+
await runAbortable(async () => {
|
|
20184
|
+
if (!provider.get) throw new Error("provider cannot reconstruct the retained environment");
|
|
20185
|
+
const environment = await provider.get(environmentId);
|
|
20186
|
+
if (environment === null) return;
|
|
20187
|
+
if (environment.id !== environmentId || environment.provider !== provider.name) throw new Error("provider returned another retained environment");
|
|
20188
|
+
if (!environment.destroy) throw new Error("provider cannot destroy the retained environment");
|
|
20189
|
+
await environment.destroy();
|
|
20190
|
+
}, AbortSignal.timeout(3e4), "retained owner cleanup timed out");
|
|
20191
|
+
destroyed = true;
|
|
20192
|
+
} catch {
|
|
20193
|
+
detail = "retained owner environment cleanup was not confirmed";
|
|
20194
|
+
unconfirmed = true;
|
|
20195
|
+
}
|
|
20196
|
+
await args.journal.appendEvent(args.rootId, {
|
|
20197
|
+
kind: "environment-teardown",
|
|
20198
|
+
id: args.nodeId,
|
|
20199
|
+
provider: provider.name,
|
|
20200
|
+
environmentId,
|
|
20201
|
+
destroyed,
|
|
20202
|
+
...detail === void 0 ? {} : { detail },
|
|
20203
|
+
seq: state.nextSequence(),
|
|
20204
|
+
at: new Date(args.now()).toISOString()
|
|
20205
|
+
});
|
|
20206
|
+
}
|
|
20207
|
+
return unconfirmed ? [{
|
|
20208
|
+
id: args.nodeId,
|
|
20209
|
+
label: "scope owner",
|
|
20210
|
+
runtime: provider.name,
|
|
20211
|
+
status: "done"
|
|
20212
|
+
}] : [];
|
|
20213
|
+
}
|
|
19941
20214
|
/** Resume the original backend prompt; rebuilt coordination observations cannot replace it. */
|
|
19942
20215
|
async function prepareScopeRetainedOwnerTask(scope, task) {
|
|
19943
20216
|
const state = owners.get(scope);
|
|
@@ -19955,6 +20228,8 @@ async function prepareScopeRetainedOwnerTask(scope, task) {
|
|
|
19955
20228
|
if (accepted?.kind === "execution-result") state.acceptedRef = accepted;
|
|
19956
20229
|
}
|
|
19957
20230
|
if (state.prepared && state.acceptedRef && state.acceptedConsumed) {
|
|
20231
|
+
const currentEnvironment = [...state.admissions].reverse().find((admission) => admission.phase === "environment");
|
|
20232
|
+
if (currentEnvironment?.phase === "environment") state.priorSession = currentEnvironment;
|
|
19958
20233
|
delete state.inputSequence;
|
|
19959
20234
|
delete state.taskRef;
|
|
19960
20235
|
delete state.acceptedRef;
|
|
@@ -20246,6 +20521,8 @@ async function startScopeRecoveries(scope) {
|
|
|
20246
20521
|
async function releaseRetainedEnvironments(scope) {
|
|
20247
20522
|
const release = retainedReleasers.get(scope);
|
|
20248
20523
|
if (release) await release();
|
|
20524
|
+
const ownerUnconfirmed = await releaseScopeRetainedOwnerEnvironment(scope);
|
|
20525
|
+
return [...scope.workerCapacity.unconfirmed, ...ownerUnconfirmed];
|
|
20249
20526
|
}
|
|
20250
20527
|
/**
|
|
20251
20528
|
* @internal Close this scope to NEW children. Idempotent, synchronous, and irreversible.
|
|
@@ -20549,6 +20826,7 @@ function createScope(args) {
|
|
|
20549
20826
|
rootId: args.root,
|
|
20550
20827
|
parentId: args.parentId,
|
|
20551
20828
|
nodeId: id,
|
|
20829
|
+
depth: args.depth + 1,
|
|
20552
20830
|
attemptId,
|
|
20553
20831
|
...identity ? { identity } : {}
|
|
20554
20832
|
},
|
|
@@ -20853,7 +21131,7 @@ function createScope(args) {
|
|
|
20853
21131
|
try {
|
|
20854
21132
|
await interactiveBindingCommitted;
|
|
20855
21133
|
} catch {
|
|
20856
|
-
resolution = downRecord("interactive worker binding persistence failed", true, s.trace, s.metered, s.providerModel, s.outRef);
|
|
21134
|
+
resolution = downRecord("interactive worker binding persistence failed", true, s.trace, s.metered, s.providerModel, s.outRef, s.harnessTranscript);
|
|
20857
21135
|
}
|
|
20858
21136
|
live.resolved = resolution;
|
|
20859
21137
|
return resolution;
|
|
@@ -21221,6 +21499,7 @@ function createScope(args) {
|
|
|
21221
21499
|
journal: args.journal,
|
|
21222
21500
|
root: args.ownerMaterialization.journalRoot ?? args.root,
|
|
21223
21501
|
nodeId: args.ownerMaterialization.nodeId ?? args.parentId,
|
|
21502
|
+
depth: args.depth,
|
|
21224
21503
|
runtime: args.ownerMaterialization.runtime,
|
|
21225
21504
|
attemptId: args.ownerMaterialization.attemptId,
|
|
21226
21505
|
...authoredProfile === void 0 ? {} : { authoredProfile },
|
|
@@ -21406,6 +21685,7 @@ function scopeOwnerExecutorNodeContext(scope) {
|
|
|
21406
21685
|
rootId: state.root,
|
|
21407
21686
|
parentId: state.nodeId,
|
|
21408
21687
|
nodeId: state.nodeId,
|
|
21688
|
+
depth: state.depth,
|
|
21409
21689
|
attemptId: state.attemptId
|
|
21410
21690
|
});
|
|
21411
21691
|
}
|
|
@@ -21576,12 +21856,14 @@ async function appendSettlementMetering(journal, root, id, spend, at) {
|
|
|
21576
21856
|
/** An open node's reconciled floor has the same per-child sequence discipline as its metering:
|
|
21577
21857
|
* outside the cursor namespace, monotonic per node, so a node reconciled once per process (a
|
|
21578
21858
|
* retained failure, a recovery, a second retained failure) keeps its records ordered. */
|
|
21579
|
-
async function appendReconciledFloor(journal, root, id, spent, at) {
|
|
21859
|
+
async function appendReconciledFloor(journal, root, id, spent, at, harnessTranscript) {
|
|
21860
|
+
const seq = await nextPerNodeSeq(journal, root, "reconciled", id);
|
|
21580
21861
|
await appendAcknowledged(journal, root, {
|
|
21581
21862
|
kind: "reconciled",
|
|
21582
21863
|
id,
|
|
21583
21864
|
spent,
|
|
21584
|
-
|
|
21865
|
+
...harnessTranscript ? { harnessTranscript } : {},
|
|
21866
|
+
seq,
|
|
21585
21867
|
at
|
|
21586
21868
|
});
|
|
21587
21869
|
}
|
|
@@ -21641,10 +21923,11 @@ async function finalizeSettlement(child, settlement, seq, args, now) {
|
|
|
21641
21923
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
21642
21924
|
...child.budgetViolation ? { budgetViolation: child.budgetViolation } : {},
|
|
21643
21925
|
trace: settlement.trace,
|
|
21926
|
+
...settlement.harnessTranscript ? { harnessTranscript: settlement.harnessTranscript } : {},
|
|
21644
21927
|
seq,
|
|
21645
21928
|
at
|
|
21646
21929
|
});
|
|
21647
|
-
else if (settlement.reconciled !== void 0) await appendReconciledFloor(args.journal, args.root, child.id, settlement.reconciled, at);
|
|
21930
|
+
else if (settlement.reconciled !== void 0) await appendReconciledFloor(args.journal, args.root, child.id, settlement.reconciled, at, settlement.harnessTranscript);
|
|
21648
21931
|
notifyRuntimeHookEvent(args.hooks, {
|
|
21649
21932
|
id: `${child.id}:settled`,
|
|
21650
21933
|
runId: args.root,
|
|
@@ -21672,6 +21955,7 @@ async function finalizeSettlement(child, settlement, seq, args, now) {
|
|
|
21672
21955
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
21673
21956
|
...child.budgetViolation ? { budgetViolation: child.budgetViolation } : {},
|
|
21674
21957
|
trace: settlement.trace,
|
|
21958
|
+
...settlement.harnessTranscript ? { harnessTranscript: settlement.harnessTranscript } : {},
|
|
21675
21959
|
settledAt,
|
|
21676
21960
|
seq
|
|
21677
21961
|
};
|
|
@@ -21691,6 +21975,7 @@ async function finalizeSettlement(child, settlement, seq, args, now) {
|
|
|
21691
21975
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
21692
21976
|
...child.budgetViolation ? { budgetViolation: child.budgetViolation } : {},
|
|
21693
21977
|
trace: settlement.trace,
|
|
21978
|
+
...settlement.harnessTranscript ? { harnessTranscript: settlement.harnessTranscript } : {},
|
|
21694
21979
|
seq,
|
|
21695
21980
|
at
|
|
21696
21981
|
});
|
|
@@ -21722,6 +22007,7 @@ async function finalizeSettlement(child, settlement, seq, args, now) {
|
|
|
21722
22007
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
21723
22008
|
...child.budgetViolation ? { budgetViolation: child.budgetViolation } : {},
|
|
21724
22009
|
trace: settlement.trace,
|
|
22010
|
+
...settlement.harnessTranscript ? { harnessTranscript: settlement.harnessTranscript } : {},
|
|
21725
22011
|
settledAt,
|
|
21726
22012
|
seq
|
|
21727
22013
|
};
|
|
@@ -21854,6 +22140,11 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
21854
22140
|
traceEvidence ??= await captureWorkerTraceEvidence(live.readTraceSource, blobs, started);
|
|
21855
22141
|
return traceEvidence;
|
|
21856
22142
|
};
|
|
22143
|
+
let transcriptEvidence;
|
|
22144
|
+
const persistTranscriptOnce = async () => {
|
|
22145
|
+
transcriptEvidence ??= await persistHarnessTranscript(readHarnessTranscript(executor), blobs);
|
|
22146
|
+
return transcriptEvidence;
|
|
22147
|
+
};
|
|
21857
22148
|
const teardownOnce = async (grace) => {
|
|
21858
22149
|
if (teardownStarted) return;
|
|
21859
22150
|
teardownStarted = true;
|
|
@@ -21940,16 +22231,17 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
21940
22231
|
live.executorDone = true;
|
|
21941
22232
|
const ownMetered = executor.metered?.();
|
|
21942
22233
|
const trace = await captureTraceOnce();
|
|
22234
|
+
const childHarnessTranscript = await persistTranscriptOnce();
|
|
21943
22235
|
if (childAbort.signal.aborted && live.acceptedResult === void 0) {
|
|
21944
22236
|
await teardownOnce(opts.shutdown ?? "brutalKill");
|
|
21945
|
-
return downRecord("aborted before settle", true, trace, ownMetered, runtimeOwnedExecutorProviderEvidence(executor), retainedOutputRef);
|
|
22237
|
+
return downRecord("aborted before settle", true, trace, ownMetered, runtimeOwnedExecutorProviderEvidence(executor), retainedOutputRef, childHarnessTranscript);
|
|
21946
22238
|
}
|
|
21947
22239
|
const outRef = artifact.outRef;
|
|
21948
22240
|
const failureReason = executorFailureReason(artifact);
|
|
21949
22241
|
if (failureReason !== void 0) {
|
|
21950
22242
|
await teardownOnce(opts.shutdown ?? 5e3).catch(() => void 0);
|
|
21951
22243
|
return {
|
|
21952
|
-
...downRecord(failureReason, false, trace, ownMetered, runtimeOwnedExecutorProviderEvidence(executor)),
|
|
22244
|
+
...downRecord(failureReason, false, trace, ownMetered, runtimeOwnedExecutorProviderEvidence(executor), void 0, childHarnessTranscript),
|
|
21953
22245
|
outRef
|
|
21954
22246
|
};
|
|
21955
22247
|
}
|
|
@@ -21961,6 +22253,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
21961
22253
|
...artifact.verdict ? { verdict: artifact.verdict } : {},
|
|
21962
22254
|
spent: live.spent,
|
|
21963
22255
|
trace,
|
|
22256
|
+
harnessTranscript: childHarnessTranscript,
|
|
21964
22257
|
providerModel: runtimeOwnedExecutorProviderEvidence(executor),
|
|
21965
22258
|
...ownMetered ? { metered: ownMetered } : {}
|
|
21966
22259
|
};
|
|
@@ -21980,7 +22273,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
21980
22273
|
const metered = executor.metered?.();
|
|
21981
22274
|
const failureReason = executorFailureReason(accepted);
|
|
21982
22275
|
if (failureReason !== void 0) return {
|
|
21983
|
-
...downRecord(failureReason, false, trace, metered, runtimeOwnedExecutorProviderEvidence(executor)),
|
|
22276
|
+
...downRecord(failureReason, false, trace, metered, runtimeOwnedExecutorProviderEvidence(executor), void 0, await persistTranscriptOnce()),
|
|
21984
22277
|
outRef: accepted.outRef
|
|
21985
22278
|
};
|
|
21986
22279
|
return {
|
|
@@ -21990,6 +22283,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
21990
22283
|
...accepted.verdict ? { verdict: accepted.verdict } : {},
|
|
21991
22284
|
spent: live.spent,
|
|
21992
22285
|
trace,
|
|
22286
|
+
harnessTranscript: await persistTranscriptOnce(),
|
|
21993
22287
|
providerModel: runtimeOwnedExecutorProviderEvidence(executor),
|
|
21994
22288
|
...metered ? { metered } : {}
|
|
21995
22289
|
};
|
|
@@ -22015,7 +22309,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
22015
22309
|
}
|
|
22016
22310
|
live.budgetViolation = void 0;
|
|
22017
22311
|
return {
|
|
22018
|
-
...downRecord(errMessage(err), true, trace, executor.metered?.(), void 0, retainedOutputRef),
|
|
22312
|
+
...downRecord(errMessage(err), true, trace, executor.metered?.(), void 0, retainedOutputRef, await persistTranscriptOnce()),
|
|
22019
22313
|
reconciled: live.spent
|
|
22020
22314
|
};
|
|
22021
22315
|
}
|
|
@@ -22039,7 +22333,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
22039
22333
|
const aborted = childAbort.signal.aborted || isAbortError(err);
|
|
22040
22334
|
if (started && !terminalTelemetryCaptured && accounting === void 0) live.spent = unknownFloor(live.spent);
|
|
22041
22335
|
const reconcileError = reconcileOnce(accounting?.reservation ?? live.spent);
|
|
22042
|
-
return downRecord(errMessage(err), evidenceError !== void 0 || teardownError !== void 0 || reconcileError !== void 0 || aborted || isInfraError(err), trace, executor.metered?.(), providerModel, retainedOutputRef);
|
|
22336
|
+
return downRecord(errMessage(err), evidenceError !== void 0 || teardownError !== void 0 || reconcileError !== void 0 || aborted || isInfraError(err), trace, executor.metered?.(), providerModel, retainedOutputRef, await persistTranscriptOnce());
|
|
22043
22337
|
} finally {
|
|
22044
22338
|
await closeRetainedWrites();
|
|
22045
22339
|
}
|
|
@@ -22277,17 +22571,47 @@ function unknownFloor(spend) {
|
|
|
22277
22571
|
}])) }
|
|
22278
22572
|
};
|
|
22279
22573
|
}
|
|
22280
|
-
function downRecord(reason, infra, trace, metered, providerModel, outRef) {
|
|
22574
|
+
function downRecord(reason, infra, trace, metered, providerModel, outRef, harnessTranscript) {
|
|
22281
22575
|
return {
|
|
22282
22576
|
kind: "down",
|
|
22283
22577
|
reason,
|
|
22284
22578
|
infra,
|
|
22285
22579
|
trace,
|
|
22580
|
+
...harnessTranscript ? { harnessTranscript } : {},
|
|
22286
22581
|
...providerModel ? { providerModel } : {},
|
|
22287
22582
|
...metered ? { metered } : {},
|
|
22288
22583
|
...outRef === void 0 ? {} : { outRef }
|
|
22289
22584
|
};
|
|
22290
22585
|
}
|
|
22586
|
+
/**
|
|
22587
|
+
* Read one executor's harness-transcript receipt without letting a broken port escape.
|
|
22588
|
+
*
|
|
22589
|
+
* The three answers this has to keep apart, because #1214 and #1244 are both about an artifact
|
|
22590
|
+
* that reads as coverage without being coverage:
|
|
22591
|
+
* - `available` the transcript survived;
|
|
22592
|
+
* - a reason the CAPTURE produced a box existed and could not be read;
|
|
22593
|
+
* - `executor-exposes-no-transcript` this runtime has no transcript to offer at all;
|
|
22594
|
+
* - `execution-never-started` no environment was ever created (the executor's
|
|
22595
|
+
* own seed, set before `create`);
|
|
22596
|
+
* - `capture-did-not-run` the port answered nothing, so the capture was
|
|
22597
|
+
* skipped rather than attempted and failed.
|
|
22598
|
+
*
|
|
22599
|
+
* Mirrors `readInteractiveSession` above: an absence is always a named reason, never `undefined`.
|
|
22600
|
+
*/
|
|
22601
|
+
function readHarnessTranscript(executor) {
|
|
22602
|
+
if (!executor.harnessTranscript) return harnessTranscriptUnavailable("executor-exposes-no-transcript");
|
|
22603
|
+
let reported;
|
|
22604
|
+
try {
|
|
22605
|
+
reported = executor.harnessTranscript();
|
|
22606
|
+
} catch {
|
|
22607
|
+
return harnessTranscriptUnavailable("executor-exposes-no-transcript");
|
|
22608
|
+
}
|
|
22609
|
+
if (reported === void 0) return harnessTranscriptUnavailable("capture-did-not-run");
|
|
22610
|
+
const capture = reported;
|
|
22611
|
+
if (capture.status === "captured" && capture.artifact) return capture;
|
|
22612
|
+
if (capture.status === "unavailable" && capture.reason) return capture;
|
|
22613
|
+
return harnessTranscriptUnavailable("executor-exposes-no-transcript");
|
|
22614
|
+
}
|
|
22291
22615
|
/** The one place an absent interactive process is spelled, so every refusal reads the same. */
|
|
22292
22616
|
function noInteractiveSession(reason) {
|
|
22293
22617
|
return Object.freeze({
|
|
@@ -22534,8 +22858,7 @@ const driverExecutorFactory = (rawSpec, ctx) => {
|
|
|
22534
22858
|
},
|
|
22535
22859
|
async releaseRetained() {
|
|
22536
22860
|
if (nestedScopeHeld === void 0) return [];
|
|
22537
|
-
await releaseRetainedEnvironments(nestedScopeHeld);
|
|
22538
|
-
unconfirmedDescendants = nestedScopeHeld.workerCapacity.unconfirmed.map((node) => node.id);
|
|
22861
|
+
unconfirmedDescendants = (await releaseRetainedEnvironments(nestedScopeHeld)).map((node) => node.id);
|
|
22539
22862
|
return [];
|
|
22540
22863
|
},
|
|
22541
22864
|
resultArtifact() {
|
|
@@ -22747,7 +23070,8 @@ function unreportedSpend(total, prior) {
|
|
|
22747
23070
|
* ended on this loop's own `stop: 'completed'`, with the completion gate left to label the result
|
|
22748
23071
|
* rather than to change it. A completed drive whose contract is unmet is now a first-class moment:
|
|
22749
23072
|
* `reprompt.maxReprompts` re-enters the SAME live session with the unmet items, and every re-entry
|
|
22750
|
-
* crosses the same budget, deadline,
|
|
23073
|
+
* crosses the same budget, deadline, and abort bounds. Successful continuations do not consume
|
|
23074
|
+
* the failure retry allowance.
|
|
22751
23075
|
*/
|
|
22752
23076
|
/**
|
|
22753
23077
|
* The instruction a completed-but-undelivered drive is re-entered with when the caller supplies no
|
|
@@ -22864,9 +23188,14 @@ async function runDriverWithRetry(run) {
|
|
|
22864
23188
|
const maxAttempts = Math.max(1, policy.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
|
|
22865
23189
|
const initialBackoff = Math.max(0, policy.initialBackoffMs ?? DEFAULT_INITIAL_BACKOFF_MS);
|
|
22866
23190
|
const maxBackoff = Math.max(initialBackoff, policy.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS);
|
|
22867
|
-
const maxReprompts =
|
|
23191
|
+
const maxReprompts = run.reprompt?.maxReprompts ?? 0;
|
|
23192
|
+
if (maxReprompts === "until-complete") {
|
|
23193
|
+
const deadline = run.budget().deadlineMs;
|
|
23194
|
+
if (!Number.isFinite(deadline) || deadline <= 0) throw new ValidationError$1("runDriverWithRetry: until-complete requires a finite positive deadline");
|
|
23195
|
+
}
|
|
22868
23196
|
const attempts = [];
|
|
22869
23197
|
let consecutiveBarren = 0;
|
|
23198
|
+
let failures = 0;
|
|
22870
23199
|
let reprompts = 0;
|
|
22871
23200
|
let reentry;
|
|
22872
23201
|
const emit = async (record) => {
|
|
@@ -22879,11 +23208,10 @@ async function runDriverWithRetry(run) {
|
|
|
22879
23208
|
* the caller's hook is consulted last, so no hook can talk the loop past a deadline.
|
|
22880
23209
|
*/
|
|
22881
23210
|
const decideReprompt = async (attempt, after) => {
|
|
22882
|
-
if (reprompts >= maxReprompts) return { refusedBy: "reprompts-exhausted" };
|
|
23211
|
+
if (maxReprompts !== "until-complete" && reprompts >= maxReprompts) return { refusedBy: "reprompts-exhausted" };
|
|
22883
23212
|
if (run.signal.aborted) return { refusedBy: "aborted" };
|
|
22884
23213
|
const byBudget = budgetStop(run.budget(), now());
|
|
22885
23214
|
if (byBudget === "deadline" || byBudget === "budget-exhausted") return { refusedBy: byBudget };
|
|
22886
|
-
if (attempt >= maxAttempts) return { refusedBy: "max-attempts" };
|
|
22887
23215
|
const context = {
|
|
22888
23216
|
attempt,
|
|
22889
23217
|
reprompts,
|
|
@@ -22912,6 +23240,7 @@ async function runDriverWithRetry(run) {
|
|
|
22912
23240
|
try {
|
|
22913
23241
|
await run.drive(attempt, reentry);
|
|
22914
23242
|
} catch (error) {
|
|
23243
|
+
failures += 1;
|
|
22915
23244
|
const durationMs = now() - startedAt;
|
|
22916
23245
|
const classification = classifyDriverFailure(error, run.signal);
|
|
22917
23246
|
const progressed = madeProgress(before, run.progress());
|
|
@@ -22921,7 +23250,7 @@ async function runDriverWithRetry(run) {
|
|
|
22921
23250
|
if (run.signal.aborted) return "aborted";
|
|
22922
23251
|
const byBudget = budgetStop(run.budget(), now());
|
|
22923
23252
|
if (byBudget) return byBudget;
|
|
22924
|
-
if (
|
|
23253
|
+
if (failures >= maxAttempts) return "max-attempts";
|
|
22925
23254
|
if (progressed) return void 0;
|
|
22926
23255
|
return consecutiveBarren + 1 >= maxConsecutive ? "no-progress" : void 0;
|
|
22927
23256
|
})();
|
|
@@ -22953,12 +23282,13 @@ async function runDriverWithRetry(run) {
|
|
|
22953
23282
|
if (afterWait) throw new DriverAttemptsExhaustedError(error, attempts, afterWait);
|
|
22954
23283
|
continue;
|
|
22955
23284
|
}
|
|
23285
|
+
consecutiveBarren = 0;
|
|
22956
23286
|
const durationMs = now() - startedAt;
|
|
22957
23287
|
const after = run.progress();
|
|
22958
23288
|
const progressed = madeProgress(before, after);
|
|
22959
23289
|
const contract = contractOf(after);
|
|
22960
23290
|
const contractField = contract === "none" ? {} : { contract };
|
|
22961
|
-
if (contract === "unmet" && maxReprompts > 0) {
|
|
23291
|
+
if (contract === "unmet" && (maxReprompts === "until-complete" || maxReprompts > 0)) {
|
|
22962
23292
|
const decision = await decideReprompt(attempt, after);
|
|
22963
23293
|
if ("steer" in decision) {
|
|
22964
23294
|
reprompts += 1;
|
|
@@ -23075,29 +23405,49 @@ const collectDelivered = (ctx) => {
|
|
|
23075
23405
|
* Run a finalizer over a settled-worker ledger under the delivered-only invariant: filter the
|
|
23076
23406
|
* ledger to structurally delivered children, materialize their outputs, and hand the finalizer a
|
|
23077
23407
|
* blob reader that throws on any ref outside that set. This is the one call site both driver arms
|
|
23078
|
-
* (the in-process tool-loop and the MCP-mounted harness) finalize through.
|
|
23408
|
+
* (the in-process tool-loop and the MCP-mounted harness) finalize through. When a parent declares
|
|
23409
|
+
* a deliverable, its candidate must also pass that check: children may have narrower assignments.
|
|
23410
|
+
* The default selects the highest-scoring child that passes the parent's check; custom finalizers
|
|
23411
|
+
* assemble their candidate before the check. A rejection leaves the parent incomplete; a thrown
|
|
23412
|
+
* oracle surfaces a validation error. Neither changes child validity.
|
|
23079
23413
|
*/
|
|
23080
23414
|
async function runFinalizer(finalizer, args) {
|
|
23081
23415
|
const deliveredRows = args.settled.filter((w) => w.status === "done" && w.valid === true);
|
|
23082
23416
|
const deliveredRefs = /* @__PURE__ */ new Set();
|
|
23083
23417
|
for (const w of deliveredRows) if (w.outRef !== void 0) deliveredRefs.add(w.outRef);
|
|
23084
|
-
|
|
23085
|
-
|
|
23086
|
-
|
|
23087
|
-
|
|
23088
|
-
|
|
23089
|
-
|
|
23090
|
-
|
|
23091
|
-
|
|
23092
|
-
|
|
23418
|
+
const delivered = await Promise.all(deliveredRows.map(async (w) => ({
|
|
23419
|
+
id: w.id,
|
|
23420
|
+
...w.score !== void 0 ? { score: w.score } : {},
|
|
23421
|
+
...w.outRef !== void 0 ? {
|
|
23422
|
+
outRef: w.outRef,
|
|
23423
|
+
out: await args.blobs.get(w.outRef)
|
|
23424
|
+
} : {}
|
|
23425
|
+
})));
|
|
23426
|
+
const guardedBlobs = { get: (outRef) => {
|
|
23427
|
+
if (!deliveredRefs.has(outRef)) throw new ValidationError$1(`finalizer: outRef '${outRef}' is not a DELIVERED child's result — a finalizer may only operate on outputs that settled done and passed their completion oracle`);
|
|
23428
|
+
return args.blobs.get(outRef);
|
|
23429
|
+
} };
|
|
23430
|
+
const accepted = async (candidate) => {
|
|
23431
|
+
if (candidate === void 0) return false;
|
|
23432
|
+
if (args.deliverable === void 0) return true;
|
|
23433
|
+
try {
|
|
23434
|
+
return await args.deliverable.check(candidate) === true;
|
|
23435
|
+
} catch (error) {
|
|
23436
|
+
throw new ValidationError$1(`finalizer: parent completion check threw: ${error instanceof Error ? error.message : String(error)}`);
|
|
23437
|
+
}
|
|
23438
|
+
};
|
|
23439
|
+
if (finalizer === bestDelivered && args.deliverable !== void 0) {
|
|
23440
|
+
for (const output of [...delivered].sort((a, b) => (b.score ?? 0) - (a.score ?? 0))) if (await accepted(output.out)) return output.out;
|
|
23441
|
+
return;
|
|
23442
|
+
}
|
|
23443
|
+
const candidate = await finalizer({
|
|
23444
|
+
delivered,
|
|
23093
23445
|
allSettled: args.settled,
|
|
23094
23446
|
tree: args.tree,
|
|
23095
|
-
blobs:
|
|
23096
|
-
if (!deliveredRefs.has(outRef)) throw new ValidationError$1(`finalizer: outRef '${outRef}' is not a DELIVERED child's result — a finalizer may only operate on outputs that settled done and passed their completion oracle`);
|
|
23097
|
-
return args.blobs.get(outRef);
|
|
23098
|
-
} },
|
|
23447
|
+
blobs: guardedBlobs,
|
|
23099
23448
|
budget: args.budget
|
|
23100
23449
|
});
|
|
23450
|
+
return await accepted(candidate) ? candidate : void 0;
|
|
23101
23451
|
}
|
|
23102
23452
|
//#endregion
|
|
23103
23453
|
//#region src/runtime/supervise/supervisor.ts
|
|
@@ -23455,10 +23805,7 @@ function createSupervisor() {
|
|
|
23455
23805
|
const settleGraceMs = !controller.signal.aborted ? boundedSettleGrace(opts.childSettleGraceMs, rootDeadlineAtMs, now) : 0;
|
|
23456
23806
|
try {
|
|
23457
23807
|
teardownUnconfirmed = await drainLiveChildren(openScope, controller, settleGraceMs);
|
|
23458
|
-
if (retainedAtSettlement === "release")
|
|
23459
|
-
await releaseRetainedEnvironments(openScope);
|
|
23460
|
-
teardownUnconfirmed = openScope.workerCapacity.unconfirmed;
|
|
23461
|
-
}
|
|
23808
|
+
if (retainedAtSettlement === "release") teardownUnconfirmed = await releaseRetainedEnvironments(openScope);
|
|
23462
23809
|
for (const node of teardownUnconfirmed) await opts.journal.appendEvent(opts.runId, {
|
|
23463
23810
|
kind: "teardown-unconfirmed",
|
|
23464
23811
|
id: node.id,
|
|
@@ -23850,6 +24197,6 @@ function isNonEmptySpend(s) {
|
|
|
23850
24197
|
return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false || Object.values(s.resources ?? {}).some((resource) => resource.amount > 0 || !resource.known);
|
|
23851
24198
|
}
|
|
23852
24199
|
//#endregion
|
|
23853
|
-
export {
|
|
24200
|
+
export { bindReusableExecutorExecutionId as $, providerMessageText as $i, buildRuntimeEventOtelSpans as $n, providerAttemptEvidence as $r, addHarnessUsage as $t, waitUntil as A, deleteBoxSafe as Ai, RunCancellationReason as An, profileMaterializationAxes$1 as Ar, spendFromUsageTotals as At, attachWorker as B, withTimeout as Bi, defaultRedactorIdentityMaterial as Bn, worktreeCliProfileMaterialization as Br, createInbox as Bt, scopeOwnerExecutorNodeContext as C, notifySandboxEventObserver as Ci, resolveAgentEnvironmentProvider as Cn, parseCodexTokenUsage as Cr, workerTraceAnalysisStore as Ct, pollFor as D, addSpend as Di, sandboxSessionTraceSource as Dn, controlProfileMaterialization as Dr, meterUsageEvent as Dt, isWaitOutcome as E, sumSandboxUsage as Ei, decodeToolPart as En, assertProfileMaterialization as Er, createBudgetPool as Et, scopeRetainedOwnerPriorSpend as F, sleep as Fi, recoverRetainedRun as Fn, renderProfileMaterializationIssues as Fr, workerTraceSeamKey as Ft, recoverRetainedInteractiveRun as G, decodeHarnessUsage as Gi, contentAddress as Gn, attestRuntimeOwnedPendingExecutor as Gr, createPeerMailbox as Gt, workerInteractiveBindingFile as H, addResourceSpend as Hi, captureHarnessTranscript as Hn, parseCommittedJsonLines as Hr, DEFAULT_PEER_MAIL_LIMITS as Ht, scopeRetainedOwnerResult as I, stringifySafe as Ii, startRetainedRun as In, renderUnsupported as Ir, taskToPrompt as It, errMessage as J, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as Ji, readTraceContextFromEnv as Jn, finalizeRuntimeOwnedPendingExecutor as Jr, peerMailVerbNames as Jt, startRetainedInteractiveRun as K, abortError$2 as Ki, createPropagatingTraceEmitter as Kn, attestRuntimeOwnedScopeOwner as Kr, isPeerMailEnvelope as Kt, interactiveAdmissionSeamKey as L, throwAbort as Li, startRetainedRunInEnvironment as Ln, sandboxActProfileMaterialization as Lr, DEFAULT_STALL_AFTER_MS as Lt, consumeScopeRetainedOwnerResult as M, isAbortError$2 as Mi, linkAbort as Mn, promptModelProfileMaterialization as Mr, readWorkerTraceContext as Mt, prepareScopeRetainedOwnerTask as N, promptCacheTokenClasses as Ni, runAbortable as Nn, promptOnlyProfileMaterialization as Nr, workerTraceEnv as Nt, timerAt as O, chargedTokens as Oi, registerRetainedExecutorPreparation as On, defineProfileMaterializationContract as Or, newUsageTotals as Ot, scopeRetainedOwnerContext as P, randomSuffix as Pi, reconnectRetainedRun as Pn, promptResourceProfileMaterialization as Pr, workerTraceHeaders as Pt, rollingDispatch as Q, promptOptionsFromAgentTurnInput as Qi, buildLoopSpanNodes as Qn, newExecutionAttemptId as Qr, bridgeModelRouteRefusal as Qt, readWorkerInteractiveAdmissions as R, throwIfAborted as Ri, retainedCreateMaterial as Rn, unsupportedProfileDimensions as Rr, createActivityLog as Rt, restoreScopeOwnerAcceptedExecution as S, mapSandboxToolEvent as Si, providerAsSandboxClient as Sn, localHarnessExecutable as Sr, parseWorkerToolTraceArtifact as St, createWaitProbes as T, sandboxProgressEvents as Ti, createPushTraceSource as Tn, AGENT_PROFILE_MATERIALIZATION_AXES as Tr, assertValidBudget as Tt, workerInteractiveBindingsDir as U, resourceTelemetry as Ui, harnessTranscriptArtifact as Un, prepareJsonlAppend as Ur, PEER_MAIL_WIRE_KEY as Ut, readWorkerInteractiveBinding as V, zeroSpend as Vi, resolveRedactor as Vn, isNoEntError as Vr, AUTHORITY_MARKERS as Vt, reconnectRetainedInteractiveRun as W, withBudgetResources as Wi, persistHarnessTranscript as Wn, writeAllBytes as Wr, claimsAuthority as Wt, freeSlots as X, teardownExecutor as Xi, INTELLIGENCE_WIRE_VERSION as Xn, knownExecutionBindingReceipt as Xr, isTerminalNodeStatus as Xt, effectiveConcurrency as Y, armDeadlineTimer as Yi, traceContextToEnv as Yn, inheritRuntimeOwnedExecutorAttestation as Yr, isLiveNodeStatus as Yt, queueOf as Z, promptFromAgentTurnInput as Zi, buildLoopOtelSpans as Zn, knownMaterializationReceipt as Zr, bridgeAdmissionRefusal as Zt, createScope as _, createSandboxToolPartState as _i, canonicalObservedModelParts as _n, createWorktree as _r, pendingWaits as _t, pickBestDelivered as a, runtimeOwnedPendingExecutorMaterialization as ai, TERMINAL_DECISIONS as an, loopEventToOtelSpan as ar, snapshotExecutorConfig as at, meterRuntimeOwnedProviderAttempt as b, isSandboxTerminalEvent as bi, createAgentEnvironmentProviderRegistry as bn, LOCAL_HARNESSES as br, captureWorkerTraceEvidence as bt, DriverAttemptsExhaustedError as c, unknownMaterializationReceipt as ci, isTerminalDecision as cn, toOtelAttributes as cr, createSteerableSandboxSession as ct, runDriverWithRetry as d, detachedFrozen as di, probeSandboxCapabilities as dn, sanitizeAgentRuntimeEvent as dr, FileSpawnJournal as dt, recordRuntimeOwnedDriveHarnessProviderEvidence as ei, createCodexRolloutStoreReader as en, createOpenInferenceFileExporter as er, captureReusableExecutorConfig as et, driverChild as f, detachedSnapshot as fi, acquireSandbox as fn, sanitizeKnowledgeReadinessReport as fr, InMemoryResultBlobStore as ft, beginScopeOwnerAttempt as g, canonicalStreamEventFromSandboxEvent as gi, runBrainLoop as gn, captureWorktreeDiff as gr, materializeTreeView as gt, withDriverExecutor as h, assertSandboxServedModel as hi, routerBrain as hn, runWorktreeHarness as hr, loadSpawnForest as ht, collectDelivered as i, runtimeOwnedExecutorProviderEvidence as ii, bridgeStopSignalKey as in, generateSpanId as ir, createExecutorRegistry as it, bindScopeRetainedOwnerProvider as j, hasCompleteCacheBreakdown as ji, abortError as jn, promptControlProfileMaterialization as jr, WORKER_TRACE_PROPAGATION as jt, validateWaitSpec as k, cloneSpend as ki, retainedExecutorSeamKey as kn, fullProfileMaterialization as kr, spendFromUsageEvents as kt, classifyDriverFailure as l, executableAgentProfileSnapshot as li, runAgentRounds as ln, createRuntimeEventCollector as lr, createInPlaceCliExecutor as lt, isDriverSpec as m, readSandboxOutcome as mi, readPromptOptions as mn, runSettledCommand as mr, insideCursorNamespace as mt, createSupervisor as n, runtimeOwnedExecutorExecutionBinding as ni, readCodexRolloutSession as nn, exportEvalRuns as nr, cliWorktreeExecutor as nt, runFinalizer as o, runtimeOwnedScopeOwnerRuntime as oi, createSandboxForSpec as on, padSpanId as or, createWorktreeCliExecutor as ot, driverExecutorFactory as p, projectSandboxOutcome as pi, assertBoxlessPromptOptions as pn, sanitizeRuntimeStreamEvent as pr, InMemorySpawnJournal as pt, destroyInteractiveEnvironment as q, awaitAbortable$1 as qi, mergeTraceEnv as qn, authoredProfileDigest as qr, peerMailTools as qt, bestDelivered as r, runtimeOwnedExecutorMaterialization as ri, bridgeRuntimeAttachmentsKey as rn, flatOtelSpan as rr, createExecutor as rt, runTree as s, unknownExecutionBindingReceipt as si, defaultSelectWinner as sn, padTraceId as sr, DEFAULT_SANDBOX_STEERING_MAX_TURNS as st, createRootHandle as t, runtimeOwnedDriveHarnessProviderEvidence as ti, harnessUsageIsEmpty as tn, createOtelExporter as tr, cliInPlaceExecutor as tt, defaultUnmetContractSteer as u, executableAgentSpecSnapshot as ui, createSandboxLineage as un, createRuntimeStreamEventCollector as ur, FileResultBlobStore as ut, deriveNodeExecutionIdentity as v, createSandboxUsageLedger as vi, observedModelMatchesDeclared as vn, removeWorktree as vr, replaySpawnTree as vt, settledToIteration as w, sandboxEventServedBackend as wi, sandboxClientAsProvider as wn, CodexExecutionDiagnosticError as wr, BudgetReconcileFault as wt, recordScopeOwnerMaterialization as x, mapSandboxEvent as xi, providerAsExecutor as xn, harnessSupportsReasoningEffort as xr, isTraceAnalysisStore as xt, meterRuntimeOwnedAccounting as y, extractLlmCallEvent as yi, DEFAULT_SANDBOX_IDLE_TIMEOUT_SECONDS as yn, DEFAULT_LOCAL_HARNESS as yr, WORKER_TOOL_TRACE_SCHEMA_VERSION as yt, workerInteractiveAdmissionFile as z, unmeteredSpend as zi, defaultRedactor as zn, validateProfileMaterialization as zr, readWorkerProgress as zt };
|
|
23854
24201
|
|
|
23855
|
-
//# sourceMappingURL=supervisor-
|
|
24202
|
+
//# sourceMappingURL=supervisor-BVAM5glY.js.map
|