#19313: fix(session-memory): preserve rotated transcript selection on /new
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
#18103: fix: session-memory hook reads reset file after /new or /reset
by MisterGuy420 · 2026-02-16
86.8%
#6653: fix: persist archived session entry on /new or /reset
by leicao-me · 2026-02-01
80.0%
#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
by hamiltonchua · 2026-02-02
78.5%
#20183: fix(memory): index reset/deleted session transcripts
by VACInc · 2026-02-18
78.4%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
77.9%
#20526: fix(session-memory): search state-dir sessions path when workspace ...
by 7Sageer · 2026-02-19
77.3%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
77.2%
#21847: fix(session): /new and /reset no longer carry over model overrides
by hydro13 · 2026-02-20
76.3%
#14358: fix: preserve session overrides (verbose, model) across /new or /rese…
by WyattSanders · 2026-02-12
76.3%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
76.0%