← Back to PRs

#20188: fix: Update sessionFile path when rolling to new session in cron jobs

by jriff open 2026-02-18 16:38 View on GitHub →
size: XS
## 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