#20526: fix(session-memory): search state-dir sessions path when workspace differs
size: XS
## Problem
When `workspaceDir` ≠ `stateDir` (common when workspace is a custom directory like `~/clawd` while state lives in `~/.openclaw`), the session-memory hook only searched `workspaceDir/sessions` for previous transcripts after `/new` or `/reset`.
The actual JSONL session files live in `~/.openclaw/agents/<id>/sessions/`, so the hook never found them — resulting in empty memory files with only 5 lines of metadata.
This is the root cause that recent fixes (19ae7a4, d6acd71, 3fff266) were circling around. Those addressed `.reset.` file rotation but missed the fundamental path mismatch.
## Fix
Add `stateDir/agents/<agentId>/sessions` to the search paths in `saveSessionToMemory`. 3 lines, uses the already-imported `resolveStateDir`.
## Testing
- Tested locally: `/new` now generates complete memory files with conversation summaries
- `pnpm build` passes
- AI-assisted (Claude), fully tested locally
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes the root cause of incomplete session memory files by adding the actual state directory sessions path (`~/.openclaw/agents/<agentId>/sessions`) to the search locations when `workspaceDir` differs from `stateDir`.
- The session-memory hook now searches three locations: the current session file directory, `workspaceDir/sessions`, and `stateDir/agents/<agentId>/sessions`
- Previously only searched `workspaceDir/sessions`, which caused the hook to miss actual session transcripts living in `~/.openclaw/agents/<id>/sessions/`
- This resulted in empty memory files containing only 5 lines of metadata after `/new` or `/reset` commands
- The fix is minimal (3 lines), uses the already-imported `resolveStateDir` function, and follows the same pattern as other parts of the codebase that need to access per-agent session files
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is surgical, well-tested locally, and addresses a clear path mismatch bug. The implementation uses existing utility functions, follows established patterns throughout the codebase (as seen in 20+ other files that use the same `stateDir/agents/<agentId>/sessions` path pattern), and is covered by the existing test suite that already verifies session file recovery logic
- No files require special attention
<sub>Last reviewed commit: 03bd9a1</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
80.3%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
77.9%
#19313: fix(session-memory): preserve rotated transcript selection on /new
by ayanesakura · 2026-02-17
77.3%
#5638: fix: rewrite sessionFile paths during state dir migration
by lailoo · 2026-01-31
77.1%
#10591: feat(hooks): add session-start-memory bundled hook
by morningstar-daemon · 2026-02-06
76.5%
#7301: fix(hooks): use resolveAgentIdFromSessionKey instead of split(":")[0]
by tsukhani · 2026-02-02
75.8%
#17639: fix: Memory indexer skips session files
by MisterGuy420 · 2026-02-16
75.8%
#15888: fix: store relative session file paths instead of absolute
by devAnon89 · 2026-02-14
75.7%
#9026: fix(session-memory): sanitize content to prevent binary data in mem...
by Flamrru · 2026-02-04
75.6%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
75.3%