fix(cron): preserve browser tabs for persistent sessions (#113984)

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
Harjoth Khara
2026-07-28 05:31:59 -07:00
committed by GitHub
parent 981a3dfad3
commit e4907b92ec
2 changed files with 10 additions and 6 deletions

View File

@@ -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([

View File

@@ -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}`),
});
}
}
}
}