@@ -65,7 +65,6 @@ import * as recoveryOwnerRelease from "./main-session-recovery-owner-release.js"
6565import { claimMainSessionRecoveryOwner } from "./main-session-recovery-store.js" ;
6666import {
6767 markRestartAbortedMainSessions ,
68- markRestartAbortedMainSessionsFromLocks ,
6968 markStartupOrphanedMainSessionsForRecovery ,
7069 recoverStartupOrphanedMainSessions as recoverStartupOrphanedMainSessionsBase ,
7170 recoverRestartAbortedMainSessions as recoverRestartAbortedMainSessionsBase ,
@@ -75,7 +74,6 @@ import {
7574 scheduleRestartAbortedMainSessionRecovery as scheduleRestartAbortedMainSessionRecoveryBase ,
7675} from "./main-session-restart-recovery.js" ;
7776import { AGENT_RUN_RESTART_ABORT_ERROR_CODE } from "./run-termination.js" ;
78- import type { SessionLockInspection } from "./session-write-lock.js" ;
7977import {
8078 createAssistantToolCallMessage ,
8179 createSessionEntry ,
@@ -358,26 +356,6 @@ function unresumableAssistantMessage(text = "provider failed") {
358356 } ;
359357}
360358
361- function cleanedLockForPath ( lockPath : string ) : SessionLockInspection {
362- // Simulates lock cleanup after process restart: stale lock removed, owning
363- // PID dead, and the transcript path available for recovery.
364- return {
365- lockPath,
366- pid : 999_999 ,
367- pidAlive : false ,
368- createdAt : new Date ( Date . now ( ) - 1_000 ) . toISOString ( ) ,
369- ageMs : 1_000 ,
370- stale : true ,
371- staleReasons : [ "dead-pid" ] ,
372- removable : true ,
373- removed : true ,
374- } ;
375- }
376-
377- function cleanedLock ( sessionsDir : string , sessionId : string ) : SessionLockInspection {
378- return cleanedLockForPath ( path . join ( sessionsDir , `${ sessionId } .jsonl.lock` ) ) ;
379- }
380-
381359describe ( "main-session-restart-recovery" , ( ) => {
382360 it ( "marks only matching running main sessions by active session key" , async ( ) => {
383361 // Only top-level running main sessions are restart-recoverable. Completed,
@@ -768,86 +746,6 @@ describe("main-session-restart-recovery", () => {
768746 expect ( store [ "agent:main:custom-by-id" ] ?. abortedLastRun ) . toBe ( true ) ;
769747 } ) ;
770748
771- it ( "marks only main running sessions whose transcript lock was cleaned" , async ( ) => {
772- const sessionsDir = await makeSessionsDir ( ) ;
773- await writeStore ( sessionsDir , {
774- "agent:main:main" : {
775- ...runningSessionEntry ( "main-session" ) ,
776- } ,
777- "agent:main:subagent:child" : {
778- ...runningSessionEntry ( "child-session" ) ,
779- spawnDepth : 1 ,
780- } ,
781- "agent:main:other" : {
782- ...runningSessionEntry ( "other-session" ) ,
783- } ,
784- } ) ;
785-
786- const result = await markRestartAbortedMainSessionsFromLocks ( {
787- sessionsDir,
788- cleanedLocks : [
789- cleanedLock ( sessionsDir , "main-session" ) ,
790- cleanedLock ( sessionsDir , "child-session" ) ,
791- ] ,
792- } ) ;
793-
794- const store = readStore ( path . join ( sessionsDir , "sessions.json" ) ) ;
795- expect ( result ) . toEqual ( { marked : 1 , skipped : 1 } ) ;
796- expect ( store [ "agent:main:main" ] ?. abortedLastRun ) . toBe ( true ) ;
797- expect ( store [ "agent:main:subagent:child" ] ?. abortedLastRun ) . toBeUndefined ( ) ;
798- expect ( store [ "agent:main:other" ] ?. abortedLastRun ) . toBeUndefined ( ) ;
799- } ) ;
800-
801- it . each ( [
802- {
803- name : "does not mark a session for an unrelated topic lock that only shares its id prefix" ,
804- sessionKey : "agent:main:main" ,
805- sessionId : "main-session" ,
806- sessionFile : "main-session.jsonl" ,
807- lockKind : "unrelated" ,
808- marked : 0 ,
809- } ,
810- {
811- name : "falls back to the session id transcript lock when persisted sessionFile is outside the sessions dir" ,
812- sessionKey : "agent:main:main" ,
813- sessionId : "main-session" ,
814- sessionFile : "../stale/outside.jsonl" ,
815- lockKind : "session-id" ,
816- marked : 1 ,
817- } ,
818- {
819- name : "falls back to the session id transcript lock when persisted sessionFile belongs to another generated session" ,
820- sessionKey : "agent:main:main" ,
821- sessionId : "11111111-1111-4111-8111-111111111111" ,
822- sessionFile : "22222222-2222-4222-8222-222222222222.jsonl" ,
823- lockKind : "session-id" ,
824- marked : 1 ,
825- } ,
826- ] ) ( "$name" , async ( { sessionKey, sessionId, sessionFile, lockKind, marked } ) => {
827- const sessionsDir = await makeSessionsDir ( ) ;
828- await writeStore ( sessionsDir , {
829- [ sessionKey ] : runningSessionEntry ( sessionId , { sessionFile } ) ,
830- } ) ;
831- const lockFile =
832- lockKind === "unrelated"
833- ? "main-session-topic-unrelated.jsonl.lock"
834- : `${ sessionId } .jsonl.lock` ;
835- const lockPath = path . join ( sessionsDir , lockFile ) ;
836-
837- const result = await markRestartAbortedMainSessionsFromLocks ( {
838- sessionsDir,
839- cleanedLocks : [ cleanedLockForPath ( lockPath ) ] ,
840- } ) ;
841-
842- const store = readStore ( path . join ( sessionsDir , "sessions.json" ) ) ;
843- expect ( result ) . toEqual ( { marked, skipped : 0 } ) ;
844- if ( marked === 1 ) {
845- expect ( store [ sessionKey ] ?. abortedLastRun ) . toBe ( true ) ;
846- } else {
847- expect ( store [ sessionKey ] ?. abortedLastRun ) . toBeUndefined ( ) ;
848- }
849- } ) ;
850-
851749 it ( "resumes marked sessions with a tool-result transcript tail" , async ( ) => {
852750 const sessionsDir = await makeSessionsDir ( ) ;
853751 await writeStore ( sessionsDir , mainSessionStore ( ) ) ;
0 commit comments