Skip to content

fix(knowledge): treat a reach of nothing as a bounded set of nothing - #8113

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/empty-reach-short-circuit
Sep 21, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/empty-reach-short-circuit

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A member who reads no document in the bases (for example one who has not connected a source of their own yet) resolved as an unbounded reach. The vector leg then scanned the sliced sources for readable rows it could not find until its 3 s deadline, and the keyword leg ranked every match of the term to the same end, so a search that could only return nothing spent every budget it had. Measured on production with the replay harness: 8.3 s per search, both legs timed out, zero results
  • A counted reach of zero is now a bounded empty set, remembered for the same window as any reach, and both legs answer immediately. An index the planner has no row estimate for keeps its old answer, since a bound of zero looks at nothing and cannot prove emptiness
  • The count already runs under the probe's share of the deadline (fix(knowledge): give the reach count the probe's share of the deadline, not the leg's #8111); this change only interprets its result

Type of Change

  • Bug fix

Testing

  • New tests: a reach of nothing resolves as a bounded empty set on both the resolved-scope and the probe path, is remembered so the next search neither counts nor probes; an unanalyzed index is not read as a reach of nothing. The first fails with the emptiness check removed
  • vitest over lib/knowledge and app/api/knowledge (191 files, 3307 tests), bun run lint, bun run check:audits and native tsc --noEmit pass

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)

A member who reads no document in the bases, such as one with no source of their own yet, resolved as an unbounded reach: the vector leg then scanned the sliced sources for readable rows it could not find until its deadline, and the keyword leg ranked every match to the same end, so a search that could return nothing spent every budget it had. A counted reach of zero is now a bounded empty set, remembered like any reach, and both legs answer at once. An index the planner has no rows for keeps its old answer, since a bound of zero looks at nothing.
@vercel

vercel Bot commented Sep 21, 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 21, 2026 7:06pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; both previously reported correctness issues are fixed and no new actionable failures remain.

Summary

This PR makes a permission-scoped reach count of zero resolve to an explicitly bounded empty document set, allowing vector and keyword retrieval to return immediately instead of scanning until their deadlines.

  • Handles zero reach consistently in both direct reach resolution and the saturated-probe path.
  • Avoids caching emptiness so newly indexed or newly accessible documents become visible on the next search.
  • Preserves the unbounded fallback when the planner's row estimate is zero and the count therefore examined nothing.
  • Adds focused regression tests for direct, saturated-probe, repeated-search, and unanalyzed-index behavior.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Resolve permitted documents] --> B{Cached breadth?}
    B -- Yes --> C[Use unbounded strategy]
    B -- No --> D[Probe or count reachable documents]
    D --> E{Count examined rows?}
    E -- No: bound is zero --> C
    E -- Yes --> F{Reach count is zero?}
    F -- Yes --> G[Return bounded empty set]
    F -- No --> H[Return unbounded strategy]
    G --> I[Vector and keyword legs return immediately]
    H --> J[Retrieval runs with full access predicate]
    C --> J
Loading

Reviews (2) · Last reviewed commit: "fix(knowledge): count emptiness on every..."

Comment thread apps/sim/lib/knowledge/search/queries.ts Outdated
Comment thread apps/sim/lib/knowledge/search/queries.ts Outdated

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

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/knowledge/search/queries.ts Outdated
Comment thread apps/sim/lib/knowledge/search/queries.ts
…robe path

Emptiness decides completeness, not strategy, so it is never remembered: a member who gains a readable document is answered on their next search, and the count of a reach of nothing costs almost nothing. A saturated probe whose count then finds nothing answers the same bounded empty set.
@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 21, 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
waleedlatif1 merged commit 96090e0 into staging Sep 21, 2026
34 checks passed
@waleedlatif1 waleedlatif1 mentioned this pull request Sep 21, 2026
@waleedlatif1
waleedlatif1 deleted the fix/empty-reach-short-circuit branch September 21, 2026 19:37

This branch was previously deployed

1 inactive deployment
Preview 72e4068a Deployed Sep 21, 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