@@ -2475,6 +2475,57 @@ describe("AcpxRuntime fresh reset wrapper", () => {
24752475 expect ( leaseStore . leases . size ) . toBe ( 0 ) ;
24762476 } ) ;
24772477
2478+ it ( "preserves a promoted PID when the session record save fails" , async ( ) => {
2479+ const leasedCommand = `${ CODEX_ACP_WRAPPER_COMMAND } ${ OPENCLAW_ACPX_LEASE_ID_ARG } lease-partial-save ${ OPENCLAW_GATEWAY_INSTANCE_ID_ARG } gateway-test` ;
2480+ const savedRecord : Record < string , unknown > = {
2481+ name : "agent:codex:acp:binding:test" ,
2482+ agentCommand : leasedCommand ,
2483+ pid : 777 ,
2484+ } ;
2485+ const baseStore : TestSessionStore = {
2486+ load : vi . fn ( async ( ) => savedRecord ) ,
2487+ save : vi . fn ( async ( ) => {
2488+ throw new Error ( "session save failed" ) ;
2489+ } ) ,
2490+ } ;
2491+ const leaseStore = makeLeaseStore ( ) ;
2492+ leaseStore . leases . set ( "lease-partial-save" , {
2493+ leaseId : "lease-partial-save" ,
2494+ gatewayInstanceId : "gateway-test" ,
2495+ sessionKey : "agent:codex:acp:binding:test" ,
2496+ wrapperRoot : "/tmp/openclaw/acpx" ,
2497+ wrapperPath : "/tmp/openclaw/acpx/codex-acp-wrapper.mjs" ,
2498+ rootPid : 777 ,
2499+ commandHash : "hash" ,
2500+ startedAt : 1 ,
2501+ state : "open" ,
2502+ } ) ;
2503+ const { runtime, delegate, wrappedStore } = makeRuntime ( baseStore , {
2504+ openclawGatewayInstanceId : "gateway-test" ,
2505+ openclawProcessLeaseStore : leaseStore . store ,
2506+ openclawWrapperRoot : "/tmp/openclaw/acpx" ,
2507+ } ) ;
2508+ vi . spyOn ( delegate , "setMode" ) . mockImplementation ( async ( ) => {
2509+ await wrappedStore . save ( { ...savedRecord , pid : 888 } ) ;
2510+ } ) ;
2511+
2512+ await expect (
2513+ runtime . setMode ( {
2514+ handle : {
2515+ sessionKey : "agent:codex:acp:binding:test" ,
2516+ backend : "acpx" ,
2517+ runtimeSessionName : "agent:codex:acp:binding:test" ,
2518+ } ,
2519+ mode : "plan" ,
2520+ } ) ,
2521+ ) . rejects . toThrow ( "session save failed" ) ;
2522+
2523+ expect ( leaseStore . leases . get ( "lease-partial-save" ) ) . toMatchObject ( {
2524+ rootPid : 888 ,
2525+ state : "open" ,
2526+ } ) ;
2527+ } ) ;
2528+
24782529 it ( "keeps a shared pending lease until the last concurrent operation finishes" , async ( ) => {
24792530 const leasedCommand = `${ CODEX_ACP_WRAPPER_COMMAND } ${ OPENCLAW_ACPX_LEASE_ID_ARG } lease-concurrent-operations ${ OPENCLAW_GATEWAY_INSTANCE_ID_ARG } gateway-test` ;
24802531 const baseStore : TestSessionStore = {
@@ -2933,6 +2984,61 @@ describe("AcpxRuntime fresh reset wrapper", () => {
29332984 } ) ;
29342985 } ) ;
29352986
2987+ it ( "keeps close leases retryable when process listing is unavailable" , async ( ) => {
2988+ const leasedCommand = `${ CODEX_ACP_WRAPPER_COMMAND } ${ OPENCLAW_ACPX_LEASE_ID_ARG } lease-close-process-list ${ OPENCLAW_GATEWAY_INSTANCE_ID_ARG } gateway-test` ;
2989+ const baseStore : TestSessionStore = {
2990+ load : vi . fn ( async ( ) => ( {
2991+ name : "agent:codex:acp:binding:test" ,
2992+ agentCommand : leasedCommand ,
2993+ pid : 777 ,
2994+ } ) ) ,
2995+ save : vi . fn ( async ( ) => { } ) ,
2996+ } ;
2997+ const leaseStore = makeLeaseStore ( ) ;
2998+ leaseStore . leases . set ( "lease-close-process-list" , {
2999+ leaseId : "lease-close-process-list" ,
3000+ gatewayInstanceId : "gateway-test" ,
3001+ sessionKey : "agent:codex:acp:binding:test" ,
3002+ wrapperRoot : "/tmp/openclaw/acpx" ,
3003+ wrapperPath : "/tmp/openclaw/acpx/codex-acp-wrapper.mjs" ,
3004+ rootPid : 777 ,
3005+ commandHash : "hash" ,
3006+ startedAt : 1 ,
3007+ state : "open" ,
3008+ } ) ;
3009+ const { runtime, delegate } = makeRuntime (
3010+ baseStore ,
3011+ {
3012+ openclawGatewayInstanceId : "gateway-test" ,
3013+ openclawProcessLeaseStore : leaseStore . store ,
3014+ openclawWrapperRoot : "/tmp/openclaw/acpx" ,
3015+ } ,
3016+ {
3017+ openclawProcessCleanup : {
3018+ listProcesses : vi . fn ( async ( ) => {
3019+ throw new Error ( "process listing unavailable" ) ;
3020+ } ) ,
3021+ sleep : vi . fn ( async ( ) => { } ) ,
3022+ } ,
3023+ } ,
3024+ ) ;
3025+ vi . spyOn ( delegate , "close" ) . mockResolvedValue ( undefined ) ;
3026+
3027+ await runtime . close ( {
3028+ handle : {
3029+ sessionKey : "agent:codex:acp:binding:test" ,
3030+ backend : "acpx" ,
3031+ runtimeSessionName : "agent:codex:acp:binding:test" ,
3032+ } ,
3033+ reason : "user-close" ,
3034+ } ) ;
3035+
3036+ expect ( leaseStore . leases . get ( "lease-close-process-list" ) ) . toMatchObject ( {
3037+ rootPid : 777 ,
3038+ state : "open" ,
3039+ } ) ;
3040+ } ) ;
3041+
29363042 it ( "merges sidecar lease ids into loaded ACPX session records" , async ( ) => {
29373043 const leaseStore = makeLeaseStore ( ) ;
29383044 leaseStore . leases . set ( "lease-loaded" , {
0 commit comments