Skip to content

fix(code-review): show BHA the old version of moved files - #320

Merged
wongk merged 7 commits into
mainfrom
fix/iss-12737-moved-file-context
Oct 20, 2026
Merged

wongk merged 7 commits into
mainfrom
fix/iss-12737-moved-file-context

Conversation

@wongk

@wongk wongk commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Campaign chunk C3 of 3 (sequential, last): show Bug Hunter A the old version of moved-and-edited files.

Implements PLN-2214 · PR 3 for ISS-12737 (plan). Builds on #315 and #319 (merged). code-review 3.12.1 → 3.12.2.

Why

When a file is moved and heavily edited, git's default rename detection (50% similarity) reports a deletion plus an addition. Since #319, deleted files no longer go to Bug Hunter A, so it sees the moved file as brand new and can't notice behaviour dropped in the move.

A dry run over recent merged PRs found this in about 1–2% of PRs:

  • the last 100 PRs per repo had 1 such pair;
  • the full history of claude-plugins (275 PRs) plus 500 symphony-alpha PRs had 10 pairs in 8 PRs, 9 of them real moves (e.g. symphony-alpha#8970, #8671, #8645).

What changes

  • Pairing: parse-diff runs one extra git diff --name-status -M30%. Each deleted file that pairs with an added file only at the looser threshold is recorded as diff_data.moved_from[<new>] = <old>. files_to_review and file_statuses are unchanged, and the key is emitted only when non-empty.
  • Context patch: partition writes the old file's patch to patches_p<N>_context.txt for each partition holding a paired file, and records moved_from and context_patch on that partition entry.
  • Reviewer template: when a partition has a context_patch, Bug Hunter A gets a <moved_from_context> element. It is reference only: compare it with the new file to find behaviour dropped in the move, and point findings at the new file. The pairing is heuristic and the old file may be unrelated.
  • Cache: the paired old file's patch is folded into the new file's BHA cache key (v1 and v2), so changing only the old file invalidates the entry. Unpaired files keep their existing keys.

Acceptance ledger

11 criteria: 10 met, 1 met differently, 0 not met.

The met-differently criterion ("BHA reports the dropped guard on the new file") needed a live review, so the build proved only the parts that don't need one. It was then proven live: a headless /code-review:start loading this branch's plugin (--plugin-dir) on a test repo where src/store.py was moved to src/persistence/records.py (R038, so default detection reports a delete plus an add) and its if record is None: raise KeyError(key) guard was dropped.

  • moved_from recorded the pair.
  • patches_p0_context.txt held the whole old file, guard included. It was Bug Hunter A's only view of the guard, since the main patch has no store.py hunk.
  • Bug Hunter A reported "get_record lost missing-key guard; raises TypeError, not KeyError" at records.py:17, and the verifier confirmed it at HIGH. The review used the full fleet, not the fast path.

Deviations from the plan

  • Pairing filter: moved_from holds only pairs whose new path is added and old path removed at default similarity. Renames git already detects are diffed in place, so a context patch would be empty.
  • Cache key: compute-hashes was left alone; the per-file BHA key is computed in cache-check and cache-update, so the old file's patch is folded in there.
  • Template trigger: the template keys off context_patch in partitions.json rather than a file on disk, so a stale context file from an earlier run can't be picked up. uncached_diff_data.json also carries moved_from.

Review

/code-review:deep: APPROVED. All 7 reviewers ran (Bug Hunter A and B, Unified Auditor, Design Critic, three domain critics). One verified finding, downgraded to LOW:

  • _write_per_partition_patches adds moved_from and context_patch to the caller's partition dicts as a side effect. Declined. It is documented, confined to one private helper with a single caller, and partly intentional: only the writer knows whether the context file was written. Moving it would reshape the helper's return type and tests with no behaviour change.

No code changed after review, so no re-review was needed. Both the review and the live run used this branch's in-repo helpers because CLAUDE_PLUGIN_ROOT was empty; the separate pipeline-bugs PR fixes that.

origin/main was merged in to resolve a CHANGELOG-only conflict with vibe v1.0.60 and v1.0.61; all entries were kept verbatim.

Verification

  • uv run pytest plugins/code-review/tools/python/ -q: 1441 passed, 3 skipped (also after the main merge).
  • uv run ruff check .: pass. uv run pyright: 0 errors.
  • Counterfactuals: every new test fails when the line it guards is broken.
  • The live headless review described above.

Still owed

Nothing. This is the last chunk of PLN-2214.

Version note: #321 released 3.12.1 first, so this PR was re-synced with main and re-bumped to 3.12.2. Its changelog entry was regenerated with /update-documentation, and tests, ruff and pyright pass on the merged tree (1464 passed). #321 and this PR change different functions in code_review_helpers.py, so none of their changes overlap.

wongk and others added 4 commits October 20, 2026 13:07
PLN-2214 PR 3 (ISS-12737): pair moved-and-edited files at 30% similarity,
write the old file's patch as partition context, fold it into the BHA cache key.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@wongk
wongk merged commit 0a50750 into main Oct 20, 2026
10 checks passed
@wongk
wongk deleted the fix/iss-12737-moved-file-context branch October 20, 2026 19:23
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