stitchkit 0.68.2 → 0.68.3
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":"run-execution.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/run-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,UAAU,CAAC;AAEvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAapD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAKL,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"run-execution.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/run-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,UAAU,CAAC;AAEvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAapD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAKL,KAAK,QAAQ,EAMd,MAAM,WAAW,CAAC;AAuCnB,8DAA8D;AAC9D,MAAM,WAAW,uBAAuB,CAAC,OAAO,EAAE,KAAK,SAAS,OAAO;IACrE,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,IAA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AAC;KAChF,CAAC;IACF,eAAe,CAAC,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC3F;AAuND;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,QAAQ,CAAC,OAAO,CAAC,EAI/D,CAAC;AAgfF,wBAAgB,uBAAuB,CAAC,WAAW,EACjD,MAAM,EAAE,uBAAuB,CAAC,WAAW,CAAC,GAC3C,iBAAiB,CAuOnB;AAuCD,oGAAoG;AACpG,wBAAgB,6BAA6B,IAAI,iBAAiB,CAsMjE"}
|
package/dist/agent-runtime.js
CHANGED
|
@@ -1444,6 +1444,20 @@ function createIdleDeadline(parent, timeoutMs) {
|
|
|
1444
1444
|
}
|
|
1445
1445
|
|
|
1446
1446
|
// src/agent-runtime/run-execution.ts
|
|
1447
|
+
function snapshotForRunPrompt(snapshot, runId) {
|
|
1448
|
+
const runIndex = snapshot.runs.findIndex((candidate) => candidate.id === runId);
|
|
1449
|
+
if (runIndex < 0)
|
|
1450
|
+
throw new AgentRuntimeConflictError("prompt run lookup");
|
|
1451
|
+
const ownedIds = new Set(snapshot.runs.flatMap((candidate) => [
|
|
1452
|
+
...candidate.inputMessageIds,
|
|
1453
|
+
candidate.assistantMessageId
|
|
1454
|
+
]));
|
|
1455
|
+
const eligibleIds = new Set(snapshot.runs.slice(0, runIndex + 1).flatMap((candidate) => [...candidate.inputMessageIds, candidate.assistantMessageId]));
|
|
1456
|
+
return AgentSnapshotSchema.parse({
|
|
1457
|
+
...snapshot,
|
|
1458
|
+
messages: snapshot.messages.filter((message) => !ownedIds.has(message.id) || eligibleIds.has(message.id))
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1447
1461
|
function createRunExecutor(dependencies) {
|
|
1448
1462
|
const {
|
|
1449
1463
|
config,
|
|
@@ -1654,12 +1668,13 @@ function createRunExecutor(dependencies) {
|
|
|
1654
1668
|
context: input.context,
|
|
1655
1669
|
conversationId: run.conversationId
|
|
1656
1670
|
});
|
|
1671
|
+
const promptSnapshot = snapshotForRunPrompt(snapshot, run.id);
|
|
1657
1672
|
const [prompt, tools] = await Promise.all([
|
|
1658
1673
|
config.prompt({
|
|
1659
1674
|
context: input.context,
|
|
1660
1675
|
signal: executionSignal,
|
|
1661
1676
|
model: selectedModel,
|
|
1662
|
-
snapshot
|
|
1677
|
+
snapshot: promptSnapshot
|
|
1663
1678
|
}),
|
|
1664
1679
|
config.tools(runtimeContext)
|
|
1665
1680
|
]);
|
|
@@ -1701,7 +1716,7 @@ function createRunExecutor(dependencies) {
|
|
|
1701
1716
|
});
|
|
1702
1717
|
return [...detailed.messages];
|
|
1703
1718
|
};
|
|
1704
|
-
const history = await projectHistory(
|
|
1719
|
+
const history = await projectHistory(promptSnapshot);
|
|
1705
1720
|
const withCarriedSystem = (instructions) => {
|
|
1706
1721
|
if (carriedSystem.length === 0)
|
|
1707
1722
|
return instructions;
|
|
@@ -2853,15 +2868,37 @@ function historyPositions(messages) {
|
|
|
2853
2868
|
return earliest;
|
|
2854
2869
|
};
|
|
2855
2870
|
}
|
|
2871
|
+
function orderRuns(messages, runs) {
|
|
2872
|
+
const positionOf = historyPositions(messages);
|
|
2873
|
+
return [...runs].sort((left, right) => left.createdAt.localeCompare(right.createdAt) || positionOf(left) - positionOf(right) || left.id.localeCompare(right.id));
|
|
2874
|
+
}
|
|
2875
|
+
function orderRunMessages(messages, runs) {
|
|
2876
|
+
const byId = new Map(messages.map((message) => [message.id, message]));
|
|
2877
|
+
const ownedIds = new Set(runs.flatMap((run) => [...run.inputMessageIds, run.assistantMessageId]));
|
|
2878
|
+
const orderedOwned = runs.flatMap((run) => [...run.inputMessageIds, run.assistantMessageId].flatMap((id) => {
|
|
2879
|
+
const message = byId.get(id);
|
|
2880
|
+
return message ? [message] : [];
|
|
2881
|
+
}));
|
|
2882
|
+
let ownedIndex = 0;
|
|
2883
|
+
return messages.map((message) => {
|
|
2884
|
+
if (!ownedIds.has(message.id))
|
|
2885
|
+
return message;
|
|
2886
|
+
const ordered = orderedOwned[ownedIndex];
|
|
2887
|
+
if (!ordered)
|
|
2888
|
+
throw new TypeError("Stored agent history lost a run-owned message");
|
|
2889
|
+
ownedIndex += 1;
|
|
2890
|
+
return ordered;
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2856
2893
|
function snapshotOf(head, messages, records) {
|
|
2857
2894
|
validateSnapshot(head, messages, records);
|
|
2858
|
-
const
|
|
2895
|
+
const runs = orderRuns(messages, records.map((record) => record.run));
|
|
2859
2896
|
return AgentSnapshotSchema.parse({
|
|
2860
2897
|
schemaVersion: 1,
|
|
2861
2898
|
conversationId: head.conversationId,
|
|
2862
2899
|
version: head.version,
|
|
2863
|
-
messages,
|
|
2864
|
-
runs
|
|
2900
|
+
messages: orderRunMessages(messages, runs),
|
|
2901
|
+
runs
|
|
2865
2902
|
});
|
|
2866
2903
|
}
|
|
2867
2904
|
function validateSnapshot(head, messages, records) {
|
|
@@ -2920,13 +2957,15 @@ function conflict(actualVersion) {
|
|
|
2920
2957
|
return { outcome: "conflict", actualVersion };
|
|
2921
2958
|
}
|
|
2922
2959
|
function applied(current, input, effects) {
|
|
2960
|
+
const runs = input.runs ?? current.runs;
|
|
2961
|
+
const messages = input.messages ?? current.messages;
|
|
2923
2962
|
return {
|
|
2924
2963
|
outcome: "applied",
|
|
2925
2964
|
snapshot: AgentSnapshotSchema.parse({
|
|
2926
2965
|
...current,
|
|
2927
2966
|
version: current.version + 1,
|
|
2928
|
-
runs
|
|
2929
|
-
messages:
|
|
2967
|
+
runs,
|
|
2968
|
+
messages: orderRunMessages(messages, runs)
|
|
2930
2969
|
}),
|
|
2931
2970
|
...effects?.runRecords?.length && { runRecords: effects.runRecords },
|
|
2932
2971
|
...effects?.admissionReceipt && { admissionReceipt: effects.admissionReceipt },
|
package/dist/testing.js
CHANGED
|
@@ -145,7 +145,7 @@ function requireOutcome(actual, expected) {
|
|
|
145
145
|
async function runAgentStoreConformance(config) {
|
|
146
146
|
const run = `conformance-${crypto.randomUUID()}`;
|
|
147
147
|
const context = {
|
|
148
|
-
conversationIds: [run, `${run}-recovery`, `${run}-absorb`]
|
|
148
|
+
conversationIds: [run, `${run}-recovery`, `${run}-absorb`, `${run}-causal-history`]
|
|
149
149
|
};
|
|
150
150
|
const store = await config.createStore(context);
|
|
151
151
|
let failure;
|
|
@@ -165,9 +165,14 @@ async function runAgentStoreConformance(config) {
|
|
|
165
165
|
throw failure;
|
|
166
166
|
}
|
|
167
167
|
async function conformanceScenario(store, conversationIds) {
|
|
168
|
-
const [
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
const [
|
|
169
|
+
conversationId,
|
|
170
|
+
recoveryConversationId,
|
|
171
|
+
absorbConversationId,
|
|
172
|
+
causalHistoryConversationId
|
|
173
|
+
] = conversationIds;
|
|
174
|
+
if (!conversationId || !recoveryConversationId || !absorbConversationId || !causalHistoryConversationId) {
|
|
175
|
+
throw new Error("Agent store conformance requires four conversation identities");
|
|
171
176
|
}
|
|
172
177
|
const absentConversationId = `${conversationId}-absent`;
|
|
173
178
|
const firstInput = userMessage(conversationId, "input-1");
|
|
@@ -548,8 +553,59 @@ async function conformanceScenario(store, conversationIds) {
|
|
|
548
553
|
if (terminalRun?.state !== "abandoned" || terminalMessage?.status !== "failed") {
|
|
549
554
|
throw new Error("Abandon recovery did not atomically terminalize its assistant record");
|
|
550
555
|
}
|
|
556
|
+
await assertCausalHistoryOrder(store, causalHistoryConversationId);
|
|
551
557
|
await assertAbsorptionIsAtomic(store, absorbConversationId);
|
|
552
558
|
}
|
|
559
|
+
async function assertCausalHistoryOrder(store, conversationId) {
|
|
560
|
+
const leadInput = userMessage(conversationId, "causal-input-1");
|
|
561
|
+
const leadRun = queuedRun(conversationId, leadInput.id, "causal-run-1");
|
|
562
|
+
requireOutcome(await store.acceptInputAndAssignRun({
|
|
563
|
+
idempotencyKey: "causal-request-1",
|
|
564
|
+
input: leadInput,
|
|
565
|
+
run: leadRun
|
|
566
|
+
}), "applied");
|
|
567
|
+
const acquired = await store.acquireRun({
|
|
568
|
+
conversationId,
|
|
569
|
+
runId: leadRun.id,
|
|
570
|
+
expectedRevision: leadRun.revision,
|
|
571
|
+
ownerId: "causal-owner"
|
|
572
|
+
});
|
|
573
|
+
requireOutcome(acquired, "applied");
|
|
574
|
+
const running = acquired.snapshot.runs.find((run) => run.id === leadRun.id);
|
|
575
|
+
if (!running)
|
|
576
|
+
throw new Error("Causal-order run disappeared after acquisition");
|
|
577
|
+
const successorInput = userMessage(conversationId, "causal-input-2");
|
|
578
|
+
const successorRun = queuedRun(conversationId, successorInput.id, "causal-run-2");
|
|
579
|
+
requireOutcome(await store.acceptInputAndAssignRun({
|
|
580
|
+
idempotencyKey: "causal-request-2",
|
|
581
|
+
input: successorInput,
|
|
582
|
+
run: successorRun
|
|
583
|
+
}), "applied");
|
|
584
|
+
const assistant = AgentMessageSchema.parse({
|
|
585
|
+
schemaVersion: 1,
|
|
586
|
+
id: running.assistantMessageId,
|
|
587
|
+
conversationId,
|
|
588
|
+
runId: running.id,
|
|
589
|
+
role: "assistant",
|
|
590
|
+
status: "streaming",
|
|
591
|
+
parts: [{ type: "text", text: "causal answer" }],
|
|
592
|
+
createdAt: "2026-08-28T00:00:00.000Z",
|
|
593
|
+
updatedAt: "2026-08-28T00:00:01.000Z"
|
|
594
|
+
});
|
|
595
|
+
const checkpoint = await store.checkpointRunAssistant({
|
|
596
|
+
conversationId,
|
|
597
|
+
runId: running.id,
|
|
598
|
+
expectedRevision: running.revision,
|
|
599
|
+
ownerId: "causal-owner",
|
|
600
|
+
...running.fencingToken !== undefined && { fencingToken: running.fencingToken },
|
|
601
|
+
assistant
|
|
602
|
+
});
|
|
603
|
+
requireOutcome(checkpoint, "applied");
|
|
604
|
+
const order = checkpoint.snapshot.messages.map((message) => message.id).join(",");
|
|
605
|
+
if (order !== `${leadInput.id},${assistant.id},${successorInput.id}`) {
|
|
606
|
+
throw new Error(`Agent history is not in causal run order: ${order}`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
553
609
|
async function assertAbsorptionIsAtomic(store, conversationId) {
|
|
554
610
|
const leadInput = userMessage(conversationId, "absorb-input-1");
|
|
555
611
|
const leadRun = queuedRun(conversationId, leadInput.id, "absorb-run-1");
|
package/llms-full.txt
CHANGED
|
@@ -3882,6 +3882,13 @@ assistant, so physical product-history compaction cannot break idempotent retrie
|
|
|
3882
3882
|
acquisition, revision-checked assistant checkpoints and one terminal CAS. The
|
|
3883
3883
|
process-local coordinator releases its lane only after terminal commit.
|
|
3884
3884
|
|
|
3885
|
+
A queued admission is durable immediately, even if its predecessor is still awaiting ownership
|
|
3886
|
+
or its first checkpoint. Snapshots expose causal turn order rather than physical append order:
|
|
3887
|
+
the predecessor's assigned input(s) and assistant come before the successor input(s). Execution
|
|
3888
|
+
uses the same run boundary, so neither `prompt({ snapshot })` nor default/custom history
|
|
3889
|
+
projection can see inputs assigned to a later run. `inject` remains the explicit path that moves
|
|
3890
|
+
a successor input into the run already in flight.
|
|
3891
|
+
|
|
3885
3892
|
```text
|
|
3886
3893
|
input + queued run → running → execution settled → terminal CAS → successor
|
|
3887
3894
|
```
|
|
@@ -4398,7 +4405,7 @@ outbox.
|
|
|
4398
4405
|
`createAgentRaceTrace`. Barriers have bounded teardown, traces assert exact partial order, and the
|
|
4399
4406
|
helpers are exercised from packed Bun and Node consumers. `runAgentStoreConformance` runs duplicate,
|
|
4400
4407
|
coalescing, collision, stale checkpoint, replay safety, terminal race, absorption, bounded reads,
|
|
4401
|
-
compaction and recovery invariants against any fresh durable adapter.
|
|
4408
|
+
causal queued-history order, compaction and recovery invariants against any fresh durable adapter.
|
|
4402
4409
|
|
|
4403
4410
|
It picks its conversation identities itself and passes them to `createStore(context)` **before the
|
|
4404
4411
|
first mutation**, so an adapter whose runtime rows reference an application-owned conversation row
|
|
@@ -11494,6 +11501,11 @@ ordinary queued successor. The absorbed run ends with `terminalReason: 'absorbed
|
|
|
11494
11501
|
its own**; a submission on its idempotency key resolves through that pointer to the answer
|
|
11495
11502
|
(→ ADR 0113).
|
|
11496
11503
|
|
|
11504
|
+
With `queue`, a durable successor admission is not prompt eligibility: the current executor sees
|
|
11505
|
+
only records through its own run boundary. Snapshot history is normalized to causal turn order
|
|
11506
|
+
(assigned input(s), assistant, then successor input(s)) even when the storage codec physically
|
|
11507
|
+
appended the successor before the predecessor checkpoint.
|
|
11508
|
+
|
|
11497
11509
|
`AgentRuntimeStore` has two **bounded** reads beside `loadSnapshot`:
|
|
11498
11510
|
`loadRun({ conversationId, runId })` returns an `AgentRunView` — the run, the conversation version it
|
|
11499
11511
|
was read at, and the retained answer once the run is terminal — or `undefined`; `listActiveRuns(conversationId)`
|
package/package.json
CHANGED