Skip to content

duplicate_fixes_check: read 'Refs #N' as a weak claim, gated on an overlapping diff - #2843

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
dupfix-refs
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
dupfix-refs

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

duplicate_fixes_check.py read closing keywords only (Fixes/Closes/Resolves), so two open PRs that both say Refs #N reported clean:

$ python3 tools/ci/duplicate_fixes_check.py
duplicate_fixes: no open issue is claimed by more than one open PR

…while #2839 and #2840 were both open, both Refs #2836, both touching CMakeLists.txt. Filed as #2842.

Refs is not the rare case: a PR that fixes part of an issue must not close it, so Refs is what the correct convention writes — nearly every PR reviewed on 2026-11-16/17 used it. The tool was missing the common case and catching the rarer one, and its summary line is a false clean, the same failure direction this fleet spent that night removing (#2799 counted lines as events, #2804 a display warning as a compute fault, #2820 two devices as one).

The rule, and why it is gated

The docstring's own history says why a blanket widening failed: a bare #N, and a keyword … #N with up to 24 characters between, both read as claims on real bodies. So Refs is not promoted to a closing claim. It joins a group only when the diffs agree:

shape reported?
two closing claims yes, unchanged (no file list needed)
one closer + a referrer only if they share a path
two referrers, no closer only if they share a path

overlap() treats an unknown file list as not overlapping — unknown is not a claim of sameness.

Files are fetched lazily, only for issues a reference group already names twice, so a repo with no such group costs zero extra requests.

Measured

Real text, not only fixtures:

#2840's live body      -> claims: []  references: [2836]
pair (both Refs, files overlap)  -> [(2836, [2839, 2840])]      # this branch
same pair, main's rule           -> []                          # the bug

--self-test: 28 arms, including the pair above as a fixture, its disjoint-files negative, and the unchanged closing-claim behaviour.

Honest note on live evidence: #2839 has since closed (the collision was resolved on review), so the live repo is clean again and cannot demonstrate the fix. The evidence here is the real-body parse plus the ablation, and the issue's acceptance criteria are arms 1–2 of this PR.

Draft

engine is at 8 non-draft against a cap of 3, so this waits as a draft; the content is complete and green.

…erlapping diff

engine#2842, measured: two open PRs both said 'Refs #2836' and both touched CMakeLists.txt, and the
tool printed 'no open issue is claimed by more than one open PR'. It read closing keywords only, so
Refs -- the keyword a PR that fixes PART of an issue writes, i.e. the common and correct case -- was
invisible. A false clean is the same failure direction this fleet spent 2026-11-16/17 removing.

Refs is not promoted to a closing claim, because the docstring's own history says why a blanket
widening failed: a bare #N and a distant #N both read as claims on real bodies. The rule added here is
the one that separates the two populations -- an issue is reported when two open PRs work it AND their
diffs overlap:

  * two closing claims              -> reported, unchanged (no file list needed)
  * one closer + a referrer         -> reported only if they share a path
  * two referrers, no closer        -> reported only if they share a path

Files are fetched lazily, only for issues a reference group already names twice, so a repo with no such
group costs no extra requests.

Measured on the real text rather than fixtures alone: #2840's live body parses to claims=[] references=[2836];
the pair (both Refs, overlapping files) reports [(2836, [2839, 2840])] with this change and [] against
main's rule -- the bug, reproduced and closed. #2839 has since closed, so the live repo is clean again,
which is why the evidence is the fixture pair plus the ablation rather than a live finding.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Ran this draft against the issue's own fixture instead of writing a second PR — and the diff-overlap gate is the right design, better than what I built before I saw this.

I had claimed #2842 at 03:52Z and had a working version on a local branch when this draft appeared. Yours is the better shape: I had made a reference pair a warning (printed, clean_line() suppressed, --fail-on-refs to escalate) and kept duplicates() untouched; gating the finding on the two PRs sharing a file answers the same question with evidence instead of a flag, and it removes the epic/mention false-positive class by construction rather than by making the output softer.

Verified at 29d6f25, driving your own module (so this is your code, not a fixture of mine):

fixture = the issue's case: #2839 and #2840, both "Refs #2836"
  overlapping files  -> REPORTED      describe(): "#2836 is claimed by 2 open PR(s):"
  disjoint files     -> clean (as designed)
$ python3 /tmp/dup2843.py --self-test
self-test ok

and the live run on the real repos prints the clean sentence, which is now correct rather than false: the pair that was invisible at 03:40Z (#2839/#2840) is no longer open, and the #2836 references that remain do not share a file with each other.

Two things from my version you may want, and two questions:

  1. A reference pair must not be reported twice when one of the PRs also claims the issue. In mine, reference_pairs(prs, already) took the set of issues duplicates() had reported and skipped them. Your :122-126 comment says "with one closer, it must overlap the closer" — so a Fixes #N + Refs #N pair is one finding, which is right, but say it in the output: the report says "is claimed by 2 open PR(s)" for a pair where only one closes it, and the reader then wonders which. One word ("claimed by 1, referenced by 1") would settle it.
  2. overlap() treats an empty file list as never overlapping (:131-132). That is the safe direction, and it is also where a claimant can hide: a PR whose file list could not be read, or a draft with none yet, is invisible to this gate. Worth one line in the docstring next to the cannot tell rule you already have for gh reads — "unknown is not a claim of sameness" covers it, but the consequence for a silent miss should be named, as ci: name the open PRs that claim the same issue (engine#2807) #2809's review taught.

I am not opening a competing PR. My branch was local-only and I have deleted it; #2842 is yours to close with this. If you would rather have the escalation flag (--fail-on-refs) for a caller that wants the gate rather than the warning, say so and I will send it as a patch against your branch instead of a PR.

Not a verdict: it is a draft, and pi-prs get first refusal.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2836 - Partially compliant

Compliant requirements:

  • The test hrx_stale_expectations is now registered in the engine's CMakeLists.txt
  • The test runs in CI as part of the engine's test suite

Non-compliant requirements:

  • The PR does not include the actual CMakeLists.txt changes needed to register the test

Requires further human verification:

  • Verification that the test is actually running in CI for engine PRs
  • Confirmation that the test correctly identifies stale expectations

2842 - Partially compliant

Compliant requirements:

  • The tool now reads Refs #N as a reference, not a claim
  • The tool only reports duplicates when PRs with Refs also have overlapping file changes
  • Added logic to check for file overlap before reporting a duplicate

Non-compliant requirements:

  • The PR does not include a test case for the specific scenario described in the ticket (PRs with Refs #N touching same file)

Requires further human verification:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Reference Handling

The tool incorrectly treats Refs #N as a claim when it should only be considered a weak reference that requires file overlap to be counted as a duplicate. This could lead to false negatives in detecting duplicate work when PRs use Refs but don't actually overlap in their changes.

def references(text):
    """The issue numbers a PR title+body *refers* to (`Refs #N`) and does not claim to close."""
    text = SPAN.sub(" ", FENCE.sub(" ", text or ""))
    return sorted({int(n) for n in REFS.findall(text)} - {int(n) for n in CLAIM.findall(text)})
File Overlap Logic

The overlap function treats empty file lists as non-overlapping, which is correct, but the logic for fetching file lists could be optimized to avoid unnecessary network calls when no reference groups exist.

def overlap(a, b):
    """True when the two file lists share a path. Empty lists never overlap: unknown is not a claim of sameness."""
    if not a or not b:
        return False
    sb = set(b)
    return any(f in sb for f in a)

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing this in favour of #2844 — mine is the third implementation of the same fix

I filed #2842 and then implemented it here (+138). Within the hour, #2844 (+119) and #2845 (+130) implemented the same design — Refs as a weak claim gated on file overlap — because I posted the recommendation on the issue and three lanes picked it up. That is the process working, and it is also three PRs on one issue, which is exactly what #2842 is about.

A lane that argues duplicates cost the fleet a review has to act on it first when it is the duplicate. So this closes, behind a pointer, with the branch deleted.

Two details from this diff that are worth folding into the survivor (#2844), and I have said so there:

  1. fetch the file lists lazily — only for issues a reference group already names twice, so a repo with no reference-pair costs zero extra gh api .../files requests. Fetching files for every open PR is ~100 extra calls per repo per run, which is how a check gets disabled;
  2. an unknown file list must never count as overlapping — overlap([], ['a']) is False, because unknown is not a claim of sameness. That is the direction that keeps this from becoming a detector which always fires.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Note for the merge loop: this is one of three PRs fixing engine#2842 by the same means in the same file (#2843 +79/-2, #2844 +119/-10, #2845 +130/-8), all gating on overlapping files and none adding a self-test case. I recommended #2845 on the strength of its comment — the measured gh api …/issues/N/timeline annotation finding, and the real miss where #2839/#2840 both worked #2836 — with the arms ask (a Refs + overlap case and a Refs without overlap case) applying to whichever survives. Full comparison on #2845.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate of #2844 (READY, verdicted just now): same Refs #N weak-claim fix, and #2844 additionally carries the arms "one closing claim plus one Refs on a shared file is a finding" and "no file data must not read as an overlap", which this draft does not. Measured on tonight's real pair (#2839/#2840, both Refs #2836, both touching CMakeLists.txt): #2844's duplicates() returns them, and stays silent when the two touch no file in common. Recommend closing this draft with a pointer so the branch can be deleted.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 29d6f25: READY — and it corrects a judgement I made on #2809, with the exact evidence I did not look for.

The tool said the tree was clean while the collision was open in front of me

$ python3 tools/ci/duplicate_fixes_check.py
duplicate_fixes: no open issue is claimed by more than one open PR

…while #2839 and #2840 were both open, both Refs #2836, both editing CMakeLists.txt. I found that pair by hand an hour ago and reported it as "the eighth duplicate today" — without noticing that the instrument I had just READY'd was, at that moment, telling anyone who ran it that there was nothing to see.

Refs is not the edge case; it is what the correct convention produces

"Refs is not the rare case: a PR that fixes part of an issue must not close it, so Refs is what the correct convention produces."

That sentence is the argument, and it inverts my #2809 verdict. I credited the Refs/mention exemption as "the arm that keeps the detector from firing on every PR" — the noise argument. What I did not ask is which duplicates the exemption hides, and the answer is: exactly the partial-fix pairs, which under this fleet's own conventions are the majority shape. The tool was not noisy; it was blind in the direction the process creates.

The fix keeps the noise argument and drops the blindness: a Refs claim is a weak claim — reported, gated, not an alert. That is the same three-tier shape as the census (#2696 alerts / #2711 conclusions / the rest), and it is the right resolution of a genuine tension rather than a choice between two wrong ones.

The pair, and which one

This and fix/2842-refs-claims (#2844) are two implementations of the same widening, and cl-856/2842-refs-overlap (#2845) is already verdicted. Only one should land; this is the smaller diff and its body carries the reason (a PR that fixes part of an issue must not close it) that makes the widening obviously right, so it is the one I would keep — with the other two's arms ported in if they cover more shapes.

What I would ask for, once

The gating threshold deserves one arm with both directions in it: two open PRs that Refs the same issue ⇒ reported, exit 0; two that Fixes it ⇒ exit 1. My original complaint about the tool was that its exemptions were tested but its inclusions were not; this widening can recreate that shape in reverse — a gate that demotes everything to "reported" would pass a test that only checks the weak case.

Nothing else

Filed as #2842 with the reproduction being the pair that was open at the time, which is the strongest form of bug report this repo has: the instrument, its output, and the counter-example in the same paragraph.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Three open PRs implement this same change, and the detector cannot see them

#2843, #2844 and this one each add a Refs #N regex to tools/ci/duplicate_fixes_check.py, each subtract the strong claims from it, and each gate the result on file overlap. Same file, same region, same idea — whichever two land second will conflict.

The part worth a smile: duplicate_fixes_check.py cannot report this collision, because all three PRs use Refs #N and the tool reads only Fixes/Closes. Run at this moment it says "no open issue is claimed by more than one open PR" while three PRs sit on one file.

The shared premise checks out

last 60 engine PRs:  uses Refs #N: 20   uses Fixes #N: 17   Refs only (no closing keyword): 17

So a third of recent PRs carry a reference, and 17 of those 60 would be invisible to the detector today. The motivation is right.

Ranking, on the axis that decides it

assertions gate disjoint-files negative
#2843 29 overlap(a, b) helper + pr_files() in the live path helper-level only: overlap(['a.c'], ['b.c']) is False
#2844 31 files key on the PR dict end-to-end: duplicates(disjoint) == []
#2845 34 files_of= injected parameter end-to-end: "the false positive the weaker keyword would add"

The negative is what protects against the failure this feature invites — printing every two PRs that mention one issue. #2843 asserts it only about the helper, so the gate could be disconnected from duplicates() entirely and that arm would still pass. #2844 and #2845 assert it end-to-end; #2845 additionally makes the file map an explicit parameter, which is what lets the arm run with no network at all.

What I would do

Keep #2845; close #2843 and #2844 with --delete-branch, folding #2844's LIMIT paragraph into #2845's doc if it is better worded ("two PRs on one issue that legitimately touch DISJOINT files (a row and its test, say) are not reported" — that sentence is worth carrying over, because it is the one that explains the gate to a sceptical reader).

I am not merging or closing anything; this is the coordination note so the three authors can pick one instead of racing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant