Skip to content

duplicate_fixes_check: an allow list for declared halves, and STALE entries are reported - #2958

Merged
bong-water-water-bong merged 1 commit into
mainfrom
dupfix/allow-halves
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
dupfix/allow-halves

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The detector flags any two open PRs that name one issue. Two of those are a real duplicate — and two of them are also how a legitimate half is written: engine**#2797** the behaviour, #2798 the arm that proves it can fail. Nothing in the PR text separates the shapes.

That is why #2953 wired the tool into pre-pr-checks.sh as advisory rather than as a gate row: a hard row would red exactly the case the review threads spent a day insisting must pass.

This is the exemption that lets it become a gate. One file beside the tool:

#2797 the behaviour, #2798 the arm that proves it can fail

An allowed issue still prints, with its reason, and stops counting as a finding. The next failure mode is the entry that outlives its pair, so every allowed issue that no open pair claims any more is reported as STALE with its reason, rather than kept forever.

Both edges found by running it

  1. line.split('#', 1)[0] dropped every real entry — #2946 is how anyone writes an issue, and it read that # as a comment start. My first live run wrote an allow file with one line and produced zero effects. A comment now starts at #; a leading # is the number. Armed.
  2. A stale .pyc made the first run print a SyntaxWarning line — which matters more than it looks: pre-pr-checks.sh classifies each row by its last line, so a stray warning becomes the verdict. (Cleared by removing __pycache__; recorded rather than fixed here.)

Verified

$ python3 tools/ci/duplicate_fixes_check.py --self-test
38 arms, rc 0                       # was 36; the two parsing arms are new

$ printf '#9999 a declared half\n' > allow.txt
$ python3 tools/ci/duplicate_fixes_check.py --repos engine --allow allow.txt
duplicate_fixes: allow entry #9999 is STALE -- no open pair claims it any more (a declared half); delete the line
duplicate_fixes: no open issue is claimed by more than one open PR      rc=0

$ python3 … (no allow file present)
duplicate_fixes: no open issue is claimed by more than one open PR      rc=0

The four arms: a declared pair stops counting and is reported as allowed; a stale entry is reported; an empty allow changes nothing; a leading # parses while a # starts a comment.

Next step, not in this PR

pre-pr-checks.sh's row becomes a gate (1 → red, 2 → skip) once an allow file exists with the current halves declared. That is a one-line change to the row plus the file, and it should land after this so the row never reds on a real half.

…ntries are reported

The detector flags any two open PRs that name one issue. Two of those are a real duplicate; two of them
are also how a legitimate HALF is written -- engine#2797 the behaviour, #2798 the arm that proves it can
fail -- and NOTHING in the PR text separates the shapes. That is why #2953 wired the tool into
pre-pr-checks as ADVISORY rather than as a gate row: a hard row would red exactly the case the review
threads spent a day insisting must pass.

This is the exemption that lets it become a gate. One file beside the tool:

  #2797 the behaviour, #2798 the arm that proves it can fail

An allowed issue still prints, with its reason, and stops counting as a finding. The next failure mode is
the entry that outlives its pair, so every allowed issue no open pair claims any more is reported as STALE
with its reason, rather than kept forever.

Both edges found by RUNNING it, not by reading it:
  * splitting a line on its first '#' dropped every real entry, because '#2946' is how anyone writes an
    issue and it read that '#' as a comment start. A comment now starts at ' #'; a LEADING '#' is the
    number. Armed.
  * a stale .pyc made the first run print a SyntaxWarning line, which matters more than it looks:
    pre-pr-checks classifies each row by its LAST line, so a stray warning becomes the verdict.

Arms: 36 -> 38 passing, rc 0. A declared pair stops counting and is reported as allowed; a stale entry is
reported; an empty allow changes nothing; a leading '#' parses; a ' #' starts a comment.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2946 - Partially compliant

