@ftrdotdev/pi-delegates 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +57 -0
- package/README.md +448 -2
- package/ROADMAP.md +158 -0
- package/TESTING.md +1061 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +93 -4
- package/skills/pi-delegates/SKILL.md +147 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +156 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +161 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1298 -0
- package/src/domain/orchestration/control.ts +436 -0
- package/src/domain/orchestration/fanout.test.ts +419 -0
- package/src/domain/orchestration/fanout.ts +334 -0
- package/src/domain/orchestration/gates.test.ts +686 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +173 -0
- package/src/domain/orchestration/launch.ts +581 -0
- package/src/domain/orchestration/requests.test.ts +700 -0
- package/src/domain/orchestration/requests.ts +769 -0
- package/src/domain/orchestration/review.test.ts +214 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +262 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1425 -0
- package/src/domain/orchestration/workflow.ts +705 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +527 -0
- package/src/domain/shapes.test.ts +165 -0
- package/src/domain/skills.test.ts +466 -0
- package/src/domain/skills.ts +97 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +201 -0
- package/src/domain/toolkit.ts +379 -0
- package/src/domain/view.test.ts +739 -0
- package/src/domain/view.ts +459 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +481 -0
- package/src/extension/commands.ts +227 -0
- package/src/extension/entry.test.ts +1118 -0
- package/src/extension/entry.ts +342 -0
- package/src/extension/gate-alerts.test.ts +235 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1191 -0
- package/src/extension/inspector-command.ts +638 -0
- package/src/extension/prompt.test.ts +110 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/shortcut.test.ts +64 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +993 -0
- package/src/extension/tools.ts +505 -0
- package/src/extension/version.test.ts +123 -0
- package/src/extension/version.ts +97 -0
- package/src/harness-policy.test.ts +74 -0
- package/src/package-manifest.test.ts +157 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +387 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +361 -0
- package/src/presentation/inspector.test.ts +679 -0
- package/src/presentation/inspector.ts +440 -0
- package/src/presentation/overlay.test.ts +555 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +329 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +530 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/strip.test.ts +196 -0
- package/src/presentation/strip.ts +74 -0
- package/src/presentation/wording.test.ts +238 -0
- package/src/presentation/wording.ts +222 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +134 -0
- package/src/runtime/config.test.ts +44 -0
- package/src/runtime/config.ts +87 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +35 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +140 -0
- package/src/runtime/log.test.ts +128 -0
- package/src/runtime/log.ts +68 -0
- package/src/runtime/mcp.test.ts +1453 -0
- package/src/runtime/mcp.ts +938 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/session.test.ts +359 -0
- package/src/runtime/session.ts +425 -0
- package/src/runtime/timers.test.ts +31 -0
- package/src/runtime/timers.ts +10 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
2
|
+
import {
|
|
3
|
+
AgentDoc,
|
|
4
|
+
Harness,
|
|
5
|
+
MemoryStorage,
|
|
6
|
+
type HarnessInspection,
|
|
7
|
+
} from "@earendil-works/pi-durable";
|
|
8
|
+
import { assert, it } from "@effect/vitest";
|
|
9
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
10
|
+
import { capArbitrary } from "../../../test-support/arbitraries.ts";
|
|
11
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { stubHostSource } from "../../../test-support/stub-model-source.ts";
|
|
15
|
+
import { createCatalogue, presets } from "../definitions.ts";
|
|
16
|
+
import { DEFAULTS, type DelegatesConfig } from "../../runtime/config.ts";
|
|
17
|
+
import { HostModelAdapter } from "../../runtime/models.ts";
|
|
18
|
+
import { openSessionRuntime, type SessionIdentity } from "../../runtime/session.ts";
|
|
19
|
+
import { launch, type HostDefaults } from "./launch.ts";
|
|
20
|
+
import { available, liveCounts, type AdmissionHost } from "./admission.ts";
|
|
21
|
+
import { createDelegatesRegistry } from "../../runtime/extensions.ts";
|
|
22
|
+
import { emptySkills } from "../skills.ts";
|
|
23
|
+
import type { FanoutInput, FanoutState } from "./fanout.ts";
|
|
24
|
+
import { RunDoc, RunIndexDoc } from "../run-records.ts";
|
|
25
|
+
import { viewRun, viewSession } from "../view.ts";
|
|
26
|
+
|
|
27
|
+
const host: HostDefaults = {
|
|
28
|
+
model: { provider: "stub", modelId: "stub-1" },
|
|
29
|
+
thinkingLevel: "low",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const config = (overrides: Partial<Omit<DelegatesConfig, "diagnostics">>): DelegatesConfig => ({
|
|
33
|
+
...DEFAULTS,
|
|
34
|
+
...overrides,
|
|
35
|
+
diagnostics: [],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const identityFor = async (sessionId: string): Promise<SessionIdentity> => {
|
|
39
|
+
const sessionDir = await mkdtemp(join(tmpdir(), "delegates-fanout-"));
|
|
40
|
+
return { sessionId, sessionDir, cwd: sessionDir, agentDir: sessionDir };
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const deferred = (): { readonly promise: Promise<void>; readonly release: () => void } => {
|
|
44
|
+
let release: () => void = () => {};
|
|
45
|
+
const promise = new Promise<void>((resolve) => {
|
|
46
|
+
release = resolve;
|
|
47
|
+
});
|
|
48
|
+
return { promise, release };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const six = ["scout", "builder", "reviewer", "scout", "builder", "reviewer"].map(
|
|
52
|
+
(agent, index) => ({
|
|
53
|
+
agent,
|
|
54
|
+
task: `task ${index}`,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
it("a fanout of six runs at most four generations at once", async () => {
|
|
59
|
+
const source = stubHostSource({ delayMs: 15 });
|
|
60
|
+
const runtime = await openSessionRuntime({
|
|
61
|
+
identity: await identityFor("s-1"),
|
|
62
|
+
models: new HostModelAdapter(source),
|
|
63
|
+
});
|
|
64
|
+
try {
|
|
65
|
+
const result = await launch(
|
|
66
|
+
{ kind: "fanout", lane: "review", agents: six },
|
|
67
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
68
|
+
);
|
|
69
|
+
assert.strictEqual(result.view.status, "answered");
|
|
70
|
+
assert.strictEqual(result.view.children.length, 6);
|
|
71
|
+
assert.deepStrictEqual(
|
|
72
|
+
result.view.children.map((child) => child.status),
|
|
73
|
+
Array.from({ length: 6 }, () => "answered"),
|
|
74
|
+
);
|
|
75
|
+
assert.ok(source.maxConcurrent <= 4, String(source.maxConcurrent));
|
|
76
|
+
} finally {
|
|
77
|
+
await runtime.close();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("the session ceiling throttles two concurrent fanouts", async () => {
|
|
82
|
+
const source = stubHostSource({ delayMs: 15 });
|
|
83
|
+
const runtime = await openSessionRuntime({
|
|
84
|
+
identity: await identityFor("s-1"),
|
|
85
|
+
models: new HostModelAdapter(source),
|
|
86
|
+
config: config({ laneCap: 10, sessionCeiling: 8 }),
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const deps = { runtime, catalogue: createCatalogue(), host, waitMs: 30_000 };
|
|
90
|
+
await Promise.all([
|
|
91
|
+
launch({ kind: "fanout", lane: "a", agents: six }, deps),
|
|
92
|
+
launch({ kind: "fanout", lane: "b", agents: six }, deps),
|
|
93
|
+
]);
|
|
94
|
+
assert.ok(source.maxConcurrent <= 8, String(source.maxConcurrent));
|
|
95
|
+
} finally {
|
|
96
|
+
await runtime.close();
|
|
97
|
+
}
|
|
98
|
+
// Both launches share one budget of `waitMs`, so the wall must outlast that
|
|
99
|
+
// budget: a stall then fails on the launch result, not as a bare timeout.
|
|
100
|
+
}, 40_000);
|
|
101
|
+
|
|
102
|
+
it("fail-fast aborts the other children and reports the failing child", async () => {
|
|
103
|
+
const source = stubHostSource({ failAt: [2], delayAt: { 1: 0, 2: 0, 3: 2_000, 4: 2_000 } });
|
|
104
|
+
const runtime = await openSessionRuntime({
|
|
105
|
+
identity: await identityFor("s-1"),
|
|
106
|
+
models: new HostModelAdapter(source),
|
|
107
|
+
});
|
|
108
|
+
try {
|
|
109
|
+
const result = await launch(
|
|
110
|
+
{ kind: "fanout", lane: "review", agents: six, policy: "failFast" },
|
|
111
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
112
|
+
);
|
|
113
|
+
assert.strictEqual(result.view.status, "failed");
|
|
114
|
+
assert.ok(result.view.children.length < 6, String(result.view.children.length));
|
|
115
|
+
assert.ok(result.view.diagnostic?.includes("child 1"), result.view.diagnostic ?? "");
|
|
116
|
+
assert.ok(
|
|
117
|
+
result.view.children.some((child) => child.status === "stopped"),
|
|
118
|
+
JSON.stringify(result.view.children),
|
|
119
|
+
);
|
|
120
|
+
} finally {
|
|
121
|
+
await runtime.close();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("caps come from delegates.json and survive a reopen", async () => {
|
|
126
|
+
const identity = await identityFor("s-1");
|
|
127
|
+
await writeFile(
|
|
128
|
+
join(identity.agentDir, "delegates.json"),
|
|
129
|
+
JSON.stringify({ caps: { laneCap: 2, sessionCeiling: 3 } }),
|
|
130
|
+
);
|
|
131
|
+
const source = stubHostSource({ delayMs: 15 });
|
|
132
|
+
const first = await openSessionRuntime({
|
|
133
|
+
identity,
|
|
134
|
+
models: new HostModelAdapter(source),
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
assert.strictEqual(first.config.laneCap, 2);
|
|
138
|
+
await launch(
|
|
139
|
+
{ kind: "fanout", lane: "review", agents: six },
|
|
140
|
+
{ runtime: first, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
141
|
+
);
|
|
142
|
+
assert.ok(source.maxConcurrent <= 2, String(source.maxConcurrent));
|
|
143
|
+
} finally {
|
|
144
|
+
await first.close();
|
|
145
|
+
}
|
|
146
|
+
const second = await openSessionRuntime({ identity, models: new HostModelAdapter(source) });
|
|
147
|
+
try {
|
|
148
|
+
assert.strictEqual(second.config.laneCap, 2);
|
|
149
|
+
await launch(
|
|
150
|
+
{ kind: "fanout", lane: "review", agents: six },
|
|
151
|
+
{ runtime: second, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
152
|
+
);
|
|
153
|
+
assert.ok(source.maxConcurrent <= 2, String(source.maxConcurrent));
|
|
154
|
+
} finally {
|
|
155
|
+
await second.close();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("fail-fast admits no child after the failing one", async () => {
|
|
160
|
+
const source = stubHostSource({ failAt: [1] });
|
|
161
|
+
const runtime = await openSessionRuntime({
|
|
162
|
+
identity: await identityFor("s-1"),
|
|
163
|
+
models: new HostModelAdapter(source),
|
|
164
|
+
config: config({ laneCap: 1, sessionCeiling: 8 }),
|
|
165
|
+
});
|
|
166
|
+
try {
|
|
167
|
+
const result = await launch(
|
|
168
|
+
{ kind: "fanout", lane: "review", agents: six, policy: "failFast" },
|
|
169
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
170
|
+
);
|
|
171
|
+
assert.strictEqual(result.view.status, "failed");
|
|
172
|
+
assert.strictEqual(result.view.children.length, 1);
|
|
173
|
+
assert.strictEqual(result.view.children[0]?.status, "failed");
|
|
174
|
+
assert.ok(result.view.diagnostic?.includes("child 0"), result.view.diagnostic ?? "");
|
|
175
|
+
} finally {
|
|
176
|
+
await runtime.close();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("the policy defaults to allSettled", async () => {
|
|
181
|
+
const source = stubHostSource({ failAt: [2] });
|
|
182
|
+
const runtime = await openSessionRuntime({
|
|
183
|
+
identity: await identityFor("s-1"),
|
|
184
|
+
models: new HostModelAdapter(source),
|
|
185
|
+
});
|
|
186
|
+
try {
|
|
187
|
+
const result = await launch(
|
|
188
|
+
{ kind: "fanout", lane: "review", agents: six },
|
|
189
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
190
|
+
);
|
|
191
|
+
assert.strictEqual(result.view.children.length, 6);
|
|
192
|
+
assert.strictEqual(result.view.children[1]?.status, "failed");
|
|
193
|
+
assert.strictEqual(result.view.status, "failed");
|
|
194
|
+
} finally {
|
|
195
|
+
await runtime.close();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("a single launch over the ceiling parks queued and is admitted later", async () => {
|
|
200
|
+
const hold = deferred();
|
|
201
|
+
const source = stubHostSource({ hold: () => hold.promise });
|
|
202
|
+
const runtime = await openSessionRuntime({
|
|
203
|
+
identity: await identityFor("s-1"),
|
|
204
|
+
models: new HostModelAdapter(source),
|
|
205
|
+
config: config({ sessionCeiling: 1 }),
|
|
206
|
+
});
|
|
207
|
+
try {
|
|
208
|
+
const first = launch(
|
|
209
|
+
{ kind: "single", agent: "scout", task: "first" },
|
|
210
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
211
|
+
);
|
|
212
|
+
let firstRunId: string | undefined;
|
|
213
|
+
for (let i = 0; i < 100; i += 1) {
|
|
214
|
+
const index = await runtime.snapshot(RunIndexDoc);
|
|
215
|
+
firstRunId = index?.runIds[0];
|
|
216
|
+
if (firstRunId !== undefined) {
|
|
217
|
+
const viewed = await viewRun(firstRunId, runtime);
|
|
218
|
+
if (viewed.status === "running") break;
|
|
219
|
+
}
|
|
220
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
221
|
+
}
|
|
222
|
+
assert.ok(firstRunId !== undefined);
|
|
223
|
+
const second = await launch(
|
|
224
|
+
{ kind: "single", agent: "scout", task: "second" },
|
|
225
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 100 },
|
|
226
|
+
);
|
|
227
|
+
assert.strictEqual(second.view.status, "queued");
|
|
228
|
+
const queuedDoc = await runtime.snapshot(RunDoc, second.view.runId);
|
|
229
|
+
assert.notStrictEqual(queuedDoc?.taskId, null);
|
|
230
|
+
|
|
231
|
+
hold.release();
|
|
232
|
+
await first;
|
|
233
|
+
const settled = await launch(
|
|
234
|
+
{ kind: "single", agent: "scout", task: "second" },
|
|
235
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
236
|
+
);
|
|
237
|
+
assert.strictEqual(settled.view.status, "answered");
|
|
238
|
+
assert.strictEqual(settled.view.runId, second.view.runId);
|
|
239
|
+
assert.ok(source.maxConcurrent <= 1, String(source.maxConcurrent));
|
|
240
|
+
const index = await runtime.snapshot(RunIndexDoc);
|
|
241
|
+
assert.strictEqual(index?.runIds.length, 2);
|
|
242
|
+
} finally {
|
|
243
|
+
await runtime.close();
|
|
244
|
+
}
|
|
245
|
+
}, 20_000);
|
|
246
|
+
|
|
247
|
+
it.prop(
|
|
248
|
+
"admission never overshoots a cap",
|
|
249
|
+
{
|
|
250
|
+
laneCap: capArbitrary,
|
|
251
|
+
laneLive: capArbitrary,
|
|
252
|
+
sessionCeiling: capArbitrary,
|
|
253
|
+
sessionLive: capArbitrary,
|
|
254
|
+
},
|
|
255
|
+
({ laneCap, laneLive, sessionCeiling, sessionLive }) => {
|
|
256
|
+
const room = available(laneCap, laneLive, sessionCeiling, sessionLive);
|
|
257
|
+
assert.ok(room >= 0);
|
|
258
|
+
assert.ok(room <= Math.max(0, laneCap - laneLive));
|
|
259
|
+
assert.ok(room <= Math.max(0, sessionCeiling - sessionLive));
|
|
260
|
+
if (laneCap - laneLive <= 0 || sessionCeiling - sessionLive <= 0) {
|
|
261
|
+
assert.strictEqual(room, 0);
|
|
262
|
+
} else {
|
|
263
|
+
assert.strictEqual(room, Math.min(laneCap - laneLive, sessionCeiling - sessionLive));
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
it("a fanout reserves another fanout's created-but-pending children", async () => {
|
|
270
|
+
const record = (id: number, status: string) => ({
|
|
271
|
+
id,
|
|
272
|
+
kind: "delegates.run",
|
|
273
|
+
input: { lane: "review" },
|
|
274
|
+
state: { status },
|
|
275
|
+
});
|
|
276
|
+
const admission: AdmissionHost = {
|
|
277
|
+
inspect: async () =>
|
|
278
|
+
({
|
|
279
|
+
tasks: [{ record: record(1, "pending") }, { record: record(2, "pending") }],
|
|
280
|
+
}) as unknown as HarnessInspection,
|
|
281
|
+
caps: () => ({ laneCap: 2, sessionCeiling: 2 }),
|
|
282
|
+
pollMs: 60_000,
|
|
283
|
+
};
|
|
284
|
+
const { registry, tasks } = createDelegatesRegistry({
|
|
285
|
+
admission,
|
|
286
|
+
skills: emptySkills(),
|
|
287
|
+
});
|
|
288
|
+
const harness = await Harness.open(
|
|
289
|
+
new MemoryStorage(),
|
|
290
|
+
{ models: new HostModelAdapter(stubHostSource()), registry },
|
|
291
|
+
BACKGROUND_CONTEXT,
|
|
292
|
+
);
|
|
293
|
+
try {
|
|
294
|
+
const root = await harness.root(BACKGROUND_CONTEXT, {
|
|
295
|
+
agent: { extensions: [], tools: [] },
|
|
296
|
+
});
|
|
297
|
+
harness.resume();
|
|
298
|
+
const input: FanoutInput = {
|
|
299
|
+
runId: "run:probe#1",
|
|
300
|
+
lane: "review",
|
|
301
|
+
children: [
|
|
302
|
+
{ agent: "scout", task: "first", definition: presets[0]! },
|
|
303
|
+
{ agent: "scout", task: "second", definition: presets[0]! },
|
|
304
|
+
],
|
|
305
|
+
host,
|
|
306
|
+
maxTurns: 10,
|
|
307
|
+
policy: "allSettled",
|
|
308
|
+
review: false,
|
|
309
|
+
};
|
|
310
|
+
const taskId = await harness.commit(
|
|
311
|
+
async (tx) =>
|
|
312
|
+
tx.createTask(tasks.fanout, input, {
|
|
313
|
+
ownership: { kind: "conversation" },
|
|
314
|
+
conversationId: root.id,
|
|
315
|
+
}),
|
|
316
|
+
BACKGROUND_CONTEXT,
|
|
317
|
+
);
|
|
318
|
+
let task = await harness.getTask(taskId, BACKGROUND_CONTEXT);
|
|
319
|
+
for (let i = 0; i < 200; i += 1) {
|
|
320
|
+
if (task?.state.status !== "pending" && task?.state.status !== "running") break;
|
|
321
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
322
|
+
task = await harness.getTask(taskId, BACKGROUND_CONTEXT);
|
|
323
|
+
}
|
|
324
|
+
assert.ok(task !== undefined);
|
|
325
|
+
assert.strictEqual(task.state.status, "sleeping");
|
|
326
|
+
const checkpoint = task.state.checkpoint as unknown as FanoutState;
|
|
327
|
+
assert.strictEqual(checkpoint.admitted, 0);
|
|
328
|
+
} finally {
|
|
329
|
+
await harness.close(BACKGROUND_CONTEXT);
|
|
330
|
+
}
|
|
331
|
+
}, 20_000);
|
|
332
|
+
|
|
333
|
+
it("live counts merge direct owned tasks without double counting", () => {
|
|
334
|
+
const record = (id: number, lane: string, status: string) => ({
|
|
335
|
+
id,
|
|
336
|
+
kind: "delegates.run",
|
|
337
|
+
input: { lane },
|
|
338
|
+
state: { status, ...(status === "sleeping" ? { signals: [{}] } : {}) },
|
|
339
|
+
});
|
|
340
|
+
const inspection = {
|
|
341
|
+
tasks: [{ record: record(1, "review", "running") }],
|
|
342
|
+
} as unknown as Parameters<typeof liveCounts>[0];
|
|
343
|
+
assert.deepStrictEqual(
|
|
344
|
+
liveCounts(inspection, "review", {
|
|
345
|
+
ownedTasks: [
|
|
346
|
+
record(1, "review", "running"),
|
|
347
|
+
record(2, "review", "sleeping"),
|
|
348
|
+
] as unknown as NonNullable<NonNullable<Parameters<typeof liveCounts>[2]>["ownedTasks"]>,
|
|
349
|
+
}),
|
|
350
|
+
{ laneLive: 2, sessionLive: 2 },
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("admission arithmetic never exceeds either difference", () => {
|
|
355
|
+
const values = [0, 1, 2, 3, 5, 8];
|
|
356
|
+
for (const laneCap of values) {
|
|
357
|
+
for (const laneLive of values) {
|
|
358
|
+
for (const sessionCeiling of values) {
|
|
359
|
+
for (const sessionLive of values) {
|
|
360
|
+
const room = available(laneCap, laneLive, sessionCeiling, sessionLive);
|
|
361
|
+
assert.ok(room >= 0);
|
|
362
|
+
assert.ok(room <= Math.max(0, laneCap - laneLive));
|
|
363
|
+
assert.ok(room <= Math.max(0, sessionCeiling - sessionLive));
|
|
364
|
+
if (laneCap - laneLive <= 0 || sessionCeiling - sessionLive <= 0) {
|
|
365
|
+
assert.strictEqual(room, 0);
|
|
366
|
+
} else {
|
|
367
|
+
assert.strictEqual(room, Math.min(laneCap - laneLive, sessionCeiling - sessionLive));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("status reports one row per child and lane counts", async () => {
|
|
376
|
+
const runtime = await openSessionRuntime({
|
|
377
|
+
identity: await identityFor("s-1"),
|
|
378
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
379
|
+
});
|
|
380
|
+
try {
|
|
381
|
+
const result = await launch(
|
|
382
|
+
{ kind: "fanout", lane: "review", agents: six },
|
|
383
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 20_000 },
|
|
384
|
+
);
|
|
385
|
+
const run = await viewRun(result.view.runId, runtime);
|
|
386
|
+
assert.deepStrictEqual(
|
|
387
|
+
run.children.map((child) => child.status),
|
|
388
|
+
Array.from({ length: 6 }, () => "answered"),
|
|
389
|
+
);
|
|
390
|
+
const session = await viewSession(runtime);
|
|
391
|
+
assert.deepStrictEqual(session.lanes, [{ name: "review", running: 0, queued: 0, answered: 6 }]);
|
|
392
|
+
assert.strictEqual(result.text, `Run ${result.view.runId}: 6 children answered`);
|
|
393
|
+
} finally {
|
|
394
|
+
await runtime.close();
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it("a run with a missing toolkit name reports the diagnostic", async () => {
|
|
399
|
+
const runtime = await openSessionRuntime({
|
|
400
|
+
identity: await identityFor("s-1"),
|
|
401
|
+
models: new HostModelAdapter(stubHostSource()),
|
|
402
|
+
});
|
|
403
|
+
try {
|
|
404
|
+
const result = await launch(
|
|
405
|
+
{ kind: "single", agent: "scout", task: "look" },
|
|
406
|
+
{ runtime, catalogue: createCatalogue(), host, waitMs: 10_000 },
|
|
407
|
+
);
|
|
408
|
+
const doc = await runtime.snapshot(RunDoc, result.view.runId);
|
|
409
|
+
const childId = doc!.childConversationId as never;
|
|
410
|
+
await runtime.harness.commit(async (tx) => {
|
|
411
|
+
const agent = await tx.doc(AgentDoc, childId);
|
|
412
|
+
agent.extensions = ["gone-extension"];
|
|
413
|
+
}, BACKGROUND_CONTEXT);
|
|
414
|
+
const view = await viewRun(result.view.runId, runtime);
|
|
415
|
+
assert.deepStrictEqual(view.missing, ["gone-extension"]);
|
|
416
|
+
} finally {
|
|
417
|
+
await runtime.close();
|
|
418
|
+
}
|
|
419
|
+
});
|