Skip to content

fix(index): paginate per-profile rebuild/clear beyond search-page caps (MCP-3319) - #763

Merged
Dumbris merged 1 commit into
mainfrom
mcp-3319-bleve-pagination
Jun 24, 2026
Merged

Dumbris merged 1 commit into
mainfrom
mcp-3319-bleve-pagination

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Backend robustness hardening — follow-up to the CodexReviewer request_changes verdict on MCP-3307 (adversarial review of per-profile Bleve indexes, PR #756 / MCP-3240). The human merged #756 pragmatically; the two correctness gaps Codex flagged are fixed here.

Findings fixed (both shipped to main in f046f905)

  1. GetToolsByServer silently dropped tools beyond a 10000-hit search cap (internal/index/bleve.go). Sourced by Manager.RebuildProfileFromShared → a server with >10k indexed tools would have its overflow omitted from the rebuilt profile index.
  2. DeleteAll only cleared the first 100000 docs (internal/index/bleve.go). On a profile rebuild (which calls DeleteAll first), stale docs beyond 100k could survive, leaving the profile index inconsistent with the shared index.

Fix

Both operations now loop over search pages until exhausted, so coverage is never bounded by a single page:

  • GetToolsByServer paginates with From/Size, ending on a short final page (fewer hits than the page size).
  • DeleteAll deletes page-by-page from offset 0 — each batch removes the docs just enumerated, so the next search surfaces the following page — until the index is empty (no From offset bookkeeping against a shrinking set).

Page size is a configurable BleveIndex field (default 10000) so the regression tests exercise the pagination loop with a small, fast corpus instead of indexing >10k docs.

Tests (TDD)

  • TestBleveIndex_GetToolsByServer_BeyondPageCap — page size 3, 7 tools across 3 pages + an unrelated server; asserts all 7 returned and the term filter holds across pages. Fails before the fix (overflow dropped).
  • TestBleveIndex_DeleteAll_BeyondPageCap — page size 3, 10 docs; asserts GetDocumentCount()==0 after DeleteAll. Fails before the fix (docs beyond a page survive).

Verification

  • go test ./internal/index/... -race ✅
  • go test ./internal/runtime/ -run Profile -race ✅ (profile rebuild/reconcile path)
  • go build ./internal/... ✅
  • golangci-lint run --config .github/.golangci.yml ./internal/index/... → 0 issues ✅

Out of scope

DeleteServerTools carries a similar Size = 1000 per-server cap, but it was not part of the Codex findings and isn't on the profile-rebuild path. Noting it here as a candidate follow-up; left unchanged to keep this PR scoped to the two cited findings.

Provenance

Related #756.

GetToolsByServer capped a single Bleve search at 10000 hits and DeleteAll
at 100000, so a server with >10k indexed tools or an index with >100k docs
would silently drop the overflow during a per-profile rebuild/clear,
leaving the profile index inconsistent with the shared index.

Both now loop over search pages until exhausted, so coverage is never
bounded by a single page:
- GetToolsByServer paginates with From/Size, ending on a short final page.
- DeleteAll deletes page-by-page from offset 0 (each batch removes the
  enumerated docs, surfacing the next page) until the index is empty.

Page size is a configurable BleveIndex field (default 10000) so the
regression tests exercise the loop with a small, fast corpus.

Related #756. Follow-up to MCP-3240 Codex review (MCP-3307).
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: bda86fb
Status: ✅  Deploy successful!
Preview URL: https://12ec5bf3.mcpproxy-docs.pages.dev
Branch Preview URL: https://mcp-3319-bleve-pagination.mcpproxy-docs.pages.dev

View logs

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 83.33333% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/index/bleve.go 83.33% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: mcp-3319-bleve-pagination

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 28119313231 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@mcpproxy-gatekeeper mcpproxy-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Gatekeeper approval — review verdict: ACCEPT (by ClaudeReviewer+KimiReviewer, model-diverse fallback).

This approval is posted automatically by the MCPProxy Gatekeeper App on behalf of ClaudeReviewer+KimiReviewer — the model-diverse reviewer-fallback reviewer of record (verdict lives in the Paperclip review thread). Author≠approver satisfied; QA + CI gates enforced separately.

Auto-approved per Model B (MCP-1249) + reviewer-fallback (MCP-3066).

@Dumbris
Dumbris enabled auto-merge (squash) June 24, 2026 18:32
@Dumbris
Dumbris merged commit 52a07a7 into main Jun 24, 2026
48 checks passed

@Dumbris Dumbris left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ACCEPT — solid pagination fix for MCP-3319.

What the PR does:

  • Replaces single-search-with-magic-cap in DeleteAll and GetToolsByServer with proper pagination loops.
  • DeleteAll fetches from offset 0 each iteration after batch delete (correct — avoids stale offsets post-mutation).
  • GetToolsByServer uses standard from-offset pagination for read-only iteration.
  • searchPageSize field (default 10000) overridable in tests; enables fast regression with small corpus.

Tests: Both BeyondPageCap tests pass; full internal/index suite passes.

No issues found. LGTM.

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

Approved (Model B): Paperclip review verdicts = ACCEPT and qa-gate green at this head SHA. Arming auto-merge; GitHub merges when all required checks pass.

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.

2 participants