stitchkit 0.62.0 → 0.63.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.
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKL,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,wBAAwB;;;iBAGnC,CAAC;AACH,eAAO,MAAM,wBAAwB;;iBAAgD,CAAC;AACtF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGlC,CAAC;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASpC,CAAC;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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G,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7D,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC3F,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACtE,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACzF,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACnF,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC3E,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACtE,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC/E,qBAAqB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvF;;;;;;;OAOG;IACH,eAAe,CAAC,KAAK,EAAE;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,OAAO,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;CAC5D"}
@@ -1,4 +1,4 @@
1
- import { type AgentMessage, type AgentRun, type AgentSnapshot, type AgentTerminalReason } from './schemas';
1
+ import { type AgentMessage, type AgentRun, type AgentSnapshot, type AgentTerminalReason, type AgentUsage } from './schemas';
2
2
  import type { AgentRuntimeStore, AgentStoreMutationResult } from './store';
3
3
  export declare class AgentRuntimeConflictError extends Error {
4
4
  constructor(operation: string);
@@ -72,12 +72,40 @@ export declare function appliedSnapshot(result: AgentStoreMutationResult, operat
72
72
  conversationId: string;
73
73
  inputMessageIds: string[];
74
74
  assistantMessageId: string;
75
- state: "abandoned" | "cancelled" | "completed" | "failed" | "interrupt_requested" | "interrupted" | "queued" | "running" | "superseded";
75
+ state: "abandoned" | "absorbed" | "cancelled" | "completed" | "failed" | "interrupt_requested" | "interrupted" | "queued" | "running" | "superseded";
76
76
  revision: number;
77
77
  ownerId?: string | undefined;
78
78
  fencingToken?: number | undefined;
79
- terminalReason?: "abandoned" | "cancelled" | "interrupted" | "policy_stop" | "provider_failure" | "shutdown" | "success" | "superseded" | "timeout" | "tool_failure" | undefined;
79
+ terminalReason?: "abandoned" | "cancelled" | "interrupted" | "policy_stop" | "provider_failure" | "provider_stop" | "shutdown" | "success" | "superseded" | "timeout" | "tool_failure" | undefined;
80
80
  terminalPolicyName?: string | undefined;
81
+ absorbedIntoRunId?: string | undefined;
82
+ usage?: {
83
+ inputTokens: {
84
+ value?: number | undefined;
85
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
86
+ };
87
+ outputTokens: {
88
+ value?: number | undefined;
89
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
90
+ };
91
+ reasoningTokens?: {
92
+ value?: number | undefined;
93
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
94
+ } | undefined;
95
+ cacheReadTokens?: {
96
+ value?: number | undefined;
97
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
98
+ } | undefined;
99
+ cacheWriteTokens?: {
100
+ value?: number | undefined;
101
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
102
+ } | undefined;
103
+ cost?: {
104
+ value?: number | undefined;
105
+ currency?: string | undefined;
106
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
107
+ } | undefined;
108
+ } | undefined;
81
109
  createdAt: string;
82
110
  updatedAt: string;
83
111
  }[];
@@ -87,6 +115,8 @@ interface TerminalCommitCandidate {
87
115
  assistant: AgentMessage;
88
116
  reason: AgentTerminalReason;
89
117
  policyName?: string;
118
+ /** What this run cost, persisted with the terminal record. */
119
+ usage?: AgentUsage;
90
120
  }
91
121
  export interface AgentTerminalCommitResolution extends TerminalCommitCandidate {
92
122
  snapshot: AgentSnapshot;
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-commit.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAG3E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,SAAS,EAAE,MAAM,EAG5B;CACF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlF;AAED,UAAU,uBAAuB;IAC/B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAmFD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,iBAAiB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,uBAAuB,CAAC;IACnC,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA4CzC"}
1
+ {"version":3,"file":"terminal-commit.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAG3E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,SAAS,EAAE,MAAM,EAG5B;CACF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlF;AAED,UAAU,uBAAuB;IAC/B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAoFD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,iBAAiB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,uBAAuB,CAAC;IACnC,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA6CzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-status.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACnE;;;;;;;;;GASG;AACH;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,OAAO,CAOlF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAWnF"}
1
+ {"version":3,"file":"terminal-status.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACnE;;;;;;;;;GASG;AACH;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,OAAO,CAOlF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAanF"}
@@ -10,7 +10,7 @@ export { type AgentProtocol, type AgentProtocolConfig, defineAgentProtocol, } fr
10
10
  export { type AgentRuntime, type AgentRuntimeAdmission, type AgentRuntimeConfig, type AgentRuntimeInput, type AgentRuntimeInterruptInput, type AgentRuntimePrepareStep, type AgentRuntimeProtocolInput, type AgentRuntimeRecordIds, type AgentRuntimeRecoverOptions, type AgentRuntimeRecoveryDecision, type AgentRuntimeRecoveryInput, type AgentRuntimeRecoveryOutcome, type AgentRuntimeRunContext, type AgentRuntimeStopPolicy, createAgentRuntime, } from './agent-runtime/runtime';
11
11
  export type { AgentRuntimeResult } from './agent-runtime/runtime-result';
12
12
  export * from './agent-runtime/schemas';
13
- export { type AcceptInputAndAssignRun, AcceptInputAndAssignRunSchema, type AcquireAgentRun, AcquireAgentRunSchema, type AgentRuntimeStore, AgentStoreAppliedSchema, AgentStoreConflictSchema, AgentStoreDuplicateSchema, type AgentStoreMutationResult, AgentStoreMutationResultSchema, AgentStoreNotFoundSchema, type CheckpointRunAssistant, CheckpointRunAssistantSchema, type CommitRunTerminal, CommitRunTerminalSchema, type RecoverAgentRun, RecoverAgentRunSchema, type ReplaceCompactedRange, ReplaceCompactedRangeSchema, type RequestRunInterrupt, RequestRunInterruptSchema, } from './agent-runtime/store';
13
+ export { type AbsorbQueuedRun, AbsorbQueuedRunSchema, type AcceptInputAndAssignRun, AcceptInputAndAssignRunSchema, type AcquireAgentRun, AcquireAgentRunSchema, type AgentRuntimeStore, AgentStoreAppliedSchema, AgentStoreConflictSchema, AgentStoreDuplicateSchema, type AgentStoreMutationResult, AgentStoreMutationResultSchema, AgentStoreNotFoundSchema, type CheckpointRunAssistant, CheckpointRunAssistantSchema, type CommitRunTerminal, CommitRunTerminalSchema, type RecoverAgentRun, RecoverAgentRunSchema, type ReplaceCompactedRange, ReplaceCompactedRangeSchema, type RequestRunInterrupt, RequestRunInterruptSchema, } from './agent-runtime/store';
14
14
  export { type AgentAdmissionReceipt, AgentAdmissionReceiptSchema, type AgentHistoryMutation, AgentHistoryMutationSchema, type AgentRecoverableDescriptor, AgentRecoverableDescriptorSchema, type AgentRecoverablePage, AgentRecoverablePageSchema, type AgentRuntimeHead, AgentRuntimeHeadSchema, type AgentRuntimeStoreDriver, type AgentStoreCompareAndSwapResult, type AgentStoredRun, AgentStoredRunSchema, createAgentRuntimeStore, createMemoryAgentRuntimeStore, } from './agent-runtime/store-driver';
15
15
  export { AgentRuntimeConflictError } from './agent-runtime/terminal-commit';
16
16
  //# sourceMappingURL=agent-runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-runtime.d.ts","sourceRoot":"","sources":["../src/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,uBAAu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EACpB,qBAAqB,EACrB,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,0BAA0B,EAC/B,gCAAgC,EAChC,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,cAAc,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -29,7 +29,7 @@ import {
29
29
  AgentToolResultPartSchema,
30
30
  AgentUsageSchema,
31
31
  AgentUsageValueSchema
32
- } from "./index-58vkx74h.js";
32
+ } from "./index-b1k33127.js";
33
33
  import"./index-6djpbnda.js";
