#11749: fix(memory): prioritize full reindex over session-start skip in shouldSyncSessions
stale
Cluster:
Memory Management Fixes
## Summary
When the memory search SQLite database is deleted and the gateway restarts, the sync is triggered with `reason: 'session-start'`. Previously, `shouldSyncSessions` would short-circuit and return `false` for `session-start` before checking `needsFullReindex`, causing all historical session files to remain unindexed.
## Fix
Move the `needsFullReindex` check **before** the reason guard in `shouldSyncSessions`, so that a full reindex always includes session files regardless of the trigger reason.
This is a minimal, single-line-reorder fix with no behavioral change for normal (non-reindex) syncs.
Fixes #11728
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts the ordering of checks inside `shouldSyncSessions` so that `needsFullReindex` is evaluated before the `reason === 'session-start'` early return. This ensures that when the memory-search SQLite DB is missing/deleted and the gateway restarts (triggering a sync with `reason: 'session-start'`), the system still performs a full reindex and includes historical session files, instead of incorrectly skipping indexing them.
The change is localized to `src/memory/manager.ts` and aligns the sync decision logic with the intended semantics: a full reindex request should override “skip on session start” guards, while normal session-start sync behavior remains unchanged when a full reindex is not required.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is a targeted reordering inside a single decision function to ensure `needsFullReindex` takes precedence over a session-start early return. This directly addresses the described bug (unindexed historical sessions after DB deletion) and does not materially affect non-reindex syncs.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#20148: fix(memory): persist session dirty state and fix reindex gate
by togotago · 2026-02-18
87.2%
#15620: fix(memory): await sync in search to prevent database closure race
by superlowburn · 2026-02-13
81.1%
#17639: fix: Memory indexer skips session files
by MisterGuy420 · 2026-02-16
77.5%
#20149: fix(memory): expose index concurrency as config option
by togotago · 2026-02-18
76.1%
#4386: fix(memory): persist dirty flag to prevent false positive on status
by Iamadig · 2026-01-30
75.8%
#14576: Fix/memory loss bugs
by ENCHIGO · 2026-02-12
74.5%
#20183: fix(memory): index reset/deleted session transcripts
by VACInc · 2026-02-18
74.4%
#4664: fix: per-session metadata files to eliminate lock contention
by tsukhani · 2026-01-30
73.5%
#19920: fix(memory): populate FTS index in FTS-only mode so search returns ...
by forketyfork · 2026-02-18
73.2%
#6653: fix: persist archived session entry on /new or /reset
by leicao-me · 2026-02-01
73.0%