fix(queries): close correctness and stale-data defects found auditing the query layer - #6659
Conversation
… could not fail The audit found the seed contract — the whole point of #6656 — had no test, and that one existing assertion was vacuous. - prefetchWorkspaceSidebar and seedWorkspaceList now have coverage: the empty list seeds nothing (so the client reaches the route's default-workspace creation path), a populated list seeds, a rejected read neither throws nor seeds, and a host context for another workspace seeds nothing at all. Verified falsifiable — removing the empty-list guard turns the first red. - The graceful-failure row for prefetchFilesBrowser asserted on the file-list key, which that function deliberately never writes, so it held no matter what the code did. It now asserts the folder key it owns, and the setup rejects the folder read. - The sidebar was the third hand-rolled copy of the folder prefetch the shared helper was extracted to remove; it now calls prefetchResourceFolders too. - prefetchKnowledgeBases returns early without a userId like every sibling, rather than reaching the authenticator and throwing per render. - Dropped two docblock claims about a `retry` default that no longer applies server-side.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit 946ff74. Configure here. |
Greptile SummaryThe PR aligns workspace resource prefetch behavior and strengthens regression coverage for sidebar cache seeding.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/knowledge/prefetch.ts | Adds the same missing-user guard used by sibling resource prefetch functions. |
| apps/sim/app/workspace/[workspaceId]/prefetch.ts | Replaces the inline workflow-folder query with the shared resource-folder prefetch helper. |
| apps/sim/app/workspace/[workspaceId]/lib/prefetch.test.ts | Adds coverage for workspace-list seeding behavior and fixes the folder-prefetch failure assertion. |
Reviews (2): Last reviewed commit: "test(prefetch): cover the workspace-list..." | Re-trigger Greptile
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 946ff74. Configure here.
Summary
A four-agent audit of the query and server-render layers, following #6657. Every finding was verified against the code before being fixed — several were reported but turned out not to be real, and those are listed at the bottom rather than "fixed".
Functional bugs
patchCachedRowswalkedtableKeys.rowsRootnon-exact, but that is a prefix — thefindandwritesubtrees hang off it with non-paged shapes, soold.pages.mapthrew. It runs insideonMutate, so the edit rejected before reaching the server. A sibling helper already excluded those subtrees and its docstring claimed they "never match"; that was only true of the sibling. Both now share one helper.useCloudStorageConfiguredcombinedstaleTime: Infinity,retry: false, and the globalretryOnMount: falseon a workspace-independent key, and the upload path fails closed. One blip left it errored for the tab's life with no way back.useVoiceSettingscarries the same three options and already escapes it.searchasprefixbut omitted it from the query key, so typing never changed the key and no refetch fired. A log group outside the first page was unreachable. An audit of all 69 selector definitions found these two and no others.generateTempIdusedDate.now(), so two rows created in the same millisecond shared an id and one server response overwrote both.Stale data
Workspace usage/credits were invalidated nowhere — the credits chip and run gate held page-load values until a reload, while six sites already refreshed
subscriptionKeysafter credits moved. Also fixed: KB list doc counts after upload/delete, billing state after a non-redirect plan switch, workflow lists after a copilot tool call (raw key missed the archived scope and the selector prefix), and an aliased schedule key namespace.Server reads
The workspace row was read ~3× per workspace route and ~5× on settings. Memoization is deliberately partial:
getWorkspaceWithOwneraccepts a transaction andforUpdateand live callers use both, so only the plain no-options read is memoized — a row read inside a transaction or under a lock can never be served to a later caller.Guards
prefetchWorkspaceSidebar/seedWorkspaceListhad no test despite being the whole of #6656, and one existing assertion could not fail (it asserted on a key the function never writes). The file-folder seed now parses through its contract — it was the same shape bug #6657 fixed, waiting to recur.Reported but NOT real — deliberately unchanged
link-preview/unsubscriberetry traps. Same three options, no blast radius: finitestaleTime, per-URL keys, consumers that degrade correctly.oauth-connectionsswallowing errors. No consumer readsisConnected; letting it reject would blank the suggested-action rows. Documented instead.isLoading.ownerBillingfor the Inbox/Sandbox or Enterprise checks would have changed who gets those features.Type of Change
Testing
prefetch.test.ts26/26, plus new tests for the usage, knowledge, CloudWatch key, and temp-id fixes — each proven to fail without its fix.type-check,biome,lint:check,check:audits,check:react-query, and the module-count ratchet all pass.Not verified locally: several affected files cannot load in a git worktree (pre-existing postcss/tailwind resolution failure) —
workspace-files.test.tsx, the selector registry, and the upgrade/tool-event/schedules hosts. CI is the first place those run against these changes; please confirmLint and Testis green before merging.Checklist