34
34
  import"./index-cby4ar3v.js";
35
35
  import {
@@ -50,8 +50,9 @@ function isSpeakableAssistantStatus(status) {
50
50
  return status === "completed" || status === "interrupted" || status === "committed";
51
51
  }
52
52
  function assistantStatus(reason) {
53
- if (reason === "success" || reason === "policy_stop")
53
+ if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
54
54
  return "completed";
55
+ }
55
56
  if (reason === "superseded")
56
57
  return "superseded";
57
58
  if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
@@ -1058,7 +1059,10 @@ function createRuntimeAdmissionLanes() {
1058
1059
  }
1059
1060
 
1060
1061
  // src/agent-runtime/run-execution.ts
1061
- import { stepCountIs, streamText } from "ai";
1062
+ import {
1063
+ stepCountIs,
1064
+ streamText
1065
+ } from "ai";
1062
1066
 
1063
1067
  // src/agent-runtime/runtime-internals.ts
1064
1068
  import { z as z5 } from "zod";
@@ -1089,7 +1093,8 @@ function canonicalTerminal(snapshot, runId, retainedAssistant) {
1089
1093
  assistant,
1090
1094
  reason: run.terminalReason,
1091
1095
  committedByCaller: false,
1092
- ...run.terminalPolicyName && { policyName: run.terminalPolicyName }
1096
+ ...run.terminalPolicyName && { policyName: run.terminalPolicyName },
1097
+ ...run.usage && { usage: run.usage }
1093
1098
  };
1094
1099
  }
