Skip to content

fix: invalidate workspace entry cache after turn completion and revert#796

Merged
juliusmarminge merged 2 commits intopingdotgg:mainfrom
binbandit:fix/stale-workspace-entries-on-file-creation
Mar 10, 2026
Merged

fix: invalidate workspace entry cache after turn completion and revert#796
juliusmarminge merged 2 commits intopingdotgg:mainfrom
binbandit:fix/stale-workspace-entries-on-file-creation

Conversation

@binbandit
Copy link
Contributor

@binbandit binbandit commented Mar 10, 2026

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:

  1. Server-side: workspaceEntries.ts caches the full workspace file index in-memory with a 15-second TTL (WORKSPACE_CACHE_TTL_MS).
  2. Client-side: React Query marks workspace entry queries as stale after 15 seconds (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

  • Server: Export clearWorkspaceIndexCache(cwd) from workspaceEntries.ts and call it in CheckpointReactor after:
    • Turn completion (turn.completed) — files may have been created/deleted by the agent
    • Checkpoint revert (restoreCheckpoint) — filesystem was rolled back to a prior state
  • Client: Invalidate projectQueryKeys.all in the EventRouter when thread.turn-diff-completed or thread.reverted domain events arrive (alongside the existing providerQueryKeys.all invalidation), so React Query refetches workspace entries on the next @-mention query.

Testing

  • bun lint passes (only pre-existing warning)
  • bun typecheck passes (only pre-existing @dnd-kit errors in Sidebar.tsx)
  • bun run test passes (only pre-existing terminalStateStore.test.ts localStorage failures)
  • Workspace entry tests (workspaceEntries.test.ts) all pass

Note

Invalidate workspace entry cache after checkpoint capture and revert

  • Adds clearWorkspaceIndexCache(cwd) to workspaceEntries.ts, which removes the given cwd from both workspaceIndexCache and inFlightWorkspaceIndexBuilds.
  • Calls clearWorkspaceIndexCache in CheckpointReactor.ts after checkpoint capture and after successful filesystem restore, so subsequent lookups rebuild from disk.
  • Also invalidates projectQueryKeys.all React Query cache in __root.tsx alongside provider queries when domain events flush, keeping project data fresh after turns complete.

Macroscope summarized d8909dc.

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
@github-actions github-actions bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Mar 10, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2bc9eb84-d725-430f-8562-269e5495f747

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@binbandit
Copy link
Contributor Author

@juliusmarminge Nice little quick win. It makes it so newly created files can be referenced straight away within the chat

@juliusmarminge juliusmarminge merged commit ddd9887 into pingdotgg:main Mar 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Newly created files not available when using "@"

2 participants