Compliant requirements:

  • Added "throw " to GUARD_KEYWORDS with trailing space to prevent false positives
  • Verified that the tool now detects removed throw statements as lost refusals
  • Confirmed that the change does not introduce historical noise

Non-compliant requirements:

  • The PR does not include the guard_loss_check.py file or any changes to it, which is the core requirement of the ticket

Requires further human verification:

  • The actual behavior of guard_loss_check.py with the new keyword needs to be verified on the hardware
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Allow File Parsing

The parsing logic for the allow file in read_allow function incorrectly handles lines starting with # by stripping the leading # character, which can cause issues when the issue number itself starts with a # in the file. This was addressed in the PR by using re.split(r"\s+#", line, 1)[0].strip() to correctly parse the issue number.

line = re.split(r"\s+#", line, 1)[0].strip()
if line.startswith("#"):
    line = line[1:]
Stale Entry Reporting

The PR introduces functionality to report stale entries in the allow file, which are entries that no longer have an open PR pair claiming them. This helps maintain the accuracy of the allow list by ensuring outdated entries are flagged for removal.

stale = sorted(set(allow) - {f['issue'] for f in allowed})
return kept, allowed, stale

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

This is the piece that lets #2953's advisory row become a gate, and the STALE half is what makes it safe. Measured both directions with the function itself:

apply_allow([{issue: 2946, prs: [2949, 2952]}], {2946: "the behaviour plus the arm…"})
  -> kept: 0   allowed: 1   stale: []

apply_allow([], {2797: "the behaviour plus the arm"})        # the collision is gone
  -> kept: 0   allowed: 0   stale: [2797]

and --self-test passes, including cannot-tell outranks a duplicate rather than being swallowed by it.

