Skip to content

fix(pr-size): require a rename's SOURCE to be linguist-generated too (BE-8137) - #196

Merged
mattmillerai merged 2 commits into
mainfrom
matt/be-8137-rename-source-linguist-generated
Aug 20, 2026
Merged

mattmillerai merged 2 commits into
mainfrom
matt/be-8137-rename-source-linguist-generated

Conversation

@mattmillerai

@mattmillerai mattmillerai commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

ELI-5

The PR-size checker decides which files are "generated" so they skip both the line count and the review panel's patch. For a renamed file it asked "is the file's NEW path marked linguist-generated?" and nothing else. So you could git mv a hand-written file into a generated tree, edit it in the same commit, and the edit became invisible — it counted zero lines and never reached the reviewers. The three exclusion buckets sitting on the lines right next to it already asked about the OLD path too; this one just didn't. Now it does.

What changed

classify() in scripts/check-pr-size/main.go, two edits:

  1. The batched git check-attr lookup now resolves a rename's OldPath as well as its Path, so the source path's attribute is actually available.
  2. The attribute bucket now reads attrGen[f.Path] && (f.OldPath == "" || attrGen[f.OldPath]), mirroring the IsTestPath / IsLockfile / extras.Generated conjuncts immediately above it.

The classify() header comment's "a RENAME is classified on BOTH its old and new path for every exclusion bucket" list now names the attribute bucket, and spells out that this bucket's hole costs the reviewed diff as well as the count.

Chesterton's Fence

The destination-only form was an omission, not a design choice. git log -L on those lines lands on ab2066a (fix(pr-size): close the rename bypass on lockfiles too), which introduced the lockfile and extraGen both-paths conjuncts in exactly this if and left attrGen[f.Path] bare on the line between them. The change is also strictly narrowing — every case it newly declines to exclude gets counted and reviewed, never the reverse — so the failure direction stays the safe one. The base-ref invariant is untouched: attrGeneratedBatch still resolves via git check-attr -z --stdin --source <base>, which works for arbitrary path strings whether or not they exist at that ref, and a rename's source path does exist there.

Test

