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

OrchestratorMcpService.activity.test.ts

1,204 lines45.1 KB

1import {
2 EnvironmentId,
3 NodeId,
4 type OrchestratorMcpThreadReadResult,
5 type OrchestrationV2ThreadProjection,
6 type OrchestrationV2ThreadShell,
7 ProjectId,
8 ProviderDriverKind,
9 ProviderInstanceId,
10 RunId,
11 ScheduledTaskId,
12 SECRET_REQUEST_UNSAVED_NOTE,
13 ThreadId,
14 TurnItemId,
15} from "@t3tools/contracts";
16import * as DateTime from "effect/DateTime";
17import * as Effect from "effect/Effect";
18import * as Fiber from "effect/Fiber";
19import * as Layer from "effect/Layer";
20import * as Metric from "effect/Metric";
21import * as TestClock from "effect/testing/TestClock";
22import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
23import { expect, it } from "vite-plus/test";
24​
25import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts";
26import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
27import * as ProjectService from "../project/ProjectService.ts";
28import * as ScheduledTaskService from "../scheduledTasks/ScheduledTaskService.ts";
29import * as ServerSettings from "../serverSettings.ts";
30import * as SecretRequests from "../secrets/SecretRequests.ts";
31import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
32import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
33import * as RemoteDelegation from "../peer/RemoteDelegation.ts";
34import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
35import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
36import type * as McpInvocationContext from "./McpInvocationContext.ts";
37import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
38import { liveThreadShell } from "./McpToolAccess.testkit.ts";
39​
40const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
41 Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
42 Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
43);
44​
45const environmentId = EnvironmentId.make("environment-mcp-orchestrator-detail");
46const projectId = ProjectId.make("project-mcp-orchestrator-detail");
47const parentThreadId = ThreadId.make("thread-mcp-orchestrator-parent");
48const childThreadId = ThreadId.make("thread-mcp-orchestrator-child");
49const activeRunId = RunId.make("run-mcp-active");
50const cancelledRunId = RunId.make("run-mcp-cancelled");
51const childRunId = RunId.make("run-mcp-child");
52const taskId = NodeId.make("node-mcp-task-1");
53const now = DateTime.makeUnsafe("2026-08-04T12:00:00.000Z");
54const codexDriver = ProviderDriverKind.make("codex");
55​
56const customCodexInstanceId = ProviderInstanceId.make("codex-custom-workspace");
57const parentInstanceId = ProviderInstanceId.make("codex");
58​
59const makeScope = (): McpInvocationContext.McpInvocationScope => ({
60 environmentId,
61 requestNamespace: "provider-session-mcp-orchestrator-detail",
62 thread: {
63 threadId: parentThreadId,
64 providerSessionId: "provider-session-mcp-orchestrator-detail",
65 providerInstanceId: parentInstanceId,
66 },
67 client: undefined,
68 capabilities: new Set(["orchestration"]),
69 issuedAt: 1,
70});
71​
72function baseThread(input: {
73 readonly threadId: ThreadId;
74 readonly title: string;
75 readonly instanceId: ProviderInstanceId;
76 readonly model: string;
77}) {
78 return {
79 id: input.threadId,
80 projectId,
81 title: input.title,
82 createdBy: "user" as const,
83 creationSource: "mcp" as const,
84 modelSelection: {
85 instanceId: input.instanceId,
86 model: input.model,
87 },
88 runtimeMode: "full-access" as const,
89 interactionMode: "default" as const,
90 branch: null,
91 worktreePath: null,
92 lineage: {
93 parentThreadId: null,
94 relationshipToParent: null,
95 rootThreadId: input.threadId,
96 },
97 archivedAt: null,
98 deletedAt: null,
99 providerInstanceId: input.instanceId,
100 createdAt: now,
101 updatedAt: now,
102 };
104​
105function makeRun(input: {
106 readonly id: RunId;
107 readonly ordinal: number;
108 readonly status: "running" | "waiting" | "cancelled" | "queued" | "completed" | "failed";
109 readonly instanceId?: ProviderInstanceId;
110}) {
111 return {
112 id: input.id,
113 ordinal: input.ordinal,
114 status: input.status,
115 modelSelection: {
116 instanceId: input.instanceId ?? parentInstanceId,
117 model: "gpt-5.4",
118 },
119 providerInstanceId: input.instanceId ?? parentInstanceId,
120 requestedAt: now,
121 startedAt: input.status === "cancelled" || input.status === "queued" ? null : now,
122 completedAt: input.status === "cancelled" || input.status === "completed" ? now : null,
123 };
125​
126it("readThread preserves caller access errors and prefers activity-run status over a newer cancelled queued run", async () => {
127 let callerUnavailable = false;
128 let pendingBackgroundTasks: OrchestrationV2ThreadShell["pendingBackgroundTasks"] = [
129 {
130 taskId: "task-subagent",
131 kind: "subagent",
132 parentTaskId: "task-parent",
133 providerInstanceId: parentInstanceId,
134 childThreadId,
135 },
136 ];
137 const pullRequestLink = (number: number, state: "open" | "merged", watched: boolean) => ({
138 host: "github.com",
139 repository: "acme/web",
140 number,
141 url: `https://github.com/acme/web/pull/${number}`,
142 source: "agent",
143 linkedAt: `2026-08-04T11:0${number}:00.000Z`,
144 snapshot: { state },
145 stack: null,
146 ...(watched
147 ? {
148 watch: {
149 startedAt: "2026-08-04T11:30:00.000Z",
150 headSha: null,
151 failedChecks: [],
152 passed: false,
153 passedChecks: [],
154 remarksThrough: "2026-08-04T11:30:00.000Z",
155 remarkIds: [],
156 conflicting: false,
157 wakes: 0,
158 },
159 }
160 : {}),
161 });
162 const projection = {
163 thread: {
164 ...baseThread({
165 threadId: parentThreadId,
166 title: "Parent",
167 instanceId: parentInstanceId,
168 model: "gpt-5.4",
169 }),
170 pullRequests: [
171 pullRequestLink(1, "merged", false),
172 pullRequestLink(2, "open", true),
173 ...[3, 4, 5, 6, 7, 8].map((number) => pullRequestLink(number, "open", false)),
174 ],
175 },
176 runs: [
177 makeRun({ id: activeRunId, ordinal: 1, status: "running" }),
178 makeRun({ id: cancelledRunId, ordinal: 2, status: "cancelled" }),
179 ],
180 visibleTurnItems: [],
181 providerTurns: [],
182 runtimeRequests: [],
183 messages: [],
184 contextTransfers: [],
185 subagents: [],
186 updatedAt: now,
187 } as unknown as OrchestrationV2ThreadProjection;
188​
189 const layer = layerOrchestratorService.pipe(
190 Layer.provide(
191 Layer.mergeAll(
192 Layer.mock(ThreadManagementService.ThreadManagementService)({
193 getTimelinePage: () =>
194 Effect.succeed({ items: [], totalItems: 0, hasMore: false, hasEarlier: false }),
195 getThreadRecords: (threadId) =>
196 callerUnavailable
197 ? Effect.fail(
198 new Orchestrator.OrchestratorProjectionError({
199 threadId,
200 cause: "Caller unavailable",
201 }),
202 )
203 : threadId === parentThreadId
204 ? Effect.succeed(projection)
205 : Effect.die(`unexpected thread ${threadId}`),
206 getThreadShell: (threadId) =>
207 callerUnavailable
208 ? Effect.die("A failed caller read must not reach the target")
209 : Effect.succeed(
210 threadId === parentThreadId
211 ? ({
212 ...projection.thread,
213 pinnedAt: now,
214 blockedOnThreadWait: true,
215 pendingBackgroundTasks,
216 } as unknown as OrchestrationV2ThreadShell)
217 : null,
218 ),
219 getProjectThreadRecords: (input) =>
220 input.threadId === parentThreadId
221 ? Effect.succeed(projection)
222 : Effect.die(`unexpected thread ${input.threadId}`),
223 getRunCount: () => Effect.succeed(projection.runs.length),
224 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
225 ServerSettings.layerTest(),
226 Layer.mock(ProviderRegistry.ProviderRegistry)({
227 getProviders: Effect.succeed([]),
228 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
229 Layer.mock(ProjectService.ProjectService)({}),
230 Layer.mock(SecretRequests.SecretRequests)({}),
231 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
232 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
233 list: () => Effect.succeed({ tasks: [] }),
234 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
235 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
236 list: () => Effect.succeed([]),
237 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
238 NodeCrypto.layer,
239 ),
240 ),
241 );
242​
243 await Effect.gen(function* () {
244 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
245 const result = yield* service.readThread(makeScope(), { threadId: parentThreadId });
246 expect(result.thread.status).toBe("running");
247 expect(result.thread.latestRunId).toBe(cancelledRunId);
248 expect(result.thread.activeRunId).toBe(activeRunId);
249 expect(result.thread.pinned).toBe(true);
250 expect(result.thread.blockedOnThreadWait).toBe(true);
251 expect(result.thread.pendingBackgroundTasks).toEqual([
252 { taskId: "task-subagent", kind: "subagent", childThreadId },
253 ]);
254 // Every page read must not repeat each linked PR, and an open PR shows whether it is watched.
255 // A thread with many open PRs previews a few, watched first, then newest.
256 const listed = result.thread.pullRequests ?? [];
257 expect(listed.map((link) => link.number)).toEqual([2, 8, 7, 6, 5]);
258 expect(result.thread.openPullRequestCount).toBe(7);
259 expect(listed.find((link) => link.number === 2)).toMatchObject({
260 watching: true,
261 watchStartedAt: "2026-08-04T11:30:00.000Z",
262 });
263 const laterPage = yield* service.readThread(makeScope(), {
264 threadId: parentThreadId,
265 afterPosition: 0,
266 });
267 expect(laterPage.thread.pullRequests).toBeUndefined();
268 expect(laterPage.thread.pullRequestCount).toBe(8);
269​
270 Object.assign(projection, {
271 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "completed" })],
272 });
273 const awaiting = yield* service.readThread(makeScope(), { threadId: parentThreadId });
274 expect(awaiting.thread.status).toBe("waiting");
275​
276 Object.assign(projection, {
277 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "failed" })],
278 });
279 const failed = yield* service.readThread(makeScope(), { threadId: parentThreadId });
280 expect(failed.thread.status).toBe("failed");
281​
282 Object.assign(projection, {
283 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "completed" })],
284 });
285 // An unawaited command (a dev server) does not hold the thread once its turn ends.
286 pendingBackgroundTasks = [{ taskId: "dev-server", kind: "command" }];
287 const released = yield* service.readThread(makeScope(), { threadId: parentThreadId });
288 expect(released.thread.status).toBe("completed");
289​
290 callerUnavailable = true;
291 const denied = yield* service
292 .readThread({ ...makeScope(), capabilities: new Set() }, { threadId: parentThreadId })
293 .pipe(Effect.flip);
294 expect(denied.code).toBe("capability_denied");
295 const missingCaller = yield* service
296 .readThread(makeScope(), { threadId: parentThreadId })
297 .pipe(Effect.flip);
298 expect(missingCaller.code).toBe("orchestration_error");
299 expect(missingCaller.message).toContain(`Unable to read thread ${parentThreadId}:`);
300 }).pipe(Effect.provide(layer), Effect.runPromise);
301});
302​
303it("readThread pages cut-off text without splitting an emoji across pages", async () => {
304 const text = "aπŸ˜€bc";
305 const itemId = TurnItemId.make("turn-item-mcp-reasoning");
306 const projection = {
307 thread: baseThread({
308 threadId: parentThreadId,
309 title: "Parent",
310 instanceId: parentInstanceId,
311 model: "gpt-5.4",
312 }),
313 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })],
314 visibleTurnItems: [],
315 providerTurns: [],
316 runtimeRequests: [],
317 messages: [],
318 contextTransfers: [],
319 subagents: [],
320 updatedAt: now,
321 } as unknown as OrchestrationV2ThreadProjection;
322 const row = {
323 position: 0,
324 visibility: "visible",
325 sourceThreadId: parentThreadId,
326 sourceItemId: itemId,
327 item: {
328 type: "reasoning",
329 runId: activeRunId,
330 status: "completed",
331 title: null,
332 text,
333 updatedAt: now,
334 },
335 };
336 const rows = [
337 row,
338 ...Array.from({ length: 11 }, (_, index) => ({
339 ...row,
340 position: index + 1,
341 sourceItemId: TurnItemId.make(`turn-item-mcp-${index}`),
342 item: { ...row.item, text: "x".repeat(600) },
343 })),
344 ];
345​
346 const layer = layerOrchestratorService.pipe(
347 Layer.provide(
348 Layer.mergeAll(
349 Layer.mock(ThreadManagementService.ThreadManagementService)({
350 getTimelinePage: (_threadId, options) => {
351 const remaining = rows.filter(
352 (candidate) =>
353 candidate.position > (options.afterPosition ?? -1) &&
354 (options.itemId === undefined || candidate.sourceItemId === options.itemId),
355 );
356 return Effect.succeed({
357 items: remaining.slice(
358 0,
359 options.limit,
360 ) as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
361 totalItems: rows.length,
362 hasMore: remaining.length > options.limit,
363 hasEarlier: false,
364 });
365 },
366 getThreadRecords: () => Effect.succeed(projection),
367 getProjectThreadRecords: () => Effect.succeed(projection),
368 getRunCount: () => Effect.succeed(projection.runs.length),
369 getThreadShell: () =>
370 Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
371 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
372 ServerSettings.layerTest(),
373 Layer.mock(ProviderRegistry.ProviderRegistry)({
374 getProviders: Effect.succeed([]),
375 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
376 Layer.mock(ProjectService.ProjectService)({}),
377 Layer.mock(SecretRequests.SecretRequests)({}),
378 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
379 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
380 list: () => Effect.succeed({ tasks: [] }),
381 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
382 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
383 list: () => Effect.succeed([]),
384 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
385 NodeCrypto.layer,
386 ),
387 ),
388 );
389​
390 await Effect.gen(function* () {
391 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
392 for (const [maxCharsPerItem, expected] of [
393 [2, ["a", "πŸ˜€", "bc"]],
394 [1, ["a", "πŸ˜€", "b", "c"]],
395 ] as const) {
396 let textOffset = 0;
397 for (const [index, text] of expected.entries()) {
398 const result = yield* service.readThread(makeScope(), {
399 threadId: parentThreadId,
400 view: "activity",
401 itemId,
402 textOffset,
403 maxCharsPerItem,
404 });
405 textOffset += text.length;
406 expect(result.items[0]).toMatchObject({
407 text,
408 textTruncated: index < expected.length - 1,
409 nextTextOffset: index < expected.length - 1 ? textOffset : null,
410 });
411 }
412 }
413 const first = yield* service.readThread(makeScope(), {
414 threadId: parentThreadId,
415 view: "activity",
416 });
417 expect(first.items[1]).toMatchObject({
418 text: "x".repeat(500),
419 textTruncated: true,
420 nextTextOffset: 500,
421 });
422 expect(first.items).toHaveLength(10);
423 expect(first).toMatchObject({ nextPosition: 9, hasMore: true });
424 }).pipe(Effect.provide(layer), Effect.runPromise);
425});
426​
427it("readThread returns the newest items that fit the response budget", async () => {
428 const projection = {
429 thread: baseThread({
430 threadId: parentThreadId,
431 title: "Parent",
432 instanceId: parentInstanceId,
433 model: "gpt-5.4",
434 }),
435 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })],
436 visibleTurnItems: [],
437 providerTurns: [],
438 runtimeRequests: [],
439 messages: [],
440 contextTransfers: [],
441 subagents: [],
442 updatedAt: now,
443 } as unknown as OrchestrationV2ThreadProjection;
444 // A long thread's newest 100 activity items, the read agents make most.
445 const rows = Array.from({ length: 100 }, (_, position) => ({
446 position,
447 visibility: "local",
448 sourceThreadId: parentThreadId,
449 sourceItemId: TurnItemId.make(`turn-item-mcp-long-${position}`),
450 item: {
451 type: "reasoning",
452 runId: activeRunId,
453 status: "completed",
454 title: null,
455 text: "x".repeat(1_500),
456 updatedAt: now,
457 },
458 }));
459 const pageOptions: Array<unknown> = [];
460​
461 const layer = layerOrchestratorService.pipe(
462 Layer.provide(
463 Layer.mergeAll(
464 Layer.mock(ThreadManagementService.ThreadManagementService)({
465 getTimelinePage: (_threadId, options) => {
466 pageOptions.push(options);
467 return Effect.succeed({
468 items: rows as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
469 totalItems: 3_000,
470 hasMore: false,
471 hasEarlier: true,
472 });
473 },
474 getThreadRecords: () => Effect.succeed(projection),
475 getProjectThreadRecords: () => Effect.succeed(projection),
476 getRunCount: () => Effect.succeed(projection.runs.length),
477 getThreadShell: () =>
478 Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
479 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
480 ServerSettings.layerTest(),
481 Layer.mock(ProviderRegistry.ProviderRegistry)({
482 getProviders: Effect.succeed([]),
483 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
484 Layer.mock(ProjectService.ProjectService)({}),
485 Layer.mock(SecretRequests.SecretRequests)({}),
486 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
487 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
488 list: () => Effect.succeed({ tasks: [] }),
489 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
490 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
491 list: () => Effect.succeed([]),
492 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
493 NodeCrypto.layer,
494 ),
495 ),
496 );
497​
498 await Effect.gen(function* () {
499 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
500 const read = {
501 threadId: parentThreadId,
502 view: "activity" as const,
503 limit: 100,
504 maxCharsPerItem: 1_500,
505 };
506 const result = yield* service.readThread(makeScope(), read);
507 // Linked environments and the CLI read as clients without a cursor and follow only hasMore.
508 const first = yield* service.readThread({ ...makeScope(), thread: undefined }, read);
509 const fromStart = yield* service.readThread(makeScope(), { ...read, afterPosition: -1 });
510​
511 expect(pageOptions).toEqual([
512 { beforePosition: Number.POSITIVE_INFINITY, limit: 100, view: "activity" },
513 { limit: 100, view: "activity" },
514 { afterPosition: -1, limit: 100, view: "activity" },
515 ]);
516 // Claude Code saves results over ~50k chars of this JSON to a file instead of showing them.
517 expect(JSON.stringify(result).length).toBeLessThan(31_000);
518 expect(result.items.length).toBeLessThan(100);
519 expect(result.items.at(-1)?.position).toBe(99);
520 expect(result.earlierPosition).toBe(result.items[0]?.position);
521 expect(result.hasMore).toBe(false);
522 expect(first.items[0]?.position).toBe(0);
523 expect(first.hasMore).toBe(true);
524 expect(first.nextPosition).toBe(first.items.at(-1)?.position);
525 expect(fromStart.items[0]?.position).toBe(0);
526 }).pipe(Effect.provide(layer), Effect.runPromise);
527});
528​
529it("readThread keeps an activity page within an MCP client's output limit and pages the rest", async () => {
530 const projection = {
531 thread: baseThread({
532 threadId: parentThreadId,
533 title: "Parent",
534 instanceId: parentInstanceId,
535 model: "gpt-5.4",
536 }),
537 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })],
538 visibleTurnItems: [],
539 providerTurns: [],
540 runtimeRequests: [],
541 messages: [],
542 contextTransfers: [],
543 subagents: [],
544 updatedAt: now,
545 } as unknown as OrchestrationV2ThreadProjection;
546 const rows = Array.from({ length: 60 }, (_, position) => ({
547 position,
548 visibility: "visible",
549 sourceThreadId: parentThreadId,
550 sourceItemId: TurnItemId.make(`turn-item-mcp-reasoning-${position}`),
551 item: {
552 type: "reasoning",
553 runId: activeRunId,
554 status: "completed",
555 // Command titles can carry a whole command.
556 title: position === 1 ? "標".repeat(60_000) : null,
557 text: position === 0 ? "πŸ˜€a".repeat(30_000) : `${position} `.padEnd(3_000, "x"),
558 updatedAt: now,
559 },
560 }));
561​
562 const layer = layerOrchestratorService.pipe(
563 Layer.provide(
564 Layer.mergeAll(
565 Layer.mock(ThreadManagementService.ThreadManagementService)({
566 getTimelinePage: (_threadId, options) => {
567 const after =
568 options.itemId === undefined
569 ? rows.filter((row) => row.position > (options.afterPosition ?? -1))
570 : rows.filter((row) => row.sourceItemId === options.itemId);
571 return Effect.succeed({
572 items: after.slice(
573 0,
574 options.limit,
575 ) as unknown as OrchestrationV2ThreadProjection["visibleTurnItems"],
576 totalItems: rows.length,
577 hasMore: after.length > options.limit,
578 hasEarlier: false,
579 });
580 },
581 getThreadRecords: () => Effect.succeed(projection),
582 getProjectThreadRecords: () => Effect.succeed(projection),
583 getRunCount: () => Effect.succeed(projection.runs.length),
584 getThreadShell: () =>
585 Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
586 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
587 ServerSettings.layerTest(),
588 Layer.mock(ProviderRegistry.ProviderRegistry)({
589 getProviders: Effect.succeed([]),
590 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
591 Layer.mock(ProjectService.ProjectService)({}),
592 Layer.mock(SecretRequests.SecretRequests)({}),
593 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
594 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
595 list: () => Effect.succeed({ tasks: [] }),
596 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
597 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
598 list: () => Effect.succeed([]),
599 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
600 NodeCrypto.layer,
601 ),
602 ),
603 );
604​
605 await Effect.gen(function* () {
606 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
607 const positions: Array<number> = [];
608 let afterPosition: number | undefined;
609 for (let page = 0; page < rows.length; page++) {
610 const result = yield* service.readThread(makeScope(), {
611 threadId: parentThreadId,
612 view: "activity",
613 limit: 100,
614 maxCharsPerItem: 1_500,
615 afterPosition: afterPosition ?? -1,
616 });
617 // Claude Code rejects MCP results over 25k tokens; CJK text is about a token per char.
618 expect(Buffer.byteLength(JSON.stringify(result))).toBeLessThanOrEqual(50_000);
619 if (page === 0) expect(result.hasMore).toBe(true);
620 positions.push(...result.items.map((item) => item.position));
621 if (!result.hasMore) break;
622 afterPosition = result.nextPosition ?? undefined;
623 }
624 expect(positions).toEqual(rows.map((row) => row.position));
625​
626 const longText = rows[0]!.item.text;
627 const pages: Array<string> = [];
628 let textOffset: number | null = 0;
629 while (textOffset !== null) {
630 const result: OrchestratorMcpThreadReadResult = yield* service.readThread(makeScope(), {
631 threadId: parentThreadId,
632 view: "activity",
633 itemId: rows[0]!.sourceItemId,
634 textOffset,
635 maxCharsPerItem: 50_000,
636 });
637 expect(Buffer.byteLength(JSON.stringify(result))).toBeLessThanOrEqual(50_000);
638 const [item] = result.items;
639 expect(item?.text?.isWellFormed()).toBe(true);
640 pages.push(item!.text!);
641 textOffset = item!.nextTextOffset ?? null;
642 }
643 expect(pages.length).toBeGreaterThan(1);
644 expect(pages.join("")).toBe(longText);
645​
646 (projection.thread as { title: string }).title = "標".repeat(30_000);
647 const underHugeTitle = yield* service.readThread(makeScope(), {
648 threadId: parentThreadId,
649 view: "activity",
650 itemId: rows[0]!.sourceItemId,
651 maxCharsPerItem: 50_000,
652 });
653 expect(underHugeTitle.items[0]?.text?.length).toBeGreaterThan(1_000);
654 }).pipe(Effect.provide(layer), Effect.runPromise);
655});
656​
657it("taskStatus returns task.providerInstanceId rather than the driver kind", async () => {
658 const parentProjection = {
659 thread: baseThread({
660 threadId: parentThreadId,
661 title: "Parent",
662 instanceId: parentInstanceId,
663 model: "gpt-5.4",
664 }),
665 runs: [makeRun({ id: activeRunId, ordinal: 1, status: "running" })],
666 visibleTurnItems: [],
667 providerTurns: [],
668 runtimeRequests: [],
669 messages: [],
670 contextTransfers: [],
671 subagents: [
672 {
673 id: taskId,
674 threadId: parentThreadId,
675 runId: activeRunId,
676 parentNodeId: NodeId.make("node-parent"),
677 origin: "app_owned",
678 createdBy: "agent",
679 driver: codexDriver,
680 providerInstanceId: customCodexInstanceId,
681 providerThreadId: null,
682 childThreadId,
683 nativeTaskRef: null,
684 prompt: "Inspect the custom instance.",
685 title: null,
686 model: "gpt-5.4",
687 status: "running",
688 result: null,
689 startedAt: now,
690 completedAt: null,
691 updatedAt: now,
692 },
693 ],
694 updatedAt: now,
695 } as unknown as OrchestrationV2ThreadProjection;
696​
697 const childProjection = {
698 thread: {
699 ...baseThread({
700 threadId: childThreadId,
701 title: "Child",
702 instanceId: customCodexInstanceId,
703 model: "gpt-5.4",
704 }),
705 lineage: {
706 parentThreadId,
707 relationshipToParent: "subagent",
708 rootThreadId: parentThreadId,
709 },
710 createdBy: "agent",
711 },
712 runs: [
713 makeRun({
714 id: childRunId,
715 ordinal: 1,
716 status: "running",
717 instanceId: customCodexInstanceId,
718 }),
719 ],
720 visibleTurnItems: [],
721 providerTurns: [],
722 runtimeRequests: [],
723 messages: [],
724 contextTransfers: [
725 {
726 type: "subagent_spawn",
727 sourceThreadId: parentThreadId,
728 targetThreadId: childThreadId,
729 targetRunId: childRunId,
730 },
731 ],
732 subagents: [],
733 providerThreads: [],
734 updatedAt: now,
735 } as unknown as OrchestrationV2ThreadProjection;
736​
737 const layer = layerOrchestratorService.pipe(
738 Layer.provide(
739 Layer.mergeAll(
740 Layer.mock(ThreadManagementService.ThreadManagementService)({
741 getTimelinePage: () =>
742 Effect.succeed({ items: [], totalItems: 0, hasMore: false, hasEarlier: false }),
743 getThreadRecords: (threadId) => {
744 if (threadId === parentThreadId) return Effect.succeed(parentProjection);
745 if (threadId === childThreadId) return Effect.succeed(childProjection);
746 return Effect.die(`unexpected thread ${threadId}`);
747 },
748 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
749 ServerSettings.layerTest(),
750 Layer.mock(ProviderRegistry.ProviderRegistry)({
751 getProviders: Effect.succeed([]),
752 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
753 Layer.mock(ProjectService.ProjectService)({}),
754 Layer.mock(SecretRequests.SecretRequests)({}),
755 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
756 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
757 list: () => Effect.succeed({ tasks: [] }),
758 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
759 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
760 list: () => Effect.succeed([]),
761 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
762 NodeCrypto.layer,
763 ),
764 ),
765 );
766​
767 await Effect.gen(function* () {
768 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
769 const result = yield* service.taskStatus(makeScope(), taskId);
770 expect(result.providerInstanceId).toBe(customCodexInstanceId);
771 expect(result.providerInstanceId).not.toBe(ProviderInstanceId.make(String(codexDriver)));
772 expect(result.status).toBe("running");
773 expect(result.taskId).toBe(taskId);
774 expect(result.childThreadId).toBe(childThreadId);
775 }).pipe(Effect.provide(layer), Effect.runPromise);
776});
777​
778it("readThread and sendToThread reach threads in other projects", async () => {
779 let parentShell: OrchestrationV2ThreadShell | null = null;
780 let parentRuns: ReadonlyArray<unknown> = [
781 makeRun({ id: RunId.make("run-parent-live"), ordinal: 1, status: "running" }),
782 ];
783 const foreignProjectId = ProjectId.make("project-mcp-orchestrator-foreign");
784 const foreignThreadId = ThreadId.make("thread-mcp-orchestrator-foreign");
785 const parentProjection = {
786 thread: baseThread({
787 threadId: parentThreadId,
788 title: "Parent",
789 instanceId: parentInstanceId,
790 model: "gpt-5.4",
791 }),
792 get runs() {
793 return parentRuns;
794 },
795 visibleTurnItems: [],
796 providerTurns: [],
797 runtimeRequests: [],
798 messages: [],
799 contextTransfers: [],
800 subagents: [],
801 updatedAt: now,
802 } as unknown as OrchestrationV2ThreadProjection;
803 const foreignProjection = (threadId: ThreadId) =>
804 ({
805 thread: {
806 ...baseThread({
807 threadId,
808 title: "Foreign",
809 instanceId: parentInstanceId,
810 model: "gpt-5.4",
811 }),
812 projectId: foreignProjectId,
813 },
814 runs: [],
815 visibleTurnItems: [
816 {
817 position: 0,
818 visibility: "inherited",
819 sourceThreadId: threadId,
820 sourceItemId: "item-1",
821 item: {
822 id: "item-1",
823 type: "assistant_message",
824 messageId: "assistant-1",
825 status: "completed",
826 title: null,
827 text: "Foreign thread said hello",
828 createdAt: now,
829 updatedAt: now,
830 },
831 },
832 ],
833 providerTurns: [],
834 runtimeRequests: [],
835 messages: [],
836 contextTransfers: [],
837 subagents: [],
838 updatedAt: now,
839 }) as unknown as OrchestrationV2ThreadProjection;
840​
841 const layer = layerOrchestratorService.pipe(
842 Layer.provide(
843 Layer.mergeAll(
844 Layer.mock(ThreadManagementService.ThreadManagementService)({
845 getThreadRecords: (threadId) => {
846 if (threadId === parentThreadId) return Effect.succeed(parentProjection);
847 if (threadId === foreignThreadId) return Effect.succeed(foreignProjection(threadId));
848 return Effect.die(`unexpected thread ${threadId}`);
849 },
850 getThreadShell: (threadId) =>
851 Effect.succeed(
852 threadId === foreignThreadId
853 ? (foreignProjection(threadId).thread as unknown as OrchestrationV2ThreadShell)
854 : threadId === parentThreadId
855 ? parentShell
856 : null,
857 ),
858 getTimelinePage: (threadId) =>
859 Effect.succeed({
860 items: foreignProjection(threadId).visibleTurnItems,
861 totalItems: 1,
862 hasMore: false,
863 hasEarlier: false,
864 }),
865 getRunCount: (threadId) => Effect.succeed(foreignProjection(threadId).runs.length),
866 getProjectThreadRecords: (input) =>
867 input.threadId === foreignThreadId && input.projectId === foreignProjectId
868 ? Effect.succeed(foreignProjection(input.threadId))
869 : Effect.fail(
870 new ThreadManagementService.ThreadManagementThreadNotFoundError({
871 projectId: input.projectId,
872 threadId: input.threadId,
873 }),
874 ),
875 sendToThread: () =>
876 Effect.succeed({
877 run: { id: "run-foreign", status: "queued" },
878 delivery: "started",
879 } as unknown as ThreadManagementService.ThreadManagementSendResult),
880 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
881 ServerSettings.layerTest(),
882 Layer.mock(ProviderRegistry.ProviderRegistry)({
883 getProviders: Effect.succeed([]),
884 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
885 Layer.mock(ProjectService.ProjectService)({}),
886 Layer.mock(SecretRequests.SecretRequests)({}),
887 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
888 Layer.mock(ScheduledTaskService.ScheduledTaskService)({
889 list: () =>
890 Effect.succeed({
891 tasks: [
892 {
893 id: "task-foreign",
894 projectId: foreignProjectId,
895 runtimeMode: "approval-required",
896 interactionMode: "default",
897 } as never,
898 ],
899 }),
900 } satisfies Partial<ScheduledTaskService.ScheduledTaskService["Service"]>),
901 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
902 list: () => Effect.succeed([]),
903 } satisfies Partial<ProviderAdapterRegistry.ProviderAdapterRegistryV2["Service"]>),
904 NodeCrypto.layer,
905 ),
906 ),
907 );
908​
909 await Effect.gen(function* () {
910 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
911 const foreign = yield* service.readThread(makeScope(), { threadId: foreignThreadId });
912 expect(foreign.thread.threadId).toBe(foreignThreadId);
913 expect(foreign.thread.projectId).toBe(foreignProjectId);
914 expect(foreign.items.map((item) => item.text)).toEqual(["Foreign thread said hello"]);
915​
916 const sent = yield* service.sendToThread(makeScope(), {
917 threadId: foreignThreadId,
918 message: "hi",
919 });
920 expect(sent.threadId).toBe(foreignThreadId);
921​
922 parentRuns = [];
923 yield* service.readThread(makeScope(), { threadId: foreignThreadId });
924 const stale = yield* service
925 .sendToThread(makeScope(), { threadId: foreignThreadId, message: "hi again" })
926 .pipe(Effect.flip);
927 expect(stale.code).toBe("parent_not_active");
928 const staleInterrupt = yield* service
929 .interruptThread(makeScope(), { threadId: foreignThreadId })
930 .pipe(Effect.flip);
931 expect(staleInterrupt.code).toBe("parent_not_active");
932​
933 const staleSchedule = yield* service
934 .scheduleTask(makeScope(), {
935 projectId: foreignProjectId,
936 prompt: "check in later",
937 schedule: { type: "interval", everyMs: 3_600_000 },
938 })
939 .pipe(Effect.flip);
940 expect(staleSchedule.code).toBe("parent_not_active");
941 const staleUpdate = yield* service
942 .updateScheduledTask(makeScope(), {
943 scheduledTaskId: ScheduledTaskId.make("task-foreign"),
944 enabled: false,
945 })
946 .pipe(Effect.flip);
947 expect(staleUpdate.code).toBe("parent_not_active");
948 const staleDelete = yield* service
949 .deleteScheduledTask(makeScope(), { scheduledTaskId: ScheduledTaskId.make("task-foreign") })
950 .pipe(Effect.flip);
951 expect(staleDelete.code).toBe("parent_not_active");
952​
953 const backgroundTasks = [
954 {
955 taskId: "background-subagent",
956 kind: "subagent" as const,
957 providerInstanceId: parentInstanceId,
958 },
959 ];
960 parentShell = {
961 ...liveThreadShell(parentThreadId, { activeRunId: null }),
962 pendingBackgroundTasks: backgroundTasks,
963 };
964 const backgroundSent = yield* service.sendToThread(makeScope(), {
965 threadId: foreignThreadId,
966 message: "background",
967 });
968 expect(backgroundSent.threadId).toBe(foreignThreadId);
969 const delegate = yield* service
970 .delegateTask(makeScope(), { task: "requires a run" })
971 .pipe(Effect.flip);
972 expect(delegate.code).toBe("parent_not_active");
973 const create = yield* service
974 .createThreads(makeScope(), { threads: [{ prompt: "requires a run" }] })
975 .pipe(Effect.flip);
976 expect(create.code).toBe("parent_not_active");
977 const secret = yield* service
978 .requestSecret(makeScope(), { label: "Secret", reason: "requires a run" })
979 .pipe(Effect.flip);
980 expect(secret.code).toBe("parent_not_active");
981​
982 parentShell = { ...parentShell, providerInstanceId: customCodexInstanceId };
983 const switchedScope = {
984 ...makeScope(),
985 thread: { ...makeScope().thread!, providerInstanceId: customCodexInstanceId },
986 };
987 const switched = yield* service
988 .sendToThread(switchedScope, { threadId: foreignThreadId, message: "wrong owner" })
989 .pipe(Effect.flip);
990 expect(switched.code).toBe("parent_not_active");
991 const mismatched = yield* service
992 .sendToThread(makeScope(), { threadId: foreignThreadId, message: "stale provider" })
993 .pipe(Effect.flip);
994 expect(mismatched.code).toBe("parent_not_active");
995​
996 parentShell = liveThreadShell(parentThreadId);
997 const restarted = yield* service.sendToThread(makeScope(), {
998 threadId: foreignThreadId,
999 message: "new run",
1000 });
1001 expect(restarted.threadId).toBe(foreignThreadId);
1002​
1003 parentShell = {
1004 ...parentShell,
1005 activeRunId: null,
1006 pendingBackgroundTasks: backgroundTasks,
1007 archivedAt: now,
1008 };
1009 const archived = yield* service
1010 .sendToThread(makeScope(), { threadId: foreignThreadId, message: "archived" })
1011 .pipe(Effect.flip);
1012 expect(archived.code).toBe("parent_not_active");
1013​
1014 parentShell = { ...parentShell, archivedAt: null, pendingBackgroundTasks: [] };
1015 const stopped = yield* service
1016 .sendToThread(makeScope(), { threadId: foreignThreadId, message: "after stop" })
1017 .pipe(Effect.flip);
1018 expect(stopped.code).toBe("parent_not_active");
1019 }).pipe(Effect.provide(layer), Effect.runPromise);
1020});
1021​
1022it("requestSecret saves a pasted value to a file without opening a card", async () => {
1023 const projection = {
1024 thread: baseThread({
1025 threadId: parentThreadId,
1026 title: "Parent",
1027 instanceId: parentInstanceId,
1028 model: "gpt-5.4",
1029 }),
1030 runs: [{ ...makeRun({ id: activeRunId, ordinal: 1, status: "running" }), rootNodeId: taskId }],
1031 visibleTurnItems: [],
1032 providerTurns: [],
1033 runtimeRequests: [],
1034 messages: [],
1035 contextTransfers: [],
1036 subagents: [],
1037 updatedAt: now,
1038 } as unknown as OrchestrationV2ThreadProjection;
1039 const dispatched: Array<unknown> = [];
1040 const saved: Array<{
1041 readonly requestNamespace: string;
1042 readonly requestKey: string;
1043 readonly value: string;
1044 }> = [];
1045 const file = "/home/user/.t3/userdata/secrets/files/0123456789abcdef0123456789abcdef";
1046​
1047 const layer = layerOrchestratorService.pipe(
1048 Layer.provide(
1049 Layer.mergeAll(
1050 Layer.mock(ThreadManagementService.ThreadManagementService)({
1051 getThreadRecords: (threadId) =>
1052 threadId === parentThreadId
1053 ? Effect.succeed(projection)
1054 : Effect.die(`unexpected thread ${threadId}`),
1055 getThreadShell: (threadId) =>
1056 Effect.succeed(
1057 threadId === parentThreadId
1058 ? (projection.thread as unknown as OrchestrationV2ThreadShell)
1059 : null,
1060 ),
1061 dispatch: (command) => Effect.sync(() => void dispatched.push(command) as never),
1062 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
1063 ServerSettings.layerTest(),
1064 Layer.mock(ProviderRegistry.ProviderRegistry)({
1065 getProviders: Effect.succeed([]),
1066 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
1067 Layer.mock(ProjectService.ProjectService)({}),
1068 Layer.mock(SecretRequests.SecretRequests)({
1069 savePasted: (input) =>
1070 Effect.sync(() => {
1071 saved.push({
1072 requestNamespace: input.requestNamespace,
1073 requestKey: input.requestKey,
1074 value: input.value,
1075 });
1076 return file;
1077 }),
1078 }),
1079 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
1080 Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
1081 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
1082 NodeCrypto.layer,
1083 ),
1084 ),
1085 );
1086 const counted = Metric.snapshot.pipe(
1087 Effect.map((snapshots) => {
1088 const found = snapshots.find(
1089 (snapshot) =>
1090 snapshot.id === "t3_secret_requests_total" &&
1091 snapshot.attributes?.status === "saved_pasted",
1092 );
1093 return found?.type === "Counter" ? Number(found.state.count) : 0;
1094 }),
1095 );
1096​
1097 await Effect.gen(function* () {
1098 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
1099 const before = yield* counted;
1100 const result = yield* service.requestSecret(makeScope(), {
1101 label: "Pixel PIN",
1102 reason: "Unlocks the test phone.",
1103 value: "482916",
1104 clientRequestId: "pin-1",
1105 });
1106 expect(result).toEqual({ status: "saved", file });
1107 expect(JSON.stringify(result)).not.toContain("482916");
1108 expect(saved).toEqual([
1110 requestNamespace: "provider-session-mcp-orchestrator-detail",
1111 requestKey: "pin-1",
1112 value: "482916",
1113 },
1114 ]);
1115 expect(dispatched).toEqual([]);
1116 expect((yield* counted) - before).toBe(1);
1117​
1118 const asRef = yield* service
1119 .requestSecret(makeScope(), {
1120 label: "Pixel PIN",
1121 reason: "Unlocks the test phone.",
1122 value: "482916",
1123 delivery: "secretRef",
1124 })
1125 .pipe(Effect.flip);
1126 expect(asRef.code).toBe("invalid_request");
1127 expect(asRef.message).not.toContain("482916");
1128 expect(saved).toHaveLength(1);
1129 expect(dispatched).toEqual([]);
1130 }).pipe(Effect.provide(layer), Effect.runPromise);
1131});
1132​
1133it("requestSecret returns the unsaved note for a declined, cancelled or timed-out card", async () => {
1134 const outcomes = ["declined", "cancelled", "pending"] as const;
1135 const results = await Effect.forEach(outcomes, (outcome) => {
1136 const dispatched: Array<{ readonly type: string; readonly turnItemId?: string }> = [];
1137 const projection = () => {
1138 const card = dispatched.find((command) => command.type === "secret_request.record");
1139 return {
1140 thread: baseThread({
1141 threadId: parentThreadId,
1142 title: "Parent",
1143 instanceId: parentInstanceId,
1144 model: "gpt-5.4",
1145 }),
1146 runs: [
1147 { ...makeRun({ id: activeRunId, ordinal: 1, status: "running" }), rootNodeId: taskId },
1148 ],
1149 visibleTurnItems: [],
1150 turnItems:
1151 card === undefined
1152 ? []
1153 : [{ type: "secret_request", id: card.turnItemId, secretStatus: outcome }],
1154 providerTurns: [],
1155 runtimeRequests: [],
1156 messages: [],
1157 contextTransfers: [],
1158 subagents: [],
1159 updatedAt: now,
1160 } as unknown as OrchestrationV2ThreadProjection;
1161 };
1162 const layer = layerOrchestratorService.pipe(
1163 Layer.provide(
1164 Layer.mergeAll(
1165 Layer.mock(ThreadManagementService.ThreadManagementService)({
1166 getThreadRecords: () => Effect.sync(projection),
1167 getThreadShell: () =>
1168 Effect.sync(() => projection().thread as unknown as OrchestrationV2ThreadShell),
1169 dispatch: (command) => Effect.sync(() => void dispatched.push(command) as never),
1170 } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
1171 ServerSettings.layerTest(),
1172 Layer.mock(ProviderRegistry.ProviderRegistry)({
1173 getProviders: Effect.succeed([]),
1174 } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),
1175 Layer.mock(ProjectService.ProjectService)({}),
1176 Layer.mock(SecretRequests.SecretRequests)({}),
1177 Layer.mock(RemoteDelegation.RemoteDelegation)({}),
1178 Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
1179 Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
1180 NodeCrypto.layer,
1181 ),
1182 ),
1183 );
1184 return Effect.gen(function* () {
1185 const service = yield* OrchestratorMcpService.OrchestratorMcpService;
1186 const request = yield* service
1187 .requestSecret(makeScope(), {
1188 label: "Staging password",
1189 reason: "Signs in the QA account.",
1190 delivery: "file",
1191 timeoutMs: 1_000,
1192 })
1193 .pipe(Effect.forkChild({ startImmediately: true }));
1194 yield* TestClock.adjust("2 seconds");
1195 return yield* Fiber.join(request);
1196 }).pipe(Effect.provide(Layer.merge(layer, TestClock.layer())));
1197 }).pipe(Effect.runPromise);
1198​
1199 expect(results).toEqual([
1200 { status: "declined", note: SECRET_REQUEST_UNSAVED_NOTE.declined },
1201 { status: "cancelled", note: SECRET_REQUEST_UNSAVED_NOTE.cancelled },
1202 { status: "timed_out", note: SECRET_REQUEST_UNSAVED_NOTE.timed_out },
1203 ]);
1204});