@@ -331,6 +331,17 @@ function codeModeWaitCallMessage() {
331331 } ;
332332}
333333
334+ // A provider failure is the remaining unresumable transcript tail: restart
335+ // aborts now resume, so notice-delivery tests need a shape that still fails.
336+ function unresumableAssistantMessage ( text = "provider failed" ) {
337+ return {
338+ role : "assistant" ,
339+ content : [ { type : "text" , text } ] ,
340+ stopReason : "error" ,
341+ errorMessage : "Provider finish_reason: content_filter" ,
342+ } ;
343+ }
344+
334345function cleanedLockForPath ( lockPath : string ) : SessionLockInspection {
335346 // Simulates lock cleanup after process restart: stale lock removed, owning
336347 // PID dead, and the transcript path available for recovery.
@@ -3886,33 +3897,67 @@ describe("main-session-restart-recovery", () => {
38863897 stopReason : "error" ,
38873898 } ,
38883899 ] ,
3900+ ] ) ( "does not resume %s at the transcript tail" , async ( _label , assistantMessage ) => {
3901+ const sessionsDir = await makeSessionsDir ( ) ;
3902+ await writeStore ( sessionsDir , mainSessionStore ( ) ) ;
3903+ await writeTranscript ( sessionsDir , "main-session" , [
3904+ { role : "user" , content : "do the thing" } ,
3905+ assistantMessage ,
3906+ ] ) ;
3907+
3908+ await expectRecovery ( { recovered : 0 , failed : 1 , skipped : 0 } ) ;
3909+ expect ( callGateway ) . not . toHaveBeenCalled ( ) ;
3910+ } ) ;
3911+
3912+ it . each ( [
38893913 [
3890- "aborted tool call " ,
3914+ "no abort string " ,
38913915 {
38923916 role : "assistant" ,
3893- content : [ { type : "toolCall " , id : "call-1" , name : "write" , arguments : { } } ] ,
3917+ content : [ { type : "text " , text : "partial answer" } ] ,
38943918 stopReason : "aborted" ,
38953919 } ,
3920+ false ,
38963921 ] ,
38973922 [
3898- "aborted assistant output with text " ,
3923+ "a worker abort string " ,
38993924 {
39003925 role : "assistant" ,
3901- content : [ { type : "text" , text : "partial answer " } ] ,
3926+ content : [ { type : "text" , text : "" } ] ,
39023927 stopReason : "aborted" ,
3928+ errorMessage : "Worker inference aborted." ,
39033929 } ,
3930+ false ,
39043931 ] ,
3905- ] ) ( "does not resume %s at the transcript tail" , async ( _label , assistantMessage ) => {
3906- const sessionsDir = await makeSessionsDir ( ) ;
3907- await writeStore ( sessionsDir , mainSessionStore ( ) ) ;
3908- await writeTranscript ( sessionsDir , "main-session" , [
3909- { role : "user" , content : "do the thing" } ,
3910- assistantMessage ,
3911- ] ) ;
3932+ [
3933+ "a dangling side-effecting call" ,
3934+ {
3935+ role : "assistant" ,
3936+ content : [ { type : "toolCall" , id : "call-1" , name : "write" , arguments : { } } ] ,
3937+ stopReason : "aborted" ,
3938+ errorMessage : "Worker inference aborted." ,
3939+ } ,
3940+ true ,
3941+ ] ,
3942+ ] ) (
3943+ "resumes an aborted tail persisted with %s" ,
3944+ async ( _label , assistantMessage , forceRestartSafeTools ) => {
3945+ const sessionsDir = await makeSessionsDir ( ) ;
3946+ await writeStore ( sessionsDir , mainSessionStore ( ) ) ;
3947+ await writeTranscript ( sessionsDir , "main-session" , [
3948+ { role : "user" , content : "do the thing" } ,
3949+ assistantMessage ,
3950+ ] ) ;
39123951
3913- await expectRecovery ( { recovered : 0 , failed : 1 , skipped : 0 } ) ;
3914- expect ( callGateway ) . not . toHaveBeenCalled ( ) ;
3915- } ) ;
3952+ await expectRecovery ( { recovered : 1 , failed : 0 , skipped : 0 } ) ;
3953+ expect ( callGateway ) . toHaveBeenCalledTimes ( 1 ) ;
3954+ if ( forceRestartSafeTools ) {
3955+ expect ( gatewayParams ( ) ) . toMatchObject ( { forceRestartSafeTools : true } ) ;
3956+ } else {
3957+ expect ( gatewayParams ( ) ) . not . toMatchObject ( { forceRestartSafeTools : true } ) ;
3958+ }
3959+ } ,
3960+ ) ;
39163961
39173962 it ( "keeps an unresumable Control UI notice in history despite a stale external route" , async ( ) => {
39183963 const sessionsDir = await makeSessionsDir ( ) ;
@@ -3926,11 +3971,7 @@ describe("main-session-restart-recovery", () => {
39263971 } ) ;
39273972 await writeTranscript ( sessionsDir , "main-session" , [
39283973 { role : "user" , content : "do the thing" } ,
3929- {
3930- role : "assistant" ,
3931- content : [ { type : "text" , text : "partial answer" } ] ,
3932- stopReason : "aborted" ,
3933- } ,
3974+ unresumableAssistantMessage ( ) ,
39343975 ] ) ;
39353976
39363977 await expectRecovery ( { recovered : 0 , failed : 1 , skipped : 0 } ) ;
@@ -3985,11 +4026,7 @@ describe("main-session-restart-recovery", () => {
39854026 ) ;
39864027 await writeTranscript ( sessionsDir , "main-session" , [
39874028 { role : "user" , content : "do another thing" } ,
3988- {
3989- role : "assistant" ,
3990- content : [ { type : "text" , text : "another partial answer" } ] ,
3991- stopReason : "aborted" ,
3992- } ,
4029+ unresumableAssistantMessage ( "another provider failure" ) ,
39934030 ] ) ;
39944031
39954032 await expectRecovery ( { recovered : 0 , failed : 1 , skipped : 0 } ) ;
@@ -4030,11 +4067,7 @@ describe("main-session-restart-recovery", () => {
40304067 } ) ;
40314068 await writeTranscript ( sessionsDir , "main-session" , [
40324069 { role : "user" , content : "do the thing" } ,
4033- {
4034- role : "assistant" ,
4035- content : [ { type : "text" , text : "partial answer" } ] ,
4036- stopReason : "aborted" ,
4037- } ,
4070+ unresumableAssistantMessage ( ) ,
40384071 ] ) ;
40394072 transcriptMocks . appendAssistantMessageToSessionTranscript . mockResolvedValueOnce ( {
40404073 ok : false ,
@@ -4091,11 +4124,7 @@ describe("main-session-restart-recovery", () => {
40914124 } ) ;
40924125 await writeTranscript ( sessionsDir , "interrupted-session" , [
40934126 { role : "user" , content : "do the thing" } ,
4094- {
4095- role : "assistant" ,
4096- content : [ { type : "text" , text : "partial answer" } ] ,
4097- stopReason : "aborted" ,
4098- } ,
4127+ unresumableAssistantMessage ( ) ,
40994128 ] ) ;
41004129 let entryAtExternalSend : SessionEntry | undefined ;
41014130 vi . mocked ( callGateway ) . mockImplementationOnce ( async ( ) => {
0 commit comments