TestClassifyRenameIntoAttrGeneratedTreeStillCounts (new, main_test.go) builds a throwaway repo whose base carries gen/** linguist-generated=true, then in one head commit renames a hand-written file into gen/ with an injected edit and renames a genuinely generated file within gen/. It asserts, in that order: rename detection actually fired (OldPath is the source), the moved hand-written file is NOT Generated, the intra-gen/ rename still IS, Evaluate counts the injected line, the injected marker appears in the --reviewed-diff-out patch, and the generated rename does not.

I falsified the test three ways against the unfixed code before trusting it — reverting the attrGenOK conjunct alone, reverting the OldPath batch-lookup alone, and reverting both. Each revert fails the assertion it is supposed to guard, and reverting both reproduces the ticket's reported numbers exactly: Counted = 0, everything excluded, zero occurrences of the injected marker in the reviewed diff (0 file section(s) kept, 2 generated section(s) excluded). The OldPath batch-lookup edit is load-bearing on its own: without it attrGen[f.OldPath] is always false and legitimate moves inside a generated tree would start counting.

Sweep of the buckets this PR does NOT change

classify() makes five rename-sensitive decisions. Four were already sound and I left them alone: f.Test, lockfile and extraGen carry the explicit both-paths conjunct, and the content-marker bucket fails closed on renames by construction. I probed that last one rather than reasoning about it, since it was the only non-obvious case — with markerFromBase set it reads base:<destination>, which for a true rename does not exist, so it returns false and the file is counted. Review sharpened this: the fail-closed behavior holds only under --marker-from-base, which the sole --reviewed-diff-out call site (cursor-review.yml:672) does pass. Without the flag the head read can be self-marked — but that reduces to pasting the marker in place, needs no rename, and is the already-documented count-only tradeoff, so the bucket stays destination-only with the reasoning now written down. The adjacent worry (moving a hand-written .go on top of a file that was generated at base) is not a rename at all: git reports it as a separate modify plus delete with an empty OldPath, so the hand-written deletions stay booked against their own non-generated path and still count. One hole out of five, and it is the one fixed here.

Propagation

None by hand. main.go is inside the scripts/check-pr-size/** path filter of both bump-cursor-review-callers.yml and bump-pr-size-callers.yml, so merging fans SHA-bump PRs to the pinned callers automatically. The main_test.go half is stripped by the :(exclude)scripts/check-pr-size/*_test.go negation, which only strips the paths it matches — the non-test change still triggers the bump. No consumer's ci-cursor-review.yml pin is touched in this PR.

Judgment calls and unexercised artifacts

  • Out of scope, and the reason the ticket should stay open: initTestRepo (main_test.go) does not pin the throwaway repo's initial branch, so it inherits the host's init.defaultBranch. On any machine where that is main, TestResolveMergeBaseWithAdvancedBaseBranch fails with fatal: a branch named 'main' already exists — pre-existing on the base commit, unrelated to this change, and invisible in CI because the runner's git still defaults to master. I did not fix it: it means touching an unrelated test, and this diff is scoped to the reported defect. Because it is an unfixed defect on a file the ticket names, the reference below is Refs, not Closes.
  • Not exercised: the two short SHAs the report cites as carrying the bug are not fetchable from this remote (couldn't find remote ref), so I confirmed the bare attrGen[f.Path] || form on the current origin/main tip instead, where it was still present. The private consumer-repo PR the original reproduction ran against is in another repository and out of bounds for this change; nothing here relies on it, since the repro is reproduced in-repo by the new test. The tracking ticket's own thread and any linked material were not readable from this environment.
  • full-autonomy is deliberately absent: the source ticket does not carry it, and the label does not exist on this repo.

Review round

The panel raised 5 findings; 3 were fixed and 2 documented as residuals (76bf67a).

The one that mattered — the fix was being cancelled downstream. annotateDiscounts built its patch with a pathspec naming only the DESTINATION, so git could not pair a rename and re-emitted it as a whole-file addition. Every blank/comment line then became a discount and the d > Changed() clamp drove Counted() to 0. I reproduced it end to end before touching anything: with PR_SIZE_IGNORE_COMMENTS=1 (which cursor-review's ignore_comments input feeds), git mv handwritten/big.go gen/big.go plus a one-line edit reported Counted = 0 — i.e. the count half of this PR's guard was fully nullified for that caller. It now passes OldPath as an extra pathspec, mirroring the check-attr change, and the same run reports Counted = 1. Discounts stay keyed by destination, so an unpaired old-path section finds no entry and the file counts raw.

Test hardening. The two base files in the new attribute test were byte-identical, leaving gen/keep2.json's exact-rename pairing to git's hashmap tie-break — it could have paired with the hand-written source and inverted both OldPath assertions. They now carry distinct bodies. Separately the check-attr --source probe ran before t.Chdir, where base is not a valid object; the helper reports that class of failure as supported, so the skip could never fire and an old-git runner would have died on kept.Generated with a misleading message. Probe moved after the chdir.

Documented, not changed. The content-marker bucket is destination-only by design (fails closed under --marker-from-base; without it a rename grants nothing an in-place marker paste does not). And the both-paths rule inherits whatever pairing git chooses, which a same-content generated file planted at base can bias — a KNOWN LIMIT paragraph on classify now records it. Neither is reachable as a new defect under any current caller, so neither got a follow-up ticket.

Refs BE-8137

Provenance

  • Authored by: agent-work loop
  • Verified: gofmt -l . clean; go vet ./... clean; cd scripts/check-pr-size && go test ./... — ok, 0 failures (run with a neutral GIT_CONFIG_GLOBAL, see the out-of-scope note above). Falsification: the original fix reverted three ways (each partial revert fails the assertion it guards), and the new TestAnnotateDiscountsPairsRenamesSoTheEditStillCounts re-run against the reverted annotateDiscounts change, which fails with Discounted = 1, want 0 and Counted = 0, want 1. Both the original defect and the discount cancellation were also reproduced end to end through the built binary against a throwaway repo, before and after each fix.
  • Deviations: none against the plan — both classify() edits, the header-comment update, and the test are implemented. The review round then added one behavior fix outside the original plan (annotateDiscounts rename pairing), taken on because it silently cancelled this PR's own fix rather than being adjacent cleanup. Two review findings were answered with documentation rather than code, each with the reasoning on its thread. The unrelated initTestRepo branch-name fragility described above remains a deliberate omission.

…(BE-8137)

classify() excluded a rename on the linguist-generated attribute of the
DESTINATION path alone, while the three sibling exclusion buckets on the
adjacent lines each also require OldPath to match. Renaming a hand-written file
into a linguist-generated tree and editing it in the same commit therefore hid
the edit from BOTH the size count and the --reviewed-diff-out patch fed to
cursor-review.

Feed OldPath into the batched `git check-attr` lookup so its attribute is
resolved, then require both ends to carry the attribute — mirroring how
IsTestPath / IsLockfile / extras.Generated already treat renames. Strictly
conservative: every changed direction moves toward counting and reviewing MORE.
The base-ref invariant is unchanged; attributes still come from the base
.gitattributes, never the PR head.

The omission dates to ab2066a, which extended the both-paths rule to the
lockfile and extra-glob buckets but left the attribute one bare.
@mattmillerai mattmillerai added the agent-coded Authored by the agent-work loop label Aug 20, 2026
@mattmillerai
mattmillerai marked this pull request as ready for review August 20, 2026 20:32
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your current included review allowance is based on your included PR review attempts over the past 7 days.

Next review available in: 17 minutes

Limit details: You’ve used the included review currently available. Your 94 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 96300dcb-971b-4350-80f2-a5179adfd798

📥 Commits

Reviewing files that changed from the base of the PR and between e1026f1 and 76bf67a.

📒 Files selected for processing (2)
  • scripts/check-pr-size/main.go
  • scripts/check-pr-size/main_test.go

Comment @coderabbitai help to get the list of available commands.

@mattmillerai mattmillerai added the cursor-review Multi-model cursor review label Aug 20, 2026

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

🔍 Cursor Review — Consolidated panel

Triggered by @mattmillerai.

Found 5 finding(s).

Severity Count
🟠 High 2
🟡 Medium 2
🟢 Low 1

Panel: 8/8 reviewers contributed findings.

Comment thread scripts/check-pr-size/main.go Resolved
Comment thread scripts/check-pr-size/main_test.go Resolved
Comment thread scripts/check-pr-size/main.go Resolved
Comment thread scripts/check-pr-size/main.go Resolved
Comment thread scripts/check-pr-size/main_test.go Resolved
…ncelled (BE-8137)

Review round on the both-paths rename guard.

annotateDiscounts built its patch with a pathspec naming only the DESTINATION,
so git could not pair a rename and re-emitted it as a whole-file ADDITION.
Every blank/comment line in the file then counted as a discount and the
`d > Changed()` clamp drove Counted() to 0 — silently cancelling the count half
of classify()'s rename guard for any caller running with --ignore-comments
(cursor-review's ignore_comments input feeds exactly that). Verified end to end:
`git mv handwritten/big.go gen/big.go` plus a one-line edit reported
`Counted = 0` before, `Counted = 1` after. Feed OldPath as an extra pathspec,
mirroring what classify() now does for check-attr. Discounts stay keyed by
destination, so an unpaired old-path section simply finds no entry and the file
counts raw.

Test hardening on the new attribute test:
- give the two base files distinct bodies, so gen/keep2.json is an unambiguous
  exact-rename of gen/keep.json; byte-identical bodies left the pairing to
  git's hashmap tie-break and could invert both OldPath assertions.
- move the `check-attr --source` probe after t.Chdir, so it runs where `base`
  is a valid object; from the outer repo it failed as "not a valid object",
  which the helper reports as supported, so the skip could never fire.

Documented two residuals raised in review rather than changing behavior: the
content-marker bucket is destination-only by design (it fails closed under
--marker-from-base, and without that flag a rename grants no evasion an in-place
marker paste does not already grant), and the both-paths rule inherits whatever
pairing git chooses, which a same-content file planted in the generated tree at
base can bias.
@mattmillerai
mattmillerai merged commit 00b0eef into main Aug 20, 2026
4 checks passed
@mattmillerai
mattmillerai deleted the matt/be-8137-rename-source-linguist-generated branch August 20, 2026 22:40
mattmillerai added a commit that referenced this pull request Aug 21, 2026
This branch already carried a prior merge (f438b1b) combining BE-8253's
two-tier step-output reader with BE-8220's scope-gate/with-key fixes,
resolved against main's pre-squash commit 1c66f7f. Main has since
squash-merged that same work as #202 (b92f1df) — byte-identical content
under .github/workflow-pins/, different commit hash — so this merge's
conflicts were git failing to recognize already-incorporated content
across the squash, not new upstream changes. Resolved by keeping HEAD's
already-combined version of the three workflow-pins files (verified: its
tree for that directory is unchanged from before this merge, and both
BE-8220's and BE-8253's added symbols are present). Also picked up two
unrelated, cleanly-auto-merged main changes: the cursor-review SHA bump
(#200) and the pr-size rename-discount fix (#196).

Verified: full workflow-pins test suite (160 tests) and the lint itself
pass; pr-size go tests pass except one pre-existing, pre-merge failure
(TestResolveMergeBaseWithAdvancedBaseBranch, environment-dependent,
reproduces identically on an unmodified origin/main checkout — unrelated
to this merge).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded Authored by the agent-work loop cursor-review Multi-model cursor review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants