@code-yeongyu/senpi-agent-core 2026.11.3-2 → 2026.11.4-2

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.
Files changed (118) hide show
  1. package/dist/agent-loop.js +7 -47
  2. package/dist/conformance/index.d.ts +37 -0
  3. package/dist/conformance/index.js +25 -0
  4. package/dist/conformance/loop-core-manifest.d.ts +1 -1
  5. package/dist/conformance/loop-core-manifest.js +1 -0
  6. package/dist/conformance/registry.js +31 -1
  7. package/dist/execution/canonical-json.d.ts +3 -0
  8. package/dist/execution/canonical-json.js +12 -0
  9. package/dist/execution/coordinator-codec.d.ts +5 -0
  10. package/dist/execution/coordinator-codec.js +104 -0
  11. package/dist/execution/coordinator-consent.d.ts +29 -0
  12. package/dist/execution/coordinator-consent.js +63 -0
  13. package/dist/execution/coordinator-plan.d.ts +33 -0
  14. package/dist/execution/coordinator-plan.js +106 -0
  15. package/dist/execution/coordinator-sequential.d.ts +15 -0
  16. package/dist/execution/coordinator-sequential.js +34 -0
  17. package/dist/execution/coordinator-types.d.ts +161 -0
  18. package/dist/execution/coordinator-types.js +2 -0
  19. package/dist/execution/coordinator.d.ts +27 -0
  20. package/dist/execution/coordinator.js +164 -0
  21. package/dist/execution/device-files-node.d.ts +8 -0
  22. package/dist/execution/device-files-node.js +112 -0
  23. package/dist/execution/device-files.d.ts +80 -0
  24. package/dist/execution/device-files.js +87 -0
  25. package/dist/execution/grant-verify.d.ts +70 -0
  26. package/dist/execution/grant-verify.js +87 -0
  27. package/dist/execution/ledger.d.ts +2 -0
  28. package/dist/execution/ledger.js +1 -0
  29. package/dist/execution/nested-codec.d.ts +5 -0
  30. package/dist/execution/nested-codec.js +41 -0
  31. package/dist/execution/nested-types.d.ts +92 -0
  32. package/dist/execution/nested-types.js +3 -0
  33. package/dist/execution/nested.d.ts +48 -0
  34. package/dist/execution/nested.js +206 -0
  35. package/dist/execution/plane-model.d.ts +33 -0
  36. package/dist/execution/plane-model.js +80 -0
  37. package/dist/execution/plane.d.ts +72 -0
  38. package/dist/execution/plane.js +172 -0
  39. package/dist/execution/remote-device-files.d.ts +12 -0
  40. package/dist/execution/remote-device-files.js +84 -0
  41. package/dist/execution/remote-executor.d.ts +74 -0
  42. package/dist/execution/remote-executor.js +193 -0
  43. package/dist/execution/remote-file-call.d.ts +14 -0
  44. package/dist/execution/remote-file-call.js +30 -0
  45. package/dist/execution/remote-hand-ledger.d.ts +40 -0
  46. package/dist/execution/remote-hand-ledger.js +137 -0
  47. package/dist/execution/remote-link.d.ts +36 -0
  48. package/dist/execution/remote-link.js +117 -0
  49. package/dist/execution/remote-protocol.d.ts +104 -0
  50. package/dist/execution/remote-protocol.js +104 -0
  51. package/dist/execution/remote-tool-host.d.ts +37 -0
  52. package/dist/execution/remote-tool-host.js +114 -0
  53. package/dist/execution/scope-lifecycle.d.ts +81 -0
  54. package/dist/execution/scope-lifecycle.js +173 -0
  55. package/dist/execution/testing/batch-cases.d.ts +6 -0
  56. package/dist/execution/testing/batch-cases.js +210 -0
  57. package/dist/execution/testing/batch-executor.d.ts +34 -0
  58. package/dist/execution/testing/batch-executor.js +170 -0
  59. package/dist/execution/testing/batch-harness.d.ts +58 -0
  60. package/dist/execution/testing/batch-harness.js +286 -0
  61. package/dist/execution/testing/batch-registry.d.ts +3 -0
  62. package/dist/execution/testing/batch-registry.js +30 -0
  63. package/dist/execution/testing/cancel-cases.d.ts +8 -0
  64. package/dist/execution/testing/cancel-cases.js +64 -0
  65. package/dist/execution/testing/consent-cases.d.ts +14 -0
  66. package/dist/execution/testing/consent-cases.js +66 -0
  67. package/dist/execution/testing/fault-hand-cases.d.ts +6 -0
  68. package/dist/execution/testing/fault-hand-cases.js +70 -0
  69. package/dist/execution/testing/hand-harness.d.ts +48 -0
  70. package/dist/execution/testing/hand-harness.js +136 -0
  71. package/dist/execution/testing/kill-batch.d.ts +12 -0
  72. package/dist/execution/testing/kill-batch.js +70 -0
  73. package/dist/execution/testing/kill-hand.d.ts +16 -0
  74. package/dist/execution/testing/kill-hand.js +75 -0
  75. package/dist/execution/testing/kill-nest.d.ts +6 -0
  76. package/dist/execution/testing/kill-nest.js +55 -0
  77. package/dist/execution/testing/kill-wakex.d.ts +6 -0
  78. package/dist/execution/testing/kill-wakex.js +81 -0
  79. package/dist/execution/testing/lifecycle-cases.d.ts +9 -0
  80. package/dist/execution/testing/lifecycle-cases.js +60 -0
  81. package/dist/execution/testing/lifecycle-registry.d.ts +3 -0
  82. package/dist/execution/testing/lifecycle-registry.js +19 -0
  83. package/dist/execution/testing/multi-hand-cases.d.ts +6 -0
  84. package/dist/execution/testing/multi-hand-cases.js +44 -0
  85. package/dist/execution/testing/multi-lifecycle-cases.d.ts +4 -0
  86. package/dist/execution/testing/multi-lifecycle-cases.js +34 -0
  87. package/dist/execution/testing/multi-seq-cases.d.ts +4 -0
  88. package/dist/execution/testing/multi-seq-cases.js +46 -0
  89. package/dist/execution/testing/nest-cases.d.ts +39 -0
  90. package/dist/execution/testing/nest-cases.js +181 -0
  91. package/dist/execution/testing/nest-registry.d.ts +3 -0
  92. package/dist/execution/testing/nest-registry.js +27 -0
  93. package/dist/execution/testing/scope-cases.d.ts +6 -0
  94. package/dist/execution/testing/scope-cases.js +49 -0
  95. package/dist/execution/testing/seq-cases.d.ts +6 -0
  96. package/dist/execution/testing/seq-cases.js +71 -0
  97. package/dist/execution/testing/seq-registry.d.ts +3 -0
  98. package/dist/execution/testing/seq-registry.js +32 -0
  99. package/dist/execution/testing/wake-exec-cases.d.ts +20 -0
  100. package/dist/execution/testing/wake-exec-cases.js +147 -0
  101. package/dist/execution/testing/wake-registry.d.ts +3 -0
  102. package/dist/execution/testing/wake-registry.js +26 -0
  103. package/dist/execution/tool-host.d.ts +10 -2
  104. package/dist/execution/tool-outcome-events.d.ts +11 -0
  105. package/dist/execution/tool-outcome-events.js +47 -0
  106. package/dist/execution/wake-inbox.d.ts +25 -0
  107. package/dist/execution/wake-inbox.js +85 -0
  108. package/dist/execution/wake-outbox.d.ts +30 -0
  109. package/dist/execution/wake-outbox.js +87 -0
  110. package/dist/execution/wake-types.d.ts +45 -0
  111. package/dist/execution/wake-types.js +3 -0
  112. package/dist/harness/env/nodejs.js +4 -0
  113. package/dist/index.d.ts +21 -1
  114. package/dist/index.js +19 -1
  115. package/dist/node.d.ts +1 -0
  116. package/dist/node.js +1 -0
  117. package/dist/transport/testing/multi-cases.js +8 -8
  118. package/package.json +3 -3
