Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import {
3 CommandId,
4 EventId,
5 MessageId,
6 NodeId,
7 ProjectId,
8 ProviderDriverKind,
9 ProviderInstanceId,
10 ProviderThreadId,
11 ProviderTurnId,
12 RunAttemptId,
13 RunId,
14 ThreadId,
15 TurnItemId,
16 type OrchestrationV2DomainEvent,
17} from "@t3tools/contracts";
18import * as DateTime from "effect/DateTime";
19import * as Effect from "effect/Effect";
20import * as Fiber from "effect/Fiber";
21import * as Queue from "effect/Queue";
22import * as Stream from "effect/Stream";
23import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
24import * as EffectWorker from "./EffectWorker.ts";
25import * as EventSink from "./EventSink.ts";
26import * as Orchestrator from "./Orchestrator.ts";
27import type {
28 ProviderAdapterV2Event,
29 ProviderAdapterV2InterruptInput,
30 ProviderAdapterV2Shape,
31 ProviderAdapterV2TurnInput,
32} from "./ProviderAdapter.ts";
33import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
34import * as ProviderSessionManager from "./ProviderSessionManager.ts";
35import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts";
36import { checkpointWorkspace } from "./testkit/ReplayFixtureWorkspace.ts";
37
38const driver = ProviderDriverKind.make("codex");
39const instanceId = ProviderInstanceId.make("codex");
40const modelSelection = { instanceId, model: "test-model" };
41
42// Codex turns leave commands running, then the thread moves to another
43// provider thread (a provider switch). Stop must end all of the Codex work,
44// including when it selects an older resumed run on the other provider thread.
45const stopEarlierBackgroundWork = ({
46 failedStart = false,
47 stopWithQueue,
48 olderStart = false,
49 stalledRun,
50}: {
51 readonly failedStart?: boolean;
52 readonly stopWithQueue?: "thread.stop" | "run.interrupt";
53 readonly olderStart?: boolean;
54 readonly stalledRun?:
55 | "missing-session"
56 | "missing-session-terminal"
57 | "returned-interrupt"
58 | "returned-interrupt-terminal"
59 | "superseded-attempt";
60}) =>
61 Effect.scoped(
62 Effect.gen(function* () {
63 const cwd = yield* checkpointWorkspace("background-work-stop");
64 const events = yield* Queue.unbounded<ProviderAdapterV2Event>();
65 const started: ProviderAdapterV2TurnInput[] = [];
66 const interrupts: ProviderAdapterV2InterruptInput[] = [];
67 const adapter: ProviderAdapterV2Shape = {
68 instanceId,
69 driver,
70 getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2),
71 planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }),
72 openSession: (input) =>
73 Effect.gen(function* () {
74 const now = yield* DateTime.now;
75 return {
76 instanceId,
77 driver,
78 providerSessionId: input.providerSessionId,
79 providerSession: {
80 id: input.providerSessionId,
81 driver,
82 providerInstanceId: instanceId,
83 status: "ready",
84 cwd,
85 model: modelSelection.model,
86 capabilities: CodexProviderCapabilitiesV2,
87 createdAt: now,
88 updatedAt: now,
89 lastError: null,
90 },
91 events: Stream.fromQueue(events),
92 ensureThread: ({ threadId }) =>
93 Effect.succeed({
94 id: ProviderThreadId.make(`provider-thread:codex:${threadId}`),
95 driver,
96 providerInstanceId: instanceId,
97 providerSessionId: input.providerSessionId,
98 appThreadId: threadId,
99 ownerNodeId: null,
100 nativeThreadRef: { driver, nativeId: "native-thread", strength: "strong" },
101 nativeConversationHeadRef: null,
102 status: "idle",
103 firstRunOrdinal: null,
104 lastRunOrdinal: null,
105 handoffIds: [],
106 forkedFrom: null,
107 createdAt: now,
108 updatedAt: now,
109 }),
110 resumeThread: ({ providerThread }) => Effect.succeed(providerThread),
111 startTurn: (turn) =>
112 Effect.gen(function* () {
113 started.push(turn);
114 yield* Queue.offer(events, {
115 type: "provider_turn.updated",
116 driver,
117 providerTurn: {
118 id: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
119 providerThreadId: turn.providerThread.id,
120 nodeId: turn.rootNodeId,
121 runAttemptId: turn.attemptId,
122 nativeTurnRef: {
123 driver,
124 nativeId: `native:${turn.attemptId}`,
125 strength: "strong",
126 },
127 ordinal: turn.providerTurnOrdinal,
128 status: "running",
129 startedAt: now,
130 completedAt: null,
131 },
132 });
133 }),
134 steerTurn: () => Effect.die("unused"),
135 interruptTurn: (interrupt) =>
136 Effect.sync(() => {
137 interrupts.push(interrupt);
138 }),
139 respondToRuntimeRequest: () => Effect.die("unused"),
140 readThreadSnapshot: () => Effect.die("unused"),
141 rollbackThread: () => Effect.die("unused"),
142 forkThread: () => Effect.die("unused"),
143 };
144 }),
145 };
146 yield* Effect.gen(function* () {
147 const orchestrator = yield* Orchestrator.OrchestratorV2;
148 const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
149 const sink = yield* EventSink.EventSinkV2;
150 const threadId = ThreadId.make("thread:background-work-stop");
151 const watch = (predicate: (event: OrchestrationV2DomainEvent) => boolean) =>
152 orchestrator.streamDomainEvents.pipe(
153 Stream.filter(predicate),
154 Stream.take(1),
155 Stream.runDrain,
156 Effect.forkScoped,
157 );
158 yield* orchestrator.dispatch({
159 type: "thread.create",
160 commandId: CommandId.make("create"),
161 threadId,
162 projectId: ProjectId.make("project:background-work-stop"),
163 title: "Background work stop",
164 modelSelection,
165 runtimeMode: "full-access",
166 interactionMode: "default",
167 branch: null,
168 worktreePath: cwd,
169 createdBy: "user",
170 creationSource: "web",
171 });
172 const running = yield* watch(
173 (event) => event.type === "provider-turn.updated" && event.payload.status === "running",
174 );
175 yield* orchestrator.dispatch({
176 type: "message.dispatch",
177 commandId: CommandId.make("start-dev-server"),
178 threadId,
179 messageId: MessageId.make("message:start-dev-server"),
180 text: "Start the dev server",
181 attachments: [],
182 dispatchMode: { type: "start_immediately" },
183 createdBy: "user",
184 creationSource: "web",
185 });
186 yield* worker.drain();
187 yield* Fiber.join(running);
188 const first = started[0]!;
189 const codexTurn = (yield* orchestrator.getThreadProjection(threadId)).providerTurns[0]!;
190 const devServerId = TurnItemId.make("turn-item:dev-server");
191 const now = yield* DateTime.now;
192 yield* sink.write({
193 events: [
194 {
195 id: EventId.make("dev-server"),
196 type: "turn-item.updated",
197 threadId,
198 runId: first.runId,
199 occurredAt: now,
200 payload: {
201 id: devServerId,
202 threadId,
203 runId: first.runId,
204 nodeId: first.rootNodeId,
205 providerThreadId: codexTurn.providerThreadId,
206 providerTurnId: codexTurn.id,
207 nativeItemRef: null,
208 parentItemId: null,
209 ordinal: 100,
210 status: "running",
211 title: null,
212 startedAt: now,
213 completedAt: null,
214 updatedAt: now,
215 type: "command_execution",
216 input: "vp run dev --share",
217 },
218 },
219 ],
220 });
221 if (stalledRun !== undefined) {
222 const before = yield* orchestrator.getThreadProjection(threadId);
223 const run = before.runs[0]!;
224 const node = before.nodes.find((candidate) => candidate.id === run.rootNodeId)!;
225 const attempt = before.attempts[0]!;
226 if (stalledRun === "missing-session" || stalledRun === "missing-session-terminal") {
227 const sessions = yield* ProviderSessionManager.ProviderSessionManagerV2;
228 const failed = yield* watch(
229 (event) => event.type === "run.updated" && event.payload.status === "failed",
230 );
231 yield* sessions.release({
232 providerSessionId: first.providerThread.providerSessionId!,
233 reason: "runtime_error",
234 });
235 yield* Fiber.join(failed);
236 // Disk exhaustion can lose these terminal writes. Restore that stale state.
237 yield* sink.write({
238 events: [
239 {
240 id: EventId.make("stale-run"),
241 type: "run.updated",
242 threadId,
243 occurredAt: now,
244 payload: run,
245 },
246 {
247 id: EventId.make("stale-node"),
248 type: "node.updated",
249 threadId,
250 occurredAt: now,
251 payload: node,
252 },
253 {
254 id: EventId.make("stale-attempt"),
255 type: "run-attempt.updated",
256 threadId,
257 occurredAt: now,
258 payload: attempt,
259 },
260 ],
261 });
262 }
263 const messageId = MessageId.make("partial-output");
264 const item = before.turnItems.find((candidate) => candidate.id === devServerId)!;
265 assert.ok(item.type === "command_execution");
266 const terminalProviderTurn = stalledRun.endsWith("-terminal");
267 if (terminalProviderTurn) {
268 yield* sink.write({
269 events: [
270 {
271 id: EventId.make("terminal-provider-turn"),
272 type: "provider-turn.updated",
273 threadId,
274 occurredAt: now,
275 payload: { ...codexTurn, status: "completed", completedAt: now },
276 },
277 ...(stalledRun === "missing-session-terminal"
278 ? [
279 {
280 id: EventId.make("completed-dev-server"),
281 type: "turn-item.updated" as const,
282 threadId,
283 occurredAt: now,
284 payload: { ...item, status: "completed" as const, completedAt: now },
285 },
286 ]
287 : []),
288 ],
289 });
290 }
291 yield* sink.write({
292 events: [
293 {
294 id: EventId.make("partial-message"),
295 type: "message.updated",
296 threadId,
297 runId: run.id,
298 occurredAt: now,
299 payload: {
300 id: messageId,
301 threadId,
302 runId: run.id,
303 nodeId: node.id,
304 role: "assistant",
305 text: "Partial output",
306 attachments: [],
307 streaming: true,
308 createdBy: "agent",
309 creationSource: "provider",
310 createdAt: now,
311 updatedAt: now,
312 },
313 },
314 {
315 id: EventId.make("partial-item"),
316 type: "turn-item.updated",
317 threadId,
318 runId: run.id,
319 occurredAt: now,
320 payload: {
321 ...item,
322 providerThreadId: codexTurn.providerThreadId,
323 providerTurnId: codexTurn.id,
324 id: TurnItemId.make("partial-output"),
325 type: "assistant_message",
326 messageId,
327 text: "Partial output",
328 streaming: true,
329 },
330 },
331 ],
332 });
333 if (stalledRun === "superseded-attempt") {
334 yield* sink.write({
335 events: [
336 {
337 id: EventId.make("new-attempt"),
338 type: "run.updated",
339 threadId,
340 occurredAt: now,
341 payload: { ...run, activeAttemptId: RunAttemptId.make("new-attempt") },
342 },
343 ],
344 });
345 }
346 yield* orchestrator.dispatch(
347 stalledRun === "superseded-attempt"
348 ? {
349 type: "thread.background-work.settle",
350 commandId: CommandId.make("late-settle"),
351 threadId,
352 providerThreadId: codexTurn.providerThreadId,
353 providerTurnId: codexTurn.id,
354 }
355 : {
356 type: "thread.stop",
357 commandId: CommandId.make("stop-stalled-run"),
358 threadId,
359 },
360 );
361 yield* worker.drain();
362 const after = yield* orchestrator.getThreadProjection(threadId);
363 const interrupted = stalledRun !== "superseded-attempt";
364 assert.equal(after.runs[0]?.status, interrupted ? "interrupted" : "running");
365 assert.equal(after.attempts[0]?.status, interrupted ? "interrupted" : "running");
366 assert.equal(
367 after.providerTurns[0]?.status,
368 terminalProviderTurn ? "completed" : interrupted ? "interrupted" : "running",
369 );
370 assert.equal(
371 after.nodes.find((candidate) => candidate.id === node.id)?.status,
372 interrupted ? "interrupted" : "running",
373 );
374 const output = after.messages.find((message) => message.id === messageId)!;
375 assert.equal(output.streaming, !interrupted);
376 assert.equal(output.text, "Partial output");
377 assert.equal(
378 after.turnItems.find((candidate) => candidate.id === devServerId)?.status,
379 stalledRun === "missing-session-terminal"
380 ? "completed"
381 : interrupted
382 ? "interrupted"
383 : "running",
384 );
385 assert.equal(
386 after.turnItems.find((candidate) => candidate.type === "assistant_message")?.status,
387 interrupted ? "interrupted" : "running",
388 );
389 assert.equal(
390 after.turnItems.filter((candidate) => candidate.type === "run_interrupt_result").length,
391 interrupted ? 1 : 0,
392 );
393 assert.isEmpty(after.runs.filter((candidate) => candidate.status === "waiting"));
394 return;
395 }
396 const settled = yield* watch(
397 (event) =>
398 event.type === "run.updated" &&
399 event.payload.id === first.runId &&
400 event.payload.status === "waiting",
401 );
402 yield* Queue.offer(events, {
403 type: "provider_turn.updated",
404 driver,
405 providerTurn: { ...codexTurn, status: "completed", completedAt: now },
406 });
407 yield* Queue.offer(events, {
408 type: "turn.terminal",
409 driver,
410 providerThreadId: codexTurn.providerThreadId,
411 providerTurnId: codexTurn.id,
412 runOrdinal: first.runOrdinal,
413 status: "completed",
414 failure: null,
415 threadDisposition: "reusable",
416 });
417 yield* Fiber.join(settled);
418 yield* worker.drain();
419
420 const codexProviderThread = (yield* orchestrator.getThreadProjection(threadId))
421 .providerThreads[0]!;
422 // A settled run with its root node, attempt, provider turn and,
423 // optionally, a command or native subagent it left running.
424 const settledRun = (input: {
425 readonly ordinal: number;
426 readonly providerThreadId: ProviderThreadId;
427 readonly runningItem?: {
428 readonly id: TurnItemId;
429 readonly kind: "command" | "subagent";
430 };
431 }) => {
432 const runId = RunId.make(`run:${input.ordinal}`);
433 const attemptId = RunAttemptId.make(`attempt:${input.ordinal}`);
434 const nodeId = NodeId.make(`node:${input.ordinal}`);
435 const providerTurnId = ProviderTurnId.make(`provider-turn:${input.ordinal}`);
436 const events: Array<OrchestrationV2DomainEvent> = [
437 {
438 id: EventId.make(`run:${input.ordinal}`),
439 type: "run.created",
440 threadId,
441 occurredAt: now,
442 payload: {
443 id: runId,
444 threadId,
445 ordinal: input.ordinal,
446 providerInstanceId: instanceId,
447 modelSelection,
448 providerThreadId: input.providerThreadId,
449 userMessageId: MessageId.make(`message:${input.ordinal}`),
450 rootNodeId: nodeId,
451 activeAttemptId: attemptId,
452 status: "completed",
453 requestedAt: now,
454 startedAt: now,
455 completedAt: now,
456 checkpointId: null,
457 contextHandoffId: null,
458 },
459 },
460 {
461 id: EventId.make(`node:${input.ordinal}`),
462 type: "node.updated",
463 threadId,
464 runId,
465 occurredAt: now,
466 payload: {
467 id: nodeId,
468 threadId,
469 runId,
470 parentNodeId: null,
471 rootNodeId: nodeId,
472 kind: "root_turn",
473 status: "completed",
474 countsForRun: true,
475 providerThreadId: input.providerThreadId,
476 providerTurnId,
477 nativeItemRef: null,
478 runtimeRequestId: null,
479 checkpointScopeId: null,
480 startedAt: now,
481 completedAt: now,
482 },
483 },
484 {
485 id: EventId.make(`attempt:${input.ordinal}`),
486 type: "run-attempt.created",
487 threadId,
488 occurredAt: now,
489 payload: {
490 id: attemptId,
491 runId,
492 attemptOrdinal: 1,
493 rootNodeId: nodeId,
494 providerInstanceId: instanceId,
495 providerThreadId: input.providerThreadId,
496 providerTurnId,
497 reason: "initial",
498 status: "completed",
499 startedAt: now,
500 completedAt: now,
501 },
502 },
503 {
504 id: EventId.make(`provider-turn:${input.ordinal}`),
505 type: "provider-turn.updated",
506 threadId,
507 occurredAt: now,
508 payload: {
509 id: providerTurnId,
510 providerThreadId: input.providerThreadId,
511 nodeId,
512 runAttemptId: attemptId,
513 nativeTurnRef: null,
514 ordinal: input.ordinal,
515 status: "completed",
516 startedAt: now,
517 completedAt: now,
518 },
519 },
520 ];
521 const item = input.runningItem;
522 if (item !== undefined) {
523 const base = {
524 id: item.id,
525 threadId,
526 runId,
527 nodeId,
528 providerThreadId: input.providerThreadId,
529 providerTurnId,
530 nativeItemRef: null,
531 parentItemId: null,
532 ordinal: input.ordinal * 100,
533 status: "running",
534 title: null,
535 startedAt: now,
536 completedAt: null,
537 updatedAt: now,
538 } as const;
539 events.push({
540 id: EventId.make(`item:${input.ordinal}`),
541 type: "turn-item.updated",
542 threadId,
543 runId,
544 occurredAt: now,
545 payload:
546 item.kind === "command"
547 ? { ...base, type: "command_execution", input: "vp run test --watch" }
548 : {
549 ...base,
550 // A native subagent item names its own provider thread
551 // but its parent's provider turn.
552 providerThreadId: ProviderThreadId.make("provider-thread:codex-subagent"),
553 type: "subagent",
554 subagentId: NodeId.make(`subagent:${input.ordinal}`),
555 origin: "provider_native",
556 driver,
557 providerInstanceId: instanceId,
558 childThreadId: null,
559 prompt: "Review the change",
560 result: null,
561 },
562 });
563 }
564 return { runId, providerTurnId, events };
565 };
566
567 // Later Codex runs leave a second command and a native subagent. Then
568 // the thread moves on to another provider thread, which also has a
569 // live session.
570 const watcherId = TurnItemId.make("turn-item:watcher");
571 const otherProviderThreadId = ProviderThreadId.make("provider-thread:other");
572 const watcherRun = settledRun({
573 ordinal: 2,
574 providerThreadId: olderStart ? otherProviderThreadId : codexProviderThread.id,
575 ...(olderStart ? {} : { runningItem: { id: watcherId, kind: "command" as const } }),
576 });
577 const reviewerId = TurnItemId.make("turn-item:reviewer");
578 const reviewerRun = settledRun({
579 ordinal: 3,
580 providerThreadId: codexProviderThread.id,
581 runningItem: { id: reviewerId, kind: "subagent" },
582 });
583 const latestRun = settledRun({ ordinal: 4, providerThreadId: otherProviderThreadId });
584 yield* sink.write({
585 events: [
586 ...watcherRun.events,
587 ...reviewerRun.events,
588 {
589 id: EventId.make("provider-thread:other"),
590 type: "provider-thread.updated",
591 threadId,
592 occurredAt: now,
593 payload: {
594 ...codexProviderThread,
595 id: otherProviderThreadId,
596 firstRunOrdinal: 4,
597 lastRunOrdinal: 4,
598 },
599 },
600 ...latestRun.events,
601 ],
602 });
603
604 const failedRun = settledRun({ ordinal: 5, providerThreadId: otherProviderThreadId });
605 if (failedStart) {
606 yield* sink.write({
607 events: failedRun.events.flatMap((event): Array<OrchestrationV2DomainEvent> => {
608 switch (event.type) {
609 case "provider-turn.updated":
610 return [];
611 case "run.created":
612 return [{ ...event, payload: { ...event.payload, status: "failed" } }];
613 case "node.updated":
614 return [
615 {
616 ...event,
617 payload: { ...event.payload, status: "failed", providerTurnId: null },
618 },
619 ];
620 case "run-attempt.created":
621 return [
622 {
623 ...event,
624 payload: { ...event.payload, status: "failed", providerTurnId: null },
625 },
626 ];
627 default:
628 return [event];
629 }
630 }),
631 });
632 }
633
634 if (stopWithQueue !== undefined) {
635 const owner = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
636 (run) => run.id === latestRun.runId,
637 )!;
638 // A message queues while checkpointing finishes, then the user holds the queue.
639 yield* sink.write({
640 events: [
641 {
642 id: EventId.make("latest-run-waiting"),
643 type: "run.updated",
644 threadId,
645 runId: owner.id,
646 occurredAt: now,
647 payload: { ...owner, status: "waiting", completedAt: null },
648 },
649 ],
650 });
651 yield* orchestrator.dispatch({
652 type: "message.dispatch",
653 commandId: CommandId.make("queue-follow-up"),
654 threadId,
655 messageId: MessageId.make("message:queue-follow-up"),
656 text: "Follow up after the background work",
657 attachments: [],
658 dispatchMode: { type: "queue_after_active" },
659 createdBy: "user",
660 creationSource: "web",
661 });
662 const queued = (yield* orchestrator.getThreadProjection(threadId)).runs.at(-1)!;
663 assert.equal(queued.status, "queued");
664 yield* sink.write({
665 events: [
666 {
667 id: EventId.make("queue-held"),
668 type: "run.updated",
669 threadId,
670 runId: queued.id,
671 occurredAt: now,
672 payload: { ...queued, queueHeld: true },
673 },
674 {
675 id: EventId.make("latest-run-settled"),
676 type: "run.updated",
677 threadId,
678 runId: owner.id,
679 occurredAt: now,
680 payload: owner,
681 },
682 ],
683 });
684 }
685
686 if (olderStart) {
687 const older = (yield* orchestrator.getThreadProjection(threadId)).runs.find(
688 (run) => run.id === watcherRun.runId,
689 )!;
690 // A resumed queue can start a lower-ordinal run after later runs have ended.
691 yield* sink.write({
692 events: [
693 {
694 id: EventId.make("older-run-starting"),
695 type: "run.updated",
696 threadId,
697 runId: older.id,
698 occurredAt: now,
699 payload: { ...older, status: "starting", startedAt: null, completedAt: null },
700 },
701 ],
702 });
703 }
704
705 yield* orchestrator.dispatch(
706 stopWithQueue === "thread.stop"
707 ? {
708 type: "thread.stop",
709 commandId: CommandId.make("stop-background-work"),
710 threadId,
711 }
712 : {
713 type: "run.interrupt",
714 commandId: CommandId.make("stop-background-work"),
715 threadId,
716 runId: olderStart
717 ? watcherRun.runId
718 : failedStart
719 ? failedRun.runId
720 : latestRun.runId,
721 ...(stopWithQueue === undefined ? {} : { holdQueue: true }),
722 },
723 );
724 yield* worker.drain();
725
726 // The Codex interrupt targets its latest pending work, the subagent's parent turn,
727 // so its settlement covers the Codex background work.
728 assert.sameDeepMembers(
729 interrupts.map((interrupt) => [interrupt.providerThread.id, interrupt.providerTurnId]),
730 [
731 ...(olderStart ? [] : [[otherProviderThreadId, latestRun.providerTurnId]]),
732 [codexProviderThread.id, reviewerRun.providerTurnId],
733 ],
734 );
735 const after = yield* orchestrator.getThreadProjection(threadId);
736 if (olderStart) {
737 assert.equal(
738 after.runs.find((run) => run.id === watcherRun.runId)?.status,
739 "interrupted",
740 );
741 }
742 if (stopWithQueue !== undefined) {
743 assert.equal(after.runs.at(-1)?.status, "queued");
744 assert.equal(after.runs.at(-1)?.queueHeld, true);
745 assert.lengthOf(started, 1);
746 }
747 assert.deepEqual(
748 [devServerId, ...(olderStart ? [] : [watcherId]), reviewerId].map(
749 (id) => after.turnItems.find((item) => item.id === id)?.status,
750 ),
751 olderStart
752 ? ["interrupted", "interrupted"]
753 : ["interrupted", "interrupted", "interrupted"],
754 );
755 }).pipe(
756 Effect.provide(
757 ProviderReplayHarness.layerWithRegistry(
758 { name: "background-work-stop" },
759 ProviderAdapterRegistry.layerSingle(adapter),
760 { runEffectWorker: false },
761 ),
762 ),
763 );
764 }),
765 );
766
767it.effect("Stop reaches background work an earlier provider thread still runs", () =>
768 stopEarlierBackgroundWork({}),
769);
770
771it.effect(
772 "Stop reaches earlier background work after the newest run fails before provider start",
773 () => stopEarlierBackgroundWork({ failedStart: true }),
774);
775
776it.effect.each(["thread.stop", "run.interrupt"] as const)(
777 "%s stops background work when a later message is queued",
778 (stopType) => stopEarlierBackgroundWork({ stopWithQueue: stopType }),
779);
780
781it.effect.each(["thread.stop", "run.interrupt"] as const)(
782 "%s reaches later background work when an older run is starting",
783 (stopType) => stopEarlierBackgroundWork({ stopWithQueue: stopType, olderStart: true }),
784);
785
786it.effect.each([
787 "missing-session",
788 "missing-session-terminal",
789 "returned-interrupt",
790 "returned-interrupt-terminal",
791 "superseded-attempt",
792] as const)("Stop recovers a stalled run after %s without changing a newer attempt", (stalledRun) =>
793 stopEarlierBackgroundWork({ stalledRun }),
794);