1095
1100
  function interruptedCandidate(candidate, run, now) {
@@ -1126,7 +1131,8 @@ async function commitAgentRunTerminal(input) {
1126
1131
  },
1127
1132
  assistant: candidate.assistant,
1128
1133
  reason: candidate.reason,
1129
- ...candidate.policyName && { policyName: candidate.policyName }
1134
+ ...candidate.policyName && { policyName: candidate.policyName },
1135
+ ...candidate.usage && { usage: candidate.usage }
1130
1136
  });
1131
1137
  if (committed.outcome === "applied") {
1132
1138
  const terminal2 = canonicalTerminal(committed.snapshot, candidate.run.id);
@@ -1365,7 +1371,8 @@ function createRunExecutor(dependencies) {
1365
1371
  let eventCount = 0;
1366
1372
  let sequence = 0;
1367
1373
  let terminalReason = "success";
1368
- let usage;
1374
+ let usage = input.acceptedRun.usage;
1375
+ let sawProviderFinish = false;
1369
1376
  let step = 0;
1370
1377
  let selectedModel;
1371
1378
  let internalCause;
@@ -1407,13 +1414,14 @@ function createRunExecutor(dependencies) {
1407
1414
  expectedRevision: run.revision,
1408
1415
  ownerId: runtimeEpoch,
1409
1416
  ...run.fencingToken !== undefined && { fencingToken: run.fencingToken },
1410
- assistant
1417
+ assistant,
1418
+ usage: statedUsage(usage)
1411
1419
  }), "assistant checkpoint");
1412
1420
  run = findRun(snapshot.runs, run.id);
1413
1421
  const checkpointMetrics = {
1414
1422
  partial: true,
1415
1423
  durationMs: performance.now() - runStartedAt,
1416
- ...usage && { usage },
1424
+ usage: statedUsage(usage),
1417
1425
  ...firstOutputAt !== undefined && { ttftMs: firstOutputAt - runStartedAt }
1418
1426
  };
1419
1427
  await publish({
@@ -1436,6 +1444,8 @@ function createRunExecutor(dependencies) {
1436
1444
  });
1437
1445
  snapshot = compacted.snapshot;
1438
1446
  run = findRun(snapshot.runs, run.id);
1447
+ if (compacted.usage)
1448
+ usage = addUsage(usage, compacted.usage);
1439
1449
  }
