From e4907b92ec65436c00a0c461f1cbfc0a607443d4 Mon Sep 17 00:00:00 2001 From: Harjoth Khara Date: Tue, 28 Jul 2026 05:31:59 -0700 Subject: [PATCH] fix(cron): preserve browser tabs for persistent sessions (#113984) Co-authored-by: Peter Steinberger --- .../run.session-key-isolation.test.ts | 1 + src/cron/isolated-agent/run.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cron/isolated-agent/run.session-key-isolation.test.ts b/src/cron/isolated-agent/run.session-key-isolation.test.ts index 861230b78210..ef4653b3fb81 100644 --- a/src/cron/isolated-agent/run.session-key-isolation.test.ts +++ b/src/cron/isolated-agent/run.session-key-isolation.test.ts @@ -187,6 +187,7 @@ describe("runCronIsolatedAgentTurn isolated session identity", () => { expect(runRequest.promptCacheKey).toBeUndefined(); expect(runRequest.bootstrapContextMode).toBeUndefined(); expect(runRequest.bootstrapContextRunKind).toBe("cron"); + expect(cleanupBrowserSessionsForLifecycleEndMock).not.toHaveBeenCalled(); }); it.each([ diff --git a/src/cron/isolated-agent/run.ts b/src/cron/isolated-agent/run.ts index 4199c5dfb94e..668a85f01d60 100644 --- a/src/cron/isolated-agent/run.ts +++ b/src/cron/isolated-agent/run.ts @@ -338,12 +338,15 @@ export async function runCronIsolatedAgentTurn(params: { }); } finally { prepared.context.sessionWorkAdmission.release(); - // Browser ownership follows the detached run identity, not the stable cron job key. - await cleanupBrowserSessionsForLifecycleEnd({ - cfg: prepared.context.cfgWithAgentDefaults, - sessionKeys: [prepared.context.runSessionKey], - onWarn: (message) => logWarn(`[cron:${params.job.id}] ${message}`), - }); + // Only run-scoped browser identities end with this invocation. + // Persistent cron targets keep the session and its tracked tabs alive. + if (prepared.context.runSessionKey !== prepared.context.agentSessionKey) { + await cleanupBrowserSessionsForLifecycleEnd({ + cfg: prepared.context.cfgWithAgentDefaults, + sessionKeys: [prepared.context.runSessionKey], + onWarn: (message) => logWarn(`[cron:${params.job.id}] ${message}`), + }); + } } } }