@@ -177,6 +177,7 @@ describe("ProviderSessionReaper", () => {
177177 async function createHarness ( input : {
178178 readonly readModel : ReturnType < typeof makeReadModel > ;
179179 readonly activeSessions ?: ReadonlyArray < ProviderSession > ;
180+ readonly listSessionsImplementation ?: ( ) => ReturnType < ProviderServiceShape [ "listSessions" ] > ;
180181 readonly stopSessionImplementation ?: ( input : {
181182 readonly threadId : ThreadId ;
182183 } ) => ReturnType < ProviderServiceShape [ "stopSession" ] > ;
@@ -199,7 +200,8 @@ describe("ProviderSessionReaper", () => {
199200 respondToRequest : ( ) => unsupported ( ) ,
200201 respondToUserInput : ( ) => unsupported ( ) ,
201202 stopSession,
202- listSessions : ( ) => Effect . succeed ( input . activeSessions ?? [ ] ) ,
203+ listSessions :
204+ input . listSessionsImplementation ?? ( ( ) => Effect . succeed ( input . activeSessions ?? [ ] ) ) ,
203205 getCapabilities : ( ) => Effect . succeed ( { sessionModelSwitch : "in-session" } ) ,
204206 assertConversationRollbackSupported : ( ) => unsupported ( ) ,
205207 getInstanceInfo : ( instanceId ) => {
@@ -381,6 +383,63 @@ describe("ProviderSessionReaper", () => {
381383 } ,
382384 ) ;
383385
386+ it ( "keeps reaping other providers when the live session lookup fails" , async ( ) => {
387+ const claudeThreadId = ThreadId . make ( "thread-reaper-lookup-failed-claude" ) ;
388+ const codexThreadId = ThreadId . make ( "thread-reaper-lookup-failed-codex" ) ;
389+ const now = "2026-01-01T00:00:00.000Z" ;
390+ const lastSeenAt = "2026-04-14T00:00:00.000Z" ;
391+ const harness = await createHarness ( {
392+ listSessionsImplementation : ( ) => Effect . die ( new Error ( "binding mismatch" ) ) ,
393+ readModel : makeReadModel (
394+ (
395+ [
396+ [ claudeThreadId , "claudeAgent" ] ,
397+ [ codexThreadId , "codex" ] ,
398+ ] as const
399+ ) . map ( ( [ threadId , providerName ] ) => ( {
400+ id : threadId ,
401+ session : {
402+ threadId,
403+ status : "ready" ,
404+ providerName,
405+ runtimeMode : "full-access" ,
406+ activeTurnId : null ,
407+ lastError : null ,
408+ updatedAt : now ,
409+ } ,
410+ } ) ) ,
411+ ) ,
412+ } ) ;
413+ const repository = await runtime ! . runPromise (
414+ Effect . service ( ProviderSessionRuntime . ProviderSessionRuntimeRepository ) ,
415+ ) ;
416+
417+ for ( const [ threadId , providerName ] of [
418+ [ claudeThreadId , "claudeAgent" ] ,
419+ [ codexThreadId , "codex" ] ,
420+ ] as const ) {
421+ await runtime ! . runPromise (
422+ repository . upsert ( {
423+ threadId,
424+ providerName,
425+ providerInstanceId : null ,
426+ adapterKey : providerName ,
427+ runtimeMode : "full-access" ,
428+ status : "running" ,
429+ lastSeenAt,
430+ resumeCursor : null ,
431+ runtimePayload : null ,
432+ } ) ,
433+ ) ;
434+ }
435+
436+ await sweepAt ( Date . parse ( lastSeenAt ) + 1_000 ) ;
437+
438+ expect ( harness . stopSession . mock . calls . map ( ( [ request ] ) => request ) ) . toEqual ( [
439+ { threadId : codexThreadId } ,
440+ ] ) ;
441+ } ) ;
442+
384443 it ( "skips stale sessions when the thread still has an active turn" , async ( ) => {
385444 const threadId = ThreadId . make ( "thread-reaper-active-turn" ) ;
386445 const turnId = TurnId . make ( "turn-reaper-active" ) ;
0 commit comments