Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TransferBudgetV2Fixture.integration.ts

828 lines26.2 KB

1import {
2 CheckpointId,
3 CheckpointRef,
4 CheckpointScopeId,
5 EventId,
6 MessageId,
7 NodeId,
8 PlanId,
9 ProjectId,
10 ProviderInstanceId,
11 ProviderThreadId,
12 ProviderTurnId,
13 RunId,
14 ThreadId,
15 TurnItemId,
16 type ProviderDriverKind,
17 type OrchestrationV2DomainEvent,
18 type OrchestrationV2TurnItem,
19} from "@t3tools/contracts";
20import * as DateTime from "effect/DateTime";
21import {
22 diagnosticOutput,
23 TRANSFER_HISTORY_TOOLS_PER_TURN,
24 TRANSFER_MEASURED_TOOLS,
25 TRANSFER_HISTORY_MCP_RESULT_BYTES,
26 TRANSFER_MEASURED_MCP_RESULT_BYTES,
27} from "./fixtures/transferBudget.ts";
28​
29export const THREAD_ID = ThreadId.make("transfer-budget-thread");
30type ThreadCreatedEvent = Extract<OrchestrationV2DomainEvent, { readonly type: "thread.created" }>;
31export function threadCreated(
32 provider: ProviderDriverKind,
33 threadId: ThreadId = THREAD_ID,
34 overrides: Partial<ThreadCreatedEvent["payload"]> = {},
35): ThreadCreatedEvent {
36 const now = DateTime.makeUnsafe("2026-06-01T00:00:00Z");
37 return {
38 id: EventId.make(`thread-created:${threadId}`),
39 type: "thread.created",
40 threadId,
41 occurredAt: now,
42 payload: {
43 id: threadId,
44 projectId: ProjectId.make("transfer-project"),
45 title: "Transfer budget",
46 providerInstanceId: ProviderInstanceId.make(provider),
47 modelSelection: {
48 instanceId: ProviderInstanceId.make(provider),
49 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
50 },
51 runtimeMode: "full-access",
52 interactionMode: "default",
53 branch: null,
54 worktreePath: null,
55 activeProviderThreadId: null,
56 lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
57 forkedFrom: null,
58 createdBy: "user",
59 creationSource: "web",
60 createdAt: now,
61 updatedAt: now,
62 archivedAt: null,
63 settledOverride: null,
64 settledAt: null,
65 lastVisitedAt: null,
66 deletedAt: null,
67 ...overrides,
68 },
69 };
71export function turnEvents(
72 provider: ProviderDriverKind,
73 index: number,
74 measured: boolean,
75): ReadonlyArray<OrchestrationV2DomainEvent> {
76 const now = DateTime.makeUnsafe(`2026-06-01T00:${String(index + 1).padStart(2, "0")}:00Z`);
77 const runId = RunId.make(`run-${index}`);
78 const nodeId = NodeId.make(`node-${index}`);
79 const userMessageId = MessageId.make(`user-${index}`);
80 const providerInstanceId = ProviderInstanceId.make(provider);
81 const run = {
82 id: runId,
83 threadId: THREAD_ID,
84 ordinal: index + 1,
85 providerInstanceId,
86 modelSelection: {
87 instanceId: ProviderInstanceId.make(provider),
88 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
89 },
90 providerThreadId: null,
91 userMessageId,
92 rootNodeId: nodeId,
93 activeAttemptId: null,
94 status: "running" as const,
95 requestedAt: now,
96 startedAt: now,
97 completedAt: null,
98 checkpointId: null,
99 contextHandoffId: null,
100 };
101 const common = {
102 threadId: THREAD_ID,
103 runId,
104 nodeId,
105 driver: provider,
106 providerInstanceId,
107 occurredAt: now,
108 };
109 const events: OrchestrationV2DomainEvent[] = [
110 { ...common, id: EventId.make(`run-${index}`), type: "run.created", payload: run },
111 ];
112 const answer =
113 `Completed ${provider} inspection ${index}. ` +
114 "The projection preserves transcript text and bounds tool output. ".repeat(60);
115 for (const role of ["user", "assistant"] as const) {
116 events.push({
117 ...common,
118 id: EventId.make(`${role}-${index}`),
119 type: "message.updated",
120 payload: {
121 id: MessageId.make(`${role}-${index}`),
122 threadId: THREAD_ID,
123 runId,
124 nodeId,
125 role,
126 text: role === "user" ? `Inspect transfer ${index}` : answer,
127 attachments: [],
128 streaming: false,
129 createdAt: now,
130 updatedAt: now,
131 createdBy: role === "user" ? "user" : "agent",
132 creationSource: "web",
133 },
134 });
135 }
136 const toolCount = measured ? TRANSFER_MEASURED_TOOLS : TRANSFER_HISTORY_TOOLS_PER_TURN;
137 const item = (id: string, ordinal: number, title: string | null) => ({
138 id: TurnItemId.make(id),
139 threadId: THREAD_ID,
140 runId,
141 nodeId,
142 providerThreadId: null,
143 providerTurnId: null,
144 nativeItemRef: null,
145 parentItemId: null,
146 ordinal,
147 status: "completed" as const,
148 title,
149 startedAt: now,
150 completedAt: now,
151 updatedAt: now,
152 });
153 for (let tool = 0; tool <= toolCount; tool++) {
154 const mcp = tool === toolCount;
155 const output = diagnosticOutput({
156 provider,
157 turnIndex: index,
158 toolIndex: tool,
159 targetBytes: mcp
160 ? measured
161 ? TRANSFER_MEASURED_MCP_RESULT_BYTES
162 : TRANSFER_HISTORY_MCP_RESULT_BYTES
163 : 4096,
164 });
165 const base = item(
166 `item-${index}-${tool}`,
167 tool + 1,
168 mcp ? "MCP search" : `Inspect source ${tool}`,
169 );
170 events.push({
171 ...common,
172 id: EventId.make(`tool-${index}-${tool}`),
173 type: "turn-item.updated",
174 payload: mcp
175 ? {
176 ...base,
177 type: "dynamic_tool",
178 toolName: "mcp__test__search",
179 input: { query: "transfer" },
180 output: { text: output },
181 }
182 : {
183 ...base,
184 type: "command_execution",
185 input: `cat src/module-${tool}.ts`,
186 output,
187 exitCode: 0,
188 },
189 });
190 }
191 // The live turn repeats its answer in a turn item, as adapters do, so live dedupe has work.
192 // History turns skip it to keep the fallback thread snapshot under its wire ceiling.
193 if (measured)
194 events.push({
195 ...common,
196 id: EventId.make(`answer-item-${index}`),
197 type: "turn-item.updated",
198 payload: {
199 ...item(`item-${index}-answer`, toolCount + 2, null),
200 type: "assistant_message",
201 messageId: MessageId.make(`assistant-${index}`),
202 text: answer,
203 streaming: false,
204 },
205 });
206 events.push({
207 ...common,
208 id: EventId.make(`complete-${index}`),
209 type: "run.updated",
210 payload: { ...run, status: "completed", completedAt: now },
211 });
212 return events;
214​
215export const LONG_TURN_THREAD_ID = ThreadId.make("transfer-budget-long-turn");
216export const LONG_TURN_WORK_ROWS = 900;
217​
218/**
219 * Three short user turns, then one agent turn far longer than a cold-open
220 * window, with the item kinds a long agent run produces. One batch per turn.
221 * Run, node, provider and item IDs follow the composite shapes the Claude
222 * adapter stores, and every assistant message has its record, as real threads do.
223 */
224export function longTurnThreadBatches(
225 provider: ProviderDriverKind,
226): ReadonlyArray<ReadonlyArray<OrchestrationV2DomainEvent>> {
227 const threadId = LONG_TURN_THREAD_ID;
228 const providerInstanceId = ProviderInstanceId.make(provider);
229 const modelSelection = {
230 instanceId: providerInstanceId,
231 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
232 };
233 let ordinal = 0;
234 const text = (turn: number, row: number, targetBytes: number) =>
235 diagnosticOutput({ provider, turnIndex: 100 + turn, toolIndex: row, targetBytes });
236​
237 const turn = (index: number, workRows: number): OrchestrationV2DomainEvent[] => {
238 const now = DateTime.makeUnsafe(`2026-06-02T00:${String(index).padStart(2, "0")}:00Z`);
239 const runId = RunId.make(`run:thread:${threadId}:ordinal:${index + 1}`);
240 const nodeId = NodeId.make(`node:run:${encodeURIComponent(runId)}:root`);
241 const providerThreadId = ProviderThreadId.make(
242 `provider-thread:provider:${provider}:native-thread:${encodeURIComponent(`pending:${runId}`)}`,
243 );
244 const providerTurnId = ProviderTurnId.make(
245 `provider-turn:provider:${provider}:native-turn:${encodeURIComponent(`turn:run-attempt:${encodeURIComponent(runId)}:attempt:1`)}`,
246 );
247 const common = {
248 threadId,
249 runId,
250 nodeId,
251 driver: provider,
252 providerInstanceId,
253 occurredAt: now,
254 };
255 const messageId = (role: "user" | "assistant", row: string) =>
256 MessageId.make(
257 `message:provider:${provider}:native-item:msg_01LongTurn${role}${index}x${row}`,
258 );
259 const run = {
260 id: runId,
261 threadId,
262 ordinal: index + 1,
263 providerInstanceId,
264 modelSelection,
265 providerThreadId: null,
266 userMessageId: messageId("user", "prompt"),
267 rootNodeId: nodeId,
268 activeAttemptId: null,
269 status: "running" as const,
270 requestedAt: now,
271 startedAt: now,
272 completedAt: null,
273 checkpointId: null,
274 contextHandoffId: null,
275 };
276 const base = (row: string, title: string | null) => {
277 ordinal += 1;
278 const nativeId = `toolu_01LongTurn${index}x${row}`;
279 return {
280 id: TurnItemId.make(`turn-item:provider:${provider}:native-item:${nativeId}`),
281 threadId,
282 runId,
283 nodeId,
284 providerThreadId,
285 providerTurnId,
286 nativeItemRef: { driver: provider, nativeId, strength: "strong" as const },
287 parentItemId: null,
288 ordinal,
289 status: "completed" as const,
290 title,
291 startedAt: now,
292 completedAt: now,
293 updatedAt: now,
294 };
295 };
296 const events: OrchestrationV2DomainEvent[] = [
297 { ...common, id: EventId.make(`long-turn-run-${index}`), type: "run.created", payload: run },
298 ];
299 const message = (role: "user" | "assistant", row: string, messageText: string) => {
300 const id = messageId(role, row);
301 const createdBy = role === "user" ? ("user" as const) : ("agent" as const);
302 events.push(
303 {
304 ...common,
305 id: EventId.make(`long-turn-message-${index}-${row}`),
306 type: "message.updated",
307 payload: {
308 id,
309 threadId,
310 runId,
311 nodeId,
312 role,
313 text: messageText,
314 attachments: [],
315 streaming: false,
316 createdAt: now,
317 updatedAt: now,
318 createdBy,
319 creationSource: "web",
320 },
321 },
322 {
323 ...common,
324 id: EventId.make(`long-turn-item-event-${index}-${row}`),
325 type: "turn-item.updated",
326 payload:
327 role === "user"
328 ? {
329 ...base(row, null),
330 type: "user_message",
331 createdBy,
332 creationSource: "web",
333 messageId: id,
334 inputIntent: "turn_start",
335 text: messageText,
336 attachments: [],
337 }
338 : {
339 ...base(row, null),
340 type: "assistant_message",
341 messageId: id,
342 text: messageText,
343 streaming: false,
344 },
345 },
346 );
347 };
348 const workItem = (row: number): OrchestrationV2TurnItem => {
349 if (row % 100 === 50) {
350 return {
351 ...base(String(row), "Checkpoint"),
352 type: "checkpoint",
353 checkpointId: CheckpointId.make(`long-turn-checkpoint-${index}-${row}`),
354 scopeId: CheckpointScopeId.make(`long-turn-scope-${index}`),
355 files: Array.from({ length: 40 }, (_, file) => ({
356 path: `src/feature/module-${row}-${file}.ts`,
357 kind: "modified",
358 additions: file + 1,
359 deletions: file,
360 })),
361 };
362 }
363 if (row % 100 === 99) {
364 return {
365 ...base(String(row), "Subagent"),
366 type: "subagent",
367 subagentId: NodeId.make(`long-turn-subagent-${index}-${row}`),
368 origin: "app_owned",
369 driver: provider,
370 providerInstanceId,
371 childThreadId: null,
372 prompt: text(index, row, 2_048),
373 result: text(index, row + 1, 3_072),
374 };
375 }
376 switch (row % 8) {
377 case 0:
378 case 7:
379 return {
380 ...base(String(row), "Reasoning"),
381 type: "reasoning",
382 text: text(index, row, 1_536),
383 streaming: false,
384 };
385 case 3:
386 return {
387 ...base(String(row), `Edit module ${row}`),
388 type: "file_change",
389 fileName: `src/feature/module-${row}.ts`,
390 additions: 12,
391 deletions: 4,
392 diffStr: text(index, row, 2_048),
393 };
394 case 4:
395 return {
396 ...base(String(row), "MCP search"),
397 type: "dynamic_tool",
398 toolName: "mcp__test__search",
399 input: { query: `module ${row}` },
400 output: { text: text(index, row, 6_144) },
401 };
402 default:
403 return {
404 ...base(String(row), `Run check ${row}`),
405 type: "command_execution",
406 input: `vp test run src/feature/module-${row}.test.ts`,
407 output: text(index, row, 4_096),
408 exitCode: 0,
409 };
410 }
411 };
412​
413 message("user", "prompt", `Continue the feature work, step ${index}.`);
414 for (let row = 0; row < workRows; row++) {
415 if (row % 8 === 5) {
416 message("assistant", String(row), text(index, row, 1_500));
417 continue;
418 }
419 events.push({
420 ...common,
421 id: EventId.make(`long-turn-work-${index}-${row}`),
422 type: "turn-item.updated",
423 payload: workItem(row),
424 });
425 }
426 message("assistant", "answer", text(index, workRows, 1_200));
427 events.push({
428 ...common,
429 id: EventId.make(`long-turn-complete-${index}`),
430 type: "run.updated",
431 payload: { ...run, status: "completed", completedAt: now },
432 });
433 return events;
434 };
435​
436 return [
437 [threadCreated(provider, threadId)],
438 turn(0, 4),
439 turn(1, 4),
440 turn(2, 4),
441 turn(3, LONG_TURN_WORK_ROWS),
442 ];
444​
445export const STALE_TODO_THREAD_ID = ThreadId.make("transfer-budget-stale-todo-lists");
446export const STALE_TODO_SETTLED_RUNS = 40;
447export const STALE_TODO_SUBAGENTS_PER_RUN = 2;
448export const STALE_TODO_LIVE_ROWS = 600;
449const staleTodoCheckpointId = (index: number) =>
450 CheckpointId.make(`checkpoint:thread:${STALE_TODO_THREAD_ID}:ordinal:${index + 1}`);
451/** The checkpoint clients read the last finished turn's diff from. */
452export const STALE_TODO_LAST_FINISHED_CHECKPOINT_ID = staleTodoCheckpointId(
453 STALE_TODO_SETTLED_RUNS - 1,
454);
455const staleTodoRunId = (index: number) =>
456 RunId.make(`run:thread:${STALE_TODO_THREAD_ID}:ordinal:${index + 1}`);
457export const STALE_TODO_LIVE_RUN_ID = staleTodoRunId(STALE_TODO_SETTLED_RUNS);
458​
459/**
460 * A long thread: many finished runs, then one run still at work with more rows than a window
461 * holds. Every run leaves its todo list node `running` and its plan `active`, as adapters do,
462 * and has subagents, a provider turn and (once finished) a checkpoint. One batch per run.
463 */
464export function staleTodoListThreadBatches(
465 provider: ProviderDriverKind,
466): ReadonlyArray<ReadonlyArray<OrchestrationV2DomainEvent>> {
467 const threadId = STALE_TODO_THREAD_ID;
468 const providerInstanceId = ProviderInstanceId.make(provider);
469 const modelSelection = {
470 instanceId: providerInstanceId,
471 model: provider === "codex" ? "gpt-5.4" : "claude-sonnet-4-6",
472 };
473 const providerThreadId = ProviderThreadId.make(
474 `provider-thread:provider:${provider}:native-thread:stale-todo-lists`,
475 );
476 const scopeId = CheckpointScopeId.make(`checkpoint-scope:thread:${threadId}:root`);
477 let ordinal = 0;
478 const text = (run: number, row: number, targetBytes: number) =>
479 diagnosticOutput({ provider, turnIndex: 200 + run, toolIndex: row, targetBytes });
480​
481 const turn = (index: number, live: boolean): OrchestrationV2DomainEvent[] => {
482 const now = DateTime.makeUnsafe(Date.UTC(2026, 5, 4, 0, index));
483 const runId = staleTodoRunId(index);
484 const runKey = encodeURIComponent(runId);
485 const rootNodeId = NodeId.make(`node:run:${runKey}:root`);
486 const todoNodeId = NodeId.make(`node:run:${runKey}:todo-list`);
487 const planId = PlanId.make(`plan:run:${runKey}:todo-list`);
488 const providerTurnId = ProviderTurnId.make(
489 `provider-turn:provider:${provider}:native-turn:${encodeURIComponent(`turn:run-attempt:${runKey}:attempt:1`)}`,
490 );
491 const status = live ? ("running" as const) : ("completed" as const);
492 const completedAt = live ? null : now;
493 const common = {
494 threadId,
495 runId,
496 nodeId: rootNodeId,
497 driver: provider,
498 providerInstanceId,
499 occurredAt: now,
500 };
501 const messageId = (role: "user" | "assistant") =>
502 MessageId.make(`message:provider:${provider}:native-item:msg_01StaleTodo${role}${index}`);
503 const run = {
504 id: runId,
505 threadId,
506 ordinal: index + 1,
507 providerInstanceId,
508 modelSelection,
509 providerThreadId: null,
510 userMessageId: messageId("user"),
511 rootNodeId,
512 activeAttemptId: null,
513 status: "running" as const,
514 requestedAt: now,
515 startedAt: now,
516 completedAt: null,
517 checkpointId: null,
518 contextHandoffId: null,
519 };
520 const base = (row: string, title: string | null, nodeId: NodeId = rootNodeId) => {
521 ordinal += 1;
522 const nativeId = `toolu_01StaleTodo${index}x${row}`;
523 return {
524 id: TurnItemId.make(`turn-item:provider:${provider}:native-item:${nativeId}`),
525 threadId,
526 runId,
527 nodeId,
528 providerThreadId,
529 providerTurnId,
530 nativeItemRef: { driver: provider, nativeId, strength: "strong" as const },
531 parentItemId: null,
532 ordinal,
533 status: "completed" as const,
534 title,
535 startedAt: now,
536 completedAt: now,
537 updatedAt: now,
538 };
539 };
540 const events: OrchestrationV2DomainEvent[] = [
541 { ...common, id: EventId.make(`stale-todo-run-${index}`), type: "run.created", payload: run },
542 ];
543 const node = (
544 id: NodeId,
545 kind: "root_turn" | "todo_list" | "subagent",
546 nodeStatus: "running" | "completed",
547 ) =>
548 events.push({
549 ...common,
550 id: EventId.make(`stale-todo-node-${id}`),
551 type: "node.updated",
552 nodeId: id,
553 payload: {
554 id,
555 threadId,
556 runId,
557 parentNodeId: kind === "root_turn" ? null : rootNodeId,
558 rootNodeId,
559 kind,
560 status: nodeStatus,
561 countsForRun: kind === "root_turn",
562 providerThreadId,
563 providerTurnId,
564 nativeItemRef: null,
565 runtimeRequestId: null,
566 checkpointScopeId: kind === "root_turn" ? scopeId : null,
567 startedAt: now,
568 completedAt: nodeStatus === "running" ? null : now,
569 },
570 });
571 const message = (role: "user" | "assistant", messageText: string) => {
572 const id = messageId(role);
573 const createdBy = role === "user" ? ("user" as const) : ("agent" as const);
574 events.push(
575 {
576 ...common,
577 id: EventId.make(`stale-todo-message-${index}-${role}`),
578 type: "message.updated",
579 payload: {
580 id,
581 threadId,
582 runId,
583 nodeId: rootNodeId,
584 role,
585 text: messageText,
586 attachments: [],
587 streaming: false,
588 createdAt: now,
589 updatedAt: now,
590 createdBy,
591 creationSource: "web",
592 },
593 },
594 {
595 ...common,
596 id: EventId.make(`stale-todo-message-item-${index}-${role}`),
597 type: "turn-item.updated",
598 payload:
599 role === "user"
600 ? {
601 ...base(role, null),
602 type: "user_message",
603 createdBy,
604 creationSource: "web",
605 messageId: id,
606 inputIntent: "turn_start",
607 text: messageText,
608 attachments: [],
609 }
610 : {
611 ...base(role, null),
612 type: "assistant_message",
613 messageId: id,
614 text: messageText,
615 streaming: false,
616 },
617 },
618 );
619 };
620​
621 if (index === 0)
622 events.push({
623 ...common,
624 id: EventId.make("stale-todo-scope"),
625 type: "checkpoint-scope.created",
626 payload: {
627 id: scopeId,
628 threadId,
629 runId,
630 nodeId: rootNodeId,
631 parentScopeId: null,
632 providerThreadId,
633 kind: "root_run",
634 ordinalWithinParent: 0,
635 advancesAppRunCount: true,
636 cwd: "/workspace/transfer-budget",
637 createdAt: now,
638 },
639 });
640 node(rootNodeId, "root_turn", status);
641 events.push({
642 ...common,
643 id: EventId.make(`stale-todo-provider-turn-${index}`),
644 type: "provider-turn.updated",
645 payload: {
646 id: providerTurnId,
647 providerThreadId,
648 nodeId: rootNodeId,
649 runAttemptId: null,
650 nativeTurnRef: null,
651 ordinal: index + 1,
652 status,
653 startedAt: now,
654 completedAt,
655 },
656 });
657 message("user", `Continue the migration, step ${index}.`);
658​
659 // The list is done but never closed: the node stays running and the plan stays active.
660 const steps = Array.from({ length: 6 }, (_, step) => ({
661 id: `step-${step + 1}`,
662 text: `Migrate module group ${index}.${step + 1} and run its checks`,
663 status: live && step > 2 ? ("pending" as const) : ("completed" as const),
664 }));
665 node(todoNodeId, "todo_list", "running");
666 events.push(
667 {
668 ...common,
669 id: EventId.make(`stale-todo-plan-${index}`),
670 type: "plan.updated",
671 nodeId: todoNodeId,
672 payload: {
673 id: planId,
674 threadId,
675 runId,
676 nodeId: todoNodeId,
677 status: "active",
678 kind: "todo_list",
679 steps,
680 },
681 },
682 {
683 ...common,
684 id: EventId.make(`stale-todo-plan-item-${index}`),
685 type: "turn-item.updated",
686 nodeId: todoNodeId,
687 payload: { ...base("todo", "Todo list", todoNodeId), type: "todo_list", planId, steps },
688 },
689 );
690​
691 for (let subagent = 0; subagent < STALE_TODO_SUBAGENTS_PER_RUN; subagent++) {
692 const subagentId = NodeId.make(`node:run:${runKey}:subagent:${subagent + 1}`);
693 node(subagentId, "subagent", "completed");
694 events.push({
695 ...common,
696 id: EventId.make(`stale-todo-subagent-${index}-${subagent}`),
697 type: "subagent.updated",
698 nodeId: subagentId,
699 payload: {
700 id: subagentId,
701 threadId,
702 runId,
703 parentNodeId: rootNodeId,
704 origin: "app_owned",
705 createdBy: "agent",
706 driver: provider,
707 providerInstanceId,
708 providerThreadId: null,
709 childThreadId: null,
710 nativeTaskRef: null,
711 prompt: text(index, subagent * 2, 2_048),
712 title: `Review module group ${index}.${subagent + 1}`,
713 model: modelSelection.model,
714 status: "completed",
715 result: text(index, subagent * 2 + 1, 4_096),
716 startedAt: now,
717 completedAt: now,
718 updatedAt: now,
719 },
720 });
721 }
722​
723 const workRows = live ? STALE_TODO_LIVE_ROWS : 6;
724 for (let row = 0; row < workRows; row++)
725 events.push({
726 ...common,
727 id: EventId.make(`stale-todo-work-${index}-${row}`),
728 type: "turn-item.updated",
729 payload:
730 row % 10 === 0
731 ? {
732 ...base(String(row), "Reasoning"),
733 type: "reasoning",
734 text: text(index, 10 + row, 1_024),
735 streaming: false,
736 }
737 : {
738 ...base(String(row), `Run check ${row}`),
739 type: "command_execution",
740 input: `vp test run src/migration/module-${index}-${row}.test.ts`,
741 output: text(index, 10 + row, 2_048),
742 exitCode: 0,
743 },
744 });
745 if (live) return events;
746​
747 message("assistant", text(index, 5, 1_200));
748 const checkpointId = staleTodoCheckpointId(index);
749 events.push(
750 {
751 ...common,
752 id: EventId.make(`stale-todo-checkpoint-${index}`),
753 type: "checkpoint.captured",
754 payload: {
755 id: checkpointId,
756 threadId,
757 scopeId,
758 runId,
759 nodeId: rootNodeId,
760 parentCheckpointId: index === 0 ? null : staleTodoCheckpointId(index - 1),
761 ordinalWithinScope: index + 1,
762 appRunOrdinal: index + 1,
763 ref: CheckpointRef.make(
764 `refs/t3/orchestration-v2/checkpoints/stale-todo-lists/ordinal/${index + 1}`,
765 ),
766 status: "ready",
767 files: Array.from({ length: 12 }, (_, file) => ({
768 path: `src/migration/module-${index}-${file}.ts`,
769 kind: "modified",
770 additions: file + 1,
771 deletions: file,
772 })),
773 capturedAt: now,
774 },
775 },
776 {
777 ...common,
778 id: EventId.make(`stale-todo-complete-${index}`),
779 type: "run.updated",
780 payload: { ...run, status: "completed", completedAt: now, checkpointId },
781 },
782 );
783 return events;
784 };
785​
786 return [
787 [threadCreated(provider, threadId)],
788 ...Array.from({ length: STALE_TODO_SETTLED_RUNS }, (_, index) => turn(index, false)),
789 turn(STALE_TODO_SETTLED_RUNS, true),
790 ];
792​
793export const SHELL_SETTLED_THREADS = 100;
794export const SHELL_IDLE_SUBAGENTS = 40;
795​
796/**
797 * A busy sidebar: settled top-level threads, settled a minute apart, with idle subagent children
798 * under the newest ones. Opted-in cold connects skip the children and all but 25 settled threads.
799 */
800export function shellFleetEvents(
801 provider: ProviderDriverKind,
802): ReadonlyArray<OrchestrationV2DomainEvent> {
803 return Array.from({ length: SHELL_SETTLED_THREADS }, (_, index) => {
804 const threadId = ThreadId.make(`transfer-budget-settled-${index}`);
805 const settledAt = DateTime.makeUnsafe(Date.UTC(2026, 5, 3, 0, index));
806 const settled = threadCreated(provider, threadId, {
807 title: `Settled transfer thread ${index}`,
808 branch: `feature/settled-${index}`,
809 settledOverride: "settled",
810 settledAt,
811 updatedAt: settledAt,
812 });
813 if (index < SHELL_SETTLED_THREADS - SHELL_IDLE_SUBAGENTS) return [settled];
814 const childId = ThreadId.make(`transfer-budget-settled-${index}-subagent`);
815 return [
816 settled,
817 threadCreated(provider, childId, {
818 title: `Subagent of settled thread ${index}`,
819 createdBy: "agent",
820 lineage: {
821 parentThreadId: threadId,
822 relationshipToParent: "subagent",
823 rootThreadId: threadId,
824 },
825 }),
826 ];
827 }).flat();