Repository navigation
feat(memory): refresh the code index at session start - #473
Merged
Merged
Conversation
The session auto-index was built once, when the bank had no code chunks, and never touched again. As code changed, turn recall kept offering chunks of code (and line ranges) that no longer existed, and new files were never searchable. When the index already exists, session start now refreshes it on a background thread, quietly: chunks of files that are gone are dropped, files modified since they were indexed are indexed again, and new files are added while there is room under auto_index_max_chunks. With nothing changed this is a walk and a stat per file: 70 ms on this repo in a debug build, against 13 s for a full build. Storage gains code_chunk_files (path, chunk count, oldest updated_at) and delete_code_chunks_for_path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 25, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The session auto-index (
maybe_auto_index_background) builds the code index only when the bank has no code chunks, then never touches it again. As the code changes, turn recall keeps injecting chunks of code that no longer exists, at line ranges that have moved, and new files are never searchable. The only way out was runningwhycodes memory indexby hand.Change
When the index already exists, session start now runs
MemoryService::refresh_code_indexon a background thread, quietly (no "Indexing…" notice):auto_index_max_chunks.A file that cannot be stat'ed, or a timestamp that cannot be parsed, counts as changed; re-indexing it drops it if it is gone. The first build and
memory indexare unchanged (they share a newindex_filehelper).Storage:
code_chunk_files(path, chunk count, oldestupdated_at) anddelete_code_chunks_for_path; FTS stays in sync through the existing triggers.Cost
On this repo with nothing changed (debug build): 70 ms of walking and stat'ing in the background, against 13 s for a full build.
Checks
cargo test -p whycodes-memory --lib(94). New tests cover: unchanged → no-op; edited / deleted / new / too-short-to-index files; no room under the cap; disabled;changed_sincefor future, past, unparsable and missing; background Ok / Err.cargo test -p whycodes-storage --lib(45, plus error paths for the two new queries)-skip-expansions, summary): storage 1456/1456; memory misses identical to main (Windows-only lines).cargo check --workspace --tests, ratchets🤖 Generated with Claude Code