#17639: fix: Memory indexer skips session files
stale
size: XS
Cluster:
Memory Management Fixes
## Summary
When the MemoryManager is constructed, the `dirty` flag is set to true for memory sources to ensure files get indexed on first sync. However, the `sessionsDirty` flag was never initialized, causing session files to never be indexed unless `--force` was used or session files changed externally.
This fix adds the same initialization pattern for `sessionsDirty`: it is set to true when sessions is in sources (for non-status operations). This ensures session files are indexed on first sync, matching the behavior of memory files.
## Changes
- Added initialization of `sessionsDirty` flag in `MemoryManager` constructor: `this.sessionsDirty = this.sources.has("sessions") && (statusOnly ? !meta : true);`
## Testing
- All existing memory tests pass: index.test.ts, manager.async-search.test.ts, session-files.test.ts, memory-cli.test.ts
- The fix follows the same pattern as the existing `dirty` flag initialization for memory files
Fixes openclaw/openclaw#17576
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Initialized `sessionsDirty` flag in `MemoryManager` constructor to match the existing `dirty` flag pattern, ensuring session files are indexed on first sync when sessions source is configured.
- **What Changed**: Added initialization of `sessionsDirty` flag following the same logic as `dirty` flag initialization
- **Why This Matters**: Without this initialization, session files were never indexed on first sync unless `--force` was used or files changed externally
- **Pattern Match**: The fix correctly mirrors the existing `dirty` flag pattern: `this.sources.has("sessions") && (statusOnly ? !meta : true)`
- **Integration**: The `sessionsDirty` flag is properly used throughout the sync logic in `manager-sync-ops.ts` via `shouldSyncSessions()` method
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The fix is a single-line addition that follows the exact same pattern as the existing `dirty` flag initialization. The logic is correct, consistent with the existing codebase, and addresses a clear bug where session files were skipped on first sync. The change integrates seamlessly with existing sync logic that already checks `sessionsDirty` throughout the codebase.
- No files require special attention.
<sub>Last reviewed commit: be1605f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20148: fix(memory): persist session dirty state and fix reindex gate
by togotago · 2026-02-18
79.3%
#4386: fix(memory): persist dirty flag to prevent false positive on status
by Iamadig · 2026-01-30
77.5%
#11749: fix(memory): prioritize full reindex over session-start skip in sho...
by QDenka · 2026-02-08
77.5%
#20183: fix(memory): index reset/deleted session transcripts
by VACInc · 2026-02-18
75.9%
#20526: fix(session-memory): search state-dir sessions path when workspace ...
by 7Sageer · 2026-02-19
75.8%
#4664: fix: per-session metadata files to eliminate lock contention
by tsukhani · 2026-01-30
75.4%
#15945: fix(memory-flush): only write memoryFlushCompactionCount when compa...
by aldoeliacim · 2026-02-14
75.1%
#18103: fix: session-memory hook reads reset file after /new or /reset
by MisterGuy420 · 2026-02-16
74.9%
#20188: fix: Update sessionFile path when rolling to new session in cron jobs
by jriff · 2026-02-18
74.2%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
73.9%