Skip to content

improvement(knowledge): stop consuming access batches once both overview probes saturate - #7970

Merged
waleedlatif1 merged 1 commit into
stagingfrom
improvement/access-batch-early-exit
Sep 18, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
improvement/access-batch-early-exit

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • readSearchSourceOverview loops over the access batches knowledgeReadAccessBatches yields. The first batch is free, but every later one costs a connector-discovery query plus a per-connector live-source proof over the network.
  • Both probes in the loop already stop issuing queries once they saturate (searchable on its first hit, indexing once every configured provider type is accounted for), but the loop kept pulling batches afterwards — paying the producer's cost for no probe at all.
  • Hoisted the two probe guards into closures so the loop body and the exit share one definition of each, then break once neither can change the result. The exit condition cannot drift looser than "no probe would run".
  • Output is identical in every case; this is a pure work reduction.

Diagnostics

accessBatchCount and liveProofConnectorCount are annotated inside the generator before each yield, so they now report fewer batches when the loop exits early. That matches what those fields already document — batches yielded to the caller and connector identities sent for live proof, i.e. work actually spent, never a count of the batches the owner could produce. The generator records them before the yield specifically so an abandoning caller leaves correct counts, and it holds for every batch, not just the first. There is no try/finally in the generator, so break (which invokes its return()) skips nothing.

Type of Change

  • Improvement (performance)

Testing

  • Extended search-source-overview.test.ts with a consumed-batch counter: one test that the loop exits after the first batch once both probes are satisfied, and two that it keeps consuming while either probe is still unsatisfied (one per probe).
  • Verified each new assertion can fail: removing the break turns the early-exit test red; making the break unconditional turns the keep-consuming tests red.
  • Every test asserts the full result object, so providers[].isSyncing and hasSearchableDocuments are pinned unchanged.
  • apps/sim/lib/knowledge/application + read-access.test.ts: 886 passed, 18 skipped.
  • bun run lint, check-block-registry.ts origin/staging, bun run check:audits (46 audits), bun run docs-manifest:check, bun run type-check all pass. No migrations or schema changes.

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)

…iew probes saturate

The source overview loops over the access batches the read-access generator
yields. The first batch is free, but every later one costs a connector
discovery query plus a per-connector live source proof over the network.

Both probes in the loop already stop issuing queries once they saturate — the
searchable probe on its first hit, the indexing probe once every configured
provider type is accounted for — but the loop kept pulling batches afterwards,
paying the producer's cost for no probe at all.

Hoist the two probe guards into closures so the loop body and the exit share
one definition of each, and break once neither can change the result. Output is
unchanged; only the work is dropped.
@vercel

vercel Bot commented Sep 18, 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 18, 2026 8:07am 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

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@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

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@greptile-apps

greptile-apps Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge because the early exit preserves returned behavior while avoiding access batches that cannot affect the result.

Summary

This PR reduces unnecessary source-access work by stopping batch consumption once both overview probes have reached conclusive results.

  • Hoists the searchable and indexing probe guards into closures shared by query execution and the exit condition.
  • Stops connector discovery and live-source proof work after both result dimensions become immutable.
  • Adds tests covering early termination and continued consumption while either probe remains unsatisfied.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Consume access batch] --> B{Searchable probe needed?}
  B -->|Yes| C[Probe for searchable document]
  B -->|No| D{Indexing probe needed?}
  C --> D
  D -->|Yes| E[Probe unaccounted provider types]
  D -->|No| F{Can either result still change?}
  E --> F
  F -->|Yes| A
  F -->|No| G[Stop consuming batches]
  G --> H[Return provider syncing and searchable status]
Loading

Reviews (1) · Last reviewed commit: "improvement(knowledge): stop consuming a..."

@waleedlatif1
waleedlatif1 merged commit 5249902 into staging Sep 18, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/access-batch-early-exit branch September 18, 2026 08:17
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