@@ -152,13 +152,6 @@ const abortPendingChannelReloads = vi.fn();
152152const abortEmbeddedAgentRun = vi . fn (
153153 ( _sessionId ?: string , _opts ?: { mode ?: "all" | "compacting" ; reason ?: "restart" } ) => false ,
154154) ;
155- const listActiveEmbeddedRunSessionIds = vi . fn ( ( ) => [ ] as string [ ] ) ;
156- const listActiveEmbeddedRunSessionKeys = vi . fn ( ( ) => [ ] as string [ ] ) ;
157- const markRestartAbortedMainSessions = vi . fn ( async ( _params : unknown ) => ( {
158- marked : 1 ,
159- skipped : 0 ,
160- } ) ) ;
161- const loadConfig = vi . fn ( ( ) => ( { } ) ) ;
162155const DEFAULT_RESTART_DEFERRAL_TIMEOUT_MS = 300_000 ;
163156const gatewayLog = {
164157 debug : vi . fn ( ) ,
@@ -269,17 +262,6 @@ vi.mock("../../agents/embedded-agent-runner/runs.js", () => ({
269262 sessionId ?: string ,
270263 opts ?: { mode ?: "all" | "compacting" ; reason ?: "restart" } ,
271264 ) => abortEmbeddedAgentRun ( sessionId , opts ) ,
272- listActiveEmbeddedRunSessionIds : ( ) => listActiveEmbeddedRunSessionIds ( ) ,
273- listActiveEmbeddedRunSessionKeys : ( ) => listActiveEmbeddedRunSessionKeys ( ) ,
274- } ) ) ;
275-
276- vi . mock ( "../../agents/main-session-recovery/main-session-restart-recovery-marking.js" , ( ) => ( {
277- markRestartAbortedMainSessions : ( params : unknown ) => markRestartAbortedMainSessions ( params ) ,
278- } ) ) ;
279-
280- vi . mock ( "../../config/config.js" , ( ) => ( {
281- getRuntimeConfig : ( ) => loadConfig ( ) ,
282- loadConfig : ( ) => loadConfig ( ) ,
283265} ) ) ;
284266
285267vi . mock ( "../../logging/subsystem.js" , ( ) => ( {
@@ -1049,7 +1031,7 @@ describe("runGatewayLoop", () => {
10491031 } ) ;
10501032 } ) ;
10511033
1052- it ( "does not mark drain-start runs before server close revalidates them " , async ( ) => {
1034+ it ( "waits for the drain before handing recovery ownership to server close " , async ( ) => {
10531035 vi . clearAllMocks ( ) ;
10541036 consumeGatewayRestartIntentPayloadSync . mockReturnValueOnce ( { waitMs : 0 } ) ;
10551037 const drainStart = createActiveWorkSnapshot ( { embeddedRuns : 2 } , [
@@ -1060,13 +1042,9 @@ describe("runGatewayLoop", () => {
10601042 releaseDrain = resolve ;
10611043 } ) ;
10621044 createGatewayActiveWorkSnapshot . mockReturnValueOnce ( drainStart ) ;
1063- listActiveEmbeddedRunSessionIds . mockReturnValue ( [ "session-finished" , "session-active" ] ) ;
1064- listActiveEmbeddedRunSessionKeys . mockReturnValue ( [ "agent:main:finished" , "agent:main:active" ] ) ;
10651045 waitForGatewayActiveWork . mockImplementationOnce ( async ( ) => {
1066- // One run settles while the other keeps the restart drain open. Recovery
1067- // ownership must be collected later by server close, after this window.
1068- listActiveEmbeddedRunSessionIds . mockReturnValue ( [ "session-active" ] ) ;
1069- listActiveEmbeddedRunSessionKeys . mockReturnValue ( [ "agent:main:active" ] ) ;
1046+ // Recovery ownership must be collected later by server close, after this
1047+ // window lets active work settle.
10701048 await pendingDrain ;
10711049 return { drained : true , snapshot : idleActiveWorkSnapshot } ;
10721050 } ) ;
@@ -1079,8 +1057,10 @@ describe("runGatewayLoop", () => {
10791057 sigterm ( ) ;
10801058 await vi . waitFor ( ( ) => expect ( waitForGatewayActiveWork ) . toHaveBeenCalledOnce ( ) ) ;
10811059
1082- expect ( markRestartAbortedMainSessions ) . not . toHaveBeenCalled ( ) ;
1083- expect ( abortEmbeddedAgentRun ) . not . toHaveBeenCalled ( ) ;
1060+ expect ( abortEmbeddedAgentRun ) . toHaveBeenCalledWith ( undefined , {
1061+ mode : "compacting" ,
1062+ reason : "restart" ,
1063+ } ) ;
10841064 expect ( close ) . not . toHaveBeenCalled ( ) ;
10851065
10861066 releaseDrain ?.( ) ;
0 commit comments