@code-yeongyu/senpi-agent-core 2026.11.3-3 → 2026.11.5-1
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/agent-loop.js +20 -186
- package/dist/agent.d.ts +4 -0
- package/dist/agent.js +4 -0
- package/dist/conformance/index.d.ts +30 -0
- package/dist/conformance/index.js +21 -0
- package/dist/conformance/loop-core-manifest.d.ts +1 -1
- package/dist/conformance/loop-core-manifest.js +18 -0
- package/dist/conformance/registry.js +20 -18
- package/dist/egress/types.d.ts +102 -0
- package/dist/egress/types.js +7 -0
- package/dist/execution/canonical-digest.d.ts +10 -0
- package/dist/execution/canonical-digest.js +20 -0
- package/dist/execution/canonical-json.d.ts +3 -0
- package/dist/execution/canonical-json.js +12 -0
- package/dist/execution/chain-count.d.ts +26 -0
- package/dist/execution/chain-count.js +45 -0
- package/dist/execution/coordinator-codec.js +13 -2
- package/dist/execution/coordinator-consent.d.ts +29 -0
- package/dist/execution/coordinator-consent.js +63 -0
- package/dist/execution/coordinator-plan.d.ts +1 -2
- package/dist/execution/coordinator-plan.js +4 -17
- package/dist/execution/coordinator-sequential.d.ts +15 -0
- package/dist/execution/coordinator-sequential.js +34 -0
- package/dist/execution/coordinator-types.d.ts +45 -0
- package/dist/execution/coordinator.d.ts +3 -1
- package/dist/execution/coordinator.js +35 -3
- package/dist/execution/device-files-node.d.ts +8 -0
- package/dist/execution/device-files-node.js +150 -0
- package/dist/execution/device-files.d.ts +109 -0
- package/dist/execution/device-files.js +124 -0
- package/dist/execution/ledger-types.d.ts +3 -1
- package/dist/execution/ledger.d.ts +9 -3
- package/dist/execution/ledger.js +8 -2
- package/dist/execution/loop-hook-host-hand.d.ts +33 -0
- package/dist/execution/loop-hook-host-hand.js +71 -0
- package/dist/execution/loop-hook-host-protocol.d.ts +46 -0
- package/dist/execution/loop-hook-host-protocol.js +47 -0
- package/dist/execution/loop-hook-host.d.ts +40 -0
- package/dist/execution/loop-hook-host.js +87 -0
- package/dist/execution/nested-codec.d.ts +5 -0
- package/dist/execution/nested-codec.js +41 -0
- package/dist/execution/nested-types.d.ts +92 -0
- package/dist/execution/nested-types.js +3 -0
- package/dist/execution/nested.d.ts +48 -0
- package/dist/execution/nested.js +206 -0
- package/dist/execution/plane-model.d.ts +33 -0
- package/dist/execution/plane-model.js +80 -0
- package/dist/execution/plane-session.d.ts +56 -0
- package/dist/execution/plane-session.js +178 -0
- package/dist/execution/plane.d.ts +75 -0
- package/dist/execution/plane.js +172 -0
- package/dist/execution/prepared/executor-body.d.ts +22 -0
- package/dist/execution/prepared/executor-body.js +73 -0
- package/dist/execution/prepared/executor-freeze.d.ts +17 -0
- package/dist/execution/prepared/executor-freeze.js +42 -0
- package/dist/execution/prepared/executor-pipeline.d.ts +11 -0
- package/dist/execution/prepared/executor-pipeline.js +26 -0
- package/dist/execution/prepared/executor-types.d.ts +131 -0
- package/dist/execution/prepared/executor-types.js +2 -0
- package/dist/execution/prepared/executor.d.ts +8 -0
- package/dist/execution/prepared/executor.js +261 -0
- package/dist/execution/prepared/memory-batch-store.d.ts +4 -0
- package/dist/execution/prepared/memory-batch-store.js +4 -0
- package/dist/execution/prepared/pipeline-prepared-batch.d.ts +27 -0
- package/dist/execution/prepared/pipeline-prepared-batch.js +175 -0
- package/dist/execution/prepared/pipeline-prepared.d.ts +10 -0
- package/dist/execution/prepared/pipeline-prepared.js +54 -0
- package/dist/execution/remote-device-files.d.ts +12 -0
- package/dist/execution/remote-device-files.js +113 -0
- package/dist/execution/remote-epoch-gate.d.ts +19 -0
- package/dist/execution/remote-epoch-gate.js +46 -0
- package/dist/execution/remote-epoch.d.ts +53 -0
- package/dist/execution/remote-epoch.js +74 -0
- package/dist/execution/remote-executor.d.ts +17 -0
- package/dist/execution/remote-executor.js +70 -18
- package/dist/execution/remote-file-call.d.ts +14 -0
- package/dist/execution/remote-file-call.js +31 -0
- package/dist/execution/remote-hand-ledger.d.ts +11 -3
- package/dist/execution/remote-hand-ledger.js +31 -15
- package/dist/execution/remote-link.d.ts +41 -0
- package/dist/execution/remote-link.js +153 -0
- package/dist/execution/remote-protocol.d.ts +50 -4
- package/dist/execution/remote-protocol.js +48 -2
- package/dist/execution/remote-tool-host.d.ts +23 -3
- package/dist/execution/remote-tool-host.js +25 -64
- package/dist/execution/scope-lifecycle.d.ts +81 -0
- package/dist/execution/scope-lifecycle.js +173 -0
- package/dist/execution/testing/batch-executor.js +32 -3
- package/dist/execution/testing/batch-harness.d.ts +25 -3
- package/dist/execution/testing/batch-harness.js +83 -5
- package/dist/execution/testing/cancel-cases.d.ts +8 -0
- package/dist/execution/testing/cancel-cases.js +64 -0
- package/dist/execution/testing/consent-cases.d.ts +14 -0
- package/dist/execution/testing/consent-cases.js +66 -0
- package/dist/execution/testing/epoch-cases.d.ts +8 -0
- package/dist/execution/testing/epoch-cases.js +84 -0
- package/dist/execution/testing/epoch-harness.d.ts +47 -0
- package/dist/execution/testing/epoch-harness.js +172 -0
- package/dist/execution/testing/epoch-registry.d.ts +3 -0
- package/dist/execution/testing/epoch-registry.js +17 -0
- package/dist/execution/testing/hand-harness.d.ts +3 -0
- package/dist/execution/testing/hand-harness.js +27 -22
- package/dist/execution/testing/hand-registry.d.ts +3 -0
- package/dist/execution/testing/hand-registry.js +20 -0
- package/dist/execution/testing/kill-epoch.d.ts +9 -0
- package/dist/execution/testing/kill-epoch.js +71 -0
- package/dist/execution/testing/kill-hook.d.ts +14 -0
- package/dist/execution/testing/kill-hook.js +117 -0
- package/dist/execution/testing/kill-nest.d.ts +6 -0
- package/dist/execution/testing/kill-nest.js +55 -0
- package/dist/execution/testing/kill-wakex.d.ts +6 -0
- package/dist/execution/testing/kill-wakex.js +81 -0
- package/dist/execution/testing/lifecycle-cases.d.ts +9 -0
- package/dist/execution/testing/lifecycle-cases.js +60 -0
- package/dist/execution/testing/lifecycle-registry.d.ts +3 -0
- package/dist/execution/testing/lifecycle-registry.js +19 -0
- package/dist/execution/testing/multi-epoch-cases.d.ts +4 -0
- package/dist/execution/testing/multi-epoch-cases.js +29 -0
- package/dist/execution/testing/multi-lifecycle-cases.d.ts +4 -0
- package/dist/execution/testing/multi-lifecycle-cases.js +34 -0
- package/dist/execution/testing/multi-seq-cases.d.ts +4 -0
- package/dist/execution/testing/multi-seq-cases.js +46 -0
- package/dist/execution/testing/nest-cases.d.ts +39 -0
- package/dist/execution/testing/nest-cases.js +181 -0
- package/dist/execution/testing/nest-registry.d.ts +3 -0
- package/dist/execution/testing/nest-registry.js +27 -0
- package/dist/execution/testing/scope-cases.d.ts +6 -0
- package/dist/execution/testing/scope-cases.js +49 -0
- package/dist/execution/testing/seq-cases.d.ts +6 -0
- package/dist/execution/testing/seq-cases.js +71 -0
- package/dist/execution/testing/seq-registry.d.ts +3 -0
- package/dist/execution/testing/seq-registry.js +32 -0
- package/dist/execution/testing/wake-exec-cases.d.ts +20 -0
- package/dist/execution/testing/wake-exec-cases.js +147 -0
- package/dist/execution/testing/wake-registry.d.ts +3 -0
- package/dist/execution/testing/wake-registry.js +26 -0
- package/dist/execution/tool-host.d.ts +23 -3
- package/dist/execution/tool-host.js +18 -1
- package/dist/execution/tool-outcome-events.d.ts +11 -0
- package/dist/execution/tool-outcome-events.js +47 -0
- package/dist/execution/wake-inbox.d.ts +25 -0
- package/dist/execution/wake-inbox.js +85 -0
- package/dist/execution/wake-outbox.d.ts +30 -0
- package/dist/execution/wake-outbox.js +87 -0
- package/dist/execution/wake-types.d.ts +45 -0
- package/dist/execution/wake-types.js +3 -0
- package/dist/harness/agent-harness.d.ts +6 -0
- package/dist/harness/execution/tool-host-call.d.ts +13 -0
- package/dist/harness/execution/tool-host-call.js +55 -0
- package/dist/harness/execution/tools.d.ts +2 -1
- package/dist/harness/execution/tools.js +32 -17
- package/dist/harness/runtime/drive/tools.js +1 -1
- package/dist/harness/runtime/harness.js +1 -0
- package/dist/harness/runtime/types.d.ts +1 -0
- package/dist/index.d.ts +27 -2
- package/dist/index.js +24 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.js +1 -0
- package/dist/public-entry.d.ts +10 -0
- package/dist/public-entry.js +23 -0
- package/dist/step-commit.d.ts +24 -0
- package/dist/step-commit.js +24 -0
- package/dist/tool-name-alias.d.ts +1 -7
- package/dist/tool-name-alias.js +0 -17
- package/dist/transport/testing/multi-cases.js +8 -8
- package/dist/types.d.ts +37 -1
- package/package.json +3 -3
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { nestedChildId } from "../nested.js";
|
|
3
|
+
import { NESTED_LIFETIME_MS } from "../nested-types.js";
|
|
4
|
+
import { batchHarness } from "./batch-harness.js";
|
|
5
|
+
/** The harness clock starts at 101; the parent was admitted then with a 60 s lease and a budget of 10. */
|
|
6
|
+
const NEST_ADMITTED_AT = 101;
|
|
7
|
+
const LEASE_MS = 60_000;
|
|
8
|
+
export const nestParent = {
|
|
9
|
+
executionId: "p",
|
|
10
|
+
generation: 1,
|
|
11
|
+
executor: "e1",
|
|
12
|
+
scope: "scope",
|
|
13
|
+
admittedAt: NEST_ADMITTED_AT,
|
|
14
|
+
leaseUntil: NEST_ADMITTED_AT + LEASE_MS,
|
|
15
|
+
budget: 10,
|
|
16
|
+
capabilities: { preparation: ["model"], body: ["e2"] },
|
|
17
|
+
};
|
|
18
|
+
export const nestRequest = (over = {}) => ({
|
|
19
|
+
sender: "e1",
|
|
20
|
+
parent: "p",
|
|
21
|
+
parentGeneration: 1,
|
|
22
|
+
scope: "scope",
|
|
23
|
+
childRequestId: "c1",
|
|
24
|
+
target: "model",
|
|
25
|
+
cost: 1,
|
|
26
|
+
...over,
|
|
27
|
+
});
|
|
28
|
+
export const admitted = (childRequestId, target, replayed) => ({
|
|
29
|
+
kind: "admitted",
|
|
30
|
+
child: { issuer: "brain", executionId: nestedChildId("p", childRequestId), generation: 1 },
|
|
31
|
+
target,
|
|
32
|
+
replayed,
|
|
33
|
+
});
|
|
34
|
+
export const refusedWith = (reason) => ({ kind: "refused", reason });
|
|
35
|
+
export async function openedParent(adapters) {
|
|
36
|
+
const h = await batchHarness(adapters);
|
|
37
|
+
const nested = await h.nested();
|
|
38
|
+
await nested.open(nestParent);
|
|
39
|
+
return { h, nested };
|
|
40
|
+
}
|
|
41
|
+
export const debited = async (nested) => (await nested.read("p"))?.debited;
|
|
42
|
+
/** NEST-01: a request from another hand naming a live parent, or naming a parent the brain does not hold, is refused. */
|
|
43
|
+
const wrongHand = async (adapters) => {
|
|
44
|
+
const { nested } = await openedParent(adapters);
|
|
45
|
+
expectEqual(await nested.admit(nestRequest({ sender: "e2" })), refusedWith("not_parent_executor"), "another hand");
|
|
46
|
+
expectEqual(await nested.admit(nestRequest({ parent: "forged" })), refusedWith("unknown_parent"), "forged parent");
|
|
47
|
+
expectEqual(await debited(nested), 0, "nothing debited");
|
|
48
|
+
expectEqual(await nested.admit(nestRequest()), admitted("c1", "model", false), "the parent's executor is admitted");
|
|
49
|
+
};
|
|
50
|
+
/** NEST-02: a replayed request returns the same child, also after a brain restart, and is debited once. */
|
|
51
|
+
const replay = async (adapters) => {
|
|
52
|
+
const { h, nested } = await openedParent(adapters);
|
|
53
|
+
expectEqual(await nested.admit(nestRequest()), admitted("c1", "model", false), "first admission");
|
|
54
|
+
expectEqual(await nested.admit(nestRequest()), admitted("c1", "model", true), "a replay, same child");
|
|
55
|
+
const restarted = await h.nested();
|
|
56
|
+
expectEqual(await restarted.admit(nestRequest()), admitted("c1", "model", true), "a replay after a restart");
|
|
57
|
+
expectEqual(await debited(restarted), 1, "debited once");
|
|
58
|
+
expectEqual(await restarted.admit(nestRequest({ target: "e2" })), refusedWith("conflicting_request"), "the same child request id for another call");
|
|
59
|
+
expectEqual(await restarted.open({ ...nestParent, executionId: "p/x" }), { kind: "opened" }, "a parent named p/x");
|
|
60
|
+
const nestedName = await restarted.admit(nestRequest({ parent: "p/x" }));
|
|
61
|
+
const slashedRequest = await restarted.admit(nestRequest({ childRequestId: "x/c1" }));
|
|
62
|
+
if (nestedName.kind !== "admitted" || slashedRequest.kind !== "admitted")
|
|
63
|
+
throw new Error("NEST-02: not admitted");
|
|
64
|
+
if (nestedName.child.executionId === slashedRequest.child.executionId)
|
|
65
|
+
throw new Error(`NEST-02: two children share ${nestedName.child.executionId}`);
|
|
66
|
+
};
|
|
67
|
+
/** NEST-03: siblings together never exceed the parent's reservation; the refused one debits nothing. */
|
|
68
|
+
const siblingBudget = async (adapters) => {
|
|
69
|
+
const { nested } = await openedParent(adapters);
|
|
70
|
+
expectEqual((await nested.admit(nestRequest({ cost: 6 }))).kind, "admitted", "the first sibling fits");
|
|
71
|
+
expectEqual(await nested.admit(nestRequest({ childRequestId: "c2", cost: 5 })), refusedWith("budget_exhausted"), "6 + 5 exceeds 10");
|
|
72
|
+
expectEqual(await debited(nested), 6, "the refused sibling debited nothing");
|
|
73
|
+
expectEqual((await nested.admit(nestRequest({ childRequestId: "c3", cost: 4 }))).kind, "admitted", "6 + 4 fits");
|
|
74
|
+
for (const cost of [-100, Number.NaN, Number.POSITIVE_INFINITY])
|
|
75
|
+
expectEqual(await nested.admit(nestRequest({ childRequestId: `bad-${cost}`, cost })), refusedWith("invalid_cost"), `cost ${cost}`);
|
|
76
|
+
expectEqual(await debited(nested), 10, "an invalid cost never moves the reservation");
|
|
77
|
+
expectEqual((await nested.cancel("p")).length, 2, "the record still reads: the cancel names both children");
|
|
78
|
+
};
|
|
79
|
+
/** NEST-04: the parent's executor still has to name the parent's generation and scope. */
|
|
80
|
+
const generationAndScope = async (adapters) => {
|
|
81
|
+
const { nested } = await openedParent(adapters);
|
|
82
|
+
expectEqual(await nested.admit(nestRequest({ parentGeneration: 2 })), refusedWith("stale_generation"), "generation");
|
|
83
|
+
expectEqual(await nested.admit(nestRequest({ scope: "other" })), refusedWith("scope_mismatch"), "scope");
|
|
84
|
+
expectEqual(await nested.open(nestParent), { kind: "opened" }, "opening the same parent again");
|
|
85
|
+
expectEqual(await nested.open({ ...nestParent, generation: 2 }), refusedWith("conflicting_parent"), "opening it again with another generation");
|
|
86
|
+
const { capabilities, budget, leaseUntil, admittedAt, scope, executor, generation, executionId } = nestParent;
|
|
87
|
+
expectEqual(await nested.open({ capabilities, budget, leaseUntil, admittedAt, scope, executor, generation, executionId }), { kind: "opened" }, "the same parent with its fields in another order");
|
|
88
|
+
for (const field of ["generation", "admittedAt", "leaseUntil", "budget"]) {
|
|
89
|
+
const broken = { ...nestParent, executionId: `bad-${field}`, [field]: Number.NaN };
|
|
90
|
+
let threw = false;
|
|
91
|
+
await nested.open(broken).catch(() => {
|
|
92
|
+
threw = true;
|
|
93
|
+
});
|
|
94
|
+
expectEqual([threw, await nested.read(broken.executionId)], [true, undefined], `a NaN ${field} is never written`);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/** NEST-05: during preflight only the preparation-phase set admits (a `tool_call` hook's cross-plane call). */
|
|
98
|
+
const preparationPhase = async (adapters) => {
|
|
99
|
+
const { nested } = await openedParent(adapters);
|
|
100
|
+
expectEqual(await nested.admit(nestRequest()), admitted("c1", "model", false), "a preflight cross-plane call");
|
|
101
|
+
expectEqual(await nested.admit(nestRequest({ childRequestId: "c2", target: "e2" })), refusedWith("not_in_nested_set"), "a body-phase target before release");
|
|
102
|
+
};
|
|
103
|
+
/** NEST-06: release widens the set to the body phase. */
|
|
104
|
+
const releaseWidens = async (adapters) => {
|
|
105
|
+
const { nested } = await openedParent(adapters);
|
|
106
|
+
await nested.release("p");
|
|
107
|
+
expectEqual(await nested.admit(nestRequest({ childRequestId: "c2", target: "e2" })), admitted("c2", "e2", false), "a body-phase target after release");
|
|
108
|
+
expectEqual((await nested.admit(nestRequest())).kind, "admitted", "the preparation targets stay");
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* NEST-07: a detached cell's later requests are admitted against its registered activity after the invocation ended,
|
|
112
|
+
* within the activity's subset, and refused once the activity ended. The activity never holds more than the parent.
|
|
113
|
+
*/
|
|
114
|
+
const detachedActivity = async (adapters) => {
|
|
115
|
+
const { h, nested } = await openedParent(adapters);
|
|
116
|
+
const expiresAt = nestParent.leaseUntil;
|
|
117
|
+
const activity = { activityId: "a1", parent: "p", executor: "e1", scope: "scope", budget: 3, expiresAt };
|
|
118
|
+
expectEqual(await nested.registerActivity({ ...activity, activityId: "early", targets: ["e2"] }), refusedWith("exceeds_parent"), "a body-phase target before release");
|
|
119
|
+
await nested.release("p");
|
|
120
|
+
for (const [over, what] of [
|
|
121
|
+
[{ targets: ["model", "elsewhere"] }, "a target the parent does not hold"],
|
|
122
|
+
[{ targets: ["model"], expiresAt: expiresAt + 1 }, "an expiry past the parent's"],
|
|
123
|
+
[{ targets: ["model"], budget: 11 }, "a budget over the parent's remaining"],
|
|
124
|
+
[{ targets: ["model"], executor: "e2" }, "another hand"],
|
|
125
|
+
])
|
|
126
|
+
expectEqual(await nested.registerActivity({ ...activity, ...over }), refusedWith("exceeds_parent"), what);
|
|
127
|
+
expectEqual(await nested.registerActivity({ ...activity, targets: ["model"] }), { kind: "registered" }, "registered");
|
|
128
|
+
await nested.settle("p");
|
|
129
|
+
expectEqual(await nested.admit(nestRequest()), refusedWith("parent_terminal"), "the terminal invocation");
|
|
130
|
+
expectEqual(await nested.admit(nestRequest({ activityId: "a1" })), admitted("c1", "model", false), "the live activity");
|
|
131
|
+
expectEqual(await nested.admit(nestRequest({ activityId: "a1", childRequestId: "c2", target: "e2" })), refusedWith("not_in_nested_set"), "outside the activity's subset");
|
|
132
|
+
expectEqual(await nested.admit(nestRequest({ activityId: "a9" })), refusedWith("unknown_activity"), "no such cell");
|
|
133
|
+
await nested.endActivity("p", "a1");
|
|
134
|
+
expectEqual(await nested.admit(nestRequest({ activityId: "a1", childRequestId: "c3" })), refusedWith("activity_ended"), "after the cell ended");
|
|
135
|
+
expectEqual(await nested.registerActivity({ ...activity, activityId: "late", targets: ["model"] }), refusedWith("parent_terminal"), "no activity revives an invocation that ended");
|
|
136
|
+
const fresh = await h.nested();
|
|
137
|
+
await fresh.open({ ...nestParent, executionId: "q" });
|
|
138
|
+
h.advance(LEASE_MS + 1);
|
|
139
|
+
expectEqual(await fresh.registerActivity({ ...activity, parent: "q", activityId: "expired", targets: ["model"] }), refusedWith("parent_terminal"), "nor one whose parent's set expired");
|
|
140
|
+
};
|
|
141
|
+
/** NEST-08: an activity's children are debited from its own budget and from the parent's reservation. */
|
|
142
|
+
const activityBudget = async (adapters) => {
|
|
143
|
+
const { nested } = await openedParent(adapters);
|
|
144
|
+
await nested.release("p");
|
|
145
|
+
await nested.registerActivity({
|
|
146
|
+
activityId: "a1",
|
|
147
|
+
parent: "p",
|
|
148
|
+
executor: "e1",
|
|
149
|
+
scope: "scope",
|
|
150
|
+
targets: ["model"],
|
|
151
|
+
budget: 2,
|
|
152
|
+
expiresAt: nestParent.leaseUntil,
|
|
153
|
+
});
|
|
154
|
+
for (const id of ["c1", "c2"])
|
|
155
|
+
expectEqual((await nested.admit(nestRequest({ activityId: "a1", childRequestId: id }))).kind, "admitted", id);
|
|
156
|
+
expectEqual(await nested.admit(nestRequest({ activityId: "a1", childRequestId: "c3" })), refusedWith("budget_exhausted"), "the activity's budget");
|
|
157
|
+
expectEqual((await nested.admit(nestRequest({ childRequestId: "c4", cost: 8 }))).kind, "admitted", "2 + 8 fits");
|
|
158
|
+
expectEqual(await nested.admit(nestRequest({ childRequestId: "c5" })), refusedWith("budget_exhausted"), "the parent's reservation counts the activity's children");
|
|
159
|
+
};
|
|
160
|
+
/** NEST-09: the nested set expires with the parent's lease; renewals extend it, never past the parent's lifetime. */
|
|
161
|
+
const leaseFollowsParent = async (adapters) => {
|
|
162
|
+
const { h, nested } = await openedParent(adapters);
|
|
163
|
+
h.advance(LEASE_MS + 1);
|
|
164
|
+
expectEqual(await nested.admit(nestRequest()), refusedWith("expired"), "past the parent's lease");
|
|
165
|
+
expectEqual(await nested.renew("p", nestParent.leaseUntil + LEASE_MS), nestParent.leaseUntil + LEASE_MS, "renewed");
|
|
166
|
+
expectEqual((await nested.admit(nestRequest())).kind, "admitted", "admitted after the renewal");
|
|
167
|
+
expectEqual(await nested.renew("p", NEST_ADMITTED_AT), nestParent.leaseUntil + LEASE_MS, "never moves back");
|
|
168
|
+
expectEqual(await nested.renew("p", NEST_ADMITTED_AT + 2 * NESTED_LIFETIME_MS), NEST_ADMITTED_AT + NESTED_LIFETIME_MS, "capped at the parent's lifetime");
|
|
169
|
+
};
|
|
170
|
+
export const NEST_CASES = new Map([
|
|
171
|
+
["NEST-01", wrongHand],
|
|
172
|
+
["NEST-02", replay],
|
|
173
|
+
["NEST-03", siblingBudget],
|
|
174
|
+
["NEST-04", generationAndScope],
|
|
175
|
+
["NEST-05", preparationPhase],
|
|
176
|
+
["NEST-06", releaseWidens],
|
|
177
|
+
["NEST-07", detachedActivity],
|
|
178
|
+
["NEST-08", activityBudget],
|
|
179
|
+
["NEST-09", leaseFollowsParent],
|
|
180
|
+
]);
|
|
181
|
+
//# sourceMappingURL=nest-cases.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const NEST_IMPL = "packages/agent/src/execution/testing/nest-cases.ts";
|
|
2
|
+
const CANCEL_IMPL = "packages/agent/src/execution/testing/cancel-cases.ts";
|
|
3
|
+
const KILL_NEST_IMPL = "packages/agent/src/execution/testing/kill-nest.ts";
|
|
4
|
+
const nestCase = (id, impl, expected) => ({
|
|
5
|
+
id,
|
|
6
|
+
impl,
|
|
7
|
+
intro: "#5669",
|
|
8
|
+
adapters: ["store", "executor"],
|
|
9
|
+
expected,
|
|
10
|
+
});
|
|
11
|
+
export const NEST_REGISTRY = [
|
|
12
|
+
nestCase("NEST-01", NEST_IMPL, "a nested request from another hand or naming a forged parent is refused"),
|
|
13
|
+
nestCase("NEST-02", NEST_IMPL, "a replayed nested request returns the same child, after a restart too; debited once"),
|
|
14
|
+
nestCase("NEST-03", NEST_IMPL, "sibling children over the parent's budget are refused at the reservation"),
|
|
15
|
+
nestCase("NEST-04", NEST_IMPL, "a request naming another generation or scope of the parent is refused"),
|
|
16
|
+
nestCase("NEST-05", NEST_IMPL, "a preflight cross-plane call is admitted under the preparation-phase nested set only"),
|
|
17
|
+
nestCase("NEST-06", NEST_IMPL, "release widens the nested set to the body phase"),
|
|
18
|
+
nestCase("NEST-07", NEST_IMPL, "a detached cell is admitted against its registered activity, within its subset, and refused after it ends"),
|
|
19
|
+
nestCase("NEST-08", NEST_IMPL, "an activity's children debit its own budget and the parent's reservation"),
|
|
20
|
+
nestCase("NEST-09", NEST_IMPL, "the nested set expires with the parent's lease and renewals, never past its lifetime"),
|
|
21
|
+
nestCase("CANCEL-01", CANCEL_IMPL, "a parent cancel committed first refuses the child parent_terminal"),
|
|
22
|
+
nestCase("CANCEL-02", CANCEL_IMPL, "a child admitted first exists; the parent cancel durably cascades to it until delivered"),
|
|
23
|
+
nestCase("KILL-NEST-01", KILL_NEST_IMPL, "a brain killed before a child admission is durable admits it once on retry"),
|
|
24
|
+
nestCase("KILL-NEST-02", KILL_NEST_IMPL, "a brain killed after a child admission is durable returns the same child"),
|
|
25
|
+
nestCase("KILL-NEST-03", KILL_NEST_IMPL, "a brain killed around the cancel cascade re-sends it until recorded"),
|
|
26
|
+
];
|
|
27
|
+
//# sourceMappingURL=nest-registry.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import type { BatchCaseAdapters } from "./batch-executor.ts";
|
|
3
|
+
type ScopeCase = CaseImplementation<BatchCaseAdapters>;
|
|
4
|
+
export declare const SCOPE_CASES: ReadonlyMap<string, ScopeCase>;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=scope-cases.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { BrainKilledError, batchHarness, expectRejects } from "./batch-harness.js";
|
|
3
|
+
import { bindingOf, IDLE_TTL_MS } from "./lifecycle-cases.js";
|
|
4
|
+
/** SCOPE-01: the idle TTL never closes a scope that holds a live resource; it closes an idle one that holds none. */
|
|
5
|
+
const ttlSparesLive = async (adapters) => {
|
|
6
|
+
const h = await batchHarness(adapters);
|
|
7
|
+
const scopes = await h.scopes(IDLE_TTL_MS);
|
|
8
|
+
await scopes.open(bindingOf("live"));
|
|
9
|
+
await scopes.open(bindingOf("idle"));
|
|
10
|
+
await scopes.hold("live", "bash_1", "terminal");
|
|
11
|
+
h.advance(IDLE_TTL_MS + 1);
|
|
12
|
+
expectEqual(await scopes.sweepIdle(), ["idle"], "only the scope without live resources closes");
|
|
13
|
+
expectEqual((await scopes.read("live"))?.state, "open", "the live scope stays open");
|
|
14
|
+
await scopes.release("live", "bash_1");
|
|
15
|
+
expectEqual(await scopes.sweepIdle(), [], "a release is activity: the TTL starts again");
|
|
16
|
+
h.advance(IDLE_TTL_MS + 1);
|
|
17
|
+
expectEqual(await scopes.sweepIdle(), ["live"], "then it closes");
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* SCOPE-02: a forced close writes every live resource's terminal outcome before the scope closes; a close that dies in
|
|
21
|
+
* between leaves the written outcomes and an open scope, and the next close terminates only what is left.
|
|
22
|
+
*/
|
|
23
|
+
const forcedCloseOutcomesFirst = async (adapters) => {
|
|
24
|
+
const h = await batchHarness(adapters);
|
|
25
|
+
const scopes = await h.scopes(IDLE_TTL_MS);
|
|
26
|
+
await scopes.open(bindingOf("A"));
|
|
27
|
+
await scopes.hold("A", "r1", "execution");
|
|
28
|
+
await scopes.hold("A", "r2", "terminal");
|
|
29
|
+
expectEqual(await scopes.close("brain", "A"), { kind: "refused", reason: "live_resources" }, "not without force");
|
|
30
|
+
const terminated = [];
|
|
31
|
+
const terminate = async (resource) => {
|
|
32
|
+
terminated.push(resource);
|
|
33
|
+
return { reason: "cancelled", resource };
|
|
34
|
+
};
|
|
35
|
+
const dying = await h.scopes(IDLE_TTL_MS, { label: "outcome:r1", at: "after" });
|
|
36
|
+
await expectRejects(dying.close("brain", "A", { force: true, terminate }), BrainKilledError, "dies after r1");
|
|
37
|
+
const midway = await (await h.scopes(IDLE_TTL_MS)).read("A");
|
|
38
|
+
expectEqual([midway?.state, Object.keys(midway?.outcomes ?? {})], ["open", ["r1"]], "r1's outcome, still open");
|
|
39
|
+
const restarted = await h.scopes(IDLE_TTL_MS);
|
|
40
|
+
expectEqual(await restarted.close("brain", "A", { force: true, terminate }), { kind: "closed" }, "closed");
|
|
41
|
+
expectEqual(terminated, ["r1", "r2"], "each resource terminated once");
|
|
42
|
+
const closed = await restarted.read("A");
|
|
43
|
+
expectEqual([closed?.state, Object.keys(closed?.outcomes ?? {}).sort()], ["closed", ["r1", "r2"]], "outcomes first");
|
|
44
|
+
};
|
|
45
|
+
export const SCOPE_CASES = new Map([
|
|
46
|
+
["SCOPE-01", ttlSparesLive],
|
|
47
|
+
["SCOPE-02", forcedCloseOutcomesFirst],
|
|
48
|
+
]);
|
|
49
|
+
//# sourceMappingURL=scope-cases.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import type { BatchCaseAdapters } from "./batch-executor.ts";
|
|
3
|
+
type SeqCase = CaseImplementation<BatchCaseAdapters>;
|
|
4
|
+
export declare const SEQ_CASES: ReadonlyMap<string, SeqCase>;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=seq-cases.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { createSequentialCoordinator } from "../coordinator-sequential.js";
|
|
3
|
+
import { ExecutorKilledError } from "./batch-executor.js";
|
|
4
|
+
import { BrainKilledError, batchHarness, batchPlan, expectRejects, resultOf } from "./batch-harness.js";
|
|
5
|
+
const steps = (id) => [`shim:${id}`, `hook:${id}`, `body:${id}`, `done:${id}`];
|
|
6
|
+
const notRun = { kind: "not_run", cause: "batch_abort" };
|
|
7
|
+
/**
|
|
8
|
+
* SEQ-01 (S11): `toolExecution: "sequential"` keeps today's interleaving on the coordinator: each call is its own
|
|
9
|
+
* one-call batch, prepared and run to its outcome before the next is prepared, across executors. A crash inside a call
|
|
10
|
+
* resumes from the durable batches and reruns nothing; a blocked call is a per-call result and the next call runs; a
|
|
11
|
+
* stopped preparation ends the run, and the calls after it are never prepared.
|
|
12
|
+
*/
|
|
13
|
+
const interleave = async (adapters) => {
|
|
14
|
+
const h = await batchHarness(adapters);
|
|
15
|
+
const plan = batchPlan("seq-01", [
|
|
16
|
+
["a", "e1"],
|
|
17
|
+
["b", "e2"],
|
|
18
|
+
["x", "e1", "deny"],
|
|
19
|
+
["c", "e1"],
|
|
20
|
+
]);
|
|
21
|
+
const sequential = createSequentialCoordinator(await h.brain());
|
|
22
|
+
const result = await sequential.run(plan);
|
|
23
|
+
const blocked = { kind: "blocked", result: "blocked: deny" };
|
|
24
|
+
expectEqual(result.outcomes, [resultOf("a"), resultOf("b"), blocked, resultOf("c")], "every call settles");
|
|
25
|
+
expectEqual(h.trace, [...steps("a"), ...steps("b"), "shim:x", "hook:x", ...steps("c")], "prepare and run interleave per call, a blocked call does not stop the next");
|
|
26
|
+
expectEqual(await sequential.run(plan), result, "a finished run returns its stored outcomes");
|
|
27
|
+
expectEqual(h.trace.length, 14, "and runs nothing again");
|
|
28
|
+
const crash = await batchHarness(adapters);
|
|
29
|
+
const crashPlan = batchPlan("seq-01-crash", [
|
|
30
|
+
["a", "e1"],
|
|
31
|
+
["b", "e2"],
|
|
32
|
+
["c", "e1"],
|
|
33
|
+
]);
|
|
34
|
+
const dying = createSequentialCoordinator(await crash.brain({ label: "release:b", at: "after" }));
|
|
35
|
+
await expectRejects(dying.run(crashPlan), BrainKilledError, "kill");
|
|
36
|
+
expectEqual(crash.trace, [...steps("a"), "shim:b", "hook:b"], "the crashed brain never prepared c");
|
|
37
|
+
const resumed = await createSequentialCoordinator(await crash.brain()).run(crashPlan);
|
|
38
|
+
expectEqual(resumed.outcomes, [resultOf("a"), resultOf("b"), resultOf("c")], "recovery reaches every outcome");
|
|
39
|
+
expectEqual(crash.trace, [...steps("a"), ...steps("b"), ...steps("c")], "each step once, in call order");
|
|
40
|
+
const stop = await batchHarness(adapters);
|
|
41
|
+
const stopPlan = batchPlan("seq-01-stop", [
|
|
42
|
+
["a", "e1"],
|
|
43
|
+
["s", "e2", "stop"],
|
|
44
|
+
["c", "e1"],
|
|
45
|
+
]);
|
|
46
|
+
const stopped = await createSequentialCoordinator(await stop.brain()).run(stopPlan);
|
|
47
|
+
expectEqual(stopped, { decision: "ABORT", outcomes: [resultOf("a"), notRun, notRun] }, "a stop ends the run");
|
|
48
|
+
expectEqual(stop.trace, [...steps("a"), "shim:s", "hook:s"], "the call after a stop is never prepared");
|
|
49
|
+
const replayed = await createSequentialCoordinator(await stop.brain()).run(stopPlan);
|
|
50
|
+
expectEqual(replayed, stopped, "recovery after a stop prepares nothing new");
|
|
51
|
+
expectEqual(stop.trace.length, 6, "and runs nothing again");
|
|
52
|
+
const restart = await batchHarness(adapters);
|
|
53
|
+
const restartPlan = batchPlan("seq-01-restart", [
|
|
54
|
+
["r", "e1"],
|
|
55
|
+
["c", "e2"],
|
|
56
|
+
]);
|
|
57
|
+
const hookR = restart.hold("r", "hook");
|
|
58
|
+
const brain = createSequentialCoordinator(await restart.brain());
|
|
59
|
+
const first = brain.run(restartPlan);
|
|
60
|
+
await hookR.reached;
|
|
61
|
+
await restart.restartExecutor("e1");
|
|
62
|
+
await expectRejects(first, ExecutorKilledError, "the executor died during r's preparation");
|
|
63
|
+
const interrupted = await brain.run(restartPlan);
|
|
64
|
+
expectEqual(interrupted.outcomes, [
|
|
65
|
+
{ kind: "interrupted", reason: "hand_restarted", uncertain: true },
|
|
66
|
+
{ kind: "not_run", cause: "interrupted_preparation" },
|
|
67
|
+
], "the call after an interrupted preparation replays with today's placeholder, as in one batch (X12)");
|
|
68
|
+
expectEqual(restart.count("shim:c"), 0, "and is never prepared");
|
|
69
|
+
};
|
|
70
|
+
export const SEQ_CASES = new Map([["SEQ-01", interleave]]);
|
|
71
|
+
//# sourceMappingURL=seq-cases.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const INTRO = "#5661";
|
|
2
|
+
export const SEQ_REGISTRY = [
|
|
3
|
+
{
|
|
4
|
+
id: "SEQ-01",
|
|
5
|
+
impl: "packages/agent/src/execution/testing/seq-cases.ts",
|
|
6
|
+
intro: INTRO,
|
|
7
|
+
adapters: ["store", "executor"],
|
|
8
|
+
expected: "sequential mode interleaves prepare and run per call across executors; a crash resumes without rerunning; a stop ends the run unprepared",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
id: "MULTI-FAIR-02",
|
|
12
|
+
impl: "packages/agent/src/execution/testing/multi-seq-cases.ts",
|
|
13
|
+
intro: INTRO,
|
|
14
|
+
adapters: ["store", "executor"],
|
|
15
|
+
expected: "a long sequential batch in session A does not starve session B on the same executor",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "CONSENT-01",
|
|
19
|
+
impl: "packages/agent/src/execution/testing/consent-cases.ts",
|
|
20
|
+
intro: "#5663",
|
|
21
|
+
adapters: ["store", "executor"],
|
|
22
|
+
expected: "cross-machine only: the lease expires while a call awaits Gate B consent: lease_expired, uncertain, the batch ABORTed, no successor",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "CONSENT-02",
|
|
26
|
+
impl: "packages/agent/src/execution/testing/consent-cases.ts",
|
|
27
|
+
intro: "#5663",
|
|
28
|
+
adapters: ["store", "executor"],
|
|
29
|
+
expected: "cross-machine only: an approval that arrives after the lease expired is rejected; the outcome stays lease_expired",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
//# sourceMappingURL=seq-registry.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import type { WakeInbox } from "../wake-inbox.ts";
|
|
3
|
+
import { type WakeEvent, type WakeReceipt } from "../wake-types.ts";
|
|
4
|
+
import type { BatchCaseAdapters } from "./batch-executor.ts";
|
|
5
|
+
type WakeCase = CaseImplementation<BatchCaseAdapters>;
|
|
6
|
+
/** Scope `s` belongs to hand `e1`; every other scope is not this brain's. */
|
|
7
|
+
export declare const scopeOwner: (scope: string) => string | undefined;
|
|
8
|
+
export declare const wakeOf: (n: number, scope?: string) => {
|
|
9
|
+
scope: string;
|
|
10
|
+
source: string;
|
|
11
|
+
payload: {
|
|
12
|
+
n: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/** The hand's link to the brain: a send is the inbox's answer, which the outbox then applies. */
|
|
16
|
+
export declare const linkTo: (inbox: WakeInbox, hand?: string) => (wake: WakeEvent) => Promise<WakeReceipt>;
|
|
17
|
+
export declare const ids: (wakes: readonly WakeEvent[]) => string[];
|
|
18
|
+
export declare const WAKE_EXEC_CASES: ReadonlyMap<string, WakeCase>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=wake-exec-cases.d.ts.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { WAKE_RETENTION_MS } from "../wake-types.js";
|
|
3
|
+
import { batchHarness } from "./batch-harness.js";
|
|
4
|
+
/** Scope `s` belongs to hand `e1`; every other scope is not this brain's. */
|
|
5
|
+
export const scopeOwner = (scope) => (scope === "s" ? "e1" : undefined);
|
|
6
|
+
export const wakeOf = (n, scope = "s") => ({ scope, source: "terminal", payload: { n } });
|
|
7
|
+
/** The hand's link to the brain: a send is the inbox's answer, which the outbox then applies. */
|
|
8
|
+
export const linkTo = (inbox, hand = "e1") => (wake) => inbox.receive(hand, wake);
|
|
9
|
+
async function wakePair(h) {
|
|
10
|
+
return { outbox: await h.wakeOutbox("e1"), inbox: await h.wakeInbox(scopeOwner) };
|
|
11
|
+
}
|
|
12
|
+
export const ids = (wakes) => wakes.map((wake) => wake.eventId);
|
|
13
|
+
/** WAKEX-01: a wake is committed on the hand, committed on the brain, acked, and taken by the loop once. */
|
|
14
|
+
const delivery = async (adapters) => {
|
|
15
|
+
const h = await batchHarness(adapters);
|
|
16
|
+
const { outbox, inbox } = await wakePair(h);
|
|
17
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
18
|
+
expectEqual(ids(await outbox.pending()), [wake.eventId], "durable on the hand before it is sent");
|
|
19
|
+
expectEqual(await outbox.reoffer(linkTo(inbox)), 1, "sent");
|
|
20
|
+
expectEqual(await outbox.pending(), [], "removed by its ack");
|
|
21
|
+
const taken = [];
|
|
22
|
+
expectEqual(await inbox.drain(async (got) => void taken.push(got)), 1, "taken");
|
|
23
|
+
expectEqual(taken, [wake], "the loop gets the wake once");
|
|
24
|
+
expectEqual(await inbox.drain(async () => { }), 0, "and never again");
|
|
25
|
+
};
|
|
26
|
+
/** WAKEX-02: a wake whose ack was lost is re-offered and deduplicated by its event id, then acked again. */
|
|
27
|
+
const dedup = async (adapters) => {
|
|
28
|
+
const h = await batchHarness(adapters);
|
|
29
|
+
const { outbox, inbox } = await wakePair(h);
|
|
30
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
31
|
+
expectEqual(await inbox.receive("e1", wake), { kind: "ack", eventId: wake.eventId, duplicate: false }, "committed");
|
|
32
|
+
expectEqual(ids(await outbox.pending()), [wake.eventId], "the ack was lost");
|
|
33
|
+
await outbox.reoffer(linkTo(inbox));
|
|
34
|
+
expectEqual(await outbox.pending(), [], "the duplicate's ack removes it");
|
|
35
|
+
expectEqual(ids((await inbox.read()).pending), [wake.eventId], "one wake on the brain");
|
|
36
|
+
};
|
|
37
|
+
/** WAKEX-03: wakes offered while the link is down are re-offered on reconnect, in offer order. */
|
|
38
|
+
const reconnect = async (adapters) => {
|
|
39
|
+
const h = await batchHarness(adapters);
|
|
40
|
+
const { outbox, inbox } = await wakePair(h);
|
|
41
|
+
const offered = [await outbox.offer(wakeOf(1)), await outbox.offer(wakeOf(2)), await outbox.offer(wakeOf(3))];
|
|
42
|
+
const restarted = await h.wakeOutbox("e1");
|
|
43
|
+
expectEqual(await restarted.reoffer(linkTo(inbox)), 3, "all re-offered after a restart");
|
|
44
|
+
expectEqual(ids((await inbox.read()).pending), ids(offered), "in offer order");
|
|
45
|
+
};
|
|
46
|
+
/** WAKEX-04: a wake from a hand not bound to the scope, or for a scope the brain does not own, commits nothing. */
|
|
47
|
+
const binding = async (adapters) => {
|
|
48
|
+
const h = await batchHarness(adapters);
|
|
49
|
+
const { outbox, inbox } = await wakePair(h);
|
|
50
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
51
|
+
expectEqual(await inbox.receive("e2", wake), { kind: "refused", eventId: wake.eventId, reason: "not_scope_hand" }, "another hand");
|
|
52
|
+
const foreign = await outbox.offer(wakeOf(2, "elsewhere"));
|
|
53
|
+
expectEqual(await inbox.receive("e1", foreign), { kind: "refused", eventId: foreign.eventId, reason: "unknown_scope" }, "a scope this brain does not own");
|
|
54
|
+
expectEqual(await inbox.read(), { seen: {}, pending: [], closed: {} }, "nothing committed");
|
|
55
|
+
await outbox.receipt({ kind: "refused", eventId: wake.eventId, reason: "not_scope_hand" });
|
|
56
|
+
await outbox.receipt({ kind: "refused", eventId: foreign.eventId, reason: "unknown_scope" });
|
|
57
|
+
expectEqual(ids(await outbox.pending()), [wake.eventId, foreign.eventId], "a refusal is never an ack");
|
|
58
|
+
const resent = [];
|
|
59
|
+
expectEqual(await outbox.reoffer(async (sent) => {
|
|
60
|
+
resent.push(sent.eventId);
|
|
61
|
+
return inbox.receive("e2", sent);
|
|
62
|
+
}), 1, "a wake refused for good is never re-offered; an unknown scope is retried");
|
|
63
|
+
expectEqual(resent, [foreign.eventId], "only the unknown-scope wake is sent again");
|
|
64
|
+
await outbox.closeScope("s");
|
|
65
|
+
await outbox.closeScope("elsewhere");
|
|
66
|
+
h.advance(WAKE_RETENTION_MS + 1);
|
|
67
|
+
expectEqual((await outbox.sweep()).length, 2, "refused wakes still expire with their scope");
|
|
68
|
+
};
|
|
69
|
+
/** WAKEX-05: an un-acked wake outlives its scope by the retention, then is dropped with a logged wake_expired. */
|
|
70
|
+
const retention = async (adapters) => {
|
|
71
|
+
const h = await batchHarness(adapters);
|
|
72
|
+
const outbox = await h.wakeOutbox("e1");
|
|
73
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
74
|
+
expectEqual(await outbox.sweep(), [], "an open scope never expires");
|
|
75
|
+
await outbox.closeScope("s");
|
|
76
|
+
h.advance(WAKE_RETENTION_MS);
|
|
77
|
+
expectEqual(await outbox.sweep(), [], "kept for the whole retention");
|
|
78
|
+
h.advance(1);
|
|
79
|
+
expectEqual(await outbox.sweep(), [wake.eventId], "dropped after it");
|
|
80
|
+
expectEqual(await outbox.pending(), [], "gone");
|
|
81
|
+
const logged = await h.wakeLog("e1");
|
|
82
|
+
expectEqual(logged, [{ reason: "wake_expired", eventId: wake.eventId, scope: "s" }], "logged as wake_expired");
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* WAKEX-06: the brain closes a scope: a re-offer of a committed wake is a duplicate within the retention, a new wake
|
|
86
|
+
* for it is refused scope_closed, and once the retention passed the seen ids are dropped but a late re-offer is still
|
|
87
|
+
* refused, never committed twice.
|
|
88
|
+
*/
|
|
89
|
+
const brainRetention = async (adapters) => {
|
|
90
|
+
const h = await batchHarness(adapters);
|
|
91
|
+
const { outbox, inbox } = await wakePair(h);
|
|
92
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
93
|
+
expectEqual(await inbox.receive("e1", wake), { kind: "ack", eventId: wake.eventId, duplicate: false }, "committed");
|
|
94
|
+
await inbox.closeScope("s");
|
|
95
|
+
expectEqual(await inbox.receive("e1", wake), { kind: "ack", eventId: wake.eventId, duplicate: true }, "a duplicate");
|
|
96
|
+
const late = await outbox.offer(wakeOf(2));
|
|
97
|
+
expectEqual(await inbox.receive("e1", late), { kind: "refused", eventId: late.eventId, reason: "scope_closed" }, "a new wake for a closed scope");
|
|
98
|
+
expectEqual(await inbox.sweep(), [], "kept for the whole retention");
|
|
99
|
+
h.advance(WAKE_RETENTION_MS + 1);
|
|
100
|
+
expectEqual(await inbox.sweep(), ["s"], "the seen ids are dropped after it");
|
|
101
|
+
expectEqual(await inbox.receive("e1", wake), { kind: "refused", eventId: wake.eventId, reason: "scope_closed" }, "a late re-offer is refused, never committed again");
|
|
102
|
+
expectEqual(ids((await inbox.read()).pending), [wake.eventId], "one wake on the brain");
|
|
103
|
+
expectEqual(await inbox.sweep(), [], "a scope is dropped once");
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* WAKEX-08: a wake that reaches the brain before its scope is bound (a brain restart, or the bind racing the hand's
|
|
107
|
+
* outbox) is refused unknown_scope but not for good: once the scope binds, the re-offer delivers it exactly once.
|
|
108
|
+
*/
|
|
109
|
+
const beforeBinding = async (adapters) => {
|
|
110
|
+
const h = await batchHarness(adapters);
|
|
111
|
+
let bound = false;
|
|
112
|
+
const outbox = await h.wakeOutbox("e1");
|
|
113
|
+
const inbox = await h.wakeInbox((scope) => (bound && scope === "s" ? "e1" : undefined));
|
|
114
|
+
const wake = await outbox.offer(wakeOf(1));
|
|
115
|
+
await outbox.reoffer(linkTo(inbox));
|
|
116
|
+
expectEqual(ids(await outbox.pending()), [wake.eventId], "still pending on the hand");
|
|
117
|
+
bound = true;
|
|
118
|
+
expectEqual(await outbox.reoffer(linkTo(inbox)), 1, "re-offered once the scope is bound");
|
|
119
|
+
expectEqual(await outbox.pending(), [], "acked");
|
|
120
|
+
expectEqual(ids((await inbox.read()).pending), [wake.eventId], "delivered once");
|
|
121
|
+
};
|
|
122
|
+
/** WAKEX-07: two drains at once hand each wake to the loop exactly once. */
|
|
123
|
+
const concurrentDrains = async (adapters) => {
|
|
124
|
+
const h = await batchHarness(adapters);
|
|
125
|
+
const { outbox, inbox } = await wakePair(h);
|
|
126
|
+
await outbox.offer(wakeOf(1));
|
|
127
|
+
await outbox.offer(wakeOf(2));
|
|
128
|
+
await outbox.reoffer(linkTo(inbox));
|
|
129
|
+
const taken = [];
|
|
130
|
+
const consume = async (wake) => {
|
|
131
|
+
taken.push(wake.eventId);
|
|
132
|
+
};
|
|
133
|
+
const [first, second] = await Promise.all([inbox.drain(consume), inbox.drain(consume)]);
|
|
134
|
+
expectEqual(first + second, 2, "two wakes taken in all");
|
|
135
|
+
expectEqual(new Set(taken).size === taken.length && taken.length === 2, true, "each wake once");
|
|
136
|
+
};
|
|
137
|
+
export const WAKE_EXEC_CASES = new Map([
|
|
138
|
+
["WAKEX-01", delivery],
|
|
139
|
+
["WAKEX-02", dedup],
|
|
140
|
+
["WAKEX-03", reconnect],
|
|
141
|
+
["WAKEX-04", binding],
|
|
142
|
+
["WAKEX-05", retention],
|
|
143
|
+
["WAKEX-06", brainRetention],
|
|
144
|
+
["WAKEX-07", concurrentDrains],
|
|
145
|
+
["WAKEX-08", beforeBinding],
|
|
146
|
+
]);
|
|
147
|
+
//# sourceMappingURL=wake-exec-cases.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const WAKE_EXEC_IMPL = "packages/agent/src/execution/testing/wake-exec-cases.ts";
|
|
2
|
+
const KILL_WAKEX_IMPL = "packages/agent/src/execution/testing/kill-wakex.ts";
|
|
3
|
+
const wakeCase = (id, impl, expected) => ({
|
|
4
|
+
id,
|
|
5
|
+
impl,
|
|
6
|
+
intro: "#5675",
|
|
7
|
+
adapters: ["store", "executor"],
|
|
8
|
+
expected,
|
|
9
|
+
});
|
|
10
|
+
export const WAKE_EXEC_REGISTRY = [
|
|
11
|
+
wakeCase("WAKEX-01", WAKE_EXEC_IMPL, "a wake is durable on the hand, committed on the brain, acked, taken once"),
|
|
12
|
+
wakeCase("WAKEX-02", WAKE_EXEC_IMPL, "a re-offered wake whose ack was lost is deduplicated by event id and acked"),
|
|
13
|
+
wakeCase("WAKEX-03", WAKE_EXEC_IMPL, "un-acked wakes are re-offered on reconnect in offer order"),
|
|
14
|
+
wakeCase("WAKEX-04", WAKE_EXEC_IMPL, "a wake refused for its scope commits nothing, is never acked and is not re-offered"),
|
|
15
|
+
wakeCase("WAKEX-05", WAKE_EXEC_IMPL, "an un-acked wake lives until scope close plus 7 days, then wake_expired"),
|
|
16
|
+
wakeCase("WAKEX-06", WAKE_EXEC_IMPL, "a closed scope dedups re-offers within retention and refuses late or new wakes"),
|
|
17
|
+
wakeCase("WAKEX-07", WAKE_EXEC_IMPL, "concurrent drains hand each wake to the loop exactly once"),
|
|
18
|
+
wakeCase("WAKEX-08", WAKE_EXEC_IMPL, "a wake refused before its scope binds is re-offered and delivered once it binds"),
|
|
19
|
+
wakeCase("KILL-WAKEX-01", KILL_WAKEX_IMPL, "a hand killed before the outbox commit leaves nothing to re-offer"),
|
|
20
|
+
wakeCase("KILL-WAKEX-02", KILL_WAKEX_IMPL, "a hand killed after the outbox commit re-offers the wake once"),
|
|
21
|
+
wakeCase("KILL-WAKEX-03", KILL_WAKEX_IMPL, "a brain killed before the inbox commit sent no ack; the re-offer delivers once"),
|
|
22
|
+
wakeCase("KILL-WAKEX-04", KILL_WAKEX_IMPL, "a brain killed after the inbox commit dedups the re-offer and acks it"),
|
|
23
|
+
wakeCase("KILL-WAKEX-05", KILL_WAKEX_IMPL, "a hand killed before recording the ack re-offers; the duplicate is acked"),
|
|
24
|
+
wakeCase("KILL-WAKEX-06", KILL_WAKEX_IMPL, "a brain killed before recording a take hands the same wake over again"),
|
|
25
|
+
];
|
|
26
|
+
//# sourceMappingURL=wake-registry.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ToolResultMessage } from "@earendil-works/pi-ai";
|
|
2
|
-
import type { AgentEvent, AgentToolCall, ToolExecutionMode } from "../types.ts";
|
|
1
|
+
import type { AssistantMessage, ToolResultMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { AgentContext, AgentEvent, AgentToolCall, ToolExecutionMode } from "../types.ts";
|
|
3
3
|
/** Brain-minted identity and execution root; the executor treats the identity as opaque. */
|
|
4
4
|
export interface ExecutionScope {
|
|
5
5
|
readonly id: string;
|
|
@@ -12,7 +12,7 @@ export interface ToolHostCall {
|
|
|
12
12
|
readonly mode: ToolExecutionMode;
|
|
13
13
|
}
|
|
14
14
|
export interface ExecutionPipelineWitness {
|
|
15
|
-
readonly pipeline: "
|
|
15
|
+
readonly pipeline: "prepared";
|
|
16
16
|
readonly toolCallId: string;
|
|
17
17
|
}
|
|
18
18
|
export interface ToolHostResult {
|
|
@@ -25,7 +25,27 @@ export interface ToolHostOptions {
|
|
|
25
25
|
readonly emit: (event: AgentEvent) => Promise<void> | void;
|
|
26
26
|
/** Receipt metadata only: never an AgentEvent, tool result, provider payload or EQ observable. */
|
|
27
27
|
readonly recordWitness?: (witness: ExecutionPipelineWitness) => Promise<void> | void;
|
|
28
|
+
/**
|
|
29
|
+
* The loop's own view of the batch, for a host that runs in the loop's process and runs today's preparation steps
|
|
30
|
+
* (the prepared pipeline): the context and the assistant message that issued the calls. A remote host never reads it.
|
|
31
|
+
*/
|
|
32
|
+
readonly local?: {
|
|
33
|
+
readonly context: AgentContext;
|
|
34
|
+
readonly assistantMessage: AssistantMessage;
|
|
35
|
+
};
|
|
28
36
|
}
|
|
37
|
+
/** The loop had a tool batch to run on its default pipeline but no `batchStoreFactory`; it refuses instead of guessing a store. */
|
|
38
|
+
export declare class BatchStoreMissingError extends Error {
|
|
39
|
+
readonly code = "batch_store_missing";
|
|
40
|
+
constructor();
|
|
41
|
+
}
|
|
42
|
+
/** The loop had a tool batch to run on its default pipeline but no `afterToolFreeze`; it refuses instead of dropping preflight facts. */
|
|
43
|
+
export declare class PreflightCarryMissingError extends Error {
|
|
44
|
+
readonly code = "preflight_carry_missing";
|
|
45
|
+
constructor();
|
|
46
|
+
}
|
|
47
|
+
/** The package entry's default `afterToolFreeze`: for hosts whose `beforeToolCall` binds nothing to the arguments object. */
|
|
48
|
+
export declare function noPreflightCarry(_prepared: unknown, _frozen: unknown): void;
|
|
29
49
|
export interface ToolHost {
|
|
30
50
|
execute(call: ToolHostCall, options: ToolHostOptions): Promise<ToolHostResult>;
|
|
31
51
|
}
|