@@ -418,6 +418,74 @@ it.effect("cancels a stale waiting run when no checkpoint capture can finish it"
418418 } ) . pipe ( Effect . provide ( layer ) ) ;
419419} ) ;
420420
421+ it . effect ( "tells the thread a running run stopped because the server restarted" , ( ) => {
422+ const threadId = ThreadId . make ( "thread_restart_notice" ) ;
423+ const runId = RunId . make ( "run_restart_notice" ) ;
424+ const rootNodeId = NodeId . make ( "node_restart_notice" ) ;
425+ let committedInput : Parameters < EventSink . EventSinkV2 [ "Service" ] [ "commitCommand" ] > [ 0 ] | null =
426+ null ;
427+ const projection = {
428+ thread : { id : threadId } ,
429+ runtimeRequests : [ ] ,
430+ providerSessions : [ ] ,
431+ providerThreads : [ ] ,
432+ providerTurns : [ ] ,
433+ runs : [ { id : runId , status : "running" , providerInstanceId : ProviderInstanceId . make ( "codex" ) } ] ,
434+ attempts : [
435+ {
436+ id : RunAttemptId . make ( "attempt_restart_notice" ) ,
437+ runId,
438+ rootNodeId,
439+ status : "running" ,
440+ } ,
441+ ] ,
442+ nodes : [ { id : rootNodeId , runId, status : "running" } ] ,
443+ subagents : [ ] ,
444+ messages : [ ] ,
445+ turnItems : [ ] ,
446+ } as unknown as OrchestrationV2ThreadProjection ;
447+ const layer = ProviderRuntimeRecovery . layer . pipe (
448+ Layer . provide ( ServerSettings . layerTest ( ) ) ,
449+ Layer . provide (
450+ Layer . mergeAll (
451+ Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
452+ getRecoveryThreadIds : ( ) => Effect . succeed ( [ threadId ] ) ,
453+ getRuntimeRecoveryProjection : ( ) => Effect . succeed ( projection ) ,
454+ } ) ,
455+ Layer . mock ( EventSink . EventSinkV2 ) ( {
456+ commitCommand : ( input ) => {
457+ committedInput = input ;
458+ return Effect . succeed ( { committed : true , cancelledEffectCount : 0 } as never ) ;
459+ } ,
460+ } ) ,
461+ IdAllocator . layer ,
462+ Layer . mock ( EffectWorker . OrchestrationEffectWorkerV2 ) ( {
463+ runRecoveryOnce : Effect . succeed ( false ) ,
464+ } ) ,
465+ Layer . mock ( EffectOutbox . EffectOutboxV2 ) ( {
466+ reconcileAfterProcessLoss : Effect . succeed ( { requeued : 0 , cancelled : 0 } ) ,
467+ } ) ,
468+ ) ,
469+ ) ,
470+ ) ;
471+
472+ return Effect . gen ( function * ( ) {
473+ const summary =
474+ yield * ( yield * ProviderRuntimeRecovery . ProviderRuntimeRecoveryService ) . reconcile ( "startup" ) ;
475+ assert . equal ( summary . terminalizedRuns , 1 ) ;
476+ const notices = ( committedInput ?. events ?? [ ] ) . flatMap ( ( event ) =>
477+ event . type === "turn-item.updated" &&
478+ event . payload . type === "system_notice" &&
479+ event . payload . runId === runId
480+ ? [ event . payload ]
481+ : [ ] ,
482+ ) ;
483+ assert . equal ( notices . length , 1 , "the restart-cancelled run has no notice saying why" ) ;
484+ assert . equal ( notices [ 0 ] ?. status , "completed" ) ;
485+ assert . include ( notices [ 0 ] ?. message ?? "" , "restarted" ) ;
486+ } ) . pipe ( Effect . provide ( layer ) ) ;
487+ } ) ;
488+
421489it . effect ( "recovery closes a secret card's form but leaves a link card open" , ( ) => {
422490 const threadId = ThreadId . make ( "thread_secret_recovery" ) ;
423491 const runId = RunId . make ( "run_secret_recovery" ) ;
0 commit comments