@@ -20,7 +20,10 @@ import {
2020 listActiveEmbeddedRunSessionIds ,
2121 listActiveEmbeddedRunSessionKeys ,
2222} from "./embedded-agent-runner/run-state.js" ;
23- import { transitionMainSessionRecovery } from "./main-session-recovery-state.js" ;
23+ import {
24+ normalizeMainSessionRecoveryRunFences ,
25+ transitionMainSessionRecovery ,
26+ } from "./main-session-recovery-state.js" ;
2427import {
2528 hasCurrentProcessOwner ,
2629 log ,
@@ -189,34 +192,16 @@ export async function markRestartAbortedMainSessions(params: {
189192 continue ;
190193 }
191194 const wasRunning = entry . status === "running" ;
192- const recoveryRuns = new Map < string , RestartRecoveryRun > ( ) ;
193- for ( const run of entry . restartRecoveryRuns ?? [ ] ) {
194- if ( run . lifecycleGeneration === currentLifecycleGeneration ) {
195- recoveryRuns . set ( `${ run . runId } \u0000${ run . lifecycleGeneration } ` , run ) ;
196- }
197- }
198- const replaceActiveRunMarker = ( run : RestartRecoveryRun ) => {
199- for ( const [ key , existingRun ] of recoveryRuns ) {
200- if ( existingRun . runId === run . runId ) {
201- recoveryRuns . delete ( key ) ;
202- }
203- }
204- recoveryRuns . set ( `${ run . runId } \u0000${ run . lifecycleGeneration } ` , run ) ;
205- } ;
206- for ( const run of registeredActiveRuns ) {
207- replaceActiveRunMarker ( run ) ;
208- }
209- for ( const run of matchingActiveRuns ) {
210- replaceActiveRunMarker ( {
211- runId : run . runId ,
212- lifecycleGeneration : run . lifecycleGeneration ,
213- } ) ;
214- }
215- entry . restartRecoveryRuns = [ ...recoveryRuns . values ( ) ] . toSorted ( ( a , b ) =>
216- a . runId === b . runId
217- ? a . lifecycleGeneration . localeCompare ( b . lifecycleGeneration )
218- : a . runId . localeCompare ( b . runId ) ,
219- ) ;
195+ entry . restartRecoveryRuns = normalizeMainSessionRecoveryRunFences ( [
196+ ...( entry . restartRecoveryRuns ?? [ ] ) . filter (
197+ ( run ) => run . lifecycleGeneration === currentLifecycleGeneration ,
198+ ) ,
199+ ...registeredActiveRuns ,
200+ ...matchingActiveRuns . map ( ( { runId, lifecycleGeneration } ) => ( {
201+ runId,
202+ lifecycleGeneration,
203+ } ) ) ,
204+ ] ) ;
220205 transitionMainSessionRecovery ( entry , {
221206 kind : "mark_interrupted" ,
222207 cycleId : randomUUID ( ) ,
0 commit comments