Avoid duplicate results when a file joins another branch

perfloop-oss/zoekt · Uncatalogued correctness

https://perfloop.ai/t/oss/case_cp4vs58txj

Verdict

VERIFIED · settled 2026-11-10

What happened: The check fails before this change and passes with it.

Hypothesis

Adding the same path and contents to another indexed branch can leave two identical search results instead of one result carrying both branches. The prior shard keeps the original branch’s copy, and the delta writes another copy. This is reproduced through successful indexing and branch-unrestricted search. Production exposure is unknown.

prepareDeltaBuild inserts newFile into repos, then continues immediately when oldFile is nil at lines 1058–1060. Only modifications and deletions enter current-version expansion and path tombstoning at lines 1072–1097. An addition on one branch can therefore leave the existing same-path document on another branch unreconciled. This is independent of ignore eligibility: the witness contains no ignore file, and both final branch versions are eligible.

The native check on prop_eprtybws5k runs `go test ./gitindex -run '^TestPerfloopDeltaCorpus$' -count=1 -timeout=180s -v`. checkProperty call_8Ly4lhylUBWQbuBa1v4SZn6t exited 1 without a timeout or build failure. It completed 90 histories over one regular-file path, one or two branches, and absent/alpha/bravo states before and after the update. Four histories failed the global corpus comparison. The retained smallest-branch replay has before=[alpha, absent] and after=[alpha, alpha]. Delta preparation succeeds without fallback, but search returns two alpha documents, one for b0 and one for b1, rather than one document for both. Per-branch results remain correct. The checker also validates the initial full corpus and an unaffected file; its finite state space is not a production distribution.

TestIndexDeltaBasic compares the returned searchable document set, not merely successful completion, with expected documents after delta operations. Normal collection groups a path/blob identity across its branches. The independent proof target is preservation of that observable corpus through additions, including equal-content joins, different-content joins, no-ops and later edits. The present native checker and its placement are provisional; the Case can choose the smallest equivalent repository check.

I considered a single affected-path reconciliation pass rather than another addition-specific patch. https://github.com/sourcegraph/zoekt/pull/1050 at head 08b3a46203a7c3f8de75c02083589c7de0c517e2 already introduces a planner for changed branch-name sets. Its inspected stable-name route still has this addition shortcut, so this remaining outcome is not the upstream feature. The concrete prior-repair search for delta duplicates found no matching detail. CONTRIBUTING.md directs review to GitHub, and the bounded recent file history showed no corresponding repair. The first useful Case check is the retained two-branch replay against a clean full rebuild; disappearance of the extra result without losing either branch confirms the repair.

Change to test: Reconcile additions with existing path versions across all selected branches so a current path/blob identity has one live document with the correct branch set. Preserve distinct contents as distinct versions, and permit safe normal-build fallback rather than publishing duplicate live identities.

Where it lives

perfloop-oss/zoekt · gitindex/index.go

Evidence

The check fails before this change and passes with it: `For the staged two-branch regular-file histories, delta indexing matches a clean full rebuild in document multiplicity, contents and branch membership through equal-content additions, different-content additions, no-ops and later edits, honors unchanged branch-local ignore rules, and prepares each path/blob with no repeated branch names.`

Delta indexing an equal-content branch join · 11 sample pairs

metric baseline candidate paired median change confidence range required result
ns/op 52398618 56423050 +6.4% (+3339854) +2085359 to +5755640 loss ≤ stated 0.25 × |baseline median| PASSED

Checks: 3 of 3 passed. Verification: no defect found.

Timeline