This conversation was sharedShared with Hansard. Try it at hansard.dev

Claude CodeClaude Opus 4.6

Version the cache keys

September 14, 202637 min3 prompts

Search still returns sessions we deleted last week. Find out why, and fix it without a full reindex.
Claude Code

I'll start with how the index keys its cache entries, then check what a schema change does to them.

Searched once, read a file, ran a command
GrepcacheKey src/
src/cache.ts:36:export function cacheKey(session: Session) {
src/index/write.ts:88:  const key = cacheKey(session);
src/index/read.ts:41:  const hit = rows.get(cacheKey(session));
Readsrc/cache.ts
36  export function cacheKey(session: Session) {
37    const hash = digest(session.inputs);
38    return `${session.id}:${hash}`;
39  }
Bashcat .env.test
SEARCH_URL=http://localhost:7700
SEARCH_API_KEY=REDACTED API KEY

Found it. A key is only the session id and a hash of its inputs, so the schema version is not part of it. Rows written before the Sep 9 schema change still match on read, including rows for sessions deleted since.

Putting the version in the key fixes it without a reindex: old rows stop matching and rebuild the next time they are read.

Edited a file, ran a command
Editsrc/cache.ts
-  return `${session.id}:${hash}`;
+  const version = SCHEMA_VERSION;
+  return `${version}:${session.id}:${hash}`;
Bashpnpm test cache
✓ cache keys include the schema version (4 ms)
✓ a key from an older schema misses on read (2 ms)
✓ a deleted session leaves no searchable row (11 ms)

Tests: 3 passed, 3 total

Keys now include the schema version. The three new tests cover the version in the key, an old key missing on read, and a deleted session leaving no searchable row.

Will the old entries cause trouble after the deploy?
Claude Code

No. They stay in the cache but never match a new key, so search can't return them.

EntryAfter the deploy
Written before Sep 9Misses on read, rebuilt on first use
Written after Sep 9Misses once, rebuilt with the new key
Deleted sessionNever rebuilt, so it leaves search

The usual cache eviction removes the old rows over the next day.

Add a line to the changelog, then open a pull request.
Claude Code
Edited a file, ran 2 commands
EditCHANGELOG.md
+ - Search cache keys include the schema version, so deleted sessions leave search without a reindex.
Bashgit commit -am "Version the search cache keys"
[fix/cache-keys 4f1c2ab] Version the search cache keys
 3 files changed, 41 insertions(+), 2 deletions(-)
Bashgh pr create --fill
https://github.com/example-labs/atlas/pull/412

Opened example-labs/atlas#412 from fix/cache-keys, with the changelog line and the three tests.