1440
1450
  const assertCurrent = async () => {
1441
1451
  if (executionSignal.aborted)
@@ -1484,7 +1494,7 @@ function createRunExecutor(dependencies) {
1484
1494
  if (prompt.contextDecision === "requires-compaction") {
1485
1495
  throw new Error("Agent context still exceeds the model budget after compaction");
1486
1496
  }
1487
- const history = await (config.history?.project ? config.history.project(snapshot.messages) : projectAgentHistory(snapshot.messages, {
1497
+ const projectHistory = (source) => config.history?.project ? config.history.project(source.messages) : projectAgentHistory(source.messages, {
1488
1498
  ...config.history?.resolveFile && { resolveFile: config.history.resolveFile },
1489
1499
  ...config.history?.unresolvedFile && {
1490
1500
  unresolvedFile: config.history.unresolvedFile
@@ -1492,7 +1502,44 @@ function createRunExecutor(dependencies) {
1492
1502
  ...config.history?.interruptedAssistant && {
1493
1503
  interruptedAssistant: config.history.interruptedAssistant
1494
1504
  }
1495
- }));
1505
+ });
1506
+ const history = await projectHistory(snapshot);
1507
+ const absorbPending = async () => {
1508
+ if (!input.absorbable?.size || executionSignal.aborted)
1509
+ return;
1510
+ const latest = await config.store.loadSnapshot(run.conversationId);
1511
+ const current = latest.runs.find((candidate) => candidate.id === run.id);
1512
+ if (current?.state !== "running" || current.ownerId !== runtimeEpoch) {
1513
+ return;
1514
+ }
1515
+ const pending = latest.runs.find((candidate) => candidate.state === "queued" && input.absorbable?.has(candidate.id));
1516
+ if (!pending)
1517
+ return;
1518
+ const absorbed = await config.store.absorbQueuedRun({
1519
+ conversationId: run.conversationId,
1520
+ runningRunId: current.id,
1521
+ runningExpectedRevision: current.revision,
1522
+ ownerId: runtimeEpoch,
1523
+ ...current.fencingToken !== undefined && { fencingToken: current.fencingToken },
1524
+ queuedRunId: pending.id,
1525
+ queuedExpectedRevision: pending.revision
1526
+ });
1527
+ if (absorbed.outcome !== "applied")
1528
+ return;
1529
+ input.onAbsorbed?.(pending.id);
1530
+ snapshot = absorbed.snapshot;
1531
+ run = findRun(snapshot.runs, run.id);
1532
+ await publish({
1533
+ type: "run-state",
1534
+ eventId: agentDurableEventId("run-state", run.id, snapshot.version),
1535
+ conversationId: run.conversationId,
1536
+ runId: run.id,
1537
+ snapshotVersion: snapshot.version,
1538
+ state: run.state,
1539
+ emittedAt: now().toISOString()
1540
+ });
1541
+ return [...await projectHistory(snapshot)];
1542
+ };
1496
1543
  const maxStepCondition = stepCountIs(maxSteps);
1497
1544
  const stopConditions = [
1498
1545
  async (options) => {
@@ -1518,8 +1565,10 @@ function createRunExecutor(dependencies) {
1518
1565
  abortSignal: executionSignal,
1519
1566
  maxRetries: 0,
1520
1567
  stopWhen: stopConditions,
1521
- ...config.loop?.prepareStep && {
1522
- prepareStep: (options) => config.loop?.prepareStep?.({ ...options, ...runtimeContext })
1568
+ prepareStep: async (options) => {
1569
+ const absorbed = await absorbPending();
1570
+ const prepared = await config.loop?.prepareStep?.({ ...options, ...runtimeContext }) ?? {};
1571
+ return absorbed && !prepared.messages ? { ...prepared, messages: absorbed } : prepared;
1523
1572
  }
1524
1573
  });
1525
1574
  for await (const part of result.stream) {
@@ -1752,9 +1801,13 @@ function createRunExecutor(dependencies) {
1752
1801
  });
1753
1802
  step += 1;
1754
1803
  } else if (part.type === "finish" && part.finishReason !== "stop") {
1755
- terminalReason = "policy_stop";
1804
+ if (terminalReason === "success") {
1805
+ terminalReason = part.finishReason === "error" ? "provider_failure" : "provider_stop";
1806
+ internalCause ??= { finishReason: part.finishReason };
1807
+ }
1756
1808
  }
1757
1809
  if (part.type === "finish") {
1810
+ sawProviderFinish = true;
1758
1811
  usage = mergeRunTotals(normalizeSdkUsage(part.totalUsage), usage);
1759
1812
  }
1760
1813
  if (eventCount % checkpointEveryEvents === 0)
@@ -1822,7 +1875,8 @@ function createRunExecutor(dependencies) {
1822
1875
  run,
1823
1876
  assistant,
1824
1877
  reason: terminalReason,
1825
- ...terminalPolicyName && { policyName: terminalPolicyName }
1878
+ ...terminalPolicyName && { policyName: terminalPolicyName },
1879
+ usage: spent
1826
1880
  },
1827
1881
  now
1828
1882
  });
@@ -1840,7 +1894,7 @@ function createRunExecutor(dependencies) {
1840
1894
  terminalReason = terminal.reason;
1841
1895
  terminalPolicyName = terminal.policyName;
1842
1896
  const terminalMetrics = terminal.committedByCaller ? {
1843
- partial: false,
1897
+ partial: !sawProviderFinish,
1844
1898
  durationMs: performance.now() - runStartedAt,
1845
1899
  usage: spent,
1846
1900
  ...firstOutputAt !== undefined && { ttftMs: firstOutputAt - runStartedAt }
@@ -1898,6 +1952,9 @@ function createAgentRuntime(config) {
1898
1952
  if (idleTimeoutMs !== undefined && (!Number.isSafeInteger(idleTimeoutMs) || idleTimeoutMs < 1)) {
1899
1953
  throw new TypeError("idleTimeoutMs must be a positive safe integer");
1900
1954
  }
1955
+ const absorbable = new Set;
1956
+ const absorbedInto = new Map;
1957
+ const runResults = new Map;
1901
1958
  const policyNames = new Set(["max-steps"]);
1902
1959
  for (const policy of config.loop?.stopPolicies ?? []) {
1903
1960
  if (!policy.name || policyNames.has(policy.name)) {
@@ -2030,7 +2087,8 @@ function createAgentRuntime(config) {
2030
2087
  if (existingTicket)
2031
2088
  return existingTicket;
2032
2089
  const key = config.runs?.key?.(input) ?? input.conversationId;
2033
- const policy = typeof config.runs?.inputPolicy === "function" ? config.runs.inputPolicy(input) : config.runs?.inputPolicy ?? "queue";
2090
+ const declaredPolicy = typeof config.runs?.inputPolicy === "function" ? config.runs.inputPolicy(input) : config.runs?.inputPolicy ?? "queue";
2091
+ const policy = declaredPolicy === "inject" ? "queue" : declaredPolicy;
2034
2092
  const nowIso = now().toISOString();
2035
2093
  const inputMessageId = rawInput.recordIds?.inputMessageId ?? generateId();
2036
2094
  const runId = rawInput.recordIds?.runId ?? generateId();
@@ -2156,6 +2214,8 @@ function createAgentRuntime(config) {
2156
2214
  state: acceptedRun.state,
2157
2215
  emittedAt: now().toISOString()
2158
2216
  });
2217
+ if (declaredPolicy === "inject")
2218
+ absorbable.add(acceptedRun.id);
2159
2219
  outerAccepted.resolve();
2160
2220
  if (acceptance.outcome === "duplicate") {
2161
2221
  if (!acceptedRun.terminalReason) {
@@ -2204,7 +2264,25 @@ function createAgentRuntime(config) {
2204
2264
  await waitForAdmissionAcceptances(reservation.lane);
2205
2265
  return {
2206
2266
  runId: acceptedRun.id,
2207
- execute: () => executeRun({ acceptedRun, context, signal })
2267
+ execute: () => {
2268
+ const answeredBy = absorbedInto.get(acceptedRun.id);
2269
+ const answer = answeredBy ? runResults.get(answeredBy) : undefined;
2270
+ if (answer)
2271
+ return answer;
2272
+ const running = executeRun({
2273
+ acceptedRun,
2274
+ context,
2275
+ signal,
2276
+ absorbable,
2277
+ onAbsorbed: (absorbedRunId) => {
2278
+ absorbedInto.set(absorbedRunId, acceptedRun.id);
2279
+ }
2280
+ });
2281
+ runResults.set(acceptedRun.id, running);
2282
+ return running.finally(() => {
2283
+ absorbable.delete(acceptedRun.id);
2284
+ });
2285
+ }
2208
2286
  };
2209
2287
  }
2210
2288
  });
@@ -2437,7 +2515,8 @@ var CheckpointRunAssistantSchema = z6.object({
2437
2515
  expectedRevision: AgentRecordVersionSchema,
2438
2516
  ownerId: z6.string().min(1),
2439
2517
  fencingToken: AgentRecordVersionSchema.optional(),
2440
- assistant: AgentMessageSchema
2518
+ assistant: AgentMessageSchema,
2519
+ usage: AgentUsageSchema.optional()
2441
2520
  });
2442
2521
  var CommitRunTerminalSchema = z6.object({
2443
2522
  conversationId: AgentRecordIdSchema,
@@ -2447,7 +2526,17 @@ var CommitRunTerminalSchema = z6.object({
2447
2526
  fencingToken: AgentRecordVersionSchema.optional(),
2448
2527
  assistant: AgentMessageSchema,
2449
2528
  reason: AgentTerminalReasonSchema,
2450
- policyName: z6.string().min(1).optional()
2529
+ policyName: z6.string().min(1).optional(),
2530
+ usage: AgentUsageSchema.optional()
2531
+ });
2532
+ var AbsorbQueuedRunSchema = z6.object({
2533
+ conversationId: AgentRecordIdSchema,
2534
+ runningRunId: AgentRecordIdSchema,
2535
+ runningExpectedRevision: AgentRecordVersionSchema,
2536
+ ownerId: z6.string().min(1),
2537
+ fencingToken: AgentRecordVersionSchema.optional(),
2538
+ queuedRunId: AgentRecordIdSchema,
2539
+ queuedExpectedRevision: AgentRecordVersionSchema
2451
2540
  });
2452
2541
  var RequestRunInterruptSchema = z6.object({
2453
2542
  conversationId: AgentRecordIdSchema,
@@ -2593,8 +2682,9 @@ function conflict(actualVersion) {
2593
2682
  return { outcome: "conflict", actualVersion };
2594
2683
  }
2595
2684
  function terminalState(reason) {
2596
- if (reason === "success" || reason === "policy_stop")
2685
+ if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
2597
2686
  return "completed";
2687
+ }
2598
2688
  if (reason === "interrupted")
2599
2689
  return "interrupted";
2600
2690
  if (reason === "superseded")
@@ -2616,6 +2706,7 @@ function applied(current, input, effects) {
2616
2706
  messages: input.messages ?? current.messages
2617
2707
  }),
2618
2708
  ...effects?.runRecord && { runRecord: effects.runRecord },
2709
+ ...effects?.secondaryRunRecord && { secondaryRunRecord: effects.secondaryRunRecord },
2619
2710
  ...effects?.admissionReceipt && { admissionReceipt: effects.admissionReceipt },
2620
2711
  ...effects?.historyMutation && { historyMutation: effects.historyMutation }
2621
2712
  };
@@ -2659,6 +2750,39 @@ function reduceStore(current, operation) {
2659
2750
  historyMutation: { type: "admit", input: input.input }
2660
2751
  });
2661
2752
  }
2753
+ if (operation.type === "absorb") {
2754
+ const input = operation.input;
2755
+ if (current.conversationId !== input.conversationId)
2756
+ return { outcome: "not_found" };
2757
+ const running = current.runs.find((candidate) => candidate.id === input.runningRunId);
2758
+ const queued = current.runs.find((candidate) => candidate.id === input.queuedRunId);
2759
+ if (!running || !queued)
2760
+ return { outcome: "not_found" };
2761
+ if (running.revision !== input.runningExpectedRevision || running.state !== "running" || running.ownerId !== input.ownerId || input.fencingToken !== undefined && running.fencingToken !== input.fencingToken) {
2762
+ return conflict(running.revision);
2763
+ }
2764
+ if (queued.revision !== input.queuedExpectedRevision || queued.state !== "queued" || queued.ownerId !== undefined || queued.terminalReason !== undefined || queued.id === running.id) {
2765
+ return conflict(queued.revision);
2766
+ }
2767
+ const stamp = new Date().toISOString();
2768
+ const grown = AgentRunSchema.parse({
2769
+ ...running,
2770
+ inputMessageIds: [...running.inputMessageIds, ...queued.inputMessageIds],
2771
+ revision: running.revision + 1,
2772
+ updatedAt: stamp
2773
+ });
2774
+ const emptied = AgentRunSchema.parse({
2775
+ ...queued,
2776
+ state: "absorbed",
2777
+ absorbedIntoRunId: running.id,
2778
+ revision: queued.revision + 1,
2779
+ updatedAt: stamp
2780
+ });
2781
+ return applied(current, { runs: replaceRun(replaceRun(current.runs, grown), emptied) }, {
2782
+ runRecord: AgentStoredRunSchema.parse({ schemaVersion: 1, run: grown }),
2783
+ secondaryRunRecord: AgentStoredRunSchema.parse({ schemaVersion: 1, run: emptied })
2784
+ });
2785
+ }
2662
2786
  const conversationId = operation.input.conversationId;
2663
2787
  const run = operation.type === "compact" ? undefined : current.runs.find((candidate) => candidate.id === operation.input.runId);
2664
2788
  if (operation.type !== "compact" && !run)
@@ -2688,6 +2812,7 @@ function reduceStore(current, operation) {
2688
2812
  }
2689
2813
  const next = AgentRunSchema.parse({
2690
2814
  ...run,
2815
+ ...input.usage && { usage: input.usage },
2691
2816
  revision: run.revision + 1,
2692
2817
  updatedAt: new Date().toISOString()
2693
2818
  });
@@ -2774,6 +2899,7 @@ function reduceStore(current, operation) {
2774
2899
  state: terminalState(input.reason),
2775
2900
  terminalReason: input.reason,
2776
2901
  ...input.policyName && { terminalPolicyName: input.policyName },
2902
+ ...input.usage && { usage: input.usage },
2777
2903
  revision: run.revision + 1,
2778
2904
  updatedAt: new Date().toISOString()
2779
2905
  });
@@ -2862,7 +2988,7 @@ function createAgentRuntimeStore(driver) {
2862
2988
  });
2863
2989
  const mutate = (operation) => driver.transaction(async (transaction) => {
2864
2990
  const conversationId = operationConversationId(operation);
2865
- const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" ? undefined : operation.input.runId;
2991
+ const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" ? undefined : operation.type === "absorb" ? operation.input.queuedRunId : operation.input.runId;
2866
2992
  const [stored, messages, activeRecords, operationRecord, duplicateReceipt] = await Promise.all([
2867
2993
  driver.head.load(transaction, conversationId),
2868
2994
  driver.history.load(transaction, conversationId),
@@ -2943,6 +3069,9 @@ function createAgentRuntimeStore(driver) {
2943
3069
  return conflict(outcome.actualVersion);
2944
3070
  if (reduced.runRecord)
2945
3071
  await driver.runs.save(transaction, reduced.runRecord);
3072
+ if (reduced.secondaryRunRecord) {
3073
+ await driver.runs.save(transaction, reduced.secondaryRunRecord);
3074
+ }
2946
3075
  if (reduced.admissionReceipt) {
2947
3076
  await driver.admissions.create(transaction, reduced.admissionReceipt);
2948
3077
  }
@@ -2966,6 +3095,7 @@ function createAgentRuntimeStore(driver) {
2966
3095
  type: "interrupt",
2967
3096
  input: RequestRunInterruptSchema.parse(input)
2968
3097
  }),
3098
+ absorbQueuedRun: (input) => mutate({ type: "absorb", input: AbsorbQueuedRunSchema.parse(input) }),
2969
3099
  recoverRun: (input) => mutate({ type: "recover", input: RecoverAgentRunSchema.parse(input) }),
2970
3100
  commitRunTerminal: (input) => mutate({ type: "terminal", input: CommitRunTerminalSchema.parse(input) }),
2971
3101
  replaceCompactedRange: (input) => mutate({
@@ -3138,6 +3268,7 @@ function createMemoryAgentRuntimeStore() {
3138
3268
  return createAgentRuntimeStore(driver);
3139
3269
  }
3140
3270
  export {
3271
+ AbsorbQueuedRunSchema,
3141
3272
  AcceptInputAndAssignRunSchema,
3142
3273
  AcquireAgentRunSchema,
3143
3274
  AgentAdmissionEventSchema,
@@ -99,6 +99,7 @@ var AgentRunStateSchema = z.enum([
99
99
  "completed",
100
100
  "interrupted",
101
101
  "superseded",
102
+ "absorbed",
102
103
  "failed",
103
104
  "cancelled",
104
105
  "abandoned"
@@ -106,6 +107,7 @@ var AgentRunStateSchema = z.enum([
106
107
  var AgentTerminalReasonSchema = z.enum([
107
108
  "success",
108
109
  "policy_stop",
110
+ "provider_stop",
109
111
  "interrupted",
110
112
  "superseded",
111
113
  "cancelled",
@@ -115,6 +117,23 @@ var AgentTerminalReasonSchema = z.enum([
115
117
  "tool_failure",
116
118
  "abandoned"
117
119
  ]);
120
+ var AgentUsageValueSchema = z.object({
121
+ value: z.number().nonnegative().optional(),
122
+ provenance: z.enum(["provider-reported", "computed", "estimated", "unavailable"])
123
+ });
124
+ var AgentCostValueSchema = z.object({
125
+ value: z.number().nonnegative().optional(),
126
+ currency: z.string().length(3).optional(),
127
+ provenance: z.enum(["provider-reported", "computed", "estimated", "unavailable"])
128
+ });
129
+ var AgentUsageSchema = z.object({
130
+ inputTokens: AgentUsageValueSchema,
131
+ outputTokens: AgentUsageValueSchema,
132
+ reasoningTokens: AgentUsageValueSchema.optional(),
133
+ cacheReadTokens: AgentUsageValueSchema.optional(),
134
+ cacheWriteTokens: AgentUsageValueSchema.optional(),
135
+ cost: AgentCostValueSchema.optional()
136
+ });
118
137
  var AgentRunSchema = z.object({
119
138
  schemaVersion: z.literal(1),
120
139
  id: AgentRecordIdSchema,
@@ -127,6 +146,8 @@ var AgentRunSchema = z.object({
127
146
  fencingToken: AgentRecordVersionSchema.optional(),
128
147
  terminalReason: AgentTerminalReasonSchema.optional(),
129
148
  terminalPolicyName: z.string().min(1).optional(),
149
+ absorbedIntoRunId: AgentRecordIdSchema.optional(),
150
+ usage: AgentUsageSchema.optional(),
130
151
  createdAt: AgentTimestampSchema,
131
152
  updatedAt: AgentTimestampSchema
132
153
  });
@@ -137,23 +158,6 @@ var AgentSnapshotSchema = z.object({
137
158
  messages: z.array(AgentMessageSchema),
138
159
  runs: z.array(AgentRunSchema)
139
160
  });
140
- var AgentUsageValueSchema = z.object({
141
- value: z.number().nonnegative().optional(),
142
- provenance: z.enum(["provider-reported", "computed", "estimated", "unavailable"])
143
- });
144
- var AgentCostValueSchema = z.object({
145
- value: z.number().nonnegative().optional(),
146
- currency: z.string().length(3).optional(),
147
- provenance: z.enum(["provider-reported", "computed", "estimated", "unavailable"])
148
- });
149
- var AgentUsageSchema = z.object({
150
- inputTokens: AgentUsageValueSchema,
151
- outputTokens: AgentUsageValueSchema,
152
- reasoningTokens: AgentUsageValueSchema.optional(),
153
- cacheReadTokens: AgentUsageValueSchema.optional(),
154
- cacheWriteTokens: AgentUsageValueSchema.optional(),
155
- cost: AgentCostValueSchema.optional()
156
- });
157
161
  var AgentRunMetricsSchema = z.object({
158
162
  partial: z.boolean(),
159
163
  usage: AgentUsageSchema.optional(),
@@ -161,4 +165,4 @@ var AgentRunMetricsSchema = z.object({
161
165
  ttftMs: z.number().nonnegative().optional()
162
166
  });
163
167
 
164
- export { AgentRecordIdSchema, AgentRecordVersionSchema, AgentTimestampSchema, AgentJsonObjectSchema, AgentProviderEnvelopeSchema, AgentTextPartSchema, AgentReasoningPartSchema, AgentFilePartSchema, AgentSourcePartSchema, AgentToolCallPartSchema, AgentToolResultPartSchema, AgentOpaquePartSchema, AgentControlPartSchema, AgentMessagePartSchema, AgentMessageRoleSchema, AgentMessageStatusSchema, AgentMessageSchema, AgentAssistantPlaceholderSchema, AgentRunStateSchema, AgentTerminalReasonSchema, AgentRunSchema, AgentSnapshotSchema, AgentUsageValueSchema, AgentCostValueSchema, AgentUsageSchema, AgentRunMetricsSchema };
168
+ export { AgentRecordIdSchema, AgentRecordVersionSchema, AgentTimestampSchema, AgentJsonObjectSchema, AgentProviderEnvelopeSchema, AgentTextPartSchema, AgentReasoningPartSchema, AgentFilePartSchema, AgentSourcePartSchema, AgentToolCallPartSchema, AgentToolResultPartSchema, AgentOpaquePartSchema, AgentControlPartSchema, AgentMessagePartSchema, AgentMessageRoleSchema, AgentMessageStatusSchema, AgentMessageSchema, AgentAssistantPlaceholderSchema, AgentRunStateSchema, AgentTerminalReasonSchema, AgentUsageValueSchema, AgentCostValueSchema, AgentUsageSchema, AgentRunSchema, AgentSnapshotSchema, AgentRunMetricsSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"agent-store-conformance.d.ts","sourceRoot":"","sources":["../../src/testing/agent-store-conformance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,MAAM,WAAW,2BAA2B;IAC1C,WAAW,IAAI,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/D;AAwCD,gFAAgF;AAChF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,IAAI,CAAC,CAmRf"}
1
+ {"version":3,"file":"agent-store-conformance.d.ts","sourceRoot":"","sources":["../../src/testing/agent-store-conformance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,MAAM,WAAW,2BAA2B;IAC1C,WAAW,IAAI,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/D;AAwCD,gFAAgF;AAChF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,IAAI,CAAC,CA4Sf"}
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentMessageSchema,
3
3
  AgentRunSchema
4
- } from "./index-58vkx74h.js";
4
+ } from "./index-b1k33127.js";
5
5
  import {
6
6
  createApplication
7
7
  } from "./index-eabpd4tb.js";
@@ -283,12 +283,20 @@ async function runAgentStoreConformance(config) {
283
283
  parts: [{ type: "text", text: "checkpoint" }],
284
284
  createdAt: "2026-08-22T00:00:00.000Z",
285
285
  updatedAt: "2026-08-22T00:00:01.000Z"
286
- })
286
+ }),
287
+ usage: {
288
+ inputTokens: { value: 1000, provenance: "provider-reported" },
289
+ outputTokens: { value: 100, provenance: "provider-reported" },
290
+ cost: { value: 0.25, currency: "USD", provenance: "provider-reported" }
291
+ }
287
292
  });
288
293
  requireOutcome(checkpoint, "applied");
289
294
  const checkpointedRun = checkpoint.snapshot.runs.find((run) => run.id === running.id);
290
295
  if (!checkpointedRun)
291
296
  throw new Error("Checkpointed run disappeared");
297
+ if (checkpointedRun.usage?.cost?.value !== 0.25) {
298
+ throw new Error("Checkpoint did not persist the run usage it was given");
299
+ }
292
300
  const terminalAssistant = AgentMessageSchema.parse({
293
301
  schemaVersion: 1,
294
302
  id: running.assistantMessageId,
@@ -307,7 +315,12 @@ async function runAgentStoreConformance(config) {
307
315
  expectedRevision: checkpointedRun.revision,
308
316
  ownerId: "conformance-owner",
309
317
  assistant: terminalAssistant,
310
- reason: "success"
318
+ reason: "success",
319
+ usage: {
320
+ inputTokens: { value: 3000, provenance: "computed" },
321
+ outputTokens: { value: 300, provenance: "computed" },
322
+ cost: { value: 1.5, currency: "USD", provenance: "computed" }
323
+ }
311
324
  }),
312
325
  store.commitRunTerminal({
313
326
  conversationId,
@@ -315,7 +328,12 @@ async function runAgentStoreConformance(config) {
315
328
  expectedRevision: checkpointedRun.revision,
316
329
  ownerId: "conformance-owner",
317
330
  assistant: terminalAssistant,
318
- reason: "success"
331
+ reason: "success",
332
+ usage: {
333
+ inputTokens: { value: 3000, provenance: "computed" },
334
+ outputTokens: { value: 300, provenance: "computed" },
335
+ cost: { value: 1.5, currency: "USD", provenance: "computed" }
336
+ }
319
337
  })
320
338
  ]);
321
339
  const terminalOutcomes = terminalResults.map((result) => result.outcome).sort();
@@ -326,6 +344,10 @@ async function runAgentStoreConformance(config) {
326
344
  if (terminalApplied?.outcome !== "applied") {
327
345
  throw new Error("Terminal race produced no applied result");
328
346
  }
347
+ const settledRun = terminalApplied.snapshot.runs.find((run) => run.id === running.id);
348
+ if (settledRun?.usage?.cost?.value !== 1.5) {
349
+ throw new Error("Terminal commit did not persist the run usage it was given");
350
+ }
329
351
  const compactedTerminal = await store.replaceCompactedRange({
330
352
  conversationId,
331
353
  expectedVersion: terminalApplied.snapshot.version,