← Back to PRs

#18103: fix: session-memory hook reads reset file after /new or /reset

by MisterGuy420 open 2026-02-16 14:06 View on GitHub →
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