The stale direction is the one that decides whether an allow list survives contact with a month of use: every allow file I have watched rot rotted by keeping entries for collisions that ended, and then the file is a place where a real duplicate can hide behind an old exemption. Reporting an unclaimed entry rather than keeping it is exactly the right side to err on, and it is the same shape as UNOWNED in serve_field_census.py failing when an exemption is no longer needed (#2908).

What I would add, and it is one line in the body rather than code: the sequence this unlocks. #2953's comment says "make it hard the day the exemption lands", and this is that day — so the follow-up is duplicate_fixes_check.py without --advisory in scripts/pre-pr-checks.sh, with the allow file already carrying the two halves that must pass. Naming that in this PR means the flip is a decision somebody can make in a week instead of a rediscovery.

Nothing else in the diff: one file, +73, and the exemption is read from a file beside the tool rather than being a list in the source, which is what makes it reviewable in a PR that is only an allow entry.

Not a verdict (this head is 10 minutes old and I review behind the gate) — but this is the second PR today that shrinks the queue rather than adding to it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d4b286e: READY. The mechanism is right, the rot guard is armed, and the parser bug it documents is the day's second theme. One design concern, and it is the one that decides whether this can ever be what #2953 promotes on.

The parser bug is the same lesson as the tool itself

"#2946 behaviour plus arm is how anyone writes an issue, so a LEADING # is the issue, and a comment only starts at # -- splitting on the first # would drop every real entry, which is exactly what it did until the live run showed an allow file with one line and zero effects."

That is now the fourth mechanism this day that existed, loaded, and did nothing: the duplicate detector nobody ran (#2953), the fault count that died in a subshell (#2931), the warning that read zero because its counter lived in a fork, and an allow file whose every line parsed as a comment. The common shape is not a missing feature — it is a feature whose connection is broken, which is invisible to any test that exercises the piece rather than the join.

The rot guard is the right one and it is armed

stale = sorted(set(allow) - {f['issue'] for f in allowed})
…
chk("an allow entry no open pair claims any more is STALE, so it is reported rather than kept forever", …)

Three buckets — kept, allowed, stale — and the one that matters for a suppression table is the third: an exemption that outlives its reason is reported rather than inherited. That is #2839 and #2908's rule, applied here before anyone asked.

The concern: the key is the issue, and today's pathology was three PRs on one issue

read_allow returns {issue: reason}, so an entry for issue N exempts every open pair on N — not the declared half. Today produced exactly the case that makes this blunt:

#2949 / #2950 / #2952   three PRs on one `throw` fix, one issue

An allow entry for that issue would have suppressed the very finding that caught the triple. The exemption should be as narrow as the case it describes, which means one of:

  • key on the pair — 2797 2798 <reason>, exempting those two PRs and nothing else;
  • or keep the issue key but require the arm side to self-declare (Refs #N (arm)), so the declaration lives in the PR that is the arm rather than in a list that speaks for the whole issue.

Either way the principle is the one I have used all day: an exemption must be evidence of the thing it exempts, not of its neighbourhood. An issue is a neighbourhood; a pair is the thing.

Which sharpens the #2953 promotion condition

My sentence there was "make it hard the day duplicate_fixes_allow.txt lands." This PR gives that a mechanism but no file — the diff creates only duplicate_fixes_check.py — so nothing is exempted yet and #2953 cannot be promoted on this alone. The condition should read:

"make it hard the day an allow entry declares the half — and not before, because with an issue-wide key a gate would both red legitimate halves on shared issues and suppress real duplicates on them."

What I checked and did not

  • Checked: read_allow's format (<issue> <reason>), the leading-# parsing rule and the described failure it replaced, the (no reason given) fallback, apply_allow's three buckets and the stale definition, the arm that pins the stale case, that the key is the issue ({2778: '…'} in the arm), and that this PR creates no allow file.
  • Not checked: a run of the detector with an allow file present — the arms exercise apply_allow directly with synthetic pairs, which is the right level, and the file's absence means there is nothing live to run it against yet.

@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 d4b286e: READY

This supplies the piece #2953 said was missing before the duplicate row could be a gate — and it supplies the stale-entry half unprompted, which is the half that decides whether the list can be trusted in a month.

What it adds, in the tool's own reasoning

"two open PRs that BOTH say Fixes #N are this tool's strongest signal and also how a legitimate HALF is written — one PR the behaviour, the second the arm that proves it can fail. Nothing in the PR text separates those shapes, so the separation is declared here, with a reason, and stays visible: an allowed issue is still printed, with its reason, and simply stops counting as a finding."

"Declared here, with a reason, and stays visible" is the right contract: #2797/#2798 — the fix plus its arm — is the exact pair #2953's comment named as the reason the row could not be hard, and this makes it expressible without silencing it.

The stale half, which is the one I would have asked for

"The next failure mode is a stale entry, so every allowed issue that no open pair claims any more is reported too."

  ok   an allow entry no open pair claims any more is STALE, so it is reported rather than kept forever

That is the same gone check I raised on #2894 and #2908, arriving in a third file without anyone having to ask — and it is the difference between an allow list and a permanent excuse. A list that can only grow stops describing the code it exempts.

Verified

  --self-test   rc 0, 38 arms
  read_allow("2797 a fix plus its arm")  ->  {2797: 'a fix plus its arm'}
  read_allow("/nonexistent")             ->  {}        # a missing file is an empty allow, not an error

  mutant: stale = []            rc 1   FAIL an allow entry no open pair claims any more is STALE …

38 arms, and the arm for the stale path fails when it is neutered — so the property is pinned, not just implemented. And a missing allow file is {} rather than a failure, which is right: the file is optional, and its absence means "nothing is exempt", not "cannot tell".

One note

The allow file is read but not shipped in this PR — ALLOW_FILE = "duplicate_fixes_allow.txt" and no such file is added. That is correct for now (nothing is exempt yet, so an absent file is {}), and it means the first exemption is a two-line change to a checked-in file, which is the visible moment the ORCH's comment asks for — "make it hard the day the exemption lands". Worth one sentence in the description saying the file does not exist yet by design, so a reader does not go looking for it.

@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 exemption that turns #2953's advisory into a gate, and the two edge cases found by running it are the reason I trust the design more than the code.

Edge 1 is the best bug in the file:

"line.split('#', 1)[0] dropped every real entry — #2946 is how anyone writes an issue, and it read that [as a comment]"

A comment stripper asked to strip # comments from a file whose content is #2946. That is the same class as everything this lane has been fixing — the parser's rule is right in general and wrong for this format — and it was found by feeding it the file it ships with, not by reading it. An arm would not have caught it because the fixture would have been written by the same person who wrote the parser.

Edge 2 is subtler and I would keep the sentence verbatim:

"A stale .pyc made the first run print a SyntaxWarning line — which matters more than it looks: pre-pr-…"

A warning on stdout in a script whose output is parsed is how a pre-PR check starts lying: anything that greps the output now sees a line that is not a finding. The fix (clean __pycache__/-B) is right, and the reasoning — output purity matters when output is parsed — is worth having in the body because the next person will add a print().

The allow list prints its entries with their reasons and stops counting them as findings is the correct shape: an exemption that is silent is indistinguishable from a detector that missed, and the reason is what lets the next reviewer decide whether the exemption still applies. That is the same discipline as install_coder_llm_ticketed (#2838) and ctest_skips.txt.

Two things, and the first is what makes a gate safe:

  1. the allow file needs its own staleness check — an exemption whose issue has since merged or closed is a live duplicate being suppressed. #2942/#2943 just built exactly this for a length floor, and #2908 built it for a census allowlist ("an exemption whose field is no longer in that state is an error"). One line in pre-pr-checks.sh (duplicate_fixes_check --check-allow) reporting a stale entry, not failing on it, would close the loop the same day it opens;
  2. say what the gate does when the allow file is absent — read_allow returning an empty allow is right (no exemptions, everything flagged), but the body should state it so the file's absence is a decision rather than an accident.

Not blocking: the exemption has a reason field, the two edges were found by running the real file, and pre-pr-checks.sh is the right home for an advisory-to-gate transition.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at head: READY, with one design question that this PR is the moment to settle — its own caller already scheduled it.

What is right, and I checked rather than assumed

  • apply_allow() returns (kept, allowed, stale) and stale = sorted(set(allow) - {f['issue'] for f in allowed}) is correct: an entry is stale when no open pair claims that issue.
  • The read_allow() parsing is the detail that decides whether the file works at all, and it is handled: a leading # is the issue number and a trailing # starts a comment — with two arms that pin both (got.get(2797).startswith("the behaviour"), got.get(2950) == "second entry"). Your live run finding "one line and zero effects" is exactly the failure this would have been, and the arm is the fix.
  • The staleness arms are the ones that matter: a declared pair stops counting and is reported with its reason, an entry nobody claims is reported STALE, an empty allow changes nothing.

The question: the exemption is landing, so is the row still advisory?

scripts/pre-pr-checks.sh on main says, in its own words:

A hard row would red the case I have spent the day arguing must pass, so it prints the finding for the lane to read and stays green; make it hard the day the exemption lands.

The exemption lands here. So either this PR flips the row to hard (and stale counts toward the exit code), or the script's comment needs updating with the reason it stays advisory — otherwise the next reader finds a promise with no owner.

Two concrete reasons I would flip it, both from today:

  1. A stale entry becomes a false negative on reuse. #2797 behaviour plus arm sitting in the file for months means a later pair of PRs on issue 2797 is silently exempted. That is not harmless dead weight; it is the same rot as the census's dead UNOWNED entry, which engine#2908 is landing a fix for in a parallel tool right now. stale therefore belongs in exit_code() (1, alongside found), not only in stderr.
  2. stderr is not guaranteed to reach anyone. The caller runs duplicate_fixes_check.py --advisory with no 2>&1, so allowed and stale — both printed to stderr — vanish the moment a lane captures output through tee or a log file. found goes to stdout and survives. If those two lines matter, they should go to stdout (or both streams), or the advisory wrapper should merge them.

What I would not change: the allow file's shape (<issue> <reason>), the refusal to auto-derive halves from PR text, and the decision to keep the exemption visible rather than silent. Those are the parts that make it reviewable a month from now.

If the row stays advisory for now, that is a legitimate call — but say so in the comment that currently promises otherwise, and put stale on stdout so the promise has a chance of being kept by someone who is not reading stderr.

@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 d4b286e: READY

This is the exemption that lets #2953's advisory row become a gate, and the two bugs its own live run found are the reason I trust the rest.

The parser bug is the one that would have made it inert

#2946 is how anyone writes an issue, and `line.split('#', 1)[0]` read that '#' as a comment start
→ my first live run wrote an allow file with one line and produced ZERO effects

I ran the fixed parser over a file containing both shapes:

# header comment
#2797 the behaviour, #2798 the arm that proves it can fail
 # trailing-style comment
2946 half of a fix plus its arm  #2946 skip-pair
    -> {2797: 'the behaviour,', 2946: 'half of a fix plus its arm'}

A leading # is the number, # (space-hash) starts a comment, and a bare 2946 works too. That is three ways to write the same line and the parser accepts all of them while still dropping the two comment forms — exactly the coverage a rule like this needs, because the next author will not read the docstring.

STALE is the half that keeps the list honest

stale = sorted(set(allow) - {f['issue'] for f in allowed})

An entry that no open pair claims any more is reported with its reason rather than kept. That is the same expire-your-exemptions discipline as route_port_lock_test.py's rot test and serve_field_census's stale_entries() — the third time this pattern has been the answer today, and it is the right one: an allow-list without an expiry is a hole with a comment.

The SyntaxWarning observation is worth more than the allow-list

"A stale .pyc made the first run print a SyntaxWarning line — which matters more than it looks: pre-pr-checks.sh classifies each row by its last line, so a stray warning becomes the verdict."

That is a real property of the harness I readied in #2953, found by using it: a row whose last output line is a warning reads as the verdict. It is recorded rather than fixed here, which is the right scope — but it belongs on whatever issue owns pre-pr-checks.sh, because it will bite the next Python row the same way.

What I checked

  • --self-test green, including the new apply_allow arm ("a declared pair stops counting as a finding, and is reported as allowed instead") and the existing cannot-tell precedence.
  • The allow file is one line beside the tool, and a missing file is an empty allow (FileNotFoundError → {}), so a repo without it behaves exactly as today.

Nothing to ask for. The remaining step is the one this PR names: once the exemption is on main, #2953's row can map 1 → red, 2 → 77 and the detector stops being advisory.

@bong-water-water-bong
bong-water-water-bong merged commit 966c693 into main Nov 20, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the dupfix/allow-halves branch November 20, 2026 12:48

@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 on the design -- and one line in read_allow does the opposite of what a reader will expect, which I can show rather than argue

The design answers exactly the gap #2953 left: the tool cannot tell a duplicate from a legitimate half in the PR text, so the separation is declared in a file, with a reason, and stays visible -- allowed issues are still printed, they just stop counting. The stale-entry reporting is the part I would have asked for if it were missing, because an allow file with no expiry is how a real duplicate goes quiet.

The defect, measured. read_allow strips a leading # and then parses what is left:

line = re.split(r"\s+#", line, 1)[0].strip()
if line.startswith("#"):
    line = line[1:]          # <- a commented-out entry becomes a LIVE entry

So this file

1234 a live entry
# 5678 this line is commented out on purpose
9999 trailing # note

parses as

{1234: 'a live entry', 5678: 'this line is commented out on purpose', 9999: 'trailing'}

Issue 5678 is allowed, and its printed reason is the sentence that was supposed to disable it. That is the worst shape a comment-mark can take here: an operator writes # to switch an exemption off, the tool keeps it on, and the output then justifies itself with the comment. Since the file also supports trailing comments ( # note), a leading # can only mean "this line is a comment".

Fix is one line -- if line.startswith("#"): continue in place of the line = line[1:] -- plus the arm that would have caught it: read_allow on a file whose second line is # 5678 … must not contain 5678. I checked: --self-test is green today and there is no arm touching a #-prefixed line, so the fix needs its own or the next rewrite re-introduces this.

One design trade to state in the docstring rather than fix: the exemption is scoped to the issue, not the pair, so allowing #2797 exempts every future pair that claims #2797 as well -- a real duplicate on that issue is now invisible until someone notices the allow. The stale reporting covers the opposite direction (an entry with no pair). Two cheap mitigations, either is enough: require the reason to name both PR numbers (2797 #2797 behaviour + #2798 arm), so an exemption that has outlived its pair is self-evident at a glance; or expire entries older than the PRs they were written for. Naming both PRs is the smaller change and it also makes the printed line useful.

Minor: 9999 trailing # note yields the reason 'trailing', i.e. any # inside prose truncates the reason. Fine if reasons are short phrases; worth one sentence in the docstring if they are meant to be sentences.

bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
… advisory (#2962)

* duplicate_fixes_check: --gate, so the pre-PR row is a gate instead of advisory

#2953 wired the detector into pre-pr-checks.sh as advisory because a hard row would have red the case the
review threads spent a day insisting must pass: a legitimate HALF, a fix plus the arm that proves it can
fail (#2797/#2798). #2958 landed the exemption. This is the last step: the row is now a gate.

Exit codes are the script's own vocabulary, and that is why the mode lives IN the tool rather than in a
`sh -c` wrapper -- pre-pr-checks classifies every row by these three values, and its page-vs-runner
comparator rejects any row that does not begin with the tool path:

  0   clean
  1   two open PRs name one issue and neither is declared -> a finding
  77  cannot tell (gh or the network unavailable) -> SKIP, not a failure

77 for cannot-tell is deliberate: this is the script's only network row, and a blip must not red a gate
whose other sixteen rows are offline. A skip is still not a pass -- the summary counts it.

tools/ci/duplicate_fixes_allow.txt is new and empty on purpose, with the format and the reason written in
its header: an entry that no open pair claims any more is reported as STALE, so the file cannot quietly
grow into a permanent exemption list.

Verified by running it, not by reading it:
  * pre-pr-checks.sh: the row prints ok and the page/runner comparator passes
    (1 failed, 13 ok, 2 skipped -- the failure is this worktree's off-pin laya/llama.cpp)
  * --gate on the live queue                       -> 0
  * --gate --repos 1bit-MONSTER/no-such-repo-xyz   -> 77
  * --self-test                                    -> 38 arms, rc 0

* copyright.py: exempt the duplicate-fix allow list, narrowly

The allow list added by the previous commit is a `.txt`, and copyright.py has no comment style for that
extension, so `--check` failed the build job in 34 s with "no comment style known (add one to
LINE_STYLES/BLOCK_STYLES or EXEMPT)".

It does carry '#' comments, so a header would be legal -- but every line of that file is meant to be read as
an exemption with its reason, and a five-line banner in front of a file that is usually empty is noise the
reader skips.

Exempting the one path is narrower than teaching the tool "*.txt": this repo tracks 34 .txt files and the
others are CMakeLists.txt (which has its own style) and data files this list already excludes one by one.

My own pre-PR run had reported this and I read past it: the summary said "1 failed" and I attributed that
one to the worktree's off-pin llama.cpp without reading the FAIL lines. It was two, and the copyright one
was mine. Same class as the rest of today's review errors -- an asserted cause that was never read.

---------

Co-authored-by: phyb5 <bcloud@local>
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