#20188: fix: Update sessionFile path when rolling to new session in cron jobs
size: XS
Cluster:
Cron Job Enhancements
## Summary
Fixes a bug where cron job sessions become invisible in the UI/TUI after the session expires and rolls to a new sessionId.
## Problem
When a cron job's session expires and a new `sessionId` is generated, the `sessionFile` path was not being updated to match. This caused the `sessions.json` index to point to the old session file path, making new sessions invisible in the UI/TUI even though the transcript file was being created correctly.
## Root Cause
In `src/cron/isolated-agent/session.ts`, the code spreads the old entry (`...entry`) which includes the outdated `sessionFile` path, but didn't update it when `isNewSession` was true:
```typescript
const sessionEntry: SessionEntry = {
...entry, // ← Bug: Spreads old sessionFile path
sessionId,
updatedAt: params.nowMs,
systemSent,
};
```
## Solution
Import `resolveSessionTranscriptPath` and update `sessionFile` when creating a new session to ensure the path matches the new `sessionId`:
```typescript
const sessionEntry: SessionEntry = {
...entry,
sessionId,
updatedAt: params.nowMs,
systemSent,
// Update sessionFile path when creating a new session
...(isNewSession && {
sessionFile: resolveSessionTranscriptPath(sessionId, params.agentId),
}),
};
```
## Testing
- Updated test mock to include `resolveSessionTranscriptPath`
- All existing tests pass
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Targeted bug fix that updates the `sessionFile` path in the session store entry when a cron job's session expires and rolls to a new `sessionId`. Previously, the spread of the old entry (`...entry`) preserved the stale `sessionFile` pointing to the old session, making new sessions invisible in the UI/TUI. The fix conditionally sets `sessionFile` via `resolveSessionTranscriptPath(sessionId, params.agentId)` only when `isNewSession` is true, which is the correct approach.
- The logic change in `session.ts` is correct and minimal — it only updates `sessionFile` when rolling to a new session
- The test mock for `resolveSessionTranscriptPath` is added but no test assertions verify the actual `sessionFile` value on the session entry, leaving a gap in regression coverage for the exact bug being fixed
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it's a straightforward, well-scoped bug fix that correctly addresses the stale sessionFile path.
- The fix is minimal, logically correct, and consistent with how resolveSessionTranscriptPath is used elsewhere (e.g., in run.ts:440). The conditional spread pattern is clean. Score is 4 instead of 5 because the test coverage doesn't assert the fixed behavior, which leaves a small regression risk.
- No files require special attention. The change in session.ts is correct.
<sub>Last reviewed commit: 0095414</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
86.5%
#23699: fix(cron): isolated sessions must generate fresh UUID on every run ...
by echoVic · 2026-02-22
85.1%
#6315: fix(cron): persist isolated sessions (fixes #6217) - attempt 2
by ChaitanyaSai-Meka · 2026-02-01
84.6%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
84.1%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
83.5%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
83.4%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
82.7%
#23562: feat: add sessionFreshness config for isolated cron jobs (#23539)
by MunemHashmi · 2026-02-22
82.6%
#15888: fix: store relative session file paths instead of absolute
by devAnon89 · 2026-02-14
82.1%
#3410: fix(sessions): always compute session paths from current environment
by sakunsylvi · 2026-01-28
81.7%