Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import {
3 ProjectId,
4 ThreadId,
5 TurnId,
6 ProviderDriverKind,
7 ProviderInstanceId,
8} from "@t3tools/contracts";
9import * as Clock from "effect/Clock";
10import * as Deferred from "effect/Deferred";
11import * as Effect from "effect/Effect";
12import * as Exit from "effect/Exit";
13import * as Layer from "effect/Layer";
14import * as ManagedRuntime from "effect/ManagedRuntime";
15import * as Option from "effect/Option";
16import * as Scope from "effect/Scope";
17import * as Stream from "effect/Stream";
18import { afterEach, describe, expect, it, vi } from "vite-plus/test";
19
20import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
21import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
22import * as ProviderSessionRuntime from "../../persistence/ProviderSessionRuntime.ts";
23import { ProviderValidationError } from "../Errors.ts";
24import { ProviderSessionReaper } from "../Services/ProviderSessionReaper.ts";
25import { ProviderService, type ProviderServiceShape } from "../Services/ProviderService.ts";
26import { ProviderSessionDirectoryLive } from "./ProviderSessionDirectory.ts";
27import { makeProviderSessionReaperLive } from "./ProviderSessionReaper.ts";
28
29const defaultModelSelection = {
30 instanceId: ProviderInstanceId.make("codex"),
31 model: "gpt-5-codex",
32} as const;
33
34async function waitFor(
35 predicate: () => boolean | Promise<boolean>,
36 timeoutMs = 2_000,
37): Promise<void> {
38 const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
39 const poll = async (): Promise<void> => {
40 if (await predicate()) {
41 return;
42 }
43 if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
44 throw new Error("Timed out waiting for expectation.");
45 }
46 await Effect.runPromise(Effect.yieldNow);
47 return poll();
48 };
49
50 return poll();
51}
52
53const drainFibers = Effect.forEach(Array.from({ length: 10 }), () => Effect.yieldNow, {
54 discard: true,
55});
56
57const unsupported = () => Effect.die(new Error("Unsupported provider call in test")) as never;
58
59function makeReadModel(
60 threads: ReadonlyArray<{
61 readonly id: ThreadId;
62 readonly session: {
63 readonly threadId: ThreadId;
64 readonly status: "starting" | "running" | "ready" | "interrupted" | "stopped" | "error";
65 readonly providerName: "codex" | "claudeAgent";
66 readonly runtimeMode: "approval-required" | "full-access" | "auto-accept-edits";
67 readonly activeTurnId: TurnId | null;
68 readonly lastError: string | null;
69 readonly updatedAt: string;
70 } | null;
71 readonly backgroundLiveness?: "working" | "monitoring" | null;
72 }>,
73) {
74 const now = "2026-01-01T00:00:00.000Z";
75 const projectId = ProjectId.make("project-provider-session-reaper");
76
77 return {
78 snapshotSequence: 0,
79 updatedAt: now,
80 projects: [
81 {
82 id: projectId,
83 title: "Provider Reaper Project",
84 workspaceRoot: "/tmp/provider-reaper-project",
85 defaultModelSelection,
86 scripts: [],
87 createdAt: now,
88 updatedAt: now,
89 deletedAt: null,
90 },
91 ],
92 threads: threads.map((thread) => ({
93 id: thread.id,
94 projectId,
95 title: `Thread ${thread.id}`,
96 modelSelection: defaultModelSelection,
97 interactionMode: "default" as const,
98 runtimeMode: "full-access" as const,
99 branch: null,
100 worktreePath: null,
101 pullRequests: [],
102 createdAt: now,
103 updatedAt: now,
104 archivedAt: null,
105 settledOverride: null,
106 settledAt: null,
107 latestUserMessageAt: null,
108 hasPendingApprovals: false,
109 hasPendingUserInput: false,
110 hasActionableProposedPlan: false,
111 latestTurn: null,
112 messages: [],
113 session: thread.session,
114 backgroundLiveness: thread.backgroundLiveness ?? null,
115 activities: [],
116 proposedPlans: [],
117 checkpoints: [],
118 deletedAt: null,
119 })),
120 };
121}
122
123describe("ProviderSessionReaper", () => {
124 let runtime: ManagedRuntime.ManagedRuntime<
125 ProviderSessionReaper | ProviderSessionRuntime.ProviderSessionRuntimeRepository,
126 unknown
127 > | null = null;
128 let scope: Scope.Closeable | null = null;
129
130 afterEach(async () => {
131 if (scope) {
132 await Effect.runPromise(Scope.close(scope, Exit.void));
133 }
134 scope = null;
135 if (runtime) {
136 await runtime.dispose();
137 }
138 runtime = null;
139 });
140
141 // Shared start sequence so each test adds no manual Effect runners
142 // (no-manual-effect-runtime-in-tests tracks this file's legacy count).
143 async function startReaper() {
144 await runtime!.runPromise(
145 Effect.gen(function* () {
146 const reaper = yield* ProviderSessionReaper;
147 scope = yield* Scope.make("sequential");
148 yield* reaper.start().pipe(Scope.provide(scope));
149 }),
150 );
151 }
152
153 async function sweepAt(nowMs: number) {
154 await runtime!.runPromise(
155 Effect.gen(function* () {
156 const reaper = yield* ProviderSessionReaper;
157 const clock = yield* Clock.Clock;
158 const swept = yield* Deferred.make<void>();
159 yield* reaper.start().pipe(
160 Effect.provideService(Clock.Clock, {
161 currentTimeMillis: Effect.succeed(nowMs),
162 currentTimeMillisUnsafe: () => nowMs,
163 currentTimeNanos: Effect.succeed(BigInt(nowMs) * 1_000_000n),
164 currentTimeNanosUnsafe: () => BigInt(nowMs) * 1_000_000n,
165 monotonicTimeNanos: clock.monotonicTimeNanos,
166 monotonicTimeNanosUnsafe: () => clock.monotonicTimeNanosUnsafe(),
167 // Reaching the next scheduled sleep proves this sweep has finished.
168 sleep: () => Deferred.succeed(swept, undefined).pipe(Effect.andThen(Effect.never)),
169 }),
170 );
171 yield* Deferred.await(swept);
172 }).pipe(Effect.scoped),
173 );
174 }
175
176 async function createHarness(input: {
177 readonly readModel: ReturnType<typeof makeReadModel>;
178 readonly stopSessionImplementation?: (input: {
179 readonly threadId: ThreadId;
180 }) => ReturnType<ProviderServiceShape["stopSession"]>;
181 }) {
182 const stoppedThreadIds = new Set<ThreadId>();
183 const stopSession = vi.fn<ProviderServiceShape["stopSession"]>(
184 (request) =>
185 (input.stopSessionImplementation
186 ? input.stopSessionImplementation(request)
187 : Effect.sync(() => {
188 stoppedThreadIds.add(request.threadId);
189 })) as ReturnType<ProviderServiceShape["stopSession"]>,
190 );
191
192 const providerService: ProviderServiceShape = {
193 startSession: () => unsupported(),
194 sendTurn: () => unsupported(),
195 compactThread: () => unsupported(),
196 interruptTurn: () => unsupported(),
197 respondToRequest: () => unsupported(),
198 respondToUserInput: () => unsupported(),
199 stopSession,
200 listSessions: () => Effect.succeed([]),
201 getCapabilities: () => Effect.succeed({ sessionModelSwitch: "in-session" }),
202 assertConversationRollbackSupported: () => unsupported(),
203 getInstanceInfo: (instanceId) => {
204 const driverKind = ProviderDriverKind.make(String(instanceId));
205 return Effect.succeed({
206 instanceId,
207 driverKind,
208 displayName: undefined,
209 enabled: true,
210 continuationIdentity: {
211 driverKind,
212 continuationKey: `${driverKind}:instance:${instanceId}`,
213 },
214 });
215 },
216 rollbackConversation: () => unsupported(),
217 uploadFeedback: () => unsupported(),
218 streamEvents: Stream.empty,
219 };
220
221 const runtimeRepositoryLayer = ProviderSessionRuntime.layer.pipe(
222 Layer.provide(SqlitePersistenceMemory),
223 );
224 const providerSessionDirectoryLayer = ProviderSessionDirectoryLive.pipe(
225 Layer.provide(runtimeRepositoryLayer),
226 );
227 const layer = makeProviderSessionReaperLive({
228 inactivityThresholdMs: 1_000,
229 sweepIntervalMs: 60_000,
230 }).pipe(
231 Layer.provideMerge(providerSessionDirectoryLayer),
232 Layer.provideMerge(runtimeRepositoryLayer),
233 Layer.provideMerge(Layer.succeed(ProviderService, providerService)),
234 Layer.provideMerge(
235 Layer.succeed(ProjectionSnapshotQuery, {
236 getUserInputActivity: () => Effect.die("unused"),
237 listActivitiesByKind: () => Effect.die("unused"),
238 getCommandReadModel: () => Effect.die("unused"),
239 getSnapshot: () => Effect.die("unused"),
240 getShellSnapshot: () => Effect.die("unused"),
241 getDeletedWorktreeThreads: () => Effect.die("unused"),
242 listThreadsWithPullRequests: () => Effect.die("unused"),
243 getArchivedShellSnapshot: () => Effect.die("unused"),
244 getSnapshotSequence: () =>
245 Effect.succeed({ snapshotSequence: input.readModel.snapshotSequence }),
246 getCounts: () => Effect.die("unused"),
247 getEventReplayStats: () => Effect.die("unused"),
248 getActiveProjectByWorkspaceRoot: () => Effect.die("unused"),
249 getProjectShells: () => Effect.die("unused"),
250 getProjectShellById: () => Effect.die("unused"),
251 getFirstActiveThreadIdByProjectId: () => Effect.die("unused"),
252 getImportedAgentSessionSources: () => Effect.die("unused"),
253 getThreadCheckpointContext: () => Effect.die("unused"),
254 getFullThreadDiffContext: () => Effect.die("unused"),
255 getThreadRuntimeContext: () => Effect.die("unused"),
256 getTurnStartMessage: () => Effect.die("unused"),
257 getThreadShellById: (threadId) =>
258 Effect.succeed(
259 input.readModel.threads.find((thread) => thread.id === threadId)
260 ? Option.some(input.readModel.threads.find((thread) => thread.id === threadId)!)
261 : Option.none(),
262 ),
263 getThreadDetailById: () => Effect.die("unused"),
264 getThreadDetailSnapshot: () => Effect.die("unused"),
265 searchThreads: () => Effect.succeed({ matches: [] }),
266 }),
267 ),
268 Layer.provideMerge(NodeServices.layer),
269 );
270
271 runtime = ManagedRuntime.make(layer);
272 return { stopSession, stoppedThreadIds };
273 }
274
275 it("reaps stale persisted sessions without active turns", async () => {
276 const threadId = ThreadId.make("thread-reaper-stale");
277 const now = "2026-01-01T00:00:00.000Z";
278 const harness = await createHarness({
279 readModel: makeReadModel([
280 {
281 id: threadId,
282 session: {
283 threadId,
284 status: "ready",
285 providerName: "claudeAgent",
286 runtimeMode: "full-access",
287 activeTurnId: null,
288 lastError: null,
289 updatedAt: now,
290 },
291 },
292 ]),
293 });
294 const repository = await runtime!.runPromise(
295 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
296 );
297
298 await runtime!.runPromise(
299 repository.upsert({
300 threadId,
301 providerName: "claudeAgent",
302 providerInstanceId: null,
303 adapterKey: "claudeAgent",
304 runtimeMode: "full-access",
305 status: "running",
306 lastSeenAt: "2026-04-14T00:00:00.000Z",
307 resumeCursor: {
308 opaque: "resume-stale",
309 },
310 runtimePayload: null,
311 }),
312 );
313
314 await startReaper();
315
316 await waitFor(() => harness.stopSession.mock.calls.length === 1);
317
318 expect(harness.stopSession.mock.calls[0]?.[0]).toEqual({ threadId });
319 expect(harness.stoppedThreadIds.has(threadId)).toBe(true);
320 });
321
322 it("skips stale sessions when the thread still has an active turn", async () => {
323 const threadId = ThreadId.make("thread-reaper-active-turn");
324 const turnId = TurnId.make("turn-reaper-active");
325 const now = "2026-01-01T00:00:00.000Z";
326 const harness = await createHarness({
327 readModel: makeReadModel([
328 {
329 id: threadId,
330 session: {
331 threadId,
332 status: "running",
333 providerName: "claudeAgent",
334 runtimeMode: "full-access",
335 activeTurnId: turnId,
336 lastError: null,
337 updatedAt: now,
338 },
339 },
340 ]),
341 });
342 const repository = await runtime!.runPromise(
343 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
344 );
345
346 await runtime!.runPromise(
347 repository.upsert({
348 threadId,
349 providerName: "claudeAgent",
350 providerInstanceId: null,
351 adapterKey: "claudeAgent",
352 runtimeMode: "full-access",
353 status: "running",
354 lastSeenAt: "2026-04-14T00:00:00.000Z",
355 resumeCursor: {
356 opaque: "resume-active-turn",
357 },
358 runtimePayload: null,
359 }),
360 );
361
362 await startReaper();
363 await Effect.runPromise(drainFibers);
364
365 expect(harness.stopSession).not.toHaveBeenCalled();
366 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
367 expect(Option.isSome(remaining)).toBe(true);
368 });
369
370 it("skips stale sessions while background work is still live", async () => {
371 const threadId = ThreadId.make("thread-reaper-background-work");
372 const now = "2026-01-01T00:00:00.000Z";
373 const harness = await createHarness({
374 readModel: makeReadModel([
375 {
376 id: threadId,
377 session: {
378 threadId,
379 status: "ready",
380 providerName: "claudeAgent",
381 runtimeMode: "full-access",
382 activeTurnId: null,
383 lastError: null,
384 updatedAt: now,
385 },
386 backgroundLiveness: "working",
387 },
388 ]),
389 });
390 const repository = await runtime!.runPromise(
391 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
392 );
393
394 await runtime!.runPromise(
395 repository.upsert({
396 threadId,
397 providerName: "claudeAgent",
398 providerInstanceId: null,
399 adapterKey: "claudeAgent",
400 runtimeMode: "full-access",
401 status: "running",
402 lastSeenAt: "2026-04-14T00:00:00.000Z",
403 resumeCursor: {
404 opaque: "resume-background-work",
405 },
406 runtimePayload: null,
407 }),
408 );
409
410 await startReaper();
411 await Effect.runPromise(drainFibers);
412
413 expect(harness.stopSession).not.toHaveBeenCalled();
414 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
415 expect(Option.isSome(remaining)).toBe(true);
416 });
417
418 it.each(["ready", "interrupted", "error"] as const)(
419 "gives a long turn a full idle window after becoming %s",
420 async (status) => {
421 const threadId = ThreadId.make(`thread-reaper-long-turn-${status}`);
422 const startedAt = "2026-04-14T00:00:00.000Z";
423 const completedAt = "2026-04-14T01:00:00.000Z";
424 const completedAtMs = Date.parse(completedAt);
425 const readModel = makeReadModel([
426 {
427 id: threadId,
428 session: {
429 threadId,
430 status: "running",
431 providerName: "claudeAgent",
432 runtimeMode: "full-access",
433 activeTurnId: TurnId.make("turn-reaper-long"),
434 lastError: null,
435 updatedAt: startedAt,
436 },
437 },
438 ]);
439 const harness = await createHarness({ readModel });
440 const repository = await runtime!.runPromise(
441 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
442 );
443 await runtime!.runPromise(
444 repository.upsert({
445 threadId,
446 providerName: "claudeAgent",
447 providerInstanceId: null,
448 adapterKey: "claudeAgent",
449 runtimeMode: "full-access",
450 status: "running",
451 lastSeenAt: startedAt,
452 resumeCursor: { opaque: "resume-long-turn" },
453 runtimePayload: null,
454 }),
455 );
456
457 await sweepAt(completedAtMs);
458 expect(harness.stopSession).not.toHaveBeenCalled();
459
460 // Ingestion changes the timestamp and clears the active turn in the same session row.
461 readModel.threads[0]!.session = {
462 ...readModel.threads[0]!.session!,
463 status,
464 activeTurnId: null,
465 updatedAt: completedAt,
466 };
467 await sweepAt(completedAtMs);
468 expect(harness.stopSession).not.toHaveBeenCalled();
469 await sweepAt(completedAtMs + 999);
470 expect(harness.stopSession).not.toHaveBeenCalled();
471 await sweepAt(completedAtMs + 1_000);
472 expect(harness.stopSession).toHaveBeenCalledExactlyOnceWith({ threadId });
473 },
474 );
475
476 it.each([true, false])(
477 "uses the binding idle window when the session is older or missing, hasSession=%s",
478 async (hasSession) => {
479 const threadId = ThreadId.make("thread-reaper-fresh");
480 const now = "2026-04-14T01:00:00.000Z";
481 const nowMs = Date.parse(now);
482 const harness = await createHarness({
483 readModel: makeReadModel([
484 {
485 id: threadId,
486 session: hasSession
487 ? {
488 threadId,
489 status: "ready",
490 providerName: "claudeAgent",
491 runtimeMode: "full-access",
492 activeTurnId: null,
493 lastError: null,
494 updatedAt: "2026-04-14T00:00:00.000Z",
495 }
496 : null,
497 },
498 ]),
499 });
500 const repository = await runtime!.runPromise(
501 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
502 );
503 await runtime!.runPromise(
504 repository.upsert({
505 threadId,
506 providerName: "claudeAgent",
507 providerInstanceId: null,
508 adapterKey: "claudeAgent",
509 runtimeMode: "full-access",
510 status: "running",
511 lastSeenAt: now,
512 resumeCursor: { opaque: "resume-fresh" },
513 runtimePayload: null,
514 }),
515 );
516
517 await sweepAt(nowMs + 999);
518 expect(harness.stopSession).not.toHaveBeenCalled();
519 await sweepAt(nowMs + 1_000);
520 expect(harness.stopSession).toHaveBeenCalledExactlyOnceWith({ threadId });
521 },
522 );
523
524 it("skips persisted sessions that are already marked stopped", async () => {
525 const threadId = ThreadId.make("thread-reaper-stopped");
526 const now = "2026-01-01T00:00:00.000Z";
527 const harness = await createHarness({
528 readModel: makeReadModel([
529 {
530 id: threadId,
531 session: {
532 threadId,
533 status: "stopped",
534 providerName: "claudeAgent",
535 runtimeMode: "full-access",
536 activeTurnId: null,
537 lastError: null,
538 updatedAt: now,
539 },
540 },
541 ]),
542 });
543 const repository = await runtime!.runPromise(
544 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
545 );
546
547 await runtime!.runPromise(
548 repository.upsert({
549 threadId,
550 providerName: "claudeAgent",
551 providerInstanceId: null,
552 adapterKey: "claudeAgent",
553 runtimeMode: "full-access",
554 status: "stopped",
555 lastSeenAt: "2026-04-14T00:00:00.000Z",
556 resumeCursor: {
557 opaque: "resume-stopped",
558 },
559 runtimePayload: null,
560 }),
561 );
562
563 await startReaper();
564 await Effect.runPromise(drainFibers);
565
566 expect(harness.stopSession).not.toHaveBeenCalled();
567 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
568 expect(Option.isSome(remaining)).toBe(true);
569 });
570
571 it("continues reaping other sessions when one stop attempt fails", async () => {
572 const failedThreadId = ThreadId.make("thread-reaper-stop-failure");
573 const reapedThreadId = ThreadId.make("thread-reaper-stop-success");
574 const now = "2026-01-01T00:00:00.000Z";
575 const harness = await createHarness({
576 readModel: makeReadModel([
577 {
578 id: failedThreadId,
579 session: {
580 threadId: failedThreadId,
581 status: "ready",
582 providerName: "claudeAgent",
583 runtimeMode: "full-access",
584 activeTurnId: null,
585 lastError: null,
586 updatedAt: now,
587 },
588 },
589 {
590 id: reapedThreadId,
591 session: {
592 threadId: reapedThreadId,
593 status: "ready",
594 providerName: "codex",
595 runtimeMode: "full-access",
596 activeTurnId: null,
597 lastError: null,
598 updatedAt: now,
599 },
600 },
601 ]),
602 stopSessionImplementation: (request) =>
603 request.threadId === failedThreadId
604 ? Effect.fail(
605 new ProviderValidationError({
606 operation: "ProviderSessionReaper.test",
607 issue: "simulated stop failure",
608 }),
609 )
610 : Effect.void,
611 });
612 const repository = await runtime!.runPromise(
613 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
614 );
615
616 await runtime!.runPromise(
617 repository.upsert({
618 threadId: failedThreadId,
619 providerName: "claudeAgent",
620 providerInstanceId: null,
621 adapterKey: "claudeAgent",
622 runtimeMode: "full-access",
623 status: "running",
624 lastSeenAt: "2026-04-14T00:00:00.000Z",
625 resumeCursor: {
626 opaque: "resume-failure",
627 },
628 runtimePayload: null,
629 }),
630 );
631 await runtime!.runPromise(
632 repository.upsert({
633 threadId: reapedThreadId,
634 providerName: "codex",
635 providerInstanceId: null,
636 adapterKey: "codex",
637 runtimeMode: "full-access",
638 status: "running",
639 lastSeenAt: "2026-04-14T00:01:00.000Z",
640 resumeCursor: {
641 opaque: "resume-success",
642 },
643 runtimePayload: null,
644 }),
645 );
646
647 await startReaper();
648
649 await waitFor(() => harness.stopSession.mock.calls.length === 2);
650
651 expect(harness.stopSession.mock.calls.map(([request]) => request.threadId)).toEqual([
652 failedThreadId,
653 reapedThreadId,
654 ]);
655 });
656
657 it("continues reaping other sessions when one stop attempt defects", async () => {
658 const defectThreadId = ThreadId.make("thread-reaper-stop-defect");
659 const reapedThreadId = ThreadId.make("thread-reaper-stop-after-defect");
660 const now = "2026-01-01T00:00:00.000Z";
661 const harness = await createHarness({
662 readModel: makeReadModel([
663 {
664 id: defectThreadId,
665 session: {
666 threadId: defectThreadId,
667 status: "ready",
668 providerName: "claudeAgent",
669 runtimeMode: "full-access",
670 activeTurnId: null,
671 lastError: null,
672 updatedAt: now,
673 },
674 },
675 {
676 id: reapedThreadId,
677 session: {
678 threadId: reapedThreadId,
679 status: "ready",
680 providerName: "codex",
681 runtimeMode: "full-access",
682 activeTurnId: null,
683 lastError: null,
684 updatedAt: now,
685 },
686 },
687 ]),
688 stopSessionImplementation: (request) =>
689 request.threadId === defectThreadId
690 ? Effect.die(new Error("simulated stop defect"))
691 : Effect.void,
692 });
693 const repository = await runtime!.runPromise(
694 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
695 );
696
697 await runtime!.runPromise(
698 repository.upsert({
699 threadId: defectThreadId,
700 providerName: "claudeAgent",
701 providerInstanceId: null,
702 adapterKey: "claudeAgent",
703 runtimeMode: "full-access",
704 status: "running",
705 lastSeenAt: "2026-04-14T00:00:00.000Z",
706 resumeCursor: {
707 opaque: "resume-defect",
708 },
709 runtimePayload: null,
710 }),
711 );
712 await runtime!.runPromise(
713 repository.upsert({
714 threadId: reapedThreadId,
715 providerName: "codex",
716 providerInstanceId: null,
717 adapterKey: "codex",
718 runtimeMode: "full-access",
719 status: "running",
720 lastSeenAt: "2026-04-14T00:01:00.000Z",
721 resumeCursor: {
722 opaque: "resume-after-defect",
723 },
724 runtimePayload: null,
725 }),
726 );
727
728 await startReaper();
729
730 await waitFor(() => harness.stopSession.mock.calls.length === 2);
731
732 expect(harness.stopSession.mock.calls.map(([request]) => request.threadId)).toEqual([
733 defectThreadId,
734 reapedThreadId,
735 ]);
736 });
737});