Match listed repositories by repository ID instead of name
perfloop-oss/zoekt · Identity Collision
https://perfloop.ai/t/oss/case_7qk9nd0g5j
Verdict
VERIFIED · settled 2026-11-24 · pull request opened as sourcegraph/zoekt#1296
What happened: The check fails before this change and passes with it.
Hypothesis
When listing repositories from a compound shard for a query that does not simplify to a constant, shard listing runs a bounded search and records matching repositories only by their string name. In a compound shard that contains multiple distinct repositories with the same name and different numeric IDs, any non-matching repository that shares a name with a matching repository is falsely included in the returned listing and in the returned statistics. How often same-named distinct-ID repositories co-reside in live compound shards is unmeasured in production.
In index/eval.go, indexData.List (lines 530-613) calls d.Search with ShardRepoMaxMatchCount: 1 (lines 542-544) and populates foundRepos := make(map[string]struct{}) using file.Repository alone (lines 549-552), discarding file.RepositoryID even though indexData.Search populates fileMatch.RepositoryID from md.ID (index/eval.go:299) and List itself uses rle.Repository.ID as the key for ReposMap (lines 590-604) while reserving name-only fallback for ID == 0. Compound shards are explicitly expected to support multiple repositories sharing the same Name with distinct non-zero IDs (internal/tenant/enforcement.go:22-24 and index/builder_test.go:519-521), and search/shards.go (lines 1441-1458) forwards ReposMap entries by ID and sums per-shard Stats directly into the aggregated RepoList returned over gRPC and HTTP.
A bounded property search over four compound-shard configurations (two and three same-named repositories with distinct non-zero IDs, a mixed zero-ID and non-zero-ID pair sharing a name, and a distinct-name control) across Substring, Branch, Meta, And, and RepoIDs queries and both RepoListFieldRepos and RepoListFieldReposMap modes failed all 28 same-name cases and passed all distinct-name controls. The reduced deterministic replay in index/list_repo_identity_replay_test.go (run via go test -v ./index -run TestListSameNameDistinctIDRepos) fails on all four subtests on the unmodified checkout, reporting repo IDs [1 2] instead of [1] (and Stats.Repos=2, Stats.Documents=3 instead of 1 and 1) even for query.NewRepoIDs(1) and a substring present only in repository 1. An experimental edit keying non-zero IDs by RepositoryID and zero IDs by Repository name passed both the replay and existing TestList* tests.
Checked all 40 open upstream pull requests on the code host and recent git history of index/eval.go; PR #1282 addresses ShardMaxMatchCount truncation in List and does not address repository-name collisions in foundRepos.
As a provisional proof target, the Case should confirm that List returns only the matching repository IDs and stats for same-named repositories with distinct non-zero IDs across both Repos and ReposMap modes (including query.RepoIDs, content, branch, and meta queries), preserves legacy ID == 0 matching and distinct-name behavior, and does not regress existing index and search list tests.
Change to test: Track matched repositories in indexData.List by non-zero RepositoryID, falling back to Repository name only when a repository has a zero ID for legacy backward compatibility. Keep tenant access, tombstone filtering, and both Repos and ReposMap output formats unchanged.
Where it lives
perfloop-oss/zoekt · index/eval.go
Evidence
The check fails before this change and passes with it: `For a compound shard containing distinct nonzero repository IDs and a zero-ID repository with the same name, List returns only the repository selected by an ID, content, branch, metadata, or ID-and-content query and its full statistics in both list formats, retaining the Repos fallback for ID zero.`
Checks: 3 of 3 passed. Verification: no defect found.
Timeline
2026-11-24· Case opened2026-11-24· PR opened