Skip to content

fix(knowledge): scope list counts to selected knowledge bases - #8575

Merged
icecrasher321 merged 2 commits into
stagingfrom
codex/kb-list-count-scope
Oct 2, 2026
Merged

icecrasher321 merged 2 commits into
stagingfrom
codex/kb-list-count-scope

Conversation

@icecrasher321

@icecrasher321 icecrasher321 commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Select the knowledge-base page before computing document and token totals, so shared ACL tokens cannot make a small list scan unrelated documents.
  • Count the selected KB IDs in one query using the existing large-array helper, preserving permission filters, empty bases, and pagination without per-batch round trips for unpaged lists.

Type of Change

  • Bug fix

Testing

  • Real PostgreSQL regression coverage verifies selective page scans, bounded round trips for a synthetic 10,001-base unpaged list, pagination, lifecycle filters, and permission-filtered totals. Both regressions fail before their respective fixes.
  • Knowledge-list and API/UI permission integration suites: 13 tests pass. Existing knowledge-service tests pass.
  • Full repository tests pass under Node 24.
  • Repository type-check, lint, all 58 audits, docs-manifest check, and staging-based block-registry check pass.
  • JSON test reports and query plans recorded locally; CI discovers the integration suite and uploads its test report.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • 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 Oct 2, 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 Oct 2, 2026 7:25pm 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 3 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 Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes how knowledge base document counts are calculated.

The count-query change appears sound, but the repository’s interface-naming requirement should be satisfied before merging.

Findings

  1. P2 Interfaces lack required suffixes ▶

Summary

The PR selects knowledge-base rows before counting their accessible documents, then counts the selected IDs in one query. It adds PostgreSQL regression coverage for selective scans, pagination, permissions, and large unpaged lists.

  • The latest changes adjust two Power BI tests without changing their tested behavior.
  • The new integration test has an interface-naming convention violation.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Apply base filters and pagination] --> B[Selected knowledge-base IDs]
  B --> C[Count accessible documents for selected IDs]
  C --> D[Combine counts and live-source totals]
  D --> E[List response]
Loading

Reviews (3) · Last reviewed commit: "fix(knowledge): avoid count-query fan-ou..."

Comment thread apps/sim/lib/knowledge/service.ts Outdated
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 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 8 files

Confidence score: 5/5

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

Re-trigger cubic

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@icecrasher321 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 3 files

Confidence score: 5/5

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

Re-trigger cubic

'Actual Rows': number
'Actual Loops': number
'Rows Removed by Filter'?: number
'Rows Removed by Index Recheck'?: number

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.

P2 Interfaces lack required suffixes

The new CapturedQuery interface here and ExplainNode below omit the descriptive suffix required by the repository’s interface-naming convention. Rename both with suffixes that describe their roles, such as CapturedQueryRecord and ExplainNodeData. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is accurate as a repository naming-convention issue: AGENTS.md and CLAUDE.md require a suffix on interface names. I am renaming these test-only types to CapturedQueryRecord and ExplainNodeData. The SQL, assertions, and production behavior stay unchanged.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The naming finding is accurate. I committed and validated the rename in 3f453e1, but this PR merged at its previous head before that push completed, so the rename is not included in the merge. The follow-up commit is available on the source branch. It only renames the test interfaces to CapturedQueryRecord and ExplainNodeData; the emitted JavaScript is identical. All four PostgreSQL list regressions, the full repository test suite, type-check, lint, and all 58 audits passed. I am leaving this thread open because the naming correction has not landed on staging.

@icecrasher321
icecrasher321 merged commit b36757f into staging Oct 2, 2026
34 checks passed
@icecrasher321
icecrasher321 deleted the codex/kb-list-count-scope branch October 2, 2026 19:48

This branch was previously deployed

1 inactive deployment
Preview — 2a16f914 Deployed Oct 2, 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