@tangle-network/agent-runtime 0.320.1 → 0.321.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-BSwcsNSQ.d.ts → activation-BxOOvwjo.d.ts} +2 -2
- package/dist/{activation-BKglRwjB.js → activation-CXFl5YVE.js} +2 -2
- package/dist/{activation-BKglRwjB.js.map → activation-CXFl5YVE.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/candidate-execution/index.js +3 -3
- package/dist/{coordination-driver-D85RWATT.js → coordination-driver-Bpn05N-Y.js} +4 -3
- package/dist/coordination-driver-Bpn05N-Y.js.map +1 -0
- package/dist/{delegate-BHRR-4hh.js → delegate-BHlcTOdK.js} +2 -2
- package/dist/{delegate-BHRR-4hh.js.map → delegate-BHlcTOdK.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +3 -3
- package/dist/{graph-BGMcJJP1.js → graph-DE2dLhDI.js} +4 -4
- package/dist/{graph-BGMcJJP1.js.map → graph-DE2dLhDI.js.map} +1 -1
- package/dist/{improvement-cycle-0cnwWPFY.js → improvement-cycle-CyChbojL.js} +5 -5
- package/dist/{improvement-cycle-0cnwWPFY.js.map → improvement-cycle-CyChbojL.js.map} +1 -1
- package/dist/{index-t672ISFX.d.ts → index-BxiHetnG.d.ts} +241 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/intelligence.d.ts +2 -2
- package/dist/intelligence.js +6 -6
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +9 -9
- package/dist/{loop-runner-bin-CFudOt5T.js → loop-runner-bin-CT02Vzco.js} +3 -3
- package/dist/{loop-runner-bin-CFudOt5T.js.map → loop-runner-bin-CT02Vzco.js.map} +1 -1
- package/dist/{loop-runner-bin-Fgmf_PQU.d.ts → loop-runner-bin-DInJZNgs.d.ts} +2 -2
- 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 +2 -2
- package/dist/mcp/index.js +4 -4
- package/dist/{openai-tools-DCfdg0UD.d.ts → openai-tools-DLTw576v.d.ts} +2 -2
- package/dist/{prepare-DjCLEN-q.js → prepare-CFQLx9e3.js} +2 -2
- package/dist/{prepare-DjCLEN-q.js.map → prepare-CFQLx9e3.js.map} +1 -1
- package/dist/{profile-DmVM4Gxb.js → profile-BTbpdL9h.js} +40 -4
- package/dist/profile-BTbpdL9h.js.map +1 -0
- package/dist/profiles.d.ts +1 -1
- package/dist/{protected-model-port-D1fcnYdj.js → protected-model-port-f1N2f0Uq.js} +3 -3
- package/dist/{protected-model-port-D1fcnYdj.js.map → protected-model-port-f1N2f0Uq.js.map} +1 -1
- package/dist/{provision-supervisor-BUMhF1yb.js → provision-supervisor-DvgBNtoJ.js} +3 -3
- package/dist/{provision-supervisor-BUMhF1yb.js.map → provision-supervisor-DvgBNtoJ.js.map} +1 -1
- package/dist/{runtime-B47V5Omi.js → runtime-wLgjMOaj.js} +398 -10
- package/dist/runtime-wLgjMOaj.js.map +1 -0
- package/dist/{search-executor-DjKdQluM.js → search-executor-TEKWC579.js} +2 -2
- package/dist/{search-executor-DjKdQluM.js.map → search-executor-TEKWC579.js.map} +1 -1
- package/dist/{server-Gpgr0WP-.js → server-qYhzITTm.js} +3 -3
- package/dist/{server-Gpgr0WP-.js.map → server-qYhzITTm.js.map} +1 -1
- package/dist/{supervise-C2ThvLgZ.js → supervise-C4bLIU7J.js} +37 -14
- package/dist/supervise-C4bLIU7J.js.map +1 -0
- package/dist/{supervisor-CCtmmmOz.js → supervisor-bkq2b8k-.js} +383 -43
- package/dist/supervisor-bkq2b8k-.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +13 -13
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/package.json +4 -4
- package/dist/coordination-driver-D85RWATT.js.map +0 -1
- package/dist/profile-DmVM4Gxb.js.map +0 -1
- package/dist/runtime-B47V5Omi.js.map +0 -1
- package/dist/supervise-C2ThvLgZ.js.map +0 -1
- package/dist/supervisor-CCtmmmOz.js.map +0 -1
|
@@ -17,9 +17,10 @@ import { homedir, hostname, tmpdir } from "node:os";
|
|
|
17
17
|
import { stripVTControlCharacters } from "node:util";
|
|
18
18
|
import { ATTR, deriveHexId, isW3CSpanId, isW3CTraceId } from "@tangle-network/agent-trace-contract";
|
|
19
19
|
import { REDACTION_VERSION as REDACTION_VERSION$1, redact } from "@tangle-network/agent-eval/traces";
|
|
20
|
-
import { clearImmediate, setImmediate } from "node:timers";
|
|
20
|
+
import { clearImmediate, setImmediate as setImmediate$1 } from "node:timers";
|
|
21
21
|
import { z } from "zod";
|
|
22
22
|
import { Readable } from "node:stream";
|
|
23
|
+
import { LedgerCanonicalizationError, canonicalString, jsonDocument, merkleLeafHash, merkleRoot, merkleSalt } from "@tangle-network/agent-eval/ledger-core";
|
|
23
24
|
import { SDKError, generateIdempotencyKey, withRetry } from "@tangle-network/agent-core";
|
|
24
25
|
import { collectAgentFinalMessageText, collectAgentResponseText } from "@tangle-network/sandbox";
|
|
25
26
|
import { request } from "node:http";
|
|
@@ -740,13 +741,17 @@ function sandboxTerminalUsageField(type) {
|
|
|
740
741
|
* so a sentinel `NaN` from a misbehaving backend cannot poison the ledger.
|
|
741
742
|
*/
|
|
742
743
|
function extractLlmCallEvent(event, agentRunName) {
|
|
744
|
+
const data = canonicalUsageData(event);
|
|
745
|
+
return data === void 0 ? void 0 : buildLlmCall(data, agentRunName);
|
|
746
|
+
}
|
|
747
|
+
function canonicalUsageData(event) {
|
|
743
748
|
if (!event || typeof event !== "object") return void 0;
|
|
744
749
|
const type = String(event.type ?? "");
|
|
745
750
|
const data = event.data && typeof event.data === "object" ? event.data : {};
|
|
746
|
-
if (type === "llm_call" || type === "cost.usage" || type === "usage") return
|
|
751
|
+
if (type === "llm_call" || type === "cost.usage" || type === "usage") return usageReceiptData(data, plainRecord$1(data.usage));
|
|
747
752
|
if (type === "error" || isSandboxTerminalEvent(type)) {
|
|
748
753
|
const field = type === "error" ? "tokenUsage" : sandboxTerminalUsageField(type);
|
|
749
|
-
return
|
|
754
|
+
return usageReceiptData(data, plainRecord$1(data[field]) ?? plainRecord$1(data[field === "usage" ? "tokenUsage" : "usage"]));
|
|
750
755
|
}
|
|
751
756
|
}
|
|
752
757
|
/** A {@link SandboxUsageLedger} for one worker. Pass the worker's harness to decode with that
|
|
@@ -758,7 +763,10 @@ function createSandboxUsageLedger(harness) {
|
|
|
758
763
|
const receipts = /* @__PURE__ */ new Map();
|
|
759
764
|
const settledTokens = zeroTokenUsage();
|
|
760
765
|
let turnTokens = zeroTokenUsage();
|
|
766
|
+
let turnUsageUnknown = false;
|
|
767
|
+
let settledUsage;
|
|
761
768
|
return {
|
|
769
|
+
settledUsage: () => settledUsage === void 0 ? void 0 : { ...settledUsage },
|
|
762
770
|
tokenUsage() {
|
|
763
771
|
const total = cloneTokenUsage(settledTokens);
|
|
764
772
|
addTokenUsage(total, turnTokens);
|
|
@@ -771,13 +779,17 @@ function createSandboxUsageLedger(harness) {
|
|
|
771
779
|
const receipt = creditCanonicalUsage(event, call, credited, receipts, (receipt, mode) => {
|
|
772
780
|
refineCanonicalTokens(turnTokens, call, receipt, mode);
|
|
773
781
|
});
|
|
774
|
-
if (receipt?.tokensKnown === false)
|
|
782
|
+
if (receipt?.tokensKnown === false) {
|
|
783
|
+
turnTokens.tokensKnown = false;
|
|
784
|
+
turnUsageUnknown = true;
|
|
785
|
+
}
|
|
775
786
|
return receipt;
|
|
776
787
|
}
|
|
777
788
|
let usage;
|
|
778
789
|
try {
|
|
779
790
|
usage = decodeHarnessUsage(event, harness);
|
|
780
791
|
} catch (err) {
|
|
792
|
+
turnUsageUnknown = true;
|
|
781
793
|
return {
|
|
782
794
|
type: "llm_call",
|
|
783
795
|
model: agentRunName,
|
|
@@ -793,16 +805,25 @@ function createSandboxUsageLedger(harness) {
|
|
|
793
805
|
const canonical = sawCanonical;
|
|
794
806
|
held = [];
|
|
795
807
|
sawCanonical = false;
|
|
808
|
+
const receipt = !canonical && reports.length > 0 ? harnessUsageLlmCall(reports, agentRunName) : void 0;
|
|
809
|
+
if (receipt) creditCanonicalUsage({
|
|
810
|
+
type: "llm_call",
|
|
811
|
+
data: {}
|
|
812
|
+
}, receipt, credited, receipts, (credit, mode) => refineCanonicalTokens(turnTokens, receipt, credit, mode));
|
|
813
|
+
settledUsage = !turnUsageUnknown && credited.tokensIn !== void 0 && credited.tokensOut !== void 0 ? {
|
|
814
|
+
inputTokens: credited.tokensIn,
|
|
815
|
+
outputTokens: credited.tokensOut,
|
|
816
|
+
...credited.totalTokens === void 0 ? {} : { totalTokens: credited.totalTokens },
|
|
817
|
+
...credited.reasoningTokens === void 0 ? {} : { reasoningTokens: credited.reasoningTokens },
|
|
818
|
+
...credited["promptCache.readTokens"] === void 0 ? {} : { cacheReadInputTokens: credited["promptCache.readTokens"] },
|
|
819
|
+
...credited["promptCache.writeTokens"] === void 0 ? {} : { cacheCreationInputTokens: credited["promptCache.writeTokens"] },
|
|
820
|
+
...credited.costUsd === void 0 ? {} : { cost: credited.costUsd }
|
|
821
|
+
} : void 0;
|
|
796
822
|
for (const key of Object.keys(credited)) delete credited[key];
|
|
797
823
|
receipts.clear();
|
|
798
|
-
const receipt = !canonical && reports.length > 0 ? harnessUsageLlmCall(reports, agentRunName) : void 0;
|
|
799
|
-
if (receipt) addTokenUsage(turnTokens, {
|
|
800
|
-
input: receipt.tokensIn ?? 0,
|
|
801
|
-
output: receipt.tokensOut ?? 0,
|
|
802
|
-
...promptCacheTokenClasses(receipt.tokensIn, receipt.promptCache)
|
|
803
|
-
});
|
|
804
824
|
addTokenUsage(settledTokens, turnTokens);
|
|
805
825
|
turnTokens = zeroTokenUsage();
|
|
826
|
+
turnUsageUnknown = false;
|
|
806
827
|
return receipt;
|
|
807
828
|
}
|
|
808
829
|
};
|
|
@@ -817,6 +838,11 @@ function creditCanonicalUsage(event, call, credited, receipts, onCredit) {
|
|
|
817
838
|
const mode = canonicalSandboxUsageMode(event);
|
|
818
839
|
const result = { ...call };
|
|
819
840
|
const data = plainRecord$1(event.data) ?? {};
|
|
841
|
+
const usageData = canonicalUsageData(event) ?? {};
|
|
842
|
+
const supplemental = Object.fromEntries(["totalTokens", "reasoningTokens"].flatMap((key) => {
|
|
843
|
+
const value = usageData[key];
|
|
844
|
+
return value === void 0 ? [] : [[key, typeof value === "number" && Number.isFinite(value) ? value : null]];
|
|
845
|
+
}));
|
|
820
846
|
const explicitTokensUnknown = [
|
|
821
847
|
data,
|
|
822
848
|
plainRecord$1(data.usage),
|
|
@@ -827,7 +853,8 @@ function creditCanonicalUsage(event, call, credited, receipts, onCredit) {
|
|
|
827
853
|
if (event.id) {
|
|
828
854
|
const signature = JSON.stringify({
|
|
829
855
|
mode,
|
|
830
|
-
call
|
|
856
|
+
call,
|
|
857
|
+
supplemental
|
|
831
858
|
});
|
|
832
859
|
const previous = receipts.get(event.id);
|
|
833
860
|
if (previous === signature) return void 0;
|
|
@@ -860,6 +887,8 @@ function creditCanonicalUsage(event, call, credited, receipts, onCredit) {
|
|
|
860
887
|
"costUsd",
|
|
861
888
|
"estimatedCostUsd"
|
|
862
889
|
]) if (call[key] !== void 0) result[key] = credit(key, call[key]);
|
|
890
|
+
for (const [key, value] of Object.entries(supplemental)) if (typeof value !== "number") reason = `usage receipt has an invalid ${key}`;
|
|
891
|
+
else credit(key, value);
|
|
863
892
|
if (call.promptCache) result.promptCache = Object.fromEntries(Object.entries(call.promptCache).map(([key, value]) => [key, typeof value === "number" ? credit(`promptCache.${key}`, value) : value]));
|
|
864
893
|
if (reason !== void 0) {
|
|
865
894
|
result.usdKnown = false;
|
|
@@ -1234,6 +1263,10 @@ const TERMINAL_FAILURE = /^(error|errored|failed|failure|cancelled|canceled|time
|
|
|
1234
1263
|
* surfaced in-band, never dropped).
|
|
1235
1264
|
* - bare `tool*` event types (`tool.call`, `tool_result`, …) — stateless:
|
|
1236
1265
|
* `*result*` types project to `tool_result`, the rest to `tool_call`.
|
|
1266
|
+
* - codex `raw` events whose inner `item.started` / `item.updated` /
|
|
1267
|
+
* `item.completed` carries a command, MCP, collaboration, web search or
|
|
1268
|
+
* file change item — stateful on the item id, like a tool part. Other raw
|
|
1269
|
+
* events, including opencode's raw `tool_use` echoes, project nothing.
|
|
1237
1270
|
*
|
|
1238
1271
|
* Returns `[]` for every non-tool event.
|
|
1239
1272
|
*
|
|
@@ -1248,6 +1281,7 @@ function mapSandboxToolEvent(event, state) {
|
|
|
1248
1281
|
if (String(part.type ?? "") !== "tool") return [];
|
|
1249
1282
|
return projectToolPart(part, state, typeof event.id === "string" ? event.id : void 0);
|
|
1250
1283
|
}
|
|
1284
|
+
if (type === "raw") return projectCodexItem(data, state);
|
|
1251
1285
|
if (CANONICAL_STREAM_EVENT_TYPES.has(type)) return [];
|
|
1252
1286
|
if (type.includes("tool")) {
|
|
1253
1287
|
const callId = pickString(data, [
|
|
@@ -1322,6 +1356,63 @@ function projectToolPart(part, state, eventId) {
|
|
|
1322
1356
|
}
|
|
1323
1357
|
return out;
|
|
1324
1358
|
}
|
|
1359
|
+
/** Codex item types that are tool calls. Reasoning, messages and todo lists are not. */
|
|
1360
|
+
const CODEX_TOOL_ITEMS = /* @__PURE__ */ new Set([
|
|
1361
|
+
"command_execution",
|
|
1362
|
+
"mcp_tool_call",
|
|
1363
|
+
"collab_tool_call",
|
|
1364
|
+
"web_search",
|
|
1365
|
+
"file_change"
|
|
1366
|
+
]);
|
|
1367
|
+
/** Item fields that describe the call's progress or outcome rather than what it was asked to do. */
|
|
1368
|
+
const CODEX_ITEM_OUTCOME_FIELDS = /* @__PURE__ */ new Set([
|
|
1369
|
+
"id",
|
|
1370
|
+
"type",
|
|
1371
|
+
"status",
|
|
1372
|
+
"result",
|
|
1373
|
+
"error",
|
|
1374
|
+
"aggregated_output",
|
|
1375
|
+
"exit_code"
|
|
1376
|
+
]);
|
|
1377
|
+
/**
|
|
1378
|
+
* Project a codex `item.started` / `item.updated` / `item.completed` tool item through the same
|
|
1379
|
+
* per-call state as a tool part, keyed on the item id: one `tool_call` on its first frame and one
|
|
1380
|
+
* `tool_result` when it completes. Tool names follow Eval's codex intake: `server/tool` for MCP.
|
|
1381
|
+
*/
|
|
1382
|
+
function projectCodexItem(data, state) {
|
|
1383
|
+
if (data.backend !== "codex" || !data.event || typeof data.event !== "object") return [];
|
|
1384
|
+
const inner = data.event;
|
|
1385
|
+
const phase = inner.type;
|
|
1386
|
+
if (phase !== "item.started" && phase !== "item.updated" && phase !== "item.completed") return [];
|
|
1387
|
+
if (!inner.item || typeof inner.item !== "object") return [];
|
|
1388
|
+
const item = inner.item;
|
|
1389
|
+
const itemType = pickString(item, ["type"]);
|
|
1390
|
+
if (itemType === void 0 || !CODEX_TOOL_ITEMS.has(itemType)) return [];
|
|
1391
|
+
const error = item.error && typeof item.error === "object" ? pickString(item.error, ["message"]) ?? `${itemType} failed` : void 0;
|
|
1392
|
+
const failed = item.status === "failed" || error !== void 0 || itemType === "command_execution" && typeof item.exit_code === "number" && item.exit_code !== 0;
|
|
1393
|
+
const status = phase !== "item.completed" ? "running" : failed ? "failed" : "completed";
|
|
1394
|
+
const input = Object.fromEntries(Object.entries(item).filter(([key]) => !CODEX_ITEM_OUTCOME_FIELDS.has(key)));
|
|
1395
|
+
const output = item.result ?? item.aggregated_output ?? item.changes;
|
|
1396
|
+
return projectToolPart({
|
|
1397
|
+
...typeof item.id === "string" ? { callID: item.id } : {},
|
|
1398
|
+
tool: codexToolName(itemType, item),
|
|
1399
|
+
state: {
|
|
1400
|
+
status,
|
|
1401
|
+
input,
|
|
1402
|
+
...output === void 0 || output === null ? {} : { output },
|
|
1403
|
+
...status === "failed" ? { error: error ?? `${itemType} failed` } : {}
|
|
1404
|
+
}
|
|
1405
|
+
}, state, void 0);
|
|
1406
|
+
}
|
|
1407
|
+
function codexToolName(itemType, item) {
|
|
1408
|
+
if (itemType === "mcp_tool_call") {
|
|
1409
|
+
const name = [pickString(item, ["server"]), pickString(item, ["tool"])].filter((part) => part !== void 0).join("/");
|
|
1410
|
+
return name === "" ? "mcp" : name;
|
|
1411
|
+
}
|
|
1412
|
+
if (itemType === "collab_tool_call") return pickString(item, ["tool"]) ?? "subagent";
|
|
1413
|
+
if (itemType === "web_search" || itemType === "file_change") return itemType;
|
|
1414
|
+
return pickString(item, ["name"]) ?? itemType;
|
|
1415
|
+
}
|
|
1325
1416
|
function pickString(data, keys) {
|
|
1326
1417
|
for (const key of keys) {
|
|
1327
1418
|
const value = data[key];
|
|
@@ -10605,6 +10696,17 @@ function servedIdentityParts(model) {
|
|
|
10605
10696
|
snapshot
|
|
10606
10697
|
};
|
|
10607
10698
|
}
|
|
10699
|
+
/**
|
|
10700
|
+
* A trace root is valid only beside the output it commits to, with a well-formed root, artifact
|
|
10701
|
+
* reference and leaf count (at least the summary leaf). Records written before trace roots carry
|
|
10702
|
+
* none and stay valid.
|
|
10703
|
+
*/
|
|
10704
|
+
function assertTraceRoot(event, root) {
|
|
10705
|
+
if (!("traceRoot" in event) || event.traceRoot === void 0) return;
|
|
10706
|
+
const receipt = event.traceRoot;
|
|
10707
|
+
const fields = receipt !== null && typeof receipt === "object" ? receipt : {};
|
|
10708
|
+
if (typeof event.outRef !== "string" || typeof fields.root !== "string" || !/^sha256:[0-9a-f]{64}$/.test(fields.root) || typeof fields.ref !== "string" || !/^sha256:[0-9a-f]{64}$/.test(fields.ref) || typeof fields.leafCount !== "number" || !Number.isSafeInteger(fields.leafCount) || fields.leafCount < 1) throw new Error(`spawn journal corrupted: ${event.kind} for node '${event.id}' carries a malformed trace root in tree '${root}'`);
|
|
10709
|
+
}
|
|
10608
10710
|
/** One validation implementation for memory, durable append, and cold replay. */
|
|
10609
10711
|
/** @internal shared with the SQL-backed store. */
|
|
10610
10712
|
var SpawnEventIndex = class {
|
|
@@ -10617,6 +10719,7 @@ var SpawnEventIndex = class {
|
|
|
10617
10719
|
assert(event) {
|
|
10618
10720
|
const node = this.nodes.get(event.id);
|
|
10619
10721
|
this.assertRetained(node, event);
|
|
10722
|
+
assertTraceRoot(event, this.root);
|
|
10620
10723
|
if (event.kind === "execution-evidence") {
|
|
10621
10724
|
if (!node?.spawned || !/^sha256:[0-9a-f]{64}$/.test(event.outRef)) throw new Error("spawn journal corrupted: executor evidence has no spawned node or valid content reference");
|
|
10622
10725
|
}
|
|
@@ -11103,6 +11206,204 @@ function traceEvidenceFor(event) {
|
|
|
11103
11206
|
};
|
|
11104
11207
|
}
|
|
11105
11208
|
//#endregion
|
|
11209
|
+
//#region src/runtime/supervise/trace-root.ts
|
|
11210
|
+
/**
|
|
11211
|
+
* Trace roots: one Merkle root over the events a turn archived, so a single event can be proven
|
|
11212
|
+
* against the hash its journal record carries without reading the rest of the archive.
|
|
11213
|
+
*
|
|
11214
|
+
* The leaves are the archived events in stored order, each hashed with its own random salt, then
|
|
11215
|
+
* one summary leaf that counts the events and the tool calls among them. The artifact keeps every
|
|
11216
|
+
* leaf and salt and is stored under its content address in the run's result blob store, beside
|
|
11217
|
+
* the archive it commits to. A verifier recomputes leaf `i` from `events[i]` of the `outRef` blob
|
|
11218
|
+
* and `salts[i]`, checks it against `leaves[i]`, and checks `merkleRoot(leaves)` against the root
|
|
11219
|
+
* the journal recorded. Leaf identity is `(outRef, index)`: an event's own `id` is a session
|
|
11220
|
+
* buffer offset and is absent on terminal events.
|
|
11221
|
+
*
|
|
11222
|
+
* One event array has one root per node. A result always gets its own. Evidence whose events the
|
|
11223
|
+
* node already rooted gets none: a retained owner's deferred workspace capture stores the turn it
|
|
11224
|
+
* just committed again, with the workspace fields added, under another `outRef`. A second root
|
|
11225
|
+
* over the same events would give one turn two count candidates and two run-root leaves.
|
|
11226
|
+
*
|
|
11227
|
+
* Salts are random, so a trace root can never be recomputed from the archive alone. Recovery and
|
|
11228
|
+
* replay copy the recorded receipt; they never derive a new one.
|
|
11229
|
+
*/
|
|
11230
|
+
/** Schema identifier of a stored {@link TraceRootArtifact}. */
|
|
11231
|
+
const TRACE_ROOT_SCHEMA = "agent-runtime.trace-root.v1";
|
|
11232
|
+
/** Schema identifier of the {@link TraceSummary} carried by a trace root's last leaf. */
|
|
11233
|
+
const TRACE_SUMMARY_SCHEMA = "agent-runtime.trace-summary.v1";
|
|
11234
|
+
/** @internal */
|
|
11235
|
+
function traceRootWriter(blobs, nodeId) {
|
|
11236
|
+
const roots = /* @__PURE__ */ new Map();
|
|
11237
|
+
/** Digests of the event arrays this node holds a stored root for. */
|
|
11238
|
+
const rooted = /* @__PURE__ */ new Set();
|
|
11239
|
+
const persist = async (outRef, out, evidence) => {
|
|
11240
|
+
const events = archivedEvents(out);
|
|
11241
|
+
if (events === void 0) return void 0;
|
|
11242
|
+
if (evidence) {
|
|
11243
|
+
await Promise.allSettled([...roots.values()]);
|
|
11244
|
+
if (rooted.has(await eventsDigest(events))) return void 0;
|
|
11245
|
+
}
|
|
11246
|
+
const stored = await persistTraceRoot(blobs, nodeId, outRef, events);
|
|
11247
|
+
if (stored === void 0) return void 0;
|
|
11248
|
+
rooted.add(stored.digest);
|
|
11249
|
+
return stored.receipt;
|
|
11250
|
+
};
|
|
11251
|
+
const memoized = (outRef, out, evidence) => {
|
|
11252
|
+
const known = roots.get(outRef);
|
|
11253
|
+
if (known !== void 0) return known;
|
|
11254
|
+
const pending = persist(outRef, out, evidence);
|
|
11255
|
+
roots.set(outRef, pending);
|
|
11256
|
+
pending.catch(() => roots.delete(outRef));
|
|
11257
|
+
return pending;
|
|
11258
|
+
};
|
|
11259
|
+
return {
|
|
11260
|
+
write: (outRef, out) => memoized(outRef, out, false),
|
|
11261
|
+
writeEvidence: (outRef, out) => memoized(outRef, out, true),
|
|
11262
|
+
async recorded(outRef) {
|
|
11263
|
+
if (outRef === void 0) return void 0;
|
|
11264
|
+
return roots.get(outRef)?.catch(() => void 0);
|
|
11265
|
+
}
|
|
11266
|
+
};
|
|
11267
|
+
}
|
|
11268
|
+
async function persistTraceRoot(blobs, nodeId, outRef, events) {
|
|
11269
|
+
let built;
|
|
11270
|
+
try {
|
|
11271
|
+
built = await traceRootArtifact(nodeId, outRef, events);
|
|
11272
|
+
} catch (error) {
|
|
11273
|
+
if (error instanceof LedgerCanonicalizationError) return void 0;
|
|
11274
|
+
throw error;
|
|
11275
|
+
}
|
|
11276
|
+
const { artifact, digest } = built;
|
|
11277
|
+
await nextTurn();
|
|
11278
|
+
const ref = contentAddress(artifact);
|
|
11279
|
+
await nextTurn();
|
|
11280
|
+
await blobs.put(ref, artifact);
|
|
11281
|
+
return {
|
|
11282
|
+
receipt: {
|
|
11283
|
+
root: artifact.root,
|
|
11284
|
+
ref,
|
|
11285
|
+
leafCount: artifact.leafCount
|
|
11286
|
+
},
|
|
11287
|
+
digest
|
|
11288
|
+
};
|
|
11289
|
+
}
|
|
11290
|
+
function archivedEvents(out) {
|
|
11291
|
+
if (out === null || typeof out !== "object" || Array.isArray(out)) return void 0;
|
|
11292
|
+
const events = out.events;
|
|
11293
|
+
return Array.isArray(events) ? events : void 0;
|
|
11294
|
+
}
|
|
11295
|
+
/** The longest stretch of hashing between yields to the event loop. Hashing runs about 40 µs per
|
|
11296
|
+
* event, and the largest archived turn holds 65,276 events: unbroken, that blocked the process
|
|
11297
|
+
* for 2.7 s while sibling turns, coordination calls and heartbeats waited. A slice is measured
|
|
11298
|
+
* in time, not events, because one event can be megabytes. */
|
|
11299
|
+
const SLICE_MS = 10;
|
|
11300
|
+
/** Yields to the event loop once a slice has run `SLICE_MS`; `undefined` while it has not. */
|
|
11301
|
+
function slicer() {
|
|
11302
|
+
let started = performance.now();
|
|
11303
|
+
return () => {
|
|
11304
|
+
if (performance.now() - started < SLICE_MS) return void 0;
|
|
11305
|
+
return nextTurn().then(() => {
|
|
11306
|
+
started = performance.now();
|
|
11307
|
+
});
|
|
11308
|
+
};
|
|
11309
|
+
}
|
|
11310
|
+
function nextTurn() {
|
|
11311
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
11312
|
+
}
|
|
11313
|
+
/** The identity of an event array as stored: the digest of each event's stored JSON, in order.
|
|
11314
|
+
* Two arrays with one digest have the same leaves' content. */
|
|
11315
|
+
async function eventsDigest(events) {
|
|
11316
|
+
const hash = createHash("sha256");
|
|
11317
|
+
const slice = slicer();
|
|
11318
|
+
for (const event of events) {
|
|
11319
|
+
const yielded = slice();
|
|
11320
|
+
if (yielded !== void 0) await yielded;
|
|
11321
|
+
hash.update(storedText(event)).update("\n");
|
|
11322
|
+
}
|
|
11323
|
+
return hash.digest("hex");
|
|
11324
|
+
}
|
|
11325
|
+
async function traceRootArtifact(nodeId, outRef, archived) {
|
|
11326
|
+
const salts = [];
|
|
11327
|
+
const leaves = [];
|
|
11328
|
+
const tree = merkleTree();
|
|
11329
|
+
const identity = createHash("sha256");
|
|
11330
|
+
const tools = createSandboxToolPartState();
|
|
11331
|
+
const toolCalls = /* @__PURE__ */ new Map();
|
|
11332
|
+
const slice = slicer();
|
|
11333
|
+
for (const event of archived) {
|
|
11334
|
+
const yielded = slice();
|
|
11335
|
+
if (yielded !== void 0) await yielded;
|
|
11336
|
+
const text = storedText(event);
|
|
11337
|
+
identity.update(text).update("\n");
|
|
11338
|
+
const stored = JSON.parse(text);
|
|
11339
|
+
const salt = merkleSalt();
|
|
11340
|
+
const leaf = merkleLeafHash(canonicalString(jsonDocument(stored)), salt);
|
|
11341
|
+
salts.push(salt);
|
|
11342
|
+
leaves.push(leaf);
|
|
11343
|
+
tree.push(leaf);
|
|
11344
|
+
for (const projected of mapSandboxToolEvent(stored, tools)) {
|
|
11345
|
+
if (projected.type !== "tool_call") continue;
|
|
11346
|
+
toolCalls.set(projected.toolName, (toolCalls.get(projected.toolName) ?? 0) + 1);
|
|
11347
|
+
}
|
|
11348
|
+
}
|
|
11349
|
+
const summary = {
|
|
11350
|
+
schema: TRACE_SUMMARY_SCHEMA,
|
|
11351
|
+
events: archived.length,
|
|
11352
|
+
toolCalls: Object.fromEntries(toolCalls)
|
|
11353
|
+
};
|
|
11354
|
+
const salt = merkleSalt();
|
|
11355
|
+
const leaf = merkleLeafHash(canonicalString(summary), salt);
|
|
11356
|
+
salts.push(salt);
|
|
11357
|
+
leaves.push(leaf);
|
|
11358
|
+
tree.push(leaf);
|
|
11359
|
+
return {
|
|
11360
|
+
artifact: {
|
|
11361
|
+
schema: TRACE_ROOT_SCHEMA,
|
|
11362
|
+
nodeId,
|
|
11363
|
+
outRef,
|
|
11364
|
+
root: tree.root(),
|
|
11365
|
+
leafCount: leaves.length,
|
|
11366
|
+
salts,
|
|
11367
|
+
leaves,
|
|
11368
|
+
summary
|
|
11369
|
+
},
|
|
11370
|
+
digest: identity.digest("hex")
|
|
11371
|
+
};
|
|
11372
|
+
}
|
|
11373
|
+
/**
|
|
11374
|
+
* `merkleRoot(leaves)` built as the leaves arrive, so its interior hashes run inside the sliced
|
|
11375
|
+
* leaf loop instead of in one block after it (0.4 s for 65,277 leaves). It keeps the perfect
|
|
11376
|
+
* subtrees of RFC 9162, largest first, and joins two with ledger-core's own interior hash,
|
|
11377
|
+
* `merkleRoot([left, right])`; the root folds them from the right, as RFC 9162 splits at the
|
|
11378
|
+
* largest power of two.
|
|
11379
|
+
*/
|
|
11380
|
+
function merkleTree() {
|
|
11381
|
+
const peaks = [];
|
|
11382
|
+
return {
|
|
11383
|
+
push(leaf) {
|
|
11384
|
+
let hash = leaf;
|
|
11385
|
+
let size = 1;
|
|
11386
|
+
while (peaks.at(-1)?.size === size) {
|
|
11387
|
+
hash = merkleRoot([peaks.pop().hash, hash]);
|
|
11388
|
+
size *= 2;
|
|
11389
|
+
}
|
|
11390
|
+
peaks.push({
|
|
11391
|
+
hash,
|
|
11392
|
+
size
|
|
11393
|
+
});
|
|
11394
|
+
},
|
|
11395
|
+
root() {
|
|
11396
|
+
let root = peaks.at(-1).hash;
|
|
11397
|
+
for (let index = peaks.length - 2; index >= 0; index -= 1) root = merkleRoot([peaks[index].hash, root]);
|
|
11398
|
+
return root;
|
|
11399
|
+
}
|
|
11400
|
+
};
|
|
11401
|
+
}
|
|
11402
|
+
/** One array item as `JSON.stringify` writes it: `JSON.parse` of it is what `events[i]` holds. */
|
|
11403
|
+
function storedText(event) {
|
|
11404
|
+
return JSON.stringify(event) ?? "null";
|
|
11405
|
+
}
|
|
11406
|
+
//#endregion
|
|
11106
11407
|
//#region src/runtime/supervise/upstream-unavailable.ts
|
|
11107
11408
|
/**
|
|
11108
11409
|
* An upstream that cannot serve NOW: how Runtime recognizes one, and how long an agent waits for it.
|
|
@@ -11189,14 +11490,17 @@ function jitteredMs(ms, random) {
|
|
|
11189
11490
|
const retainedExecutorSeamKey = "runtime.retainedExecutor";
|
|
11190
11491
|
/** @internal A capture may finish after cancellation; its durable citation remains appendable. */
|
|
11191
11492
|
function executorEvidenceWriter(args) {
|
|
11493
|
+
const traceRoots = args.traceRoots ?? traceRootWriter(args.blobs, args.nodeId);
|
|
11192
11494
|
return async (out) => {
|
|
11193
11495
|
const snapshot = detachedSnapshot(out, "executor evidence");
|
|
11194
11496
|
const outRef = contentAddress(snapshot);
|
|
11195
11497
|
await args.blobs.put(outRef, snapshot);
|
|
11498
|
+
const traceRoot = await traceRoots.writeEvidence(outRef, snapshot);
|
|
11196
11499
|
await args.journal.appendEvent(args.rootId, {
|
|
11197
11500
|
kind: "execution-evidence",
|
|
11198
11501
|
id: args.nodeId,
|
|
11199
11502
|
outRef,
|
|
11503
|
+
...traceRoot === void 0 ? {} : { traceRoot },
|
|
11200
11504
|
seq: args.nextSequence(),
|
|
11201
11505
|
at: new Date(args.now()).toISOString()
|
|
11202
11506
|
});
|
|
@@ -11945,6 +12249,7 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
11945
12249
|
return snapshot;
|
|
11946
12250
|
}).catch((error) => {
|
|
11947
12251
|
workspaceCaptureFailure = error;
|
|
12252
|
+
noteCaptureFailure(error);
|
|
11948
12253
|
throw error;
|
|
11949
12254
|
});
|
|
11950
12255
|
}
|
|
@@ -11995,6 +12300,18 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
11995
12300
|
schedule();
|
|
11996
12301
|
};
|
|
11997
12302
|
let nativeHoldsTranscript = false;
|
|
12303
|
+
const noteCaptureFailure = (error) => {
|
|
12304
|
+
if (nativeHoldsTranscript || harnessTranscript.status !== "unavailable") return;
|
|
12305
|
+
if (harnessTranscript.reason !== "capture-did-not-run" && harnessTranscript.reason !== "enumeration-failed") return;
|
|
12306
|
+
harnessTranscript = {
|
|
12307
|
+
status: "unavailable",
|
|
12308
|
+
reason: "enumeration-failed",
|
|
12309
|
+
skipped: [{
|
|
12310
|
+
path: workspaceExecutionId,
|
|
12311
|
+
reason: errorText(error instanceof Error ? error.message : error)
|
|
12312
|
+
}]
|
|
12313
|
+
};
|
|
12314
|
+
};
|
|
11998
12315
|
const stopNativeMirror = async () => {
|
|
11999
12316
|
if (nativeTimer !== void 0) clearTimeout(nativeTimer);
|
|
12000
12317
|
nativeTimer = void 0;
|
|
@@ -12040,7 +12357,9 @@ function createProviderExecutor(provider, profile, ctx, options, placement) {
|
|
|
12040
12357
|
if (nativeHoldsTranscript && !(copy.status === "retained" && copy.fileCount > 0)) return;
|
|
12041
12358
|
harnessTranscript = copy;
|
|
12042
12359
|
nativeHoldsTranscript = true;
|
|
12043
|
-
} catch {
|
|
12360
|
+
} catch (error) {
|
|
12361
|
+
noteCaptureFailure(error);
|
|
12362
|
+
}
|
|
12044
12363
|
}).finally(() => {
|
|
12045
12364
|
if (nativeInFlight === tracked) nativeInFlight = void 0;
|
|
12046
12365
|
});
|
|
@@ -12937,7 +13256,7 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
12937
13256
|
...priorSession === void 0 ? {} : {
|
|
12938
13257
|
existingEnvironmentId: priorSession.environmentId,
|
|
12939
13258
|
identity: {
|
|
12940
|
-
sessionId: priorSession.sessionId,
|
|
13259
|
+
sessionId: retention.newSession ? mintRetainedIdentity(environmentKey, turnId).sessionId : priorSession.sessionId,
|
|
12941
13260
|
executionId: mintRetainedIdentity(environmentKey, turnId).executionId
|
|
12942
13261
|
}
|
|
12943
13262
|
}
|
|
@@ -13067,14 +13386,14 @@ async function providerExecutionSource(args, turn, signal) {
|
|
|
13067
13386
|
observationBudgetExceeded = true;
|
|
13068
13387
|
break;
|
|
13069
13388
|
}
|
|
13070
|
-
if (observedFrames > 0 && observedFrames % RETAINED_OBSERVATION_BATCH_EVENTS === 0) await awaitAbortable$1(new Promise((resolve) => setImmediate(resolve)), signal);
|
|
13389
|
+
if (observedFrames > 0 && observedFrames % RETAINED_OBSERVATION_BATCH_EVENTS === 0) await awaitAbortable$1(new Promise((resolve) => setImmediate$1(resolve)), signal);
|
|
13071
13390
|
let next;
|
|
13072
13391
|
let wake;
|
|
13073
13392
|
try {
|
|
13074
13393
|
const remaining = observationIdleMs - (Date.now() - lastObservedAt);
|
|
13075
13394
|
if (remaining <= 0) throw new RetainedReadTimeoutError("event stream", observationIdleMs);
|
|
13076
13395
|
const exactWake = new Promise((resolve) => {
|
|
13077
|
-
wake = setImmediate(() => {
|
|
13396
|
+
wake = setImmediate$1(() => {
|
|
13078
13397
|
readExactResult().then(() => resolve({ kind: "exact-result" }), () => resolve({ kind: "exact-result" }));
|
|
13079
13398
|
});
|
|
13080
13399
|
});
|
|
@@ -13292,25 +13611,30 @@ function environmentAsSandboxInstance(environment, options) {
|
|
|
13292
13611
|
if (options.requireTerminalEvent && !terminal) throw new ValidationError(`providerAsSandboxClient(${environment.provider}): stream ended without a terminal result/done/status event`);
|
|
13293
13612
|
},
|
|
13294
13613
|
async prompt(message, promptOptions) {
|
|
13295
|
-
|
|
13614
|
+
let lastResultText;
|
|
13296
13615
|
let text = "";
|
|
13297
|
-
|
|
13616
|
+
const usageLedger = createSandboxUsageLedger();
|
|
13298
13617
|
let terminal = false;
|
|
13299
13618
|
const failures = createProviderFailureLedger();
|
|
13300
13619
|
const input = turnInputFromPrompt(message, promptOptions);
|
|
13301
13620
|
providerSessionId = input.sessionId ?? null;
|
|
13302
13621
|
noteControlRef(input.controlRef);
|
|
13303
13622
|
for await (const event of environment.stream(input)) {
|
|
13304
|
-
|
|
13623
|
+
lastResultText = resultTextFromData(event.data) ?? lastResultText;
|
|
13305
13624
|
if (isTerminalEnvironmentEvent(event)) terminal = true;
|
|
13306
|
-
|
|
13625
|
+
const sandboxEvent = sandboxEventFromEnvironmentEvent(event);
|
|
13626
|
+
failures.observe(event, sandboxEvent);
|
|
13627
|
+
const usageEvent = usageSandboxEvent(event);
|
|
13628
|
+
if (usageEvent) usageLedger.observe(usageEvent, environment.id);
|
|
13629
|
+
usageLedger.observe(sandboxEvent, environment.id);
|
|
13307
13630
|
text += textFromEnvironmentEvent(event);
|
|
13308
|
-
usage = mergeTokenUsage(usage, event.usage);
|
|
13309
13631
|
}
|
|
13310
13632
|
if (options.requireTerminalEvent && !terminal) throw new ValidationError(`providerAsSandboxClient(${environment.provider}): prompt ended without a terminal result/done/status event`);
|
|
13633
|
+
usageLedger.settleTurn(environment.id);
|
|
13634
|
+
const usage = usageLedger.settledUsage();
|
|
13311
13635
|
const outcome = failures.finish();
|
|
13312
13636
|
return {
|
|
13313
|
-
response:
|
|
13637
|
+
response: lastResultText ?? text,
|
|
13314
13638
|
success: outcome?.success ?? true,
|
|
13315
13639
|
status: outcome?.status ?? "success",
|
|
13316
13640
|
durationMs: 0,
|
|
@@ -13823,19 +14147,6 @@ function isUsageType(type) {
|
|
|
13823
14147
|
function isNestedUsageType(type) {
|
|
13824
14148
|
return isSandboxTerminalEvent(type) && sandboxTerminalUsageField(type) === "usage";
|
|
13825
14149
|
}
|
|
13826
|
-
function mergeTokenUsage(left, right) {
|
|
13827
|
-
if (!left) return right;
|
|
13828
|
-
if (!right) return left;
|
|
13829
|
-
return {
|
|
13830
|
-
inputTokens: left.inputTokens + right.inputTokens,
|
|
13831
|
-
outputTokens: left.outputTokens + right.outputTokens,
|
|
13832
|
-
...left.totalTokens !== void 0 || right.totalTokens !== void 0 ? { totalTokens: (left.totalTokens ?? 0) + (right.totalTokens ?? 0) } : {},
|
|
13833
|
-
...left.cacheReadInputTokens !== void 0 || right.cacheReadInputTokens !== void 0 ? { cacheReadInputTokens: (left.cacheReadInputTokens ?? 0) + (right.cacheReadInputTokens ?? 0) } : {},
|
|
13834
|
-
...left.cacheCreationInputTokens !== void 0 || right.cacheCreationInputTokens !== void 0 ? { cacheCreationInputTokens: (left.cacheCreationInputTokens ?? 0) + (right.cacheCreationInputTokens ?? 0) } : {},
|
|
13835
|
-
...left.reasoningTokens !== void 0 || right.reasoningTokens !== void 0 ? { reasoningTokens: (left.reasoningTokens ?? 0) + (right.reasoningTokens ?? 0) } : {},
|
|
13836
|
-
...left.cost !== void 0 || right.cost !== void 0 ? { cost: (left.cost ?? 0) + (right.cost ?? 0) } : {}
|
|
13837
|
-
};
|
|
13838
|
-
}
|
|
13839
14150
|
function stringValue(value) {
|
|
13840
14151
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
13841
14152
|
}
|
|
@@ -22363,6 +22674,7 @@ function admitContinuationPolicy(policy, context) {
|
|
|
22363
22674
|
if (usd === void 0 || !finite(usd.perContinuation) || !finite(usd.perRun) || usd.perContinuation <= 0 || usd.perRun < usd.perContinuation) throw new ValidationError$1(`${context}: continuation.panel 'on' needs panelUsd with 0 < perContinuation <= perRun`);
|
|
22364
22675
|
}
|
|
22365
22676
|
if (policy.append !== void 0 && typeof policy.append !== "function") throw new ValidationError$1(`${context}: continuation.append must be a function`);
|
|
22677
|
+
if (policy.session !== void 0 && policy.session !== "native" && policy.session !== "fresh") throw new ValidationError$1(`${context}: continuation.session must be 'native' or 'fresh'`);
|
|
22366
22678
|
admitContinuationProfile(policy.profile, context);
|
|
22367
22679
|
return deadlineMs;
|
|
22368
22680
|
}
|
|
@@ -23847,6 +24159,7 @@ function settlementFields(subject, settlement) {
|
|
|
23847
24159
|
reason: settlement.reason,
|
|
23848
24160
|
...settlement.retainedPendingCause === void 0 ? {} : { retainedPendingCause: settlement.retainedPendingCause },
|
|
23849
24161
|
...settlement.outRef ? { outRef: settlement.outRef } : {},
|
|
24162
|
+
...settlement.outRef && settlement.traceRoot ? { traceRoot: settlement.traceRoot } : {},
|
|
23850
24163
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
23851
24164
|
...subject.budgetViolation ? { budgetViolation: subject.budgetViolation } : {},
|
|
23852
24165
|
trace: settlement.trace,
|
|
@@ -23982,6 +24295,7 @@ async function healReleasedSlots(opts, signal, now) {
|
|
|
23982
24295
|
...floor.infra === void 0 ? {} : { infra: floor.infra },
|
|
23983
24296
|
trace: floor.trace,
|
|
23984
24297
|
...floor.outRef ? { outRef: floor.outRef } : {},
|
|
24298
|
+
...floor.traceRoot ? { traceRoot: floor.traceRoot } : {},
|
|
23985
24299
|
...floor.providerModel ? { providerModel: floor.providerModel } : {},
|
|
23986
24300
|
...floor.harnessTranscript ? { harnessTranscript: floor.harnessTranscript } : {},
|
|
23987
24301
|
...floor.retainedPendingCause ? { retainedPendingCause: floor.retainedPendingCause } : {}
|
|
@@ -24099,6 +24413,7 @@ async function prepareInterruptedExecutors(opts, events, signal, now, parentId =
|
|
|
24099
24413
|
id: result.id,
|
|
24100
24414
|
status: reason === void 0 ? "done" : "down",
|
|
24101
24415
|
outRef: result.outRef,
|
|
24416
|
+
...result.traceRoot === void 0 ? {} : { traceRoot: result.traceRoot },
|
|
24102
24417
|
...reason === void 0 ? {} : { reason },
|
|
24103
24418
|
...infra === void 0 ? {} : { infra },
|
|
24104
24419
|
spent: result.spent,
|
|
@@ -24612,6 +24927,7 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
24612
24927
|
const acceptedRef = [...attempt].reverse().find((event) => event.kind === "execution-result");
|
|
24613
24928
|
const priorSession = taskEvent === void 0 ? void 0 : committedSession(events, start);
|
|
24614
24929
|
let sequence = Math.max(0, ...events.map((event) => "seq" in event ? event.seq : 0));
|
|
24930
|
+
const traceRoots = traceRootWriter(args.blobs, args.nodeId);
|
|
24615
24931
|
const state = {
|
|
24616
24932
|
args,
|
|
24617
24933
|
admissions,
|
|
@@ -24631,6 +24947,9 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
24631
24947
|
get priorSession() {
|
|
24632
24948
|
return state.priorSession;
|
|
24633
24949
|
},
|
|
24950
|
+
get newSession() {
|
|
24951
|
+
return state.freshSessions === true && state.priorSession !== void 0;
|
|
24952
|
+
},
|
|
24634
24953
|
preserveEnvironment: true,
|
|
24635
24954
|
admissions,
|
|
24636
24955
|
get restoreWorkspace() {
|
|
@@ -24673,7 +24992,8 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
24673
24992
|
rootId: args.rootId,
|
|
24674
24993
|
nodeId: args.nodeId,
|
|
24675
24994
|
nextSequence: () => state.nextSequence(),
|
|
24676
|
-
now: args.now
|
|
24995
|
+
now: args.now,
|
|
24996
|
+
traceRoots
|
|
24677
24997
|
}),
|
|
24678
24998
|
onWorkspaceCapture: workspaceCaptureWriter({
|
|
24679
24999
|
journal: args.journal,
|
|
@@ -24694,10 +25014,12 @@ function registerScopeRetainedOwner(scope, args) {
|
|
|
24694
25014
|
const outRef = contentAddress(result.out);
|
|
24695
25015
|
await args.blobs.put(outRef, result.out);
|
|
24696
25016
|
scope.signal.throwIfAborted();
|
|
25017
|
+
const traceRoot = await traceRoots.write(outRef, result.out);
|
|
24697
25018
|
const event = {
|
|
24698
25019
|
kind: "execution-result",
|
|
24699
25020
|
id: args.nodeId,
|
|
24700
25021
|
outRef,
|
|
25022
|
+
...traceRoot === void 0 ? {} : { traceRoot },
|
|
24701
25023
|
spent: detachedSnapshot(result.spent, "retained owner spend"),
|
|
24702
25024
|
...result.verdict ? { verdict: result.verdict } : {},
|
|
24703
25025
|
...result.outcome ? { outcome: result.outcome } : {},
|
|
@@ -25924,11 +26246,14 @@ async function reconcileScopeRetainedOwnerEnvironment(scope) {
|
|
|
25924
26246
|
environmentId
|
|
25925
26247
|
};
|
|
25926
26248
|
}
|
|
25927
|
-
/** Resume the original backend prompt; rebuilt coordination observations cannot replace it.
|
|
25928
|
-
|
|
26249
|
+
/** Resume the original backend prompt; rebuilt coordination observations cannot replace it.
|
|
26250
|
+
* `session: 'fresh'` makes every invocation after the first start a new harness session in the
|
|
26251
|
+
* environment it continues. */
|
|
26252
|
+
async function prepareScopeRetainedOwnerTask(scope, task, session = "native") {
|
|
25929
26253
|
const state = owners.get(scope);
|
|
25930
26254
|
if (!state) return task;
|
|
25931
26255
|
const { args } = state;
|
|
26256
|
+
state.freshSessions = session === "fresh";
|
|
25932
26257
|
scope.signal.throwIfAborted();
|
|
25933
26258
|
const owned = (await args.journal.loadTree(args.rootId) ?? []).filter((event) => event.id === args.nodeId);
|
|
25934
26259
|
const latestInput = [...owned].reverse().find((event) => event.kind === "execution-input");
|
|
@@ -26805,6 +27130,7 @@ function createScope(args) {
|
|
|
26805
27130
|
const recoveryReady = recovery?.spawned.ownedTreeRoot === void 0 || budgetGranted !== void 0 ? void 0 : new Promise((resolve) => {
|
|
26806
27131
|
markRecoveryReady = resolve;
|
|
26807
27132
|
});
|
|
27133
|
+
const traceRoots = traceRootWriter(args.blobs, id);
|
|
26808
27134
|
const retainedWrites = /* @__PURE__ */ new Set();
|
|
26809
27135
|
let retainedWritesClosed = false;
|
|
26810
27136
|
const retainedWrite = (write) => {
|
|
@@ -26849,10 +27175,12 @@ function createScope(args) {
|
|
|
26849
27175
|
const outRef = contentAddress(result.out);
|
|
26850
27176
|
await args.blobs.put(outRef, result.out);
|
|
26851
27177
|
controller.signal.throwIfAborted();
|
|
27178
|
+
const traceRoot = await traceRoots.write(outRef, result.out);
|
|
26852
27179
|
await args.journal.appendEvent(args.root, {
|
|
26853
27180
|
kind: "execution-result",
|
|
26854
27181
|
id,
|
|
26855
27182
|
outRef,
|
|
27183
|
+
...traceRoot === void 0 ? {} : { traceRoot },
|
|
26856
27184
|
spent: result.spent,
|
|
26857
27185
|
...result.verdict ? { verdict: result.verdict } : {},
|
|
26858
27186
|
...result.outcome ? { outcome: result.outcome } : {},
|
|
@@ -26898,7 +27226,8 @@ function createScope(args) {
|
|
|
26898
27226
|
rootId: args.root,
|
|
26899
27227
|
nodeId: id,
|
|
26900
27228
|
nextSequence: () => ordinal,
|
|
26901
|
-
now
|
|
27229
|
+
now,
|
|
27230
|
+
traceRoots
|
|
26902
27231
|
}),
|
|
26903
27232
|
onPause,
|
|
26904
27233
|
onWorkspaceCapture,
|
|
@@ -26990,6 +27319,7 @@ function createScope(args) {
|
|
|
26990
27319
|
...opts.assignmentId === void 0 ? {} : { assignmentId: opts.assignmentId },
|
|
26991
27320
|
...opts.key !== void 0 ? { key: opts.key } : {},
|
|
26992
27321
|
spent: zeroSpend(),
|
|
27322
|
+
traceRoots,
|
|
26993
27323
|
settled: void 0,
|
|
26994
27324
|
delivered: false,
|
|
26995
27325
|
executorDone: false,
|
|
@@ -27209,12 +27539,20 @@ function createScope(args) {
|
|
|
27209
27539
|
const ready = await readInteractiveReadyUntilWorkerEnds(live.readInteractiveReady, childRun, controller.signal);
|
|
27210
27540
|
if (ready !== void 0 && (ready.status === "available" || ready.reason !== "interactive-session-not-started")) writeWorkerInteractiveBinding(args.interactiveBindingDir, id, opts.label, args.root, ready, now);
|
|
27211
27541
|
});
|
|
27212
|
-
const settled = childRun.then(async (
|
|
27542
|
+
const settled = childRun.then(async (ran) => {
|
|
27543
|
+
const traceRoot = await live.traceRoots.recorded(ran.outRef);
|
|
27544
|
+
const s = traceRoot === void 0 ? ran : {
|
|
27545
|
+
...ran,
|
|
27546
|
+
traceRoot
|
|
27547
|
+
};
|
|
27213
27548
|
let resolution = s;
|
|
27214
27549
|
try {
|
|
27215
27550
|
await interactiveBindingCommitted;
|
|
27216
27551
|
} catch {
|
|
27217
|
-
resolution =
|
|
27552
|
+
resolution = {
|
|
27553
|
+
...downRecord("interactive worker binding persistence failed", true, s.trace, s.metered, s.providerModel, s.outRef, s.harnessTranscript),
|
|
27554
|
+
...s.traceRoot === void 0 ? {} : { traceRoot: s.traceRoot }
|
|
27555
|
+
};
|
|
27218
27556
|
}
|
|
27219
27557
|
live.resolved = resolution;
|
|
27220
27558
|
return resolution;
|
|
@@ -27636,7 +27974,7 @@ function createScope(args) {
|
|
|
27636
27974
|
const nested = child.readNestedScope?.();
|
|
27637
27975
|
if (nested !== void 0) await closeRetainedSlots(nested);
|
|
27638
27976
|
}
|
|
27639
|
-
const open = [...children.values()].filter((child) => child.recoveryPending === true &&
|
|
27977
|
+
const open = [...children.values()].filter((child) => child.recoveryPending === true && isTerminalNodeStatus(child.status) && child.retainedExecution !== "released" && child.retainedExecution !== "release-unconfirmed");
|
|
27640
27978
|
if (open.length === 0) return;
|
|
27641
27979
|
const prior = await args.journal.loadTree(args.root) ?? [];
|
|
27642
27980
|
for (const child of open) await closeRetainedSlot(child, "release-unconfirmed", prior);
|
|
@@ -28122,6 +28460,7 @@ async function finalizeSettlement(child, settlement, seq, args, now) {
|
|
|
28122
28460
|
id: child.id,
|
|
28123
28461
|
status: "done",
|
|
28124
28462
|
outRef: settlement.outRef,
|
|
28463
|
+
...settlement.traceRoot === void 0 ? {} : { traceRoot: settlement.traceRoot },
|
|
28125
28464
|
...settlement.verdict ? { verdict: settlement.verdict } : {},
|
|
28126
28465
|
spent: settlement.spent,
|
|
28127
28466
|
...settlement.providerModel ? { providerModel: settlement.providerModel } : {},
|
|
@@ -28201,6 +28540,7 @@ async function runChild(live, executor, childAbort, task, opts, pool, ticket, bl
|
|
|
28201
28540
|
const out = detachedSnapshot(result.out, "scope child output");
|
|
28202
28541
|
const outRef = contentAddress(out);
|
|
28203
28542
|
await blobs.put(outRef, out);
|
|
28543
|
+
await live.traceRoots.write(outRef, out);
|
|
28204
28544
|
retainedOutputRef = outRef;
|
|
28205
28545
|
if (usageError !== void 0) throw usageError;
|
|
28206
28546
|
return {
|
|
@@ -31009,6 +31349,6 @@ function isNonEmptySpend(s) {
|
|
|
31009
31349
|
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);
|
|
31010
31350
|
}
|
|
31011
31351
|
//#endregion
|
|
31012
|
-
export { environmentReader as $,
|
|
31352
|
+
export { environmentReader as $, runtimeOwnedExecutorProviderEvidence as $i, captureWorkerTraceEvidence as $n, flatOtelSpan as $r, PEER_MAIL_WIRE_KEY as $t, scopeOwnerExecutorNodeContext as A, promptControlProfileMaterialization as Ai, resolveAgentEnvironmentProvider as An, persistHarnessTranscript as Ar, captureReusableExecutorConfig as At, consumeScopeRetainedOwnerResult as B, attestRuntimeOwnedPendingExecutor as Bi, FileResultBlobStore as Bn, ROUTER_PRICE_SOURCE as Br, createInPlaceCliExecutor as Bt, deriveNodeExecutionIdentity as C, abortError$1 as Ca, AGENT_PROFILE_MATERIALIZATION_AXES as Ci, readPromptOptions as Cn, openSlotGroup as Cr, createContinuationKeeper as Ct, recordScopeOwnerMaterialization as D, providerMessageText as Da, defineProfileMaterializationContract as Di, createAgentEnvironmentProviderRegistry as Dn, runAbortable as Dr, passedItems as Dt, recordScopeOwnerDriverAttempt as E, promptOptionsFromAgentTurnInput as Ea, controlProfileMaterialization as Ei, LEAF_CONTINUATION_TASK as En, linkAbort as Er, failedItems as Et, seatExecutionProfile as F, renderUnsupported as Fi, retainedExecutorSeamKey as Fn, createCodeModeTools as Fr, snapshotExecutorConfig as Ft, scopeRetainedOwnerContext as G, knownExecutionBindingReceipt as Gi, loadSpawnForest as Gn, defaultRedactor as Gr, workerTraceSeamKey as Gt, prepareScopeRetainedOwnerSeatSwitch as H, authoredProfileDigest as Hi, InMemoryResultBlobStore as Hn, mergeTraceEnv as Hr, readWorkerTraceContext as Ht, abandonScopeRetainedOwnerInvocation as I, sandboxActProfileMaterialization as Ii, unavailablePauseMs as In, describeCodeModeTools as Ir, createWorktreeCliExecutor as It, scopeRetainedOwnerResourceReader as J, providerAttemptEvidence as Ji, isNoEntError as Jn, buildLoopOtelSpans as Jr, createActivityLog as Jt, scopeRetainedOwnerJournalRoot as K, knownMaterializationReceipt as Ki, materializeTreeView as Kn, defaultRedactorIdentityMaterial as Kr, taskToPrompt as Kt, beginScopeRetainedOwnerDrive as L, unsupportedProfileDimensions as Li, unavailableSignalOfFailure as Ln, runCodeMode as Lr, DEFAULT_SANDBOX_STEERING_MAX_TURNS as Lt, SeatChain as M, promptOnlyProfileMaterialization as Mi, decodeToolPart as Mn, resolveHarnessTranscriptCapture as Mr, cliWorktreeExecutor as Mt, SeatChainExhaustedError as N, promptResourceProfileMaterialization as Ni, sandboxSessionTraceSource as Nn, retainHarnessTranscript as Nr, createExecutor as Nt, recordScopeOwnerPause as O, fullProfileMaterialization as Oi, providerAsExecutor as On, captureHarnessTranscript as Or, verdictFromJudgeScore as Ot, authoredSeatStages as P, renderProfileMaterializationIssues as Pi, registerRetainedExecutorPreparation as Pn, contentAddress as Pr, createExecutorRegistry as Pt, SPAWN_RESOURCE_PATH_MAX_BYTES as Q, runtimeOwnedExecutorMaterialization as Qi, WORKER_TOOL_TRACE_SCHEMA_VERSION as Qn, createOtelExporter as Qr, DEFAULT_PEER_MAIL_LIMITS as Qt, bindScopeRetainedOwnerEnvironmentId as R, validateProfileMaterialization as Ri, TRACE_ROOT_SCHEMA as Rn, priceTokens as Rr, createSteerableSandboxSession as Rt, createScope as S, decodeHarnessUsage as Sa, terminateProcessTreeAndConfirm as Si, assertBoxlessPromptOptions as Sn, createWorkerSlots as Sr, checkVerdictOf as St, meterRuntimeOwnedProviderAttempt as T, promptFromAgentTurnInput as Ta, assertProfileMaterializes as Ti, runBrainLoop as Tn, abortError as Tr, expandQuestions as Tt, prepareScopeRetainedOwnerTask as U, finalizeRuntimeOwnedPendingExecutor as Ui, InMemorySpawnJournal as Un, readTraceContextFromEnv as Ur, workerTraceEnv as Ut, noteScopeRetainedOwnerCoordination as V, attestRuntimeOwnedScopeOwner as Vi, FileSpawnJournal as Vn, createPropagatingTraceEmitter as Vr, WORKER_TRACE_PROPAGATION as Vt, reconcileScopeRetainedOwnerEnvironment as W, inheritRuntimeOwnedExecutorAttestation as Wi, insideCursorNamespace as Wn, traceContextToEnv as Wr, workerTraceHeaders as Wt, scopeRetainedOwnerResult as X, runtimeOwnedDriveHarnessProviderEvidence as Xi, readCommittedJsonLines as Xn, buildRuntimeEventOtelSpans as Xr, createInbox as Xt, scopeRetainedOwnerRestorePoint as Y, recordRuntimeOwnedDriveHarnessProviderEvidence as Yi, prepareJsonlAppend as Yn, buildLoopSpanNodes as Yr, readWorkerProgress as Yt, scopeRetainedOwnerTurnEnded as Z, runtimeOwnedExecutorExecutionBinding as Zi, writeAllBytes as Zn, createOpenInferenceFileExporter as Zr, AUTHORITY_MARKERS as Zt, isDriverSpec as _, mapSandboxToolEvent as _a, harnessInvocation as _i, runAgentRounds as _n, startRetainedRun as _r, CONTINUATION_FACTS as _t, collectDelivered as a, executableAgentSpecSnapshot as aa, createRuntimeEventCollector as ai, isLiveNodeStatus as an, ReservationWaitRefused as ar, interactiveAdmissionSeamKey as at, assertRecursiveReservationPolicy as b, sandboxProgressEvents as ba, parseCodexTokenUsage as bi, SandboxEvidenceRetentionError as bn, destroyInteractiveEnvironment as br, admitFinding as bt, runTree as c, projectSandboxOutcome as ca, sanitizeKnowledgeReadinessReport as ci, bridgeModelRouteRefusal as cn, meterUsageEvent as cr, reconnectRetainedInteractiveRun as ct, classifyDriverFailure as d, canonicalStreamEventFromSandboxEvent as da, runWorktreeHarness as di, harnessUsageIsEmpty as dn, spendFromUsageTotals as dr, freeSlots as dt, runtimeOwnedPendingExecutorMaterialization as ea, generateSpanId as ei, claimsAuthority as en, isTraceAnalysisStore as er, hostDirectoryReader as et, runDriverWithRetry as f, createSandboxToolPartState as fa, captureWorktreeDiff as fi, readCodexRolloutSession as fn, bridgeRuntimeAttachmentsKey as fr, queueOf as ft, driverExecutorFactory as g, mapSandboxEvent as ga, LOCAL_HARNESSES as gi, isTerminalDecision as gn, recoverRetainedRun as gr, CONTINUATIONS_DIR as gt, driverChild as h, isSandboxTerminalEvent as ha, DEFAULT_LOCAL_HARNESS as hi, defaultSelectWinner as hn, reconnectRetainedRun as hr, mapExecutorResult as ht, bestDelivered as i, executableAgentProfileSnapshot as ia, toOtelAttributes as ii, peerMailVerbNames as in, BudgetReconcileFault as ir, providerVisibleProfile as it, settledToIteration as j, promptModelProfileMaterialization as ji, createPushTraceSource as jn, readHarnessTranscript as jr, cliInPlaceExecutor as jt, restoreScopeOwnerAcceptedExecution as k, profileMaterializationAxes$1 as ki, providerAsSandboxClient as kn, harnessTranscriptArtifact as kr, bindReusableExecutorExecutionId as kt, DriverAttemptsExhaustedError as l, readSandboxOutcome as la, sanitizeRuntimeStreamEvent as li, addHarnessUsage as ln, newUsageTotals as lr, recoverRetainedInteractiveRun as lt, upstreamUnavailableSignal as m, extractLlmCallEvent as ma, removeWorktree as mi, createSandboxForSpec as mn, errMessage as mr, gateOnDeliverable as mt, createRootHandle as n, unknownExecutionBindingReceipt as na, padSpanId as ni, isPeerMailEnvelope as nn, workerTraceAnalysisStore as nr, coordinationMcpAlias as nt, pickBestDelivered as o, detachedFrozen as oa, createRuntimeStreamEventCollector as oi, isTerminalNodeStatus as on, assertValidBudget as or, attachWorker as ot, summarizeDriverAttempts as p, createSandboxUsageLedger as pa, createWorktree as pi, TERMINAL_DECISIONS as pn, bridgeStopSignalKey as pr, rollingDispatch as pt, scopeRetainedOwnerPriorSpend as q, newExecutionAttemptId as qi, replaySpawnTree as qn, resolveRedactor as qr, DEFAULT_STALL_AFTER_MS as qt, createSupervisor as r, unknownMaterializationReceipt as ra, padTraceId as ri, peerMailTools as rn, executorFailure as rr, coordinationProfileToolPrefix as rt, runFinalizer as s, detachedSnapshot as sa, sanitizeAgentRuntimeEvent as si, bridgeAdmissionRefusal as sn, createBudgetPool as sr, readWorkerInteractiveBinding as st, DEFAULT_MAX_DEPTH as t, runtimeOwnedScopeOwnerRuntime as ta, loopEventToOtelSpan as ti, createPeerMailbox as tn, parseWorkerToolTraceArtifact as tr, resolveSpawnResourcePaths as tt, HarnessTurnFailedError as u, assertSandboxServedModel as ua, runSettledCommand as ui, createCodexRolloutStoreReader as un, spendFromUsageEvents as ur, startRetainedInteractiveRun as ut, withDriverExecutor as v, notifySandboxEventObserver as va, harnessSupportsReasoningEffort as vi, createSandboxLineage as vn, startRetainedRunInEnvironment as vr, CheckUnavailableError as vt, meterRuntimeOwnedAccounting as w, awaitAbortable$1 as wa, assertProfileMaterialization as wi, routerBrain as wn, RunCancellationReason as wr, distillFindings as wt, beginScopeOwnerAttempt as x, sumSandboxUsage as xa, CodexExecutionDiagnosticError as xi, captureBeforeDestroy as xn, environmentGone as xr, bestComposite as xt, SUBTREE_RESULT_LIMIT as y, sandboxEventServedBackend as ya, localHarnessExecutable as yi, acquireSandbox as yn, retainedCreateMaterial as yr, admitContinuationPolicy as yt, bindScopeRetainedOwnerProvider as z, worktreeCliProfileMaterialization as zi, TRACE_SUMMARY_SCHEMA as zn, routerTokenPrice as zr, createRouterTranscript as zt };
|
|
31013
31353
|
|
|
31014
|
-
//# sourceMappingURL=supervisor-
|
|
31354
|
+
//# sourceMappingURL=supervisor-bkq2b8k-.js.map
|