Fix broad query invalidation on checkpoint/captured events

Scope invalidation to only the checkpoint diff query for the newly
captured turn instead of invalidating all provider queries. The
checkpoint/captured event carries a turnCount in its payload, so we
use a predicate to match only the query whose toTurnCount equals the
captured turn. This prevents N unnecessary refetches of immutable
diffs for already-completed turns on each new turn completion.
This commit is contained in:
Cursor Agent authored and Julius Marminge committed 2026-02-19 00:37:06 -08:00
1 parent 22e1a4cf92
commit 24c617d32e
1 file changed
+9 -2
+9 -2
View File
@@ -6,7 +6,6 @@ import { AnchoredToastProvider, ToastProvider } from "../components/ui/toast";
import { isElectron } from "../env";
import { useNativeApi } from "../hooks/useNativeApi";
import { invalidateGitQueries } from "../lib/gitReactQuery";
import { providerQueryKeys } from "../lib/providerReactQuery";
import { DEFAULT_MODEL } from "../model-logic";
import { useStore } from "../store";
import { onServerWelcome } from "../wsNativeApi";
@@ -59,7 +58,15 @@ function EventRouter() {
void invalidateGitQueries(queryClient);
}
if (event.method === "checkpoint/captured") {
void queryClient.invalidateQueries({ queryKey: providerQueryKeys.all });
const payload = event.payload as { turnCount?: number } | undefined;
const turnCount = payload?.turnCount;
void queryClient.invalidateQueries({
queryKey: ["providers", "checkpointDiff"] as const,
predicate: (query) => {
if (typeof turnCount !== "number") return true;
return query.queryKey[5] === turnCount;
},
});
}
if (!activeThreadId) return;
dispatch({