fix(frontend): harden the persisted query cache

Persist only data that survives a JSON round trip, bound both the age and
the size of what is written, and stop a restore from being read as a
missing or empty list.

- Drop the repository git status rule: its `Map` data serializes to `{}`,
  so a restored cache made `gitStatuses.get` throw. Round-trip every
  remaining rule through the real persister to catch class-backed data.
- Persist only the unfiltered session list and give just that list the 24h
  gcTime; a search key keeps the default and is collected when unused.
- Set the 24h gcTime in the vcs info query options instead of a prefix
  default, so vcs status and diff keep their normal gcTime.
- Drop the oldest half of the persisted queries per retry pass instead of
  one per pass, sorting once per save, and cap infinite queries to their
  first page before the write.
- Build the session-pin and active-work rules from the shared keys.
This commit is contained in:
Chris Scott committed 2026-10-24 19:24:26 -04:00
1 parent b6c21de0bb
commit b0a1640565
9 files changed
+471 -23

No files matched your search

+7
View File
@@ -31,6 +31,7 @@ import { useSendErrorStore } from "../stores/sendErrorStore";
import { useSessionStatus, useChildLifecycleForSession } from "../stores/sessionStatusStore";
import { isRunningLifecycle } from "../lib/backgroundWork";
import { childSessionReconciliationQueryKey, invalidateSessionListCaches, sessionTranscriptQueryKey } from "../lib/queryInvalidation";
import { PERSISTED_CACHE_MAX_AGE_MS } from "../lib/queryPersistence";
import { buildPinnedSessionKeys, buildSessionKey } from "../lib/sessionKey";
import { toggleSessionPin } from "../api/sessionPins";
import { SESSION_PINS_QUERY_KEY } from "./useSessionPins";
@@ -82,6 +83,11 @@ export const useSessionsAcrossDirectories = (
const projectScoped = !allDirectories && projectId !== undefined;
const singleCursor = allDirectories || projectScoped;
const includeChildren = options?.includeChildren ?? false;
/**
* Only the unfiltered list is restored from disk, so only it keeps the longer `gcTime`; a search
* result stays at the default and is collected as soon as it goes unused.
*/
const persistedGcTime = normalizedSearch === undefined ? PERSISTED_CACHE_MAX_AGE_MS : undefined;
const directoryKey = uniqueDirectories.join('|');
const childSessionsParam = includeChildren ? { includeChildren: true } : {};
@@ -179,6 +185,7 @@ export const useSessionsAcrossDirectories = (
getNextPageParam: (lastPage) => lastPage.nextParam,
enabled: uniqueDirectories.length > 0 || allDirectories,
staleTime: 10000,
gcTime: persistedGcTime,
refetchOnWindowFocus: true,
refetchOnReconnect: true,
});