@@ -157,6 +157,37 @@ describe("main-session-restart-recovery", () => {
157157 expect ( store [ "agent:main:main" ] ?. abortedLastRun ) . toBe ( true ) ;
158158 } ) ;
159159
160+ it ( "fails channel-backed sessions instead of replaying a restart-recovery turn" , async ( ) => {
161+ const sessionsDir = await makeSessionsDir ( ) ;
162+ await writeStore ( sessionsDir , {
163+ "agent:main:discord:channel:123" : {
164+ sessionId : "discord-session" ,
165+ updatedAt : Date . now ( ) - 10_000 ,
166+ status : "running" ,
167+ abortedLastRun : true ,
168+ channel : "discord" ,
169+ lastTo : "channel:123" ,
170+ origin : {
171+ provider : "discord" ,
172+ surface : "channel" ,
173+ } ,
174+ } ,
175+ } ) ;
176+ await writeTranscript ( sessionsDir , "discord-session" , [
177+ { role : "user" , content : "do the thing" } ,
178+ { role : "assistant" , content : [ { type : "toolCall" , id : "call-1" , name : "exec" } ] } ,
179+ { role : "toolResult" , content : "done" } ,
180+ ] ) ;
181+
182+ const result = await recoverRestartAbortedMainSessions ( { stateDir : tmpDir } ) ;
183+
184+ expect ( result ) . toEqual ( { recovered : 0 , failed : 1 , skipped : 0 } ) ;
185+ expect ( callGateway ) . not . toHaveBeenCalled ( ) ;
186+ const store = loadSessionStore ( path . join ( sessionsDir , "sessions.json" ) ) ;
187+ expect ( store [ "agent:main:discord:channel:123" ] ?. status ) . toBe ( "failed" ) ;
188+ expect ( store [ "agent:main:discord:channel:123" ] ?. abortedLastRun ) . toBe ( true ) ;
189+ } ) ;
190+
160191 it ( "does not scan ordinary running sessions without the restart-aborted marker" , async ( ) => {
161192 const sessionsDir = await makeSessionsDir ( ) ;
162193 await writeStore ( sessionsDir , {
0 commit comments