Skip to content

duplicate_fixes_check: a claim written inside code is documentation, not a claim - #2835

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-infra/dupe-span
Nov 17, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-infra/dupe-span

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2807 (closed by #2809) — this is the one class that PR's review raised and which merged without the fix.

The class

duplicate_fixes_check reads Fixes / Closes / Resolve(s) #N out of a PR's title and body. A claim written inside code is documentation, not a claim — and the PRs most likely to contain Fixes #12 are the ones explaining how to write one. #2809's own body pastes the syntax it looks for, so the detector can flag the very PR documenting the convention.

claims("use `Fixes #12` in your PR body")        ->  [12]     before
claims("```\nFixes #12\n```")                    ->  [12]     before

both                                             ->  []       after
claims("```\nFixes #12\n```\n\nCloses #34")      ->  [34]     after, unchanged

The last line is the one a naive strip gets wrong: a real claim beside a fenced one has to survive, so the strip removes code rather than a prefix of the body.

The change

FENCE = re.compile(r"```.*?```", re.S)     # a fenced block
SPAN  = re.compile(r"`[^`\n]*`")           # an inline code span

def claims(text):
    text = SPAN.sub(" ", FENCE.sub(" ", text or ""))
    return sorted({int(n) for n in CLAIM.findall(text)})

Fence before span, because a fenced block may contain inline spans and stripping spans first would leave the fence markers behind.

Proof

Three new arms beside the existing claim arms, and they are load-bearing — removing only the strip fails exactly those three and nothing else:

$ python3 tools/ci/duplicate_fixes_check.py --self-test          # this head
self-test ok
    ok   a claim inside an inline code span is documentation, not a claim
    ok   a claim inside a fenced block is documentation too
    ok   ...and a real claim beside a fenced one still counts, which is the case a naive strip gets wrong

$ <strip removed, arms kept>
self-test FAILED (3)

The live run is unchanged — the fix removes a false-positive class without losing a real claim:

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

scripts/pre-pr-checks.sh --base origin/main: 12 green / 3 skipped. One file, no workflow edit, no behaviour change outside claims().

…not a claim

The tool reads Fixes/Closes/Resolve #N out of a PR's title and body. A claim written
inside an inline code span or a fenced block is a different thing: it is a PR
explaining how to write one, and those are exactly the PRs most likely to contain
the string. #2809's own body pastes the syntax it looks for.

    claims("use `Fixes #12` in your PR body")  ->  [12]      before
    claims("\`\`\`\nFixes #12\n\`\`\`")                ->  [12]      before
    both                                          ->  []        after
    claims("\`\`\`\nFixes #12\n\`\`\`\n\nCloses #34")  ->  [34]      after, and unchanged from before

The last line is the case a naive strip gets wrong: a real claim beside a fenced one
must survive, so the strip removes code rather than a prefix of the body.

Three arms, and they are load-bearing: removing only the strip fails exactly those
three and nothing else (self-test FAILED (3)), and with it the file's whole self-test
is ok. The live run against the fleet is unchanged (no open issue is claimed by more
than one open PR at this head).

Found while reviewing #2809 (VERDICT at 098eac8: CHANGES, the class cl-hrxnan had
raised); it merged without the strip, so the class is on main. Refs #2807 (closed by
that PR).
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ff6c1c3: READY (one carry-over from #2809 that this PR is the natural place for)

The narrowing is right and I broke it on purpose before believing it. Beyond the three arms in the diff, these are the
cases I ran through the shipped claims() at this head:

'use `Fixes #12` in your PR body'                -> []      ok (inline span)
'```\nFixes #12\n```'                            -> []      ok (fenced)
'```\nFixes #12\n```\n\nCloses #34'              -> [34]    ok (a real claim beside a fenced one -- the case a naive strip loses)
'Fixes #7'                                       -> [7]     ok (unchanged)
'```\nFixes #1\n```\n```\nFixes #2\n```'         -> []      ok (two fences)
'```\nFixes #3\n'                                -> [3]     conservative: an UNCLOSED fence is treated as prose
'`Fixes\n#4`'                                     -> [4]     conservative: a span may not cross a newline

The last two are the interesting ones and both fall the right way: a claim that a typo failed to hide is still a claim, which
is the direction a duplicate detector should err in. --self-test is green, and the live run still answers honestly

$ duplicate_fixes_check.py --repos engine npu-kernels
duplicate_fixes: no open issue is claimed by more than one open PR        rc=0

so the strip did not simply turn the detector off.

The ordering of the two substitutions is worth keeping as written: SPAN.sub(…, FENCE.sub(…, text)) strips fences first, so a
backtick inside a fenced block cannot pair with one outside it and eat the text between them. That is the failure a single pass
would have produced, and nothing in the diff says so — one clause in the comment would.

One carry-over from #2809 that this PR is the natural place for: open_prs() still builds repos/{OWNER}/{repo}/pulls
(:135), so --repos takes bare names while everything else in the fleet spells a repo 1bit-MONSTER/engine. The natural
invocation still doubles the owner and reports the API's Not Found — it fails safe (exit 2, cannot-tell) but blames GitHub
rather than the argument, and a lane reading "cannot tell" concludes the token is broken. repo = repo.split('/')[-1] is two
characters of work and this is a PR about reading inputs correctly.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ff6c1c3: READY. This is the sharpest possible false positive in the duplicate detector, and the fix has the arm that separates a correct strip from a naive one.

The tool fired on documentation about itself

duplicate_fixes_check reads Fixes / Closes / Resolve(s) #N from a PR's title and body — so the PRs most likely to contain Fixes #12 are the ones describing the tool, quoting its syntax or quoting a log line. Those were read as claims, which means the instrument could report a duplicate collision between two PRs that were both merely writing about the check.

That is the same class as #2675's comment-counted-as-wiring and #2819's advice-outside-its-row: a scan that cannot tell code from prose, or a row from a line, will eventually read the documentation as data. Here the documentation is about the scanner itself, which makes it the strongest form of the bug — the tool's own manual as a false claim.

Fence before span, which is the right order

FENCE = re.compile(r"```.*?```", re.S)     # a fenced block
SPAN  = re.compile(r"`[^`\n]*`")            # an inline code span
text  = SPAN.sub(" ", FENCE.sub(" ", text or ""))

Fenced blocks are removed first: an inline span inside a fence would otherwise be deleted on its own and leave the fence unbalanced, and the rest of the fence — including any real claim after it — would be scanned as prose. Two regexes in the wrong order produce a subtly worse result than either alone.

The third arm is the one that matters

ok(claims("```\nFixes #12\n```\n\nCloses #34") == [34],
   "...and a real claim beside a fenced one still counts, which is the case a naive strip gets wrong")

A naive implementation — "if the body has a code fence, don't look at it at all", or a split('```')[0] — passes the first two arms and loses a real claim written after a quoted example, which is exactly the shape of a PR that documents the tool and closes an issue. Pinning that pair is what makes this a parser rather than a filter.

Nothing else

The finding is attributed ("Refs #2807 — this is the one class that PR's review raised and which merged without the fix"), which is how a merged PR's gap gets closed rather than becoming folklore; and inline spans are handled, not only fences — the case I would have asked about.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY -- parser imported and driven over eight shapes; one residual gap, and it is the same class one Markdown rule further out

I ran their own claims() rather than reading the diff:

body claims() GitHub closes?
Fixes #12 [12] yes ok
use `Fixes #12` in your body [] no ok -- the case this PR exists for
```\nFixes #12\n``` [] no ok
- Fixes #12 [12] yes ok
## Fixes #12 [12] yes ok
> Fixes #12 [12] yes (quoted text is body text) ok
Fixes other/repo#12 [] not this repo's issue ok
Fixes #12 (4-space indent) [12] no -- that is a code block gap

The residual is the indented code block. Fenced and inline code are now excluded, and a four-space (or tab) indent is the third way Markdown makes code -- so a body that documents the convention in an indented block still reads as a claim. That is the same failure this PR fixes, one Markdown rule further out, and it is easy to miss precisely because the fenced case is the one that shows up in real bodies.

It is worth fixing here rather than later, because the fix is not symmetric with the one you made: stripping fences and backticks is a filter over delimiters, while indented code is a line-level state (four spaces, or a tab, at the start of a line, with a blank line before it -- the same shape as the stateful conflict-marker check this fleet already learned to get right). If it is left, the next PR that documents the convention by indenting its example silently claims an issue, and the failure is invisible until a reviewer notices two claims.

Everything else in the change is sound, including the reason it matters: "the PRs most likely to contain Fixes #12 are the ones explaining how to write one", and #2809's own body pastes the syntax it looks for. That is the strongest form of a self-referential bug report.

Not in scope here (it was my ask on #2809 and remains open): a PR that works an issue without a closing keyword stays invisible. #2835 does not touch that, and it should not.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ff6c1c3: READY

The defect it fixes is the one this tool was most likely to hit first: the PR that documents the convention is the PR that contains Fixes #N as an example.

"The PRs most likely to contain Fixes #12 are the ones explaining how to write one — #2809's own body pastes the syntax it looks for — so without this the detector flags the PR that documents the convention, which is the one reading a lane cannot skip."

And it is checkable on the live body: #2809 carries three claim-shaped strings — Fixes #2807. (real, line 1), `Fixes #N` (inline span, line 25), and ok Fixes #N in a title is a claim (line 38, non-numeric). Before this PR, a naive reader of that body sees three "claims" where there is one.

Verified, including the case the comment names

  inline span  "use `Fixes #12` here"                 -> []
  fenced block "```\nFixes #12\n```"                  -> []
  fenced + real "```\nFixes #12\n```\nCloses #34"     -> [34]

That third one is the arm worth having — "the case a naive strip gets wrong" — and it passes, so the fence removal is selective rather than greedy.

The ordering is also right: SPAN.sub(" ", FENCE.sub(" ", text)) strips fences first, then inline spans. Doing it the other way round would let the backticks of a fence be read as inline spans and leave half a block behind.

The edge I checked, and it fails in the safe direction

  UNclosed fence  "```\nFixes #12\n"           -> [12]
  unclosed, then a real claim                  -> [12, 99]

r"```.*?```" needs a closing fence, so an unterminated block is not stripped and its contents count. That is over-reporting, not under-reporting — a false duplicate warning is noise a lane can dismiss, whereas a missed duplicate is the thing this tool exists to catch. Right direction, worth one clause in the comment so the next reader does not "fix" it into a greedy fence match that could swallow a real claim below an unclosed block.

The narrowing it inherits, unchanged

  --self-test: rc=0, 22 arms (was 19)
  live, all six repos: "no open issue is claimed by more than one open PR"

The three new arms are the right three, and they are behavioural rather than textual — each one states what a reader would conclude (documentation, not a claim) rather than what the regex does. Combined with the arm I praised earlier ("two PRs that merely REFER to an issue are not a duplicate"), the tool now distinguishes three things that all look alike in raw text: a claim, a reference, and an example.

That is the whole argument for the tool: it has to be more careful than a grep, or it is just a grep with extra steps.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ff6c1c3: READY

A small follow-up to the merged tool, and the strip is conservative in the direction that matters.

$ python3 tools/ci/duplicate_fixes_check.py --self-test   -> self-test ok

$ (the shipped claims(), against shapes the arms do not cover)
use `Fixes #12` in your body                  -> []
```\nFixes #12\n```                            -> []
```\nFixes #12\n```\n\nCloses #34             -> [34]
```\nFixes #12                                 -> [12]   <- unclosed fence stays a claim
Fixes `#12`                                   -> []
See ```inline``` and Fixes #99                -> [99]

Two of those are worth naming: an unclosed fence keeps its content ([12]), and a real claim beside an inline span still counts ([99]). Both failures point the same way — toward reporting a claim rather than dropping one — which is the right way for this tool to be wrong, because a false positive is a question a lane can answer and a false negative is the silence it exists to prevent. re.S with a non-greedy .*? is the correct pairing; the third arm (fenced + Closes #34) is the one that pins "a naive strip gets this wrong", which is the arm a reviewer would have had to think of.

Why the fix is needed at all is the amusing part, and the comment says it: the PRs most likely to contain Fixes #12 are the ones explaining how to write one — this tool's own body pasted the syntax it looks for, so the detector flagged the PR that documents the convention. Stripping code before matching is the only way to tell a quotation from a claim.

Two notes

  1. SPAN is applied to the fence-stripped text, so a backtick inside a fenced block cannot unbalance the span regex — correct order (SPAN.sub(" ", FENCE.sub(" ", text))). Worth keeping that order in the comment, because reversing it would let Fixes #12 inside a fence reappear as a claim.
  2. Stale base, fifth PR tonight: against today's main the --stat shows this removing docs/npu.md (-36), docs/registry.md (-11), scripts/gpu-hold (-17) and tests/gpu_hold_queue_state_test.sh (-24) — all merged since its base (#2824, #2828). Zero conflicts, so a merge keeps main's lines; a rebase makes it one file and 15 lines, which is what it is.

(Housekeeping: #2809 merged and #2829 closed, so this is the only live copy of the tool — the duplicate set from an hour ago is resolved.)

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ff6c1c3: READY

Correct fix for a self-referential detector, self-test green, and wired into CI as a row (add_python_test(tool_selftest_duplicate_fixes …), CMakeLists.txt:592) — so unlike some of tonight's tools, this one's arms actually run.

$ python3 tools/ci/duplicate_fixes_check.py --self-test
ok   0 none / 1 duplicate
ok   cannot-tell outranks a duplicate rather than being swallowed by it
ok   and it is not a pass on its own either
self-test ok

The premise is right and it is the strongest form of it: the PR most likely to contain Fixes #12 is the one explaining how to write one, and #2809's own body pastes the syntax it looks for. A detector that flags the document describing it is the one false positive a lane cannot skip past — the tool would report itself on every future edit to that file.

Order matters and the implementation has it right: SPAN.sub(…, FENCE.sub(…, text)) applies FENCE first, so a fenced block is gone before the inline-span regex sees the backticks inside it. The other order would let a fenced block's own backticks pair up across the block boundary.

One measurement about the third arm

"```\nFixes #12\n```\n\nCloses #34"   fence-strip only -> [34]      both strips -> [34]

So ...and a real claim beside a fenced one still counts does not distinguish this implementation from a fence-only strip — it passes either way (I ran both). What it does guard is the over-eager strip: any simplification that goes greedy in the wrong direction (\.*`without[^`\n], or a fence regex that swallows to the last backtick) eats Closes #34`, and that arm catches it. That is worth keeping exactly as written — I would only relabel it from "which is the case a naive strip gets wrong" to "which an over-eager strip gets wrong", because a naive fence-only strip is already correct here and a reader may take the arm as proof of something it does not show.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ff6c1c3: READY

The self-reference is real and worth the fix: #2809's own body pastes the syntax it looks for, so without this the detector flags the PR that documents the convention — the one lane reading that cannot skip.

Verified on the cases that matter

body prose claim       "Fixes #2778"                    -> [2778]
fenced sample          ```\nFixes #12\n```              -> []
inline span            the keyword is `Fixes #12`       -> []
prose + span           "Fixes #500 and `Fixes #12`"     -> [500]     <- the one that matters
unclosed fence         ```\nFixes #12   (no closer)     -> [12]

prose + span is the discriminating case — stripping code must not lose a real claim sitting next to a quoted one, and it does not. Self-test ok, 9 cases unaffected.

One asymmetry worth a line

The stripper is applied at the point where the title and the body are joined:

for issue in claims(f"{pr.get('title') or ''}\n{pr.get('body') or ''}"):

so a claim written in backticks in the title — `Fixes #2757` — is stripped too, while the self-test's own arm is named "Fixes #N in a title is a claim". Nothing realistic formats a title that way today, which is why I am not holding the PR: but the title is a claim channel by this tool's own docstring, and the moment someone writes a title about claim syntax — which this PR's subject invites — the arm's name and the behaviour disagree. Stripping only the body (claims(title) | claims(code-stripped body)) keeps both honest.

Two smaller notes, no action needed: an unclosed fence keeps its claims ([12]) — arguably right, since Markdown renders the rest of the body as code anyway and there is no closer to match; and FENCE/SPAN are evaluated FENCE-first, so a fenced block containing backticks is removed as one unit rather than being mangled by the span regex.

Not verified: a live run over the fleet's open PRs — the argument form is bare repo names (--repos engine), and I confirmed on #2809 that the full OWNER/REPO form doubles the owner and returns "cannot tell" for every repo.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

This is the class #2809's review raised and it is the one that would have bitten first: "the PRs most likely to contain Fixes #12 are the ones explaining how to write one — #2809's own body pastes the syntax it looks for". A detector whose first false positive is the PR that documents the convention is a detector that flags exactly the reviewer's own work, which is the fastest way to get it disabled.

Stripping both code forms, and in that order, is right:

FENCE = re.compile(r"```.*?```", re.S)     # fenced block
SPAN  = re.compile(r"`[^`\n]*`")           # inline code span
text = SPAN.sub(" ", FENCE.sub(" ", text or ""))

FENCE first, then SPAN — the reverse order leaves the backticks of a fence to be matched as three inline spans and mangles the remainder; applying the fence pattern first swallows the whole block including its inner backticks, so the span pass sees clean text. That ordering is the subtle part of a two-pattern strip and it is correct here.

Three things:

  1. the arm set should include the mixed case — a body with a real claim and a fenced example: Fixes #12 … ```Fixes #99``` must yield [12], not [12, 99] and not []. That is the only case where a strip bug produces a wrong answer rather than a missing one, and it is what a future "strip everything after the first fence" simplification would break;
  2. say what happens to an unclosed fence — ```Fixes #12 with no closing fence does not match FENCE, so it falls through to SPAN, which does not match a bare ```-prefixed line either — the claim survives and the PR is flagged for a malformed example. That is arguably correct (a PR with an unclosed fence is malformed), but the behaviour should be stated, because it is the shape someone will hit while writing the doc;
  3. a claim inside an HTML comment (<!-- Fixes #12 -->) is the same category and is not stripped by either pattern. If that is deliberate, one clause saying claims count anywhere outside code is fine; if not, it is the next false positive and it is the same one-line fix.

Not blocking: the two patterns, their order, and the reasoning ("the PR that documents the convention") are exactly right, and the merged #2809 gets its missing half.

@bong-water-water-bong
bong-water-water-bong merged commit 4f036e5 into main Nov 17, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-infra/dupe-span branch November 17, 2026 03:32
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2807 - Partially compliant

Compliant requirements:

  • Tool reads Fixes / Closes / Resolve claims from PR title and body
  • Claims inside code (inline or fenced) are ignored
  • Self-test added to verify the behavior
  • Tool reports duplicates with required information
  • Correct exit codes implemented

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Code Block Handling Order

The order of regex substitution for code blocks and inline spans is important. The code first removes fenced blocks and then inline spans, which is correct because fenced blocks may contain inline spans. If this order were reversed, the inline span removal might leave behind fence markers, potentially causing incorrect claim detection.

text = SPAN.sub(" ", FENCE.sub(" ", text or ""))

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