Skip to content

fix(queries): close correctness and stale-data defects found auditing the query layer - #6659

Merged
waleedlatif1 merged 1 commit into
stagingfrom
audit/prefetch-perf-verification
Aug 13, 2026
Merged

fix(queries): close correctness and stale-data defects found auditing the query layer#6659
waleedlatif1 merged 1 commit into
stagingfrom
audit/prefetch-perf-verification

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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

  • Table cell edits threw after using search. patchCachedRows walked tableKeys.rowsRoot non-exact, but that is a prefix — the find and write subtrees hang off it with non-paged shapes, so old.pages.map threw. It runs inside onMutate, 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.
  • A transient failure permanently disabled cloud uploads. useCloudStorageConfigured combined staleTime: Infinity, retry: false, and the global retryOnMount: false on a workspace-independent key, and the upload path fails closed. One blip left it errored for the tab's life with no way back. useVoiceSettings carries the same three options and already escapes it.
  • CloudWatch server-side filtering was dead. The log-group and log-stream selectors forwarded search as prefix but 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.
  • Optimistic rows could collide. generateTempId used Date.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 subscriptionKeys after 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: getWorkspaceWithOwner accepts a transaction and forUpdate and 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 / seedWorkspaceList had 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

  • CSV preview staleness. The key already folds in the file version and storage key, so a content update addresses a different entry.
  • link-preview / unsubscribe retry traps. Same three options, no blast radius: finite staleTime, per-URL keys, consumers that degrade correctly.
  • oauth-connections swallowing errors. No consumer reads isConnected; letting it reject would blank the suggested-action rows. Documented instead.
  • A "permanent spinner" from the selector gate. The precedence bug was real, but the symptom was not — the throw happens before any request and the sole consumer never reads isLoading.
  • Substituting ownerBilling for the Inbox/Sandbox or Enterprise checks would have changed who gets those features.

Type of Change

  • Bug fix

Testing

prefetch.test.ts 26/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 confirm Lint and Test is green before merging.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

… 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.
@vercel

vercel Bot commented Aug 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 13, 2026 7:33am

Request Review

@cursor

cursor Bot commented Aug 13, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Prefetch-only optimizations and tests; no auth or mutation paths change, aside from skipping work when userId is absent.

Overview
This slice tightens workspace SSR prefetch behavior and test coverage around list seeding and shared folder prefetch.

prefetchKnowledgeBases now returns immediately when userId is missing, matching other resource prefetches so unauthenticated passes do not run protected list reads.

prefetchWorkspaceSidebar no longer inlines workflow folder loading; it calls prefetchResourceFolders so sidebar and list pages share the same folder key, mapper, and viewer guard.

prefetch.test.ts adds prefetchWorkspaceSidebar / seedWorkspaceList cases: empty workspace list must not set workspaceKeys.list('active') (so client default-workspace creation still runs), successful seed when workspaces exist, swallow-on-reject without throwing, and skip when host context workspace id mismatches. The graceful-failure matrix now asserts prefetchFilesBrowser against workspaceFileFolderKeys (not the file list key the layout owns) and mocks folder-folder rejections.

Reviewed by Cursor Bugbot for commit 946ff74. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR aligns workspace resource prefetch behavior and strengthens regression coverage for sidebar cache seeding.

  • Skips knowledge-base prefetching when no user principal is available.
  • Reuses the shared resource-folder prefetch helper for workflow folders.
  • Adds workspace-sidebar seed tests and corrects the file-folder graceful-failure assertion.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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

@waleedlatif1
waleedlatif1 merged commit 618cee5 into staging Aug 13, 2026
24 checks passed
@waleedlatif1
waleedlatif1 deleted the audit/prefetch-perf-verification branch August 13, 2026 07:36
@waleedlatif1 waleedlatif1 changed the title test(prefetch): cover the workspace-list seed and fix two unfalsifiable tests fix(queries): close correctness and stale-data defects found auditing the query layer Aug 13, 2026
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant