@@ -2565,6 +2565,87 @@ describe("ProviderCommandReactor", () => {
25652565 expect ( harness . stopSession ) . toHaveBeenCalledWith ( { threadId : ThreadId . make ( "thread-1" ) } ) ;
25662566 } ) ;
25672567
2568+ it ( "does not overwrite a session that became ready while an interrupt failed" , async ( ) => {
2569+ const harness = await createHarness ( ) ;
2570+ const now = "2026-01-01T00:00:00.000Z" ;
2571+ const completedAt = "2026-01-01T00:00:01.000Z" ;
2572+
2573+ await Effect . runPromise (
2574+ harness . engine . dispatch ( {
2575+ type : "thread.session.set" ,
2576+ commandId : CommandId . make ( "cmd-session-set-interrupt-race" ) ,
2577+ threadId : ThreadId . make ( "thread-1" ) ,
2578+ session : {
2579+ threadId : ThreadId . make ( "thread-1" ) ,
2580+ status : "running" ,
2581+ providerName : "codex" ,
2582+ runtimeMode : "approval-required" ,
2583+ activeTurnId : asTurnId ( "turn-1" ) ,
2584+ lastError : null ,
2585+ updatedAt : now ,
2586+ } ,
2587+ createdAt : now ,
2588+ } ) ,
2589+ ) ;
2590+
2591+ harness . interruptTurn . mockImplementation ( ( ) =>
2592+ harness . engine
2593+ . dispatch ( {
2594+ type : "thread.session.set" ,
2595+ commandId : CommandId . make ( "cmd-session-set-natural-completion" ) ,
2596+ threadId : ThreadId . make ( "thread-1" ) ,
2597+ session : {
2598+ threadId : ThreadId . make ( "thread-1" ) ,
2599+ status : "ready" ,
2600+ providerName : "codex" ,
2601+ runtimeMode : "approval-required" ,
2602+ activeTurnId : null ,
2603+ lastError : null ,
2604+ updatedAt : completedAt ,
2605+ } ,
2606+ createdAt : completedAt ,
2607+ } )
2608+ . pipe (
2609+ Effect . catchCause ( ( cause ) => Effect . die ( cause ) ) ,
2610+ Effect . andThen (
2611+ Effect . fail (
2612+ new ProviderAdapterRequestError ( {
2613+ provider : "codex" ,
2614+ method : "thread.interrupt" ,
2615+ detail : "provider session disappeared" ,
2616+ } ) ,
2617+ ) ,
2618+ ) ,
2619+ ) ,
2620+ ) ;
2621+
2622+ await Effect . runPromise (
2623+ harness . engine . dispatch ( {
2624+ type : "thread.turn.interrupt" ,
2625+ commandId : CommandId . make ( "cmd-turn-interrupt-race" ) ,
2626+ threadId : ThreadId . make ( "thread-1" ) ,
2627+ turnId : asTurnId ( "turn-1" ) ,
2628+ createdAt : now ,
2629+ } ) ,
2630+ ) ;
2631+
2632+ await harness . drain ( ) ;
2633+
2634+ const thread = ( await harness . readModel ( ) ) . threads . find (
2635+ ( entry ) => entry . id === ThreadId . make ( "thread-1" ) ,
2636+ ) ;
2637+ expect ( thread ?. session ) . toMatchObject ( {
2638+ status : "ready" ,
2639+ activeTurnId : null ,
2640+ lastError : null ,
2641+ updatedAt : completedAt ,
2642+ } ) ;
2643+ expect ( harness . stopSession ) . not . toHaveBeenCalled ( ) ;
2644+ expect (
2645+ thread ?. activities . some ( ( activity ) => activity . kind === "provider.turn.interrupt.failed" ) ,
2646+ ) . toBe ( false ) ;
2647+ } ) ;
2648+
25682649 it ( "starts a fresh session when only projected session state exists" , async ( ) => {
25692650 const harness = await createHarness ( ) ;
25702651 const now = "2026-01-01T00:00:00.000Z" ;
0 commit comments