Skip to content

fix(workspace-files): keep the file-search claim on the ordered pending index instead of a hash join - #8128

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/file-search-dispatch-claim-plan
Sep 22, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/file-search-dispatch-claim-plan

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The file-search dispatcher's claim query joined workspace_files with an INNER JOIN; under FOR UPDATE (no parallel plans) the planner mis-estimates the timestamp equi-join and picks a hash join over every file and every pending revision of the workspace before the top-N sort, which exceeded the 10 s statement timeout for a workspace with a large backlog and failed the dispatch task with SQLSTATE 57014
  • The join is now a correlated LATERAL lookup with LIMIT 1, which cannot be flattened into a hash join, so the claim walks the ordered pending index and stops after the batch size: measured 4.6 s → 0.7 ms on the same workspace, same predicates and lock target

Type of Change

  • Bug fix

Testing

  • Added an integration test that captures the exact claim statement the dispatcher runs, pins the planner with SET LOCAL enable_nestloop = off (at fixture scale it already nests the join, so this reproduces production's choice), and asserts the LockRows subtree is fed by an index scan of workspace_file_search_revision_pending_idx with no sort over the backlog. Verified it fails against the old INNER JOIN spelling (LockRows -> Sort -> Hash Join) and passes with the LATERAL
  • vitest run --mode integration lib/workspace-files/search/dispatcher.integration.ts against a local disposable PostgreSQL: 9 passed
  • vitest run lib/workspace-files/search/dispatcher.test.ts lib/workspace-files/search/enqueue-dispatch.test.ts: 11 passed
  • bun run type-check in apps/sim: clean
  • bun run lint: clean
  • bun run check:audits: every content audit passed (including check:api-validation:strict, check:sql-date-binding, check:utils, check:source-text); the only failures were audits that shell out to turbo/biome/tsc binaries missing from the isolated worktree, unrelated to this change

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)

@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 22, 2026 5:43am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the query rewrite preserves claim semantics and adds focused coverage for the production performance regression.

Summary

This PR rewrites the file-search claim query's live-file check as a correlated LATERAL lookup, preventing the claim from degrading into a hash join and backlog-wide sort while preserving candidate eligibility and row-locking behavior.

  • Keeps candidate selection on workspace_file_search_revision_pending_idx.
  • Retains the existing workspace, deletion, context, and content-version checks.
  • Adds an integration regression test that captures the production claim SQL and verifies the ordered index-backed plan.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Select queued workspace] --> B[Walk ordered pending revision index]
  B --> C[Probe matching live workspace file via LATERAL LIMIT 1]
  C --> D{Eligible and unlocked?}
  D -- No --> B
  D -- Yes --> E[Lock revision with SKIP LOCKED]
  E --> F{Workspace and global capacity reached?}
  F -- No --> B
  F -- Yes --> G[Mark claimed revisions dispatched]
Loading

Reviews (1) · Last reviewed commit: "fix(workspace-files): keep the file-sear..."

@waleedlatif1
waleedlatif1 merged commit b37ce85 into staging Sep 22, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/file-search-dispatch-claim-plan branch September 22, 2026 05:47

This branch was previously deployed

1 inactive deployment
Preview 4f5514a7 Deployed Sep 22, 2026 by vercel[bot]
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