@@ -54,7 +54,7 @@ it("keeps the note for the provider thread that lost the work across a provider
5454 providerTurns : runs . filter ( ( source ) => source . id !== target . id ) . map ( turnFor ) ,
5555 compactionMessageIds : new Set ( ) ,
5656 run : target ,
57- runAttemptIds : target . activeAttemptId === null ? [ ] : [ target . activeAttemptId ] ,
57+ attempts : [ { id : target . activeAttemptId ! , runId : target . id } ] ,
5858 } ) ;
5959
6060 // Codex never lost the work, so it neither receives nor consumes the note.
@@ -83,7 +83,7 @@ it("delivers a resumed queued run's note even after a higher-ordinal run", () =>
8383 providerTurns : [ resumed , ranFirst ] . map ( turnFor ) ,
8484 compactionMessageIds : new Set ( ) ,
8585 run : next ,
86- runAttemptIds : next . activeAttemptId === null ? [ ] : [ next . activeAttemptId ] ,
86+ attempts : [ { id : next . activeAttemptId ! , runId : next . id } ] ,
8787 } ) ,
8888 lost ,
8989 ) ;
@@ -150,7 +150,7 @@ it("does not repeat the note when a steer restarts the run on a new attempt", ()
150150 ] ,
151151 compactionMessageIds : new Set ( ) ,
152152 run : steered ,
153- runAttemptIds,
153+ attempts : runAttemptIds . map ( ( id ) => ( { id , runId : steered . id } ) ) ,
154154 } ) ;
155155
156156 // The first attempt reached the provider with the note; its replacement must not repeat it.
@@ -164,12 +164,13 @@ it("counts a prompted mid-turn or chained continuation as delivering the note",
164164 const cutTurn = { ...turnFor ( cut ) , status : "cancelled" as const } ;
165165 const continuation = run ( 2 , claudeThread , { restartContinuationOfRunId : cut . id } ) ;
166166 // A turn cut mid-way that lost work is prompted with the note, not resumed natively.
167- assert . isTrue ( isRestartNoteContinuation ( continuation , [ cut , continuation ] , [ cutTurn ] ) ) ;
167+ assert . isTrue ( isRestartNoteContinuation ( continuation , [ cut , continuation ] , [ cutTurn ] , [ ] ) ) ;
168168 assert . isFalse (
169169 isRestartNoteContinuation (
170170 continuation ,
171171 [ { ...cut , restartCancelledBackgroundWork : [ ] } , continuation ] ,
172172 [ cutTurn ] ,
173+ [ ] ,
173174 ) ,
174175 ) ;
175176 const later = run ( 3 , claudeThread ) ;
@@ -179,7 +180,7 @@ it("counts a prompted mid-turn or chained continuation as delivering the note",
179180 providerTurns : [ cutTurn , ...( delivered ? [ turnFor ( continuation ) ] : [ ] ) ] ,
180181 compactionMessageIds : new Set ( ) ,
181182 run : later ,
182- runAttemptIds : [ later . activeAttemptId ! ] ,
183+ attempts : [ { id : later . activeAttemptId ! , runId : later . id } ] ,
183184 } ) ;
184185 assert . deepEqual ( pending ( true ) , [ ] ) ;
185186 // A continuation that never reached the provider delivered nothing.
@@ -188,16 +189,16 @@ it("counts a prompted mid-turn or chained continuation as delivering the note",
188189 // Its own continuation carries the original note forward.
189190 const unstarted = { ...continuation , status : "cancelled" as const } ;
190191 const chained = run ( 3 , claudeThread , { restartContinuationOfRunId : unstarted . id } ) ;
191- assert . deepEqual ( restartContinuationNote ( unstarted , [ cut , unstarted ] , [ cutTurn ] ) , {
192+ assert . deepEqual ( restartContinuationNote ( unstarted , [ cut , unstarted ] , [ cutTurn ] , [ ] ) , {
192193 work : lost ,
193194 settled : false ,
194195 } ) ;
195- assert . isTrue ( isRestartNoteContinuation ( chained , [ cut , unstarted , chained ] , [ cutTurn ] ) ) ;
196+ assert . isTrue ( isRestartNoteContinuation ( chained , [ cut , unstarted , chained ] , [ cutTurn ] , [ ] ) ) ;
196197 // Claude announces running before accepting the prompt. A second restart
197198 // can cancel that turn without delivering anything to the provider.
198199 for ( const status of [ "running" , "cancelled" ] as const ) {
199200 const turns = [ cutTurn , { ...turnFor ( unstarted ) , status } ] ;
200- assert . deepEqual ( restartContinuationNote ( unstarted , [ cut , unstarted ] , turns ) , {
201+ assert . deepEqual ( restartContinuationNote ( unstarted , [ cut , unstarted ] , turns , [ ] ) , {
201202 work : lost ,
202203 settled : false ,
203204 } ) ;
@@ -207,9 +208,30 @@ it("counts a prompted mid-turn or chained continuation as delivering the note",
207208 providerTurns : turns ,
208209 compactionMessageIds : new Set ( ) ,
209210 run : later ,
210- runAttemptIds : [ later . activeAttemptId ! ] ,
211+ attempts : [ { id : later . activeAttemptId ! , runId : later . id } ] ,
211212 } ) ,
212213 lost ,
213214 ) ;
214215 }
216+
217+ // A steer replaced the attempt after its completed turn delivered the note.
218+ const steered = { ...unstarted , activeAttemptId : RunAttemptId . make ( "attempt:replacement" ) } ;
219+ const attempts = [ { id : unstarted . activeAttemptId ! , runId : steered . id } ] ;
220+ const turns = [
221+ cutTurn ,
222+ turnFor ( unstarted ) ,
223+ { ...turnFor ( steered ) , status : "cancelled" as const } ,
224+ ] ;
225+ assert . deepEqual ( restartContinuationNote ( steered , [ cut , steered ] , turns , attempts ) . work , [ ] ) ;
226+ assert . isFalse ( isRestartNoteContinuation ( chained , [ cut , steered , chained ] , turns , attempts ) ) ;
227+ assert . deepEqual (
228+ pendingRestartCancelledBackgroundWork ( {
229+ runs : [ cut , steered , later ] ,
230+ providerTurns : turns ,
231+ compactionMessageIds : new Set ( ) ,
232+ run : later ,
233+ attempts,
234+ } ) ,
235+ [ ] ,
236+ ) ;
215237} ) ;
0 commit comments