Skip to content

improvement(knowledge): remember a caller's saturated search reach - #8006

Merged
waleedlatif1 merged 2 commits into
stagingfrom
improvement/search-reach-cache
Sep 19, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
improvement/search-reach-cache

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A caller whose tokens reach past the permitted-set limit re-ran the reach count on every search, only to learn again that the set is unbounded. That count was ~200ms of server time per search for a broad member on a production-sized copy
  • The saturated answer is now remembered per bases and token set for 5 minutes (bounded LRUCache, token set hashed)
  • probeVisibleDocuments returns documents | saturated | timed_out instead of null for both of the latter, so a probe that ran out of time is never mistaken for a broad caller
  • Safe when stale: an unbounded set only means both legs apply the full access predicate per candidate, so a cached answer can cost speed, never access

Type of Change

  • Improvement

Testing

  • New tests: saturation is remembered and skips the probe, is keyed by bases and token set, and is never inferred from a bounded set or a timed-out probe; each fails when the cache write is removed or widened to timeouts
  • lib/knowledge/search suite (185 passing), type-check, bun run lint, check:audits

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 caller whose tokens reach more documents than the permitted-set limit
paid the reach count on every search only to learn again that the set is
unbounded. That answer is now remembered per bases and token set for five
minutes. The probe now reports saturation apart from a timeout, and only
saturation is remembered; an unbounded set only means the legs apply the
full access predicate per candidate, so a stale answer costs speed, never
access.
@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
Image docs Skipped Skipped Sep 19, 2026 7:01am 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 19, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness, security, or repository-rule issues identified.

Summary

This PR avoids repeatedly probing broad callers whose permitted-document reach has already saturated:

  • Distinguishes bounded document results, saturation, and probe timeouts with explicit outcomes.
  • Caches saturation for five minutes using a bounded LRU keyed by sorted knowledge-base IDs and a hash of sorted user tokens.
  • Preserves the full access predicate when using the cached unbounded path.
  • Adds tests covering cache reuse, key isolation, bounded results, and timeouts.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Resolve permitted documents] --> B{Cached saturation for bases and token set?}
  B -->|Yes| C[Return unbounded]
  B -->|No| D[Probe visible documents]
  D --> E{Probe outcome}
  E -->|Documents| F[Return bounded document set]
  E -->|Saturated| G[Cache saturation for five minutes]
  G --> C
  E -->|Timed out| C
Loading

Reviews (2) · Last reviewed commit: "improvement(knowledge): keep the permitt..."

@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 19, 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 d96c991 into staging Sep 19, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/search-reach-cache branch September 20, 2026 00:00

This branch was previously deployed

1 inactive deployment
Preview 3cf9dd12 Deployed Sep 19, 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