#23562: feat: add sessionFreshness config for isolated cron jobs (#23539)
size: S
Cluster:
Cron Job Enhancements
## Summary
- Adds a `sessionFreshness` field to `CronJob` (`"reuse-if-fresh"` |
`"always-new"`)
- When set to `"always-new"`, each isolated cron run gets a brand-new session
UUID, preventing context accumulation across runs
- Default (`undefined` / `"reuse-if-fresh"`) preserves existing behavior
## Problem
PR #18031 changed isolated cron jobs to reuse session IDs when fresh,
contradicting the documented guarantee that "each run starts a fresh session."
This caused stale data references and 20–50% token overhead from accumulated
context.
## Changes
- `src/cron/types.ts` — new `CronSessionFreshness` type and optional field on
`CronJob`
- `src/cron/normalize.ts` — normalization + validation (case-insensitive)
- `src/cron/isolated-agent/run.ts` — wires `sessionFreshness === "always-new"`
to existing `forceNew` param in `resolveCronSession()`
- `src/cron/service/jobs.ts` — passes through field in `createJob()` and
`applyJobPatch()`
- `src/cron/normalize.test.ts` — 3 new tests
## Usage
\`\`\`json
{
"sessionFreshness": "always-new",
"sessionTarget": "isolated"
}
\`\`\`
Closes #23539
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds an optional `sessionFreshness` configuration field to control session reuse behavior for isolated cron jobs. When set to `"always-new"`, each cron run creates a fresh session UUID, preventing context accumulation. The default behavior (`undefined` or `"reuse-if-fresh"`) preserves the existing session reuse logic introduced in PR #18031.
The implementation:
- Defines a new `CronSessionFreshness` type with two valid values: `"reuse-if-fresh"` and `"always-new"`
- Adds normalization logic with case-insensitive string handling and validation
- Wires the field through the job creation and update pipelines (`createJob`, `applyJobPatch`)
- Passes `forceNew: true` to `resolveCronSession()` when `sessionFreshness === "always-new"`
- Includes comprehensive test coverage for normalization of valid and invalid values
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is clean, well-tested, and follows existing patterns in the codebase. It introduces a backward-compatible optional field with proper validation, normalization, and test coverage. The change is minimal and focused, touching only the necessary files to wire through the new configuration option.
- No files require special attention
<sub>Last reviewed commit: 3ed4954</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23501: fix(cron): force new session ID for isolated cron jobs (#23470)
by stakeswky · 2026-02-22
87.0%
#23699: fix(cron): isolated sessions must generate fresh UUID on every run ...
by echoVic · 2026-02-22
86.1%
#15294: fix(cron): reset token counters when creating new isolated session
by Elarwei001 · 2026-02-13
83.7%
#6315: fix(cron): persist isolated sessions (fixes #6217) - attempt 2
by ChaitanyaSai-Meka · 2026-02-01
82.8%
#20188: fix: Update sessionFile path when rolling to new session in cron jobs
by jriff · 2026-02-18
82.6%
#16511: feat(cron): support custom session IDs and auto-bind to current ses...
by kkhomej33-netizen · 2026-02-14
81.0%
#8341: feat: add per-job cache control for cron jobs
by vishaltandale00 · 2026-02-03
79.3%
#19541: fix: schedule nextWakeAtMs for isolated sessionTarget cron jobs
by guirguispierre · 2026-02-17
78.7%
#10836: feat(session_status): include ISO-8601 and Unix timestamps for sche...
by jeanlucthumm · 2026-02-07
77.6%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
77.1%