fix: invalidate workspace entry cache after turn completion and revert#796
Conversation
The @-mention file picker showed stale results after the LLM created or deleted files because the workspace index was cached for 15 seconds on both the server (in-memory TTL) and the client (React Query staleTime). Server: export clearWorkspaceIndexCache() from workspaceEntries and call it in CheckpointReactor after turn completion and checkpoint revert so the next search request rescans the filesystem. Client: invalidate projectQueryKeys alongside providerQueryKeys when thread.turn-diff-completed or thread.reverted domain events arrive so React Query refetches workspace entries on the next @-mention query. Closes pingdotgg#791
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
clearWorkspaceIndexCache only deleted from workspaceIndexCache, leaving a stale promise in inFlightWorkspaceIndexBuilds. The next getWorkspaceIndex call would return that stale in-flight promise instead of triggering a fresh scan.
|
@juliusmarminge Nice little quick win. It makes it so newly created files can be referenced straight away within the chat |
Summary
Fixes #791 — newly created files were not visible in the
@-mention file picker until the workspace entry cache expired (up to 15 seconds on both server and client).Problem
The
@-mention file picker is backed by two layers of caching:workspaceEntries.tscaches the full workspace file index in-memory with a 15-second TTL (WORKSPACE_CACHE_TTL_MS).DEFAULT_SEARCH_ENTRIES_STALE_TIME).When the LLM creates, modifies, or deletes files during a turn, neither cache is invalidated. The user must wait up to 30 seconds (or trigger a query by running a command) before the
@-mention dropdown reflects the new filesystem state.Fix
clearWorkspaceIndexCache(cwd)fromworkspaceEntries.tsand call it inCheckpointReactorafter:turn.completed) — files may have been created/deleted by the agentrestoreCheckpoint) — filesystem was rolled back to a prior stateprojectQueryKeys.allin theEventRouterwhenthread.turn-diff-completedorthread.reverteddomain events arrive (alongside the existingproviderQueryKeys.allinvalidation), so React Query refetches workspace entries on the next@-mention query.Testing
bun lintpasses (only pre-existing warning)bun typecheckpasses (only pre-existing@dnd-kiterrors inSidebar.tsx)bun run testpasses (only pre-existingterminalStateStore.test.tslocalStorage failures)workspaceEntries.test.ts) all passNote
Invalidate workspace entry cache after checkpoint capture and revert
clearWorkspaceIndexCache(cwd)to workspaceEntries.ts, which removes the givencwdfrom bothworkspaceIndexCacheandinFlightWorkspaceIndexBuilds.clearWorkspaceIndexCachein CheckpointReactor.ts after checkpoint capture and after successful filesystem restore, so subsequent lookups rebuild from disk.projectQueryKeys.allReact Query cache in __root.tsx alongside provider queries when domain events flush, keeping project data fresh after turns complete.Macroscope summarized d8909dc.