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 sessionCommand: () => unsupported(),
219 streamEvents: Stream.empty,
220 };
221
222 const runtimeRepositoryLayer = ProviderSessionRuntime.layer.pipe(
223 Layer.provide(SqlitePersistenceMemory),
224 );
225 const providerSessionDirectoryLayer = ProviderSessionDirectoryLive.pipe(
226 Layer.provide(runtimeRepositoryLayer),
227 );
228 const layer = makeProviderSessionReaperLive({
229 inactivityThresholdMs: 1_000,
230 sweepIntervalMs: 60_000,
231 }).pipe(
232 Layer.provideMerge(providerSessionDirectoryLayer),
233 Layer.provideMerge(runtimeRepositoryLayer),
234 Layer.provideMerge(Layer.succeed(ProviderService, providerService)),
235 Layer.provideMerge(
236 Layer.succeed(ProjectionSnapshotQuery, {
237 getUserInputActivity: () => Effect.die("unused"),
238 listActivitiesByKind: () => Effect.die("unused"),
239 getCommandReadModel: () => Effect.die("unused"),
240 getSnapshot: () => Effect.die("unused"),
241 getShellSnapshot: () => Effect.die("unused"),
242 getDeletedWorktreeThreads: () => Effect.die("unused"),
243 listThreadsWithPullRequests: () => Effect.die("unused"),
244 getArchivedShellSnapshot: () => Effect.die("unused"),
245 getSnapshotSequence: () =>
246 Effect.succeed({ snapshotSequence: input.readModel.snapshotSequence }),
247 getCounts: () => Effect.die("unused"),
248 getEventReplayStats: () => Effect.die("unused"),
249 getActiveProjectByWorkspaceRoot: () => Effect.die("unused"),
250 getProjectShells: () => Effect.die("unused"),
251 getProjectShellById: () => Effect.die("unused"),
252 getFirstActiveThreadIdByProjectId: () => Effect.die("unused"),
253 getImportedAgentSessionSources: () => Effect.die("unused"),
254 getThreadCheckpointContext: () => Effect.die("unused"),
255 getFullThreadDiffContext: () => Effect.die("unused"),
256 getThreadRuntimeContext: () => Effect.die("unused"),
257 getTurnStartMessage: () => Effect.die("unused"),
258 getThreadShellById: (threadId) =>
259 Effect.succeed(
260 input.readModel.threads.find((thread) => thread.id === threadId)
261 ? Option.some(input.readModel.threads.find((thread) => thread.id === threadId)!)
262 : Option.none(),
263 ),
264 getThreadDetailById: () => Effect.die("unused"),
265 getThreadDetailSnapshot: () => Effect.die("unused"),
266 searchThreads: () => Effect.succeed({ matches: [] }),
267 }),
268 ),
269 Layer.provideMerge(NodeServices.layer),
270 );
271
272 runtime = ManagedRuntime.make(layer);
273 return { stopSession, stoppedThreadIds };
274 }
275
276 it("reaps stale persisted sessions without active turns", async () => {
277 const threadId = ThreadId.make("thread-reaper-stale");
278 const now = "2026-01-01T00:00:00.000Z";
279 const harness = await createHarness({
280 readModel: makeReadModel([
281 {
282 id: threadId,
283 session: {
284 threadId,
285 status: "ready",
286 providerName: "claudeAgent",
287 runtimeMode: "full-access",
288 activeTurnId: null,
289 lastError: null,
290 updatedAt: now,
291 },
292 },
293 ]),
294 });
295 const repository = await runtime!.runPromise(
296 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
297 );
298
299 await runtime!.runPromise(
300 repository.upsert({
301 threadId,
302 providerName: "claudeAgent",
303 providerInstanceId: null,
304 adapterKey: "claudeAgent",
305 runtimeMode: "full-access",
306 status: "running",
307 lastSeenAt: "2026-04-14T00:00:00.000Z",
308 resumeCursor: {
309 opaque: "resume-stale",
310 },
311 runtimePayload: null,
312 }),
313 );
314
315 await startReaper();
316
317 await waitFor(() => harness.stopSession.mock.calls.length === 1);
318
319 expect(harness.stopSession.mock.calls[0]?.[0]).toEqual({ threadId });
320 expect(harness.stoppedThreadIds.has(threadId)).toBe(true);
321 });
322
323 it("skips stale sessions when the thread still has an active turn", async () => {
324 const threadId = ThreadId.make("thread-reaper-active-turn");
325 const turnId = TurnId.make("turn-reaper-active");
326 const now = "2026-01-01T00:00:00.000Z";
327 const harness = await createHarness({
328 readModel: makeReadModel([
329 {
330 id: threadId,
331 session: {
332 threadId,
333 status: "running",
334 providerName: "claudeAgent",
335 runtimeMode: "full-access",
336 activeTurnId: turnId,
337 lastError: null,
338 updatedAt: now,
339 },
340 },
341 ]),
342 });
343 const repository = await runtime!.runPromise(
344 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
345 );
346
347 await runtime!.runPromise(
348 repository.upsert({
349 threadId,
350 providerName: "claudeAgent",
351 providerInstanceId: null,
352 adapterKey: "claudeAgent",
353 runtimeMode: "full-access",
354 status: "running",
355 lastSeenAt: "2026-04-14T00:00:00.000Z",
356 resumeCursor: {
357 opaque: "resume-active-turn",
358 },
359 runtimePayload: null,
360 }),
361 );
362
363 await startReaper();
364 await Effect.runPromise(drainFibers);
365
366 expect(harness.stopSession).not.toHaveBeenCalled();
367 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
368 expect(Option.isSome(remaining)).toBe(true);
369 });
370
371 it("skips stale sessions while background work is still live", async () => {
372 const threadId = ThreadId.make("thread-reaper-background-work");
373 const now = "2026-01-01T00:00:00.000Z";
374 const harness = await createHarness({
375 readModel: makeReadModel([
376 {
377 id: threadId,
378 session: {
379 threadId,
380 status: "ready",
381 providerName: "claudeAgent",
382 runtimeMode: "full-access",
383 activeTurnId: null,
384 lastError: null,
385 updatedAt: now,
386 },
387 backgroundLiveness: "working",
388 },
389 ]),
390 });
391 const repository = await runtime!.runPromise(
392 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
393 );
394
395 await runtime!.runPromise(
396 repository.upsert({
397 threadId,
398 providerName: "claudeAgent",
399 providerInstanceId: null,
400 adapterKey: "claudeAgent",
401 runtimeMode: "full-access",
402 status: "running",
403 lastSeenAt: "2026-04-14T00:00:00.000Z",
404 resumeCursor: {
405 opaque: "resume-background-work",
406 },
407 runtimePayload: null,
408 }),
409 );
410
411 await startReaper();
412 await Effect.runPromise(drainFibers);
413
414 expect(harness.stopSession).not.toHaveBeenCalled();
415 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
416 expect(Option.isSome(remaining)).toBe(true);
417 });
418
419 it.each(["ready", "interrupted", "error"] as const)(
420 "gives a long turn a full idle window after becoming %s",
421 async (status) => {
422 const threadId = ThreadId.make(`thread-reaper-long-turn-${status}`);
423 const startedAt = "2026-04-14T00:00:00.000Z";
424 const completedAt = "2026-04-14T01:00:00.000Z";
425 const completedAtMs = Date.parse(completedAt);
426 const readModel = makeReadModel([
427 {
428 id: threadId,
429 session: {
430 threadId,
431 status: "running",
432 providerName: "claudeAgent",
433 runtimeMode: "full-access",
434 activeTurnId: TurnId.make("turn-reaper-long"),
435 lastError: null,
436 updatedAt: startedAt,
437 },
438 },
439 ]);
440 const harness = await createHarness({ readModel });
441 const repository = await runtime!.runPromise(
442 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
443 );
444 await runtime!.runPromise(
445 repository.upsert({
446 threadId,
447 providerName: "claudeAgent",
448 providerInstanceId: null,
449 adapterKey: "claudeAgent",
450 runtimeMode: "full-access",
451 status: "running",
452 lastSeenAt: startedAt,
453 resumeCursor: { opaque: "resume-long-turn" },
454 runtimePayload: null,
455 }),
456 );
457
458 await sweepAt(completedAtMs);
459 expect(harness.stopSession).not.toHaveBeenCalled();
460
461 // Ingestion changes the timestamp and clears the active turn in the same session row.
462 readModel.threads[0]!.session = {
463 ...readModel.threads[0]!.session!,
464 status,
465 activeTurnId: null,
466 updatedAt: completedAt,
467 };
468 await sweepAt(completedAtMs);
469 expect(harness.stopSession).not.toHaveBeenCalled();
470 await sweepAt(completedAtMs + 999);
471 expect(harness.stopSession).not.toHaveBeenCalled();
472 await sweepAt(completedAtMs + 1_000);
473 expect(harness.stopSession).toHaveBeenCalledExactlyOnceWith({ threadId });
474 },
475 );
476
477 it.each([true, false])(
478 "uses the binding idle window when the session is older or missing, hasSession=%s",
479 async (hasSession) => {
480 const threadId = ThreadId.make("thread-reaper-fresh");
481 const now = "2026-04-14T01:00:00.000Z";
482 const nowMs = Date.parse(now);
483 const harness = await createHarness({
484 readModel: makeReadModel([
485 {
486 id: threadId,
487 session: hasSession
488 ? {
489 threadId,
490 status: "ready",
491 providerName: "claudeAgent",
492 runtimeMode: "full-access",
493 activeTurnId: null,
494 lastError: null,
495 updatedAt: "2026-04-14T00:00:00.000Z",
496 }
497 : null,
498 },
499 ]),
500 });
501 const repository = await runtime!.runPromise(
502 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
503 );
504 await runtime!.runPromise(
505 repository.upsert({
506 threadId,
507 providerName: "claudeAgent",
508 providerInstanceId: null,
509 adapterKey: "claudeAgent",
510 runtimeMode: "full-access",
511 status: "running",
512 lastSeenAt: now,
513 resumeCursor: { opaque: "resume-fresh" },
514 runtimePayload: null,
515 }),
516 );
517
518 await sweepAt(nowMs + 999);
519 expect(harness.stopSession).not.toHaveBeenCalled();
520 await sweepAt(nowMs + 1_000);
521 expect(harness.stopSession).toHaveBeenCalledExactlyOnceWith({ threadId });
522 },
523 );
524
525 it("skips persisted sessions that are already marked stopped", async () => {
526 const threadId = ThreadId.make("thread-reaper-stopped");
527 const now = "2026-01-01T00:00:00.000Z";
528 const harness = await createHarness({
529 readModel: makeReadModel([
530 {
531 id: threadId,
532 session: {
533 threadId,
534 status: "stopped",
535 providerName: "claudeAgent",
536 runtimeMode: "full-access",
537 activeTurnId: null,
538 lastError: null,
539 updatedAt: now,
540 },
541 },
542 ]),
543 });
544 const repository = await runtime!.runPromise(
545 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
546 );
547
548 await runtime!.runPromise(
549 repository.upsert({
550 threadId,
551 providerName: "claudeAgent",
552 providerInstanceId: null,
553 adapterKey: "claudeAgent",
554 runtimeMode: "full-access",
555 status: "stopped",
556 lastSeenAt: "2026-04-14T00:00:00.000Z",
557 resumeCursor: {
558 opaque: "resume-stopped",
559 },
560 runtimePayload: null,
561 }),
562 );
563
564 await startReaper();
565 await Effect.runPromise(drainFibers);
566
567 expect(harness.stopSession).not.toHaveBeenCalled();
568 const remaining = await runtime!.runPromise(repository.getByThreadId({ threadId }));
569 expect(Option.isSome(remaining)).toBe(true);
570 });
571
572 it("continues reaping other sessions when one stop attempt fails", async () => {
573 const failedThreadId = ThreadId.make("thread-reaper-stop-failure");
574 const reapedThreadId = ThreadId.make("thread-reaper-stop-success");
575 const now = "2026-01-01T00:00:00.000Z";
576 const harness = await createHarness({
577 readModel: makeReadModel([
578 {
579 id: failedThreadId,
580 session: {
581 threadId: failedThreadId,
582 status: "ready",
583 providerName: "claudeAgent",
584 runtimeMode: "full-access",
585 activeTurnId: null,
586 lastError: null,
587 updatedAt: now,
588 },
589 },
590 {
591 id: reapedThreadId,
592 session: {
593 threadId: reapedThreadId,
594 status: "ready",
595 providerName: "codex",
596 runtimeMode: "full-access",
597 activeTurnId: null,
598 lastError: null,
599 updatedAt: now,
600 },
601 },
602 ]),
603 stopSessionImplementation: (request) =>
604 request.threadId === failedThreadId
605 ? Effect.fail(
606 new ProviderValidationError({
607 operation: "ProviderSessionReaper.test",
608 issue: "simulated stop failure",
609 }),
610 )
611 : Effect.void,
612 });
613 const repository = await runtime!.runPromise(
614 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
615 );
616
617 await runtime!.runPromise(
618 repository.upsert({
619 threadId: failedThreadId,
620 providerName: "claudeAgent",
621 providerInstanceId: null,
622 adapterKey: "claudeAgent",
623 runtimeMode: "full-access",
624 status: "running",
625 lastSeenAt: "2026-04-14T00:00:00.000Z",
626 resumeCursor: {
627 opaque: "resume-failure",
628 },
629 runtimePayload: null,
630 }),
631 );
632 await runtime!.runPromise(
633 repository.upsert({
634 threadId: reapedThreadId,
635 providerName: "codex",
636 providerInstanceId: null,
637 adapterKey: "codex",
638 runtimeMode: "full-access",
639 status: "running",
640 lastSeenAt: "2026-04-14T00:01:00.000Z",
641 resumeCursor: {
642 opaque: "resume-success",
643 },
644 runtimePayload: null,
645 }),
646 );
647
648 await startReaper();
649
650 await waitFor(() => harness.stopSession.mock.calls.length === 2);
651
652 expect(harness.stopSession.mock.calls.map(([request]) => request.threadId)).toEqual([
653 failedThreadId,
654 reapedThreadId,
655 ]);
656 });
657
658 it("continues reaping other sessions when one stop attempt defects", async () => {
659 const defectThreadId = ThreadId.make("thread-reaper-stop-defect");
660 const reapedThreadId = ThreadId.make("thread-reaper-stop-after-defect");
661 const now = "2026-01-01T00:00:00.000Z";
662 const harness = await createHarness({
663 readModel: makeReadModel([
664 {
665 id: defectThreadId,
666 session: {
667 threadId: defectThreadId,
668 status: "ready",
669 providerName: "claudeAgent",
670 runtimeMode: "full-access",
671 activeTurnId: null,
672 lastError: null,
673 updatedAt: now,
674 },
675 },
676 {
677 id: reapedThreadId,
678 session: {
679 threadId: reapedThreadId,
680 status: "ready",
681 providerName: "codex",
682 runtimeMode: "full-access",
683 activeTurnId: null,
684 lastError: null,
685 updatedAt: now,
686 },
687 },
688 ]),
689 stopSessionImplementation: (request) =>
690 request.threadId === defectThreadId
691 ? Effect.die(new Error("simulated stop defect"))
692 : Effect.void,
693 });
694 const repository = await runtime!.runPromise(
695 Effect.service(ProviderSessionRuntime.ProviderSessionRuntimeRepository),
696 );
697
698 await runtime!.runPromise(
699 repository.upsert({
700 threadId: defectThreadId,
701 providerName: "claudeAgent",
702 providerInstanceId: null,
703 adapterKey: "claudeAgent",
704 runtimeMode: "full-access",
705 status: "running",
706 lastSeenAt: "2026-04-14T00:00:00.000Z",
707 resumeCursor: {
708 opaque: "resume-defect",
709 },
710 runtimePayload: null,
711 }),
712 );
713 await runtime!.runPromise(
714 repository.upsert({
715 threadId: reapedThreadId,
716 providerName: "codex",
717 providerInstanceId: null,
718 adapterKey: "codex",
719 runtimeMode: "full-access",
720 status: "running",
721 lastSeenAt: "2026-04-14T00:01:00.000Z",
722 resumeCursor: {
723 opaque: "resume-after-defect",
724 },
725 runtimePayload: null,
726 }),
727 );
728
729 await startReaper();
730
731 await waitFor(() => harness.stopSession.mock.calls.length === 2);
732
733 expect(harness.stopSession.mock.calls.map(([request]) => request.threadId)).toEqual([
734 defectThreadId,
735 reapedThreadId,
736 ]);
737 });
738});