@@ -29,6 +29,7 @@ import {
2929 mockRunCronFallbackPassthrough ,
3030 patchSessionEntryMock ,
3131 preflightCronModelProviderMock ,
32+ removeCronRunContinuationSessionIfIdleMock ,
3233 resetRunCronIsolatedAgentTurnHarness ,
3334 resolveCronSessionMock ,
3435 resolveCronDeliveryPlanMock ,
@@ -461,6 +462,52 @@ describe("runCronIsolatedAgentTurn session lifecycle", () => {
461462 }
462463 } ) ;
463464
465+ it ( "removes the idle exact-run continuation only after releasing its admission" , async ( ) => {
466+ const sessionKey = "agent:main:cron:test-job" ;
467+ const sessionId = "isolated-session" ;
468+ const storePath = inMemoryStorePath ;
469+ resolveCronSessionMock . mockReturnValue (
470+ makeCronSession ( {
471+ storePath,
472+ initialSessionEntry : undefined ,
473+ isNewSession : true ,
474+ sessionEntry : makeCronSessionEntry ( { sessionId } ) ,
475+ } ) ,
476+ ) ;
477+ loadSessionEntryMock . mockReturnValue ( undefined ) ;
478+ let continuationRowExists = true ;
479+ let admissionActiveDuringRemoval : boolean | undefined ;
480+ removeCronRunContinuationSessionIfIdleMock . mockImplementationOnce (
481+ async ( exactRunSessionKey : string ) => {
482+ expect ( exactRunSessionKey ) . toContain ( ":run:" ) ;
483+ admissionActiveDuringRemoval = isSessionWorkAdmissionActive ( storePath , [
484+ exactRunSessionKey ,
485+ sessionId ,
486+ ] ) ;
487+ if ( ! admissionActiveDuringRemoval ) {
488+ continuationRowExists = false ;
489+ }
490+ } ,
491+ ) ;
492+
493+ await expect (
494+ runCronIsolatedAgentTurn (
495+ makeIsolatedAgentParamsFixture ( {
496+ agentId : "main" ,
497+ sessionKey : "cron:test-job" ,
498+ job : makeIsolatedAgentJobFixture ( {
499+ sessionTarget : "isolated" ,
500+ delivery : { mode : "none" } ,
501+ } ) ,
502+ } ) ,
503+ ) ,
504+ ) . resolves . toMatchObject ( { status : "ok" } ) ;
505+
506+ expect ( removeCronRunContinuationSessionIfIdleMock ) . toHaveBeenCalledTimes ( 1 ) ;
507+ expect ( admissionActiveDuringRemoval ) . toBe ( false ) ;
508+ expect ( continuationRowExists ) . toBe ( false ) ;
509+ } ) ;
510+
464511 it . each ( [ "none" , "silent" , "best-effort" , "execution error" , "presentation warning" ] ) (
465512 "settles isolated %s cleanup after releasing its lease" ,
466513 async ( outcome ) => {
0 commit comments