← Back to PRs

#19313: fix(session-memory): preserve rotated transcript selection on /new

by ayanesakura open 2026-02-17 17:28 View on GitHub →
size: S
## Summary Closes #18459 When `session-memory` receives a `previousSessionEntry.sessionFile` that already points to a rotated `.jsonl.reset.*` transcript, it could still switch to a newer empty `.jsonl` file created by `/new`. That causes the hook to miss real conversation content and fall back to a timestamp-only slug path. This change keeps the selected reset transcript stable in that edge case. ### Changes - **`src/hooks/bundled/session-memory/handler.ts`** - updated `findPreviousSessionFile` to prefer the exact pointed `.reset.*` transcript when it exists, before scanning fallback non-reset files. - **`src/hooks/bundled/session-memory/handler.test.ts`** - added regression coverage for the race where a fresh empty active `.jsonl` exists alongside the pointed reset transcript. ## Test plan - [x] `npx oxfmt src/hooks/bundled/session-memory/handler.ts src/hooks/bundled/session-memory/handler.test.ts` - [x] `npx oxlint src/hooks/bundled/session-memory/handler.ts src/hooks/bundled/session-memory/handler.test.ts` - [x] `pnpm vitest run src/hooks/bundled/session-memory/handler.test.ts` <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixed a race condition where `session-memory` could incorrectly prefer a newly created empty `.jsonl` file over an already-rotated `.jsonl.reset.*` transcript when handling `/new` commands. **Key changes:** - Added early-return path in `findPreviousSessionFile` (handler.ts:131-138) that preserves the exact pointed reset transcript when `currentSessionFile` already contains `.reset.` - Added regression test covering the scenario where a reset transcript pointer coexists with a newer empty active session file - This ensures the hook captures real conversation content instead of falling back to timestamp-only slugs <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is narrowly scoped, well-tested with comprehensive regression coverage, and the logic change is straightforward - it simply adds an early-return condition to preserve an already-pointed reset transcript. The existing fallback paths remain intact, ensuring backward compatibility. - No files require special attention <sub>Last reviewed commit: dc518cf</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs