#18103: fix: session-memory hook reads reset file after /new or /reset
size: S
trusted-contributor
When a user runs /new or /reset, the session-memory hook was reading from the current (empty/rotated) session file instead of the .jsonl.reset.* file containing the actual conversation.
This fix adds:
1. findMostRecentResetFile() - finds the most recent reset file for a session
2. getRecentSessionContentWithResetFallback() - reads from reset file when current file is empty
3. getRecentSessionContentFromFile() - helper to extract messages from any session file
The hook now properly falls back to reading the reset file when the current session file does not contain meaningful content, preserving conversation history for memory indexing.
Fixes openclaw/openclaw#18088
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes the session-memory hook to properly read conversation history after `/new` or `/reset` by falling back to the `.jsonl.reset.*` archived session file when the current session file lacks meaningful content.
- Adds `findMostRecentResetFile()` to locate the most recently rotated session transcript by scanning the sessions directory for files matching the `<baseName>.jsonl.reset.*` pattern
- Adds `getRecentSessionContentWithResetFallback()` as a wrapper that checks the current session file for content before falling back to the reset file
- Renames the original `getRecentSessionContent` to `getRecentSessionContentFromFile` as a shared helper
- No test coverage for the new reset-file fallback path — the existing tests in `handler.test.ts` only exercise the happy path where the session file has content. Consider adding tests that simulate the post-reset scenario (empty current file + reset file present) to validate the fallback behavior
<h3>Confidence Score: 3/5</h3>
- The PR addresses a real bug with a reasonable approach, but has an unhandled edge case (file-missing scenario skips fallback) and no tests for the new fallback logic
- Score of 3 reflects that the core logic is correct for the primary use case (empty session file triggers reset-file lookup), but the error handling gap where a missing/unreadable session file skips the fallback entirely (already noted in prior review thread) means the fix won't work in all scenarios. The lack of test coverage for the new behavior also reduces confidence.
- `src/hooks/bundled/session-memory/handler.ts` — the `getRecentSessionContentWithResetFallback` function's outer catch swallows file-read errors without attempting the reset fallback, and the happy path reads the file twice
<sub>Last reviewed commit: 6d378c7</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19313: fix(session-memory): preserve rotated transcript selection on /new
by ayanesakura · 2026-02-17
86.8%
#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
by hamiltonchua · 2026-02-02
80.6%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
80.5%
#20526: fix(session-memory): search state-dir sessions path when workspace ...
by 7Sageer · 2026-02-19
80.3%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
78.2%
#6653: fix: persist archived session entry on /new or /reset
by leicao-me · 2026-02-01
78.1%
#9026: fix(session-memory): sanitize content to prevent binary data in mem...
by Flamrru · 2026-02-04
78.0%
#14358: fix: preserve session overrides (verbose, model) across /new or /rese…
by WyattSanders · 2026-02-12
77.5%
#11613: fix: clear stale model metadata on /new and /reset
by mcaxtr · 2026-02-08
77.5%
#9782: feat(hooks): implement session:start and session:end lifecycle events
by kentaro · 2026-02-05
76.5%