fix(search): align corpus ranking and MCP retrieval contracts#111
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
morluto
force-pushed
the
fix/search-ranking-mcp-contracts
branch
from
July 23, 2026 02:03
a643955 to
0335329
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Corpus search mixed several ranking models: repository results used a handwritten score, thread and hydrated-facet ranks came from separate FTS indexes, exact repository filters bypassed normal query matching, and combined search compared ranks that had no shared scale. MCP exposed those inconsistencies through a large overlapping catalog and sometimes returned details or coverage from a different read than the ranked result.
This change gives each searchable corpus a single retrieval contract:
Thread headers and bounded hydrated evidence are materialized into one atomic search document, so one BM25 invocation determines rank. Hydrated replacements update that document only after a complete retrieval, and results distinguish retained hydrated evidence from thread text while reporting truncation. Relevance is the default order, source freshness breaks equal-rank ties, and
sort=updatedprovides explicit newest-first retrieval. Combinedsearch allis rejected because BM25 ranks from different indexes are not comparable.Repository and code search now return bounded matching excerpts.
explain_matchreads the exact FTS evidence for repository topics and descriptions, thread fields and facets, and exact code documents, so its snippet cannot silently omit a match outside an arbitrary content prefix.Code snapshots persist an indexing manifest and return selected-snapshot coverage in the same SQLite read transaction as matches and totals. Re-indexing the same commit atomically replaces both its manifest and child documents while preserving the commit's original ordering; a failed replacement rolls back to the prior searchable snapshot. Legacy snapshots report unknown coverage instead of implying that zero recorded skips means complete coverage.
The MCP surface is narrowed around those contracts:
--read-onlymode advertise only available operations;contributecatalog stays below a 96 KiB serialized context budget with measured headroom;Existing corpora require the explicit, backed-up
gitcontribute corpus migrate --yesflow to advance from schema 1 to schema 4. Corpus reads remain offline, GitHub access remains an explicit read capability, and no GitHub mutation path is added.Suggested review order
internal/corpus/migrations/,search.go, andrepository_search.gofor unified FTS documents, weighting, canonical repository queries, evidence excerpts, and atomic facet replacement.internal/corpus/code.goand its tests for snapshot-consistent results, same-commit replacement, coverage, and totals.internal/app/search.goandmcp_v1.gofor ordering, cursor scope, exact explanations, and removal of cross-index ranking.internal/mcpserver/catalog.go,server.go, and the capability-specific files for toolsets, interfaces, schemas, annotations, and output bounds.The branch is split into ten semantic commits following that progression: corpus projections, MCP contracts, application wiring, tests/docs, read cleanup, adapter splits, capability binding, query/retry correctness, exact evidence handling, and the final SQL row-lifecycle correction found by CI.
Testing
make verifymake test-raceowner/repoqueries, cursor scope, atomic hydrated evidence, same-commit code re-indexing and rollback, truncation attribution, exact explanation excerpts, code-index coverage, exact totals, tool discovery, read-only mode, and managed workspace pathsCompatibility and scope
Compatibility changes are intentional: combined cross-index search is removed, the default MCP catalog is smaller, specialized tools require their toolset, and existing corpora require an explicit migration before use with this schema.