#23501: fix(cron): force new session ID for isolated cron jobs (#23470)
app: web-ui
agents
size: S
Cluster:
Cron Job Enhancements
## Problem
Closes #23470.
`sessionTarget: "isolated"` cron jobs were reusing the same session ID across runs. `resolveCronSession` was called without `forceNew`, so the freshness check returned the existing session — giving the agent full context of the previous run.
## Root cause
In `src/cron/isolated-agent/run.ts`, the call to `resolveCronSession` did not pass `forceNew`, regardless of `job.sessionTarget`:
```ts
// before
const cronSession = resolveCronSession({
cfg: params.cfg,
sessionKey: agentSessionKey,
agentId,
nowMs: now,
});
```
## Fix
Pass `forceNew: true` when `job.sessionTarget === 'isolated'`:
```ts
const cronSession = resolveCronSession({
cfg: params.cfg,
sessionKey: agentSessionKey,
agentId,
nowMs: now,
forceNew: params.job.sessionTarget === 'isolated',
});
```
This ensures every isolated run gets a fresh UUID from `crypto.randomUUID()`, with no context from prior runs.
## Tests
Added a regression test in `session.test.ts` that simulates two consecutive isolated runs against the same stored entry and asserts the resulting session IDs are distinct and different from the stored one.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR bundles four related fixes:
**Cron isolated session fix (#23470)**: Passes `forceNew: true` to `resolveCronSession` when `job.sessionTarget === 'isolated'`, ensuring each isolated cron run gets a fresh session ID instead of reusing previous runs' context. The regression test validates distinct session IDs across consecutive isolated runs.
**Anthropic quota failover fix (#23440)**: Fixes HTTP 400 `insufficient_quota` errors being misclassified as format errors. The logic now checks if the error message matches known failover patterns (billing/rate_limit/etc.) before falling back to "format", and adds "insufficient_quota"/"insufficient quota" to the billing patterns list.
**Dashboard agent edit fix**: Replaces `config.set` with `config.patch` for agent edits via dashboard, preventing silent data loss when agents are added/modified externally between load and save. Uses `mergeObjectArraysById` to merge by agent `id`.
**Formatting**: Applies oxfmt formatting to `config.ts`.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- All changes are well-targeted bug fixes with comprehensive test coverage. The cron session fix correctly implements the `forceNew` parameter with regression tests. The failover logic fix properly handles Anthropic quota errors without breaking existing behavior. The dashboard config.patch change prevents data loss with a safer merge strategy. No breaking changes or risky refactors.
- No files require special attention
<sub>Last reviewed commit: 29c92a9</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23699: fix(cron): isolated sessions must generate fresh UUID on every run ...
by echoVic · 2026-02-22
94.9%
#23562: feat: add sessionFreshness config for isolated cron jobs (#23539)
by MunemHashmi · 2026-02-22
87.0%
#6315: fix(cron): persist isolated sessions (fixes #6217) - attempt 2
by ChaitanyaSai-Meka · 2026-02-01
86.6%
#20188: fix: Update sessionFile path when rolling to new session in cron jobs
by jriff · 2026-02-18
86.5%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
85.4%
#23086: fix(cron): surface channel resolution error for isolated sessions w...
by hydro13 · 2026-02-22
83.3%
#15294: fix(cron): reset token counters when creating new isolated session
by Elarwei001 · 2026-02-13
83.1%
#19385: fix: pass authProfileId from cron session to runEmbeddedPiAgent
by gigi-trifle · 2026-02-17
82.4%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
81.0%
#19541: fix: schedule nextWakeAtMs for isolated sessionTarget cron jobs
by guirguispierre · 2026-02-17
81.0%