← Back to PRs

#23501: fix(cron): force new session ID for isolated cron jobs (#23470)

by stakeswky open 2026-02-22 11:04 View on GitHub →
app: web-ui agents size: S
## 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