@@ -0,0 +1,136 @@
1
+ import { createAdmissionLine } from "../../durable/store-admission.js";
2
+ import { createManualTimers } from "../../durable/testing/manual-timers.js";
3
+ import { claimedStore } from "../../durable/testing/store-cases.js";
4
+ import { createInProcessNetwork } from "../../transport/in-process-carrier.js";
5
+ import { localEndpoint } from "../../transport/local-endpoint.js";
6
+ import { createExecutionLedger } from "../ledger.js";
7
+ import { createRemoteExecutor } from "../remote-executor.js";
8
+ import { createHandLedger } from "../remote-hand-ledger.js";
9
+ import { createRemoteToolHost } from "../remote-tool-host.js";
10
+ const TICK_MS = 5;
11
+ const LEASE_MS = 3_600_000;
12
+ const drain = async () => {
13
+ for (let turn = 0; turn < 32; turn++)
14
+ await Promise.resolve();
15
+ };
16
+ export function call(id) {
17
+ return { type: "toolCall", id, name: "probe", arguments: { id } };
18
+ }
19
+ export async function openHandRig(adapters, options) {
20
+ const timers = createManualTimers(1_000);
21
+ const network = createInProcessNetwork({ schedule: (deliver) => void timers.setTimer(deliver, 0) });
22
+ const sessionSide = adapters.transport.createSide(timers);
23
+ const handSide = adapters.transport.createSide(timers);
24
+ const installed = options.fault?.(timers);
25
+ const outer = (side) => (installed === undefined ? side : installed.wrap(side));
26
+ const endpoint = localEndpoint(adapters.platform, "hand-conformance", "/run/senpi-conformance");
27
+ network.listen(endpoint, outer(handSide));
28
+ const link = network.dial(endpoint, outer(sessionSide));
29
+ link.connect();
30
+ installed?.start(link);
31
+ const { medium } = await claimedStore(adapters.store);
32
+ const bodies = [];
33
+ const faults = [];
34
+ const gates = new Map();
35
+ let gated = false;
36
+ const killed = Promise.withResolvers();
37
+ const scopeRunner = (scopeId) => ({
38
+ run: async (handCall) => {
39
+ bodies.push(`${scopeId}:${handCall.toolCallId}`);
40
+ if (gated) {
41
+ const gate = gates.get(handCall.toolCallId) ?? Promise.withResolvers();
42
+ gates.set(handCall.toolCallId, gate);
43
+ await gate.promise;
44
+ }
45
+ return { content: [{ type: "text", text: `ran:${handCall.toolCallId}` }], details: {} };
46
+ },
47
+ isSequential: () => false,
48
+ dispose: async () => { },
49
+ });
50
+ const startHand = (store) => {
51
+ const ledger = createExecutionLedger({ store, epoch: 1, admission: createAdmissionLine() });
52
+ return createRemoteExecutor({
53
+ authority: { kind: "self" },
54
+ transport: handSide,
55
+ openScope: async (scope) => scopeRunner(scope.id),
56
+ ledger: createHandLedger({
57
+ ledger,
58
+ executor: "hand",
59
+ issuer: "session",
60
+ workspace: "workspace",
61
+ now: timers.now,
62
+ leaseMs: LEASE_MS,
63
+ }),
64
+ onFault: (error) => faults.push(error),
65
+ });
66
+ };
67
+ let commit = -1;
68
+ let dead = false;
69
+ const killing = (point) => {
70
+ if (dead)
71
+ throw new Error("the hand was killed");
72
+ if (point.op !== "commit")
73
+ return;
74
+ if (point.at === "before")
75
+ commit += 1;
76
+ const kill = options.killAt;
77
+ if (kill !== undefined && kill.commit === commit && kill.at === point.at) {
78
+ dead = true;
79
+ killed.resolve();
80
+ throw new Error(`hand killed ${point.at} commit ${commit}`);
81
+ }
82
+ };
83
+ let current = await adapters.store.open(medium, { onWritePoint: killing });
84
+ await startHand(current).ready;
85
+ const host = createRemoteToolHost({ transport: sessionSide, placement: options.placement });
86
+ const pump = async (stop, ms) => {
87
+ const end = timers.now() + ms;
88
+ await drain();
89
+ while (!stop() && timers.now() < end) {
90
+ await timers.advanceTo(Math.min(end, timers.now() + TICK_MS));
91
+ await drain();
92
+ }
93
+ };
94
+ const runUntil = async (done, what, budgetMs = 600_000) => {
95
+ await pump(done, budgetMs);
96
+ if (!done())
97
+ throw new Error(`${what}: not reached within ${budgetMs} ms of transport time`);
98
+ };
99
+ const settle = async (promise, what, budgetMs = 600_000) => {
100
+ let outcome;
101
+ promise.then((value) => void (outcome = { value }), (error) => void (outcome = { error }));
102
+ await runUntil(() => outcome !== undefined, what, budgetMs);
103
+ if (outcome === undefined || "error" in outcome)
104
+ throw outcome?.error;
105
+ return outcome.value;
106
+ };
107
+ return {
108
+ advance: (ms) => pump(() => false, ms),
109
+ bodies,
110
+ faults,
111
+ killed: killed.promise,
112
+ execute: (scope, calls, mode = "parallel") => host.execute({ scope: { id: scope, root: `/work/${scope}` }, calls, mode }, { emit: () => { } }),
113
+ async restart() {
114
+ current = await adapters.store.open(medium);
115
+ await settle(startHand(current).ready, "the restarted hand recovered");
116
+ },
117
+ gateBodies: () => {
118
+ gated = true;
119
+ },
120
+ release(toolCallId) {
121
+ const gate = gates.get(toolCallId) ?? Promise.withResolvers();
122
+ gates.set(toolCallId, gate);
123
+ gate.resolve();
124
+ },
125
+ settle,
126
+ runUntil,
127
+ disconnect: () => link.drop(),
128
+ reconnect: () => link.connect(),
129
+ rows: async () => createExecutionLedger({
130
+ store: await adapters.store.open(medium),
131
+ epoch: 1,
132
+ admission: createAdmissionLine(),
133
+ }).scan(),
134
+ };
135
+ }
136
+ //# sourceMappingURL=hand-harness.js.map
@@ -0,0 +1,12 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { BatchCaseAdapters } from "./batch-executor.ts";
3
+ import { type BrainKill } from "./batch-harness.ts";
4
+ export interface KillBatchDeclaration {
5
+ readonly id: string;
6
+ readonly scenario: string;
7
+ readonly kill: BrainKill;
8
+ readonly placement: "everywhere";
9
+ }
10
+ export declare const KILL_BATCH_DECLARATIONS: readonly KillBatchDeclaration[];
11
+ export declare const KILL_BATCH_CASES: ReadonlyMap<string, CaseImplementation<BatchCaseAdapters>>;
12
+ //# sourceMappingURL=kill-batch.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { expectEqual } from "../../durable/testing/store-harness.js";
2
+ import { BrainKilledError, batchHarness, batchPlan, expectRejects, resultOf, } from "./batch-harness.js";
3
+ const notRun = { kind: "not_run", cause: "batch_abort" };
4
+ const SCENARIOS = [
5
+ {
6
+ name: "a released wave then a sequential call",
7
+ calls: [
8
+ ["a", "e1"],
9
+ ["b", "e2"],
10
+ ["c", "e1", "read", "sequential"],
11
+ ],
12
+ writes: ["manifest", "prepare:a", "prepare:b", "prepare:c", "decision", "release:a", "release:b"].concat([
13
+ "outcome:a",
14
+ "outcome:b",
15
+ "release:c",
16
+ "outcome:c",
17
+ ]),
18
+ expected: { decision: "RELEASE", outcomes: [resultOf("a"), resultOf("b"), resultOf("c")] },
19
+ prepared: ["a", "b", "c"],
20
+ ran: ["a", "b", "c"],
21
+ },
22
+ {
23
+ name: "a batch_abort reply",
24
+ calls: [
25
+ ["a", "e1"],
26
+ ["b", "e2", "stop"],
27
+ ["c", "e1"],
28
+ ],
29
+ writes: ["manifest", "prepare:a", "prepare:b", "decision", "outcome:a", "outcome:b", "outcome:c"],
30
+ expected: { decision: "ABORT", outcomes: [notRun, notRun, notRun] },
31
+ prepared: ["a", "b"],
32
+ ran: [],
33
+ },
34
+ {
35
+ name: "a blocked call beside a released call (the executor's blocked reply must be durable)",
36
+ calls: [
37
+ ["a", "e1", "deny"],
38
+ ["b", "e2"],
39
+ ],
40
+ writes: ["manifest", "prepare:a", "prepare:b", "decision", "outcome:a", "release:b", "outcome:b"],
41
+ expected: { decision: "RELEASE", outcomes: [{ kind: "blocked", result: "blocked: deny" }, resultOf("b")] },
42
+ prepared: ["a", "b"],
43
+ ran: ["b"],
44
+ },
45
+ ];
46
+ const AT = ["before", "after"];
47
+ const cases = SCENARIOS.flatMap((scenario, scenarioIndex) => scenario.writes.flatMap((label, writeIndex) => AT.map((at, atIndex) => {
48
+ const number = SCENARIOS.slice(0, scenarioIndex).reduce((sum, s) => sum + s.writes.length, 0) + writeIndex + 1;
49
+ const id = `KILL-BATCH-${String(number).padStart(2, "0")}-${atIndex + 1}`;
50
+ const kill = { label, at };
51
+ const run = async (adapters) => {
52
+ const h = await batchHarness(adapters);
53
+ const plan = batchPlan(id.toLowerCase(), scenario.calls);
54
+ await expectRejects((await h.brain(kill)).run(plan), BrainKilledError, `${at} ${label}`);
55
+ expectEqual(await (await h.brain()).run(plan), scenario.expected, "recovery reaches the uncrashed outcomes");
56
+ for (const [executionId, executor] of scenario.calls) {
57
+ const preparedOnce = scenario.prepared.includes(executionId) ? 1 : 0;
58
+ for (const step of ["shim", "hook"])
59
+ expectEqual(h.count(`${step}:${executionId}`), preparedOnce, `${step}:${executionId} once at most`);
60
+ const ranOnce = scenario.ran.includes(executionId) ? 1 : 0;
61
+ expectEqual(h.count(`body:${executionId}`), ranOnce, `body:${executionId}`);
62
+ if (preparedOnce === 1)
63
+ expectEqual(await h.ledgerState(executor, executionId), "settled", "stable ids");
64
+ }
65
+ };
66
+ return { id, scenario: scenario.name, kill, placement: "everywhere", run };
67
+ })));
68
+ export const KILL_BATCH_DECLARATIONS = cases.map(({ run: _run, ...entry }) => entry);
69
+ export const KILL_BATCH_CASES = new Map(cases.map(({ id, run }) => [id, run]));
70
+ //# sourceMappingURL=kill-batch.js.map
@@ -0,0 +1,16 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { HandPlacement } from "../remote-tool-host.ts";
3
+ import { type HandCaseAdapters, type KillPoint } from "./hand-harness.ts";
4
+ /** The ledger commits one call makes on a hand, in order. */
5
+ declare const COMMITS: readonly ["admit", "prepare", "effect", "freeze", "release", "dispatch", "settle", "ack"];
6
+ export interface KillHandDeclaration {
7
+ readonly id: string;
8
+ readonly operation: (typeof COMMITS)[number];
9
+ readonly at: KillPoint["at"];
10
+ readonly placement: HandPlacement;
11
+ readonly expected: string;
12
+ }
13
+ export declare const KILL_HAND_DECLARATIONS: readonly KillHandDeclaration[];
14
+ export declare const KILL_HAND_CASES: ReadonlyMap<string, CaseImplementation<HandCaseAdapters>>;
15
+ export {};
16
+ //# sourceMappingURL=kill-hand.d.ts.map
@@ -0,0 +1,75 @@
1
+ import { TOOL_RESULT_PLACEHOLDER } from "@earendil-works/pi-ai";
2
+ import { expectEqual } from "../../durable/testing/store-harness.js";
3
+ import { call, openHandRig } from "./hand-harness.js";
4
+ /** The ledger commits one call makes on a hand, in order. */
5
+ const COMMITS = ["admit", "prepare", "effect", "freeze", "release", "dispatch", "settle", "ack"];
6
+ const PLACEMENTS = ["split-local", "cross-machine"];
7
+ function expectedAfter(lastDurable) {
8
+ if (lastDurable < 0)
9
+ return { outcome: "result" };
10
+ if (lastDurable <= 2)
11
+ return { outcome: "restarted", uncertain: lastDurable >= 2 };
12
+ if (lastDurable <= 4)
13
+ return { outcome: "result" };
14
+ if (lastDurable === 5)
15
+ return { outcome: "restarted", uncertain: true };
16
+ return { outcome: "result" };
17
+ }
18
+ /** How many times the body ran in total: once, or never when the kill came before it ran. */
19
+ function bodyRuns(kill, lastDurable) {
20
+ if (lastDurable >= 0 && lastDurable <= 2)
21
+ return 0;
22
+ if (lastDurable === 5)
23
+ return kill.commit === 6 ? 1 : 0;
24
+ return 1;
25
+ }
26
+ function describeExpected(placement, expected, runs) {
27
+ const body = runs === 0 ? "the tool never runs" : "the tool runs exactly once";
28
+ if (expected.outcome === "result")
29
+ return `the session gets the tool's result; ${body}`;
30
+ return placement === "split-local"
31
+ ? `the session gets today's placeholder result, no uncertain outcome; ${body}`
32
+ : `the session gets hand_restarted, ${expected.uncertain ? "uncertain" : "not uncertain"}, never rerun; ${body}`;
33
+ }
34
+ const cases = COMMITS.flatMap((operation, commit) => ["before", "durable"].flatMap((at) => PLACEMENTS.map((placement) => {
35
+ const kill = { commit, at };
36
+ const lastDurable = at === "durable" ? commit : commit - 1;
37
+ const expected = expectedAfter(lastDurable);
38
+ const runs = bodyRuns(kill, lastDurable);
39
+ const id = `KILL-HAND-${String(commit + 1).padStart(2, "0")}-${at === "before" ? "B" : "D"}-${placement === "split-local" ? "SL" : "XM"}`;
40
+ const what = `${id} (${operation} ${at}, ${placement})`;
41
+ const run = async (adapters) => {
42
+ const rig = await openHandRig(adapters, { placement, killAt: kill });
43
+ const outcome = rig.execute("scope", [call("c1")]);
44
+ await rig.settle(rig.killed, `${what}: the kill point fired`);
45
+ await rig.restart();
46
+ const { messages } = await rig.settle(outcome, `${what}: the session got the call's outcome`);
47
+ await rig.advance(200);
48
+ const [message] = messages;
49
+ const text = message?.content.map((part) => (part.type === "text" ? part.text : "")).join("");
50
+ if (expected.outcome === "result") {
51
+ expectEqual([text, message?.isError], ["ran:c1", false], `${what}: the tool's result`);
52
+ }
53
+ else if (placement === "split-local") {
54
+ expectEqual([text, message?.isError], [TOOL_RESULT_PLACEHOLDER, false], `${what}: today's placeholder`);
55
+ }
56
+ else {
57
+ expectEqual(message?.details, { outcome: "hand_restarted", uncertain: expected.uncertain, hooksRan: expected.uncertain }, `${what}: the endpoint outcome`);
58
+ expectEqual(message?.isError, true, `${what}: reported as an error`);
59
+ }
60
+ expectEqual(rig.bodies.length, runs, `${what}: tool body runs`);
61
+ const rows = await rig.rows();
62
+ expectEqual(rows.map((row) => row.progress.state), ["acked"], `${what}: one durable record, acknowledged`);
63
+ };
64
+ const declaration = {
65
+ id,
66
+ operation,
67
+ at,
68
+ placement,
69
+ expected: `${placement}: kill ${at} the ${operation} commit; ${describeExpected(placement, expected, runs)}; one durable record`,
70
+ };
71
+ return { declaration, run };
72
+ })));
73
+ export const KILL_HAND_DECLARATIONS = cases.map(({ declaration }) => declaration);
74
+ export const KILL_HAND_CASES = new Map(cases.map(({ declaration, run }) => [declaration.id, run]));
75
+ //# sourceMappingURL=kill-hand.js.map
@@ -0,0 +1,6 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { BatchCaseAdapters } from "./batch-executor.ts";
3
+ type KillNestCase = CaseImplementation<BatchCaseAdapters>;
4
+ export declare const KILL_NEST_CASES: ReadonlyMap<string, KillNestCase>;
5
+ export {};
6
+ //# sourceMappingURL=kill-nest.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { expectEqual } from "../../durable/testing/store-harness.js";
2
+ import { nestedChildId } from "../nested.js";
3
+ import { BrainKilledError, batchHarness, expectRejects } from "./batch-harness.js";
4
+ import { cancelTargetOf } from "./cancel-cases.js";
5
+ import { admitted, debited, nestParent, nestRequest } from "./nest-cases.js";
6
+ async function killedAround(adapters, label, at) {
7
+ const h = await batchHarness(adapters);
8
+ await (await h.nested()).open(nestParent);
9
+ await (await h.nested()).release("p");
10
+ return { h, dying: await h.nested({ label, at }) };
11
+ }
12
+ /** KILL-NEST-01: the brain dies before the admission is durable: nothing was debited, the retry admits it once. */
13
+ const beforeAdmission = async (adapters) => {
14
+ const { h, dying } = await killedAround(adapters, `admit:${nestedChildId("p", "c1")}`, "before");
15
+ await expectRejects(dying.admit(nestRequest()), BrainKilledError, "the dying admission");
16
+ const restarted = await h.nested();
17
+ expectEqual(await debited(restarted), 0, "nothing durable");
18
+ expectEqual(await restarted.admit(nestRequest()), admitted("c1", "model", false), "admitted on the retry");
19
+ expectEqual(await debited(restarted), 1, "debited once");
20
+ };
21
+ /** KILL-NEST-02: the brain dies after the admission is durable, before replying: the retry gets the same child. */
22
+ const afterAdmission = async (adapters) => {
23
+ const { h, dying } = await killedAround(adapters, `admit:${nestedChildId("p", "c1")}`, "after");
24
+ await expectRejects(dying.admit(nestRequest()), BrainKilledError, "the dying admission");
25
+ const restarted = await h.nested();
26
+ expectEqual(await restarted.admit(nestRequest()), admitted("c1", "model", true), "the same child");
27
+ expectEqual(await debited(restarted), 1, "never debited twice");
28
+ };
29
+ /**
30
+ * KILL-NEST-03: the brain dies after the cancel is durable (before any delivery), then again after a delivery was sent
31
+ * but before it was recorded: each restart re-sends the cascade until it is recorded, and nothing else is sent.
32
+ */
33
+ const aroundCascade = async (adapters) => {
34
+ const h = await batchHarness(adapters);
35
+ const nested = await h.nested();
36
+ await nested.open(nestParent);
37
+ await nested.release("p");
38
+ await nested.admit(nestRequest({ target: "e2" }));
39
+ await expectRejects((await h.nested({ label: "cancel", at: "after" })).cancel("p"), BrainKilledError, "dies after the cancel");
40
+ expectEqual((await (await h.nested()).read("p"))?.cancels, { [nestedChildId("p", "c1")]: "queued" }, "the cascade is durable");
41
+ const sent = [];
42
+ const send = async (target) => {
43
+ sent.push(target);
44
+ };
45
+ await expectRejects((await h.nested({ label: `cancel_delivered:${nestedChildId("p", "c1")}`, at: "before" })).deliverCancels("p", send), BrainKilledError, "dies after sending, before recording");
46
+ expectEqual(await (await h.nested()).deliverCancels("p", send), 1, "the restart re-sends it");
47
+ expectEqual(await (await h.nested()).deliverCancels("p", send), 0, "recorded: never sent again");
48
+ expectEqual(sent, [cancelTargetOf("c1", "e2"), cancelTargetOf("c1", "e2")], "sent until recorded");
49
+ };
50
+ export const KILL_NEST_CASES = new Map([
51
+ ["KILL-NEST-01", beforeAdmission],
52
+ ["KILL-NEST-02", afterAdmission],
53
+ ["KILL-NEST-03", aroundCascade],
54
+ ]);
55
+ //# sourceMappingURL=kill-nest.js.map
@@ -0,0 +1,6 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { BatchCaseAdapters } from "./batch-executor.ts";
3
+ type KillWakeCase = CaseImplementation<BatchCaseAdapters>;
4
+ export declare const KILL_WAKEX_CASES: ReadonlyMap<string, KillWakeCase>;
5
+ export {};
6
+ //# sourceMappingURL=kill-wakex.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { expectEqual } from "../../durable/testing/store-harness.js";
2
+ import { BrainKilledError, batchHarness, expectRejects } from "./batch-harness.js";
3
+ import { ids, linkTo, scopeOwner, wakeOf } from "./wake-exec-cases.js";
4
+ /** KILL-WAKEX-01: the hand dies before the offer is durable: there is nothing to re-offer and nothing reached the brain. */
5
+ const beforeOffer = async (adapters) => {
6
+ const h = await batchHarness(adapters);
7
+ await expectRejects((await h.wakeOutbox("e1", { label: "offer", at: "before" })).offer(wakeOf(1)), BrainKilledError, "the dying offer");
8
+ expectEqual(await (await h.wakeOutbox("e1")).pending(), [], "nothing durable");
9
+ };
10
+ /** KILL-WAKEX-02: the hand dies after the offer is durable, before sending it: its restart re-offers it once. */
11
+ const afterOffer = async (adapters) => {
12
+ const h = await batchHarness(adapters);
13
+ await expectRejects((await h.wakeOutbox("e1", { label: "offer", at: "after" })).offer(wakeOf(1)), BrainKilledError, "the dying offer");
14
+ const outbox = await h.wakeOutbox("e1");
15
+ const inbox = await h.wakeInbox(scopeOwner);
16
+ expectEqual(await outbox.reoffer(linkTo(inbox)), 1, "re-offered after the restart");
17
+ expectEqual((await inbox.read()).pending.length, 1, "delivered once");
18
+ expectEqual(await outbox.pending(), [], "acked");
19
+ };
20
+ /** KILL-WAKEX-03: the brain dies before the inbox commit: no ack was sent, so the re-offer delivers it once. */
21
+ const beforeCommit = async (adapters) => {
22
+ const h = await batchHarness(adapters);
23
+ const outbox = await h.wakeOutbox("e1");
24
+ const wake = await outbox.offer(wakeOf(1));
25
+ const dying = await h.wakeInbox(scopeOwner, { label: `commit:${wake.eventId}`, at: "before" });
26
+ await expectRejects(outbox.reoffer(linkTo(dying)), BrainKilledError, "the dying commit");
27
+ expectEqual(ids(await outbox.pending()), [wake.eventId], "never acked");
28
+ const inbox = await h.wakeInbox(scopeOwner);
29
+ await outbox.reoffer(linkTo(inbox));
30
+ expectEqual(ids((await inbox.read()).pending), [wake.eventId], "committed once");
31
+ expectEqual(await outbox.pending(), [], "acked after the commit");
32
+ };
33
+ /** KILL-WAKEX-04: the brain dies after the inbox commit, before its ack left: the re-offer is a duplicate, then acked. */
34
+ const afterCommit = async (adapters) => {
35
+ const h = await batchHarness(adapters);
36
+ const outbox = await h.wakeOutbox("e1");
37
+ const wake = await outbox.offer(wakeOf(1));
38
+ const dying = await h.wakeInbox(scopeOwner, { label: `commit:${wake.eventId}`, at: "after" });
39
+ await expectRejects(outbox.reoffer(linkTo(dying)), BrainKilledError, "the dying ack");
40
+ const inbox = await h.wakeInbox(scopeOwner);
41
+ await outbox.reoffer(linkTo(inbox));
42
+ expectEqual(ids((await inbox.read()).pending), [wake.eventId], "one wake on the brain");
43
+ expectEqual(await outbox.pending(), [], "the duplicate's ack removed it");
44
+ };
45
+ /** KILL-WAKEX-05: the hand dies after the ack arrived, before recording it: the re-offer is a duplicate, acked again. */
46
+ const beforeAckRecord = async (adapters) => {
47
+ const h = await batchHarness(adapters);
48
+ const offered = await (await h.wakeOutbox("e1")).offer(wakeOf(1));
49
+ const inbox = await h.wakeInbox(scopeOwner);
50
+ await expectRejects((await h.wakeOutbox("e1", { label: "ack", at: "before" })).reoffer(linkTo(inbox)), BrainKilledError, "the dying ack record");
51
+ const outbox = await h.wakeOutbox("e1");
52
+ expectEqual(ids(await outbox.pending()), [offered.eventId], "still pending on the hand");
53
+ await outbox.reoffer(linkTo(inbox));
54
+ expectEqual(await outbox.pending(), [], "acked by the duplicate");
55
+ expectEqual(ids((await inbox.read()).pending), [offered.eventId], "never a second wake");
56
+ };
57
+ /**
58
+ * KILL-WAKEX-06: the brain dies after the loop took a wake, before recording it: the restart hands the same wake (same
59
+ * id) over again, so the loop's consumer must be idempotent by event id; nothing is lost.
60
+ */
61
+ const beforeTakeRecord = async (adapters) => {
62
+ const h = await batchHarness(adapters);
63
+ const outbox = await h.wakeOutbox("e1");
64
+ const wake = await outbox.offer(wakeOf(1));
65
+ await outbox.reoffer(linkTo(await h.wakeInbox(scopeOwner)));
66
+ const taken = [];
67
+ const consume = async (got) => void taken.push(got);
68
+ await expectRejects((await h.wakeInbox(scopeOwner, { label: `take:${wake.eventId}`, at: "before" })).drain(consume), BrainKilledError, "the dying take");
69
+ expectEqual(await (await h.wakeInbox(scopeOwner)).drain(consume), 1, "handed over again after the restart");
70
+ expectEqual(ids(taken), [wake.eventId, wake.eventId], "the same wake, by the same id");
71
+ expectEqual(await (await h.wakeInbox(scopeOwner)).drain(consume), 0, "then recorded");
72
+ };
73
+ export const KILL_WAKEX_CASES = new Map([
74
+ ["KILL-WAKEX-01", beforeOffer],
75
+ ["KILL-WAKEX-02", afterOffer],
76
+ ["KILL-WAKEX-03", beforeCommit],
77
+ ["KILL-WAKEX-04", afterCommit],
78
+ ["KILL-WAKEX-05", beforeAckRecord],
79
+ ["KILL-WAKEX-06", beforeTakeRecord],
80
+ ]);
81
+ //# sourceMappingURL=kill-wakex.js.map
@@ -0,0 +1,9 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { ScopeBinding } from "../scope-lifecycle.ts";
3
+ import type { BatchCaseAdapters } from "./batch-executor.ts";
4
+ type LifecycleCase = CaseImplementation<BatchCaseAdapters>;
5
+ export declare const IDLE_TTL_MS = 30000;
6
+ export declare const bindingOf: (scope: string, issuer?: string) => ScopeBinding;
7
+ export declare const LIFECYCLE_CASES: ReadonlyMap<string, LifecycleCase>;
8
+ export {};
9
+ //# sourceMappingURL=lifecycle-cases.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { expectEqual } from "../../durable/testing/store-harness.js";
2
+ import { batchHarness } from "./batch-harness.js";
3
+ export const IDLE_TTL_MS = 30_000;
4
+ export const bindingOf = (scope, issuer = "brain") => ({
5
+ issuer,
6
+ workspace: "workspace",
7
+ scope,
8
+ generation: 1,
9
+ allowedRoots: ["/work"],
10
+ });
11
+ /** LIFECYCLE-01: a call submitted after a lifecycle event runs only once the event's handler effect is committed. */
12
+ const commitBeforeNextCall = async (adapters) => {
13
+ const h = await batchHarness(adapters);
14
+ const scopes = await h.scopes(IDLE_TTL_MS);
15
+ await scopes.open(bindingOf("A"));
16
+ const order = [];
17
+ const handlerHeld = Promise.withResolvers();
18
+ const event = scopes.lifecycle("brain", "A", "agent_end", async () => {
19
+ order.push("handler");
20
+ await handlerHeld.promise;
21
+ return { revoked: true };
22
+ });
23
+ const call = scopes.call("A", async () => {
24
+ order.push(`call sees ${(await scopes.read("A"))?.events.length ?? 0} committed event(s)`);
25
+ return "ran";
26
+ });
27
+ handlerHeld.resolve();
28
+ expectEqual(await event, { kind: "committed", seq: 1 }, "the event committed");
29
+ expectEqual(await call, "ran", "the call ran");
30
+ expectEqual(order, ["handler", "call sees 1 committed event(s)"], "the next call follows the commit");
31
+ };
32
+ /** LIFECYCLE-02: only the scope's issuer submits lifecycle events or closes it. */
33
+ const issuerOnly = async (adapters) => {
34
+ const h = await batchHarness(adapters);
35
+ const scopes = await h.scopes(IDLE_TTL_MS);
36
+ await scopes.open(bindingOf("A"));
37
+ let ran = false;
38
+ expectEqual(await scopes.lifecycle("intruder", "A", "turn_start", async () => {
39
+ ran = true;
40
+ return null;
41
+ }), { kind: "refused", reason: "not_issuer" }, "a lifecycle event from another party");
42
+ expectEqual(ran, false, "its handler never ran");
43
+ expectEqual(await scopes.close("intruder", "A"), { kind: "refused", reason: "not_issuer" }, "a close from another party");
44
+ expectEqual((await scopes.read("A"))?.state, "open", "still open");
45
+ };
46
+ /** LIFECYCLE-03: a closed scope admits no lifecycle event and is not reopened under another binding. */
47
+ const closedIsTerminal = async (adapters) => {
48
+ const h = await batchHarness(adapters);
49
+ const scopes = await h.scopes(IDLE_TTL_MS);
50
+ await scopes.open(bindingOf("A"));
51
+ expectEqual(await scopes.close("brain", "A"), { kind: "closed" }, "closed by its issuer");
52
+ expectEqual(await scopes.lifecycle("brain", "A", "turn_start", async () => null), { kind: "refused", reason: "closed" }, "no event after the close");
53
+ expectEqual(await scopes.open(bindingOf("A")), { kind: "refused", reason: "conflicting_scope" }, "not reopened");
54
+ };
55
+ export const LIFECYCLE_CASES = new Map([
56
+ ["LIFECYCLE-01", commitBeforeNextCall],
57
+ ["LIFECYCLE-02", issuerOnly],
58
+ ["LIFECYCLE-03", closedIsTerminal],
59
+ ]);
60
+ //# sourceMappingURL=lifecycle-cases.js.map
@@ -0,0 +1,3 @@
1
+ import type { RegisteredCase } from "../../conformance/registry.ts";
2
+ export declare const LIFECYCLE_REGISTRY: readonly RegisteredCase[];
3
+ //# sourceMappingURL=lifecycle-registry.d.ts.map
@@ -0,0 +1,19 @@
1
+ const LIFECYCLE_IMPL = "packages/agent/src/execution/testing/lifecycle-cases.ts";
2
+ const SCOPE_IMPL = "packages/agent/src/execution/testing/scope-cases.ts";
3
+ const MULTI_LIFE_IMPL = "packages/agent/src/execution/testing/multi-lifecycle-cases.ts";
4
+ const lifecycleCase = (id, impl, expected) => ({
5
+ id,
6
+ impl,
7
+ intro: "#5681",
8
+ adapters: ["store", "executor"],
9
+ expected,
10
+ });
11
+ export const LIFECYCLE_REGISTRY = [
12
+ lifecycleCase("LIFECYCLE-01", LIFECYCLE_IMPL, "a call after a lifecycle event runs only once the event's effect committed"),
13
+ lifecycleCase("LIFECYCLE-02", LIFECYCLE_IMPL, "only the scope's issuer submits lifecycle events or closes it"),
14
+ lifecycleCase("LIFECYCLE-03", LIFECYCLE_IMPL, "a closed scope admits no lifecycle event and is not reopened"),
15
+ lifecycleCase("SCOPE-01", SCOPE_IMPL, "the idle TTL never closes a scope that holds live resources"),
16
+ lifecycleCase("SCOPE-02", SCOPE_IMPL, "a forced close writes every live resource's outcome before the scope closes"),
17
+ lifecycleCase("MULTI-LIFE-01", MULTI_LIFE_IMPL, "A's agent_end and turn_start effects stay in A; B is untouched"),
18
+ ];
19
+ //# sourceMappingURL=lifecycle-registry.js.map
@@ -0,0 +1,6 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import { type HandCaseAdapters } from "./hand-harness.ts";
3
+ type HandCase = CaseImplementation<HandCaseAdapters>;
4
+ export declare const MULTI_HAND_CASES: ReadonlyMap<string, HandCase>;
5
+ export {};
6
+ //# sourceMappingURL=multi-hand-cases.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { expectEqual } from "../../durable/testing/store-harness.js";
2
+ import { call, openHandRig } from "./hand-harness.js";
3
+ const SCOPES = ["a", "b", "c"];
4
+ const CALLS_PER_SCOPE = 3;
5
+ const callIds = (scope) => Array.from({ length: CALLS_PER_SCOPE }, (_, index) => `${scope}${index + 1}`);
6
+ const texts = (messages) => messages.map((message) => message.content.map((part) => (part.type === "text" ? part.text : "")).join(""));
7
+ /** Several sessions' scopes run batches at once on one hand: each scope's calls start in its lane order. */
8
+ const manyScopesOnOneHand = async (adapters) => {
9
+ const rig = await openHandRig(adapters, { placement: "split-local" });
10
+ rig.gateBodies();
11
+ const batches = SCOPES.map((scope) => rig.execute(scope, callIds(scope).map(call)));
12
+ await rig.runUntil(() => rig.bodies.length === SCOPES.length * CALLS_PER_SCOPE, "MULTI-HAND-01: every body started");
13
+ for (const scope of SCOPES)
14
+ expectEqual(rig.bodies.filter((body) => body.startsWith(`${scope}:`)), callIds(scope).map((id) => `${scope}:${id}`), `MULTI-HAND-01: scope ${scope} kept its lane order`);
15
+ for (const scope of [...SCOPES].reverse())
16
+ for (const id of [...callIds(scope)].reverse())
17
+ rig.release(id);
18
+ const results = await rig.settle(Promise.all(batches), "MULTI-HAND-01: every batch settled");
19
+ expectEqual(results.map(({ messages }) => texts(messages)), SCOPES.map((scope) => callIds(scope).map((id) => `ran:${id}`)), "MULTI-HAND-01: each scope's results in its source order");
20
+ };
21
+ /** A hand killed with several scopes' calls in flight: each scope recovers on its own, nothing runs twice. */
22
+ const killWithScopesInFlight = async (adapters) => {
23
+ const dispatchCommits = SCOPES.length * 6;
24
+ const rig = await openHandRig(adapters, {
25
+ placement: "cross-machine",
26
+ killAt: { commit: dispatchCommits, at: "before" },
27
+ });
28
+ rig.gateBodies();
29
+ const batches = SCOPES.map((scope) => rig.execute(scope, [call(`${scope}1`)]));
30
+ await rig.runUntil(() => rig.bodies.length === SCOPES.length, "MULTI-KILL-01: every scope's call is running");
31
+ rig.release("a1");
32
+ await rig.settle(rig.killed, "MULTI-KILL-01: the hand died while the scopes were in flight");
33
+ await rig.restart();
34
+ const results = await rig.settle(Promise.all(batches), "MULTI-KILL-01: every scope got its outcome");
35
+ expectEqual(results.map(({ messages }) => messages.map((message) => message.details)), SCOPES.map(() => [{ outcome: "hand_restarted", uncertain: true, hooksRan: true }]), "MULTI-KILL-01: each scope's call ended hand_restarted, uncertain");
36
+ expectEqual(rig.bodies, SCOPES.map((scope) => `${scope}:${scope}1`), "MULTI-KILL-01: no call ran twice");
37
+ await rig.advance(200);
38
+ expectEqual((await rig.rows()).map((row) => row.progress.state), SCOPES.map(() => "acked"), "MULTI-KILL-01: one durable record per call, acknowledged");
39
+ };
40
+ export const MULTI_HAND_CASES = new Map([
41
+ ["MULTI-HAND-01", manyScopesOnOneHand],
42
+ ["MULTI-KILL-01", killWithScopesInFlight],
43
+ ]);
44
+ //# sourceMappingURL=multi-hand-cases.js.map
@@ -0,0 +1,4 @@
1
+ import type { CaseImplementation } from "../../conformance/runner.ts";
2
+ import type { BatchCaseAdapters } from "./batch-executor.ts";
3
+ export declare const MULTI_LIFECYCLE_CASES: ReadonlyMap<string, CaseImplementation<BatchCaseAdapters>>;
4
+ //# sourceMappingURL=multi-lifecycle-cases.d.ts.map