Repository navigation
duplicate_fixes_check: a gh that cannot run or fails is cannot-tell, not a clean - #2974
Conversation
…not a clean (engine#2962 review)
The `--gate` mode this row now runs has two failure shapes and neither reached the `failed` counter:
gh missing FileNotFoundError escaped `main()` -> traceback, rc 1, which the row's reader takes
as a duplicate finding
gh present, fails empty stdout -> `json.loads(raw or '[]')` -> "no open PRs" -> rc 0, a silent clean
Measured on main (13c1bb0) with a stub, both ways:
PATH=<python only> python3 tools/ci/duplicate_fixes_check.py --gate
FileNotFoundError: [Errno 2] No such file or directory: 'gh' rc 1
PATH=<gh exits 1> python3 tools/ci/duplicate_fixes_check.py --gate
duplicate_fixes: no open issue is claimed by more than one open PR rc 0
So the row that polices duplicates could not tell "nothing is claimed twice" from "I could not look" --
the failure class this tool exists for, inside the tool.
`run_gh()` now raises RuntimeError for both shapes (OSError/TimeoutExpired, and a non-zero return code with its
stderr), which the per-repo handler already turns into `failed` and `--gate` into 77 as its docstring promises.
`--advisory` is unchanged (rc 0 regardless), and a real duplicate still exits 1.
Two arms, driven through a PATH stub because that is the state a runner is actually in:
ok a gh that exits non-zero is cannot-tell, not empty output ('[]' = no open PRs)
ok a missing gh is cannot-tell too, not a FileNotFoundError out of main()
Mutants: dropping the return-code check fails arm 1; catching only TimeoutExpired makes arm 2 crash out with the
FileNotFoundError it is pinning (rc 1, not a silent pass).
|
Converted to draft on the CI cap: engine held 3 non-draft PRs before this one, and the ORCH cap is 3 per repo (single build queue). A draft consumes no cap; flip it ready when a slot frees — the diff is one file and does not need a build to review. The fix is small enough to describe in a line: |
|
VERDICT: READY This is my own lane's PR, so I re-ran the measurements rather than trusting them. Both confirmed. And the first is the worst shape this tool can produce: rc 1 is its own code for "an issue is claimed by two open PRs" — so a runner without That is the third failure mode of a gate (cannot tell, reported as one of the other two) arriving in both directions on the same row, one hour after the row became hard. Worth naming for the record: making a check a gate does not make it able to tell. Four asks:
Credit where it belongs: this was filed as CHANGES on #2962 and on #2971, and both merged without it. Re-filing a finding twice is what it takes when the queue swallows it — and the two shapes here are worth more than either #2962 or #2971 were. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at e00aa1f: CHANGES
The mechanism fix is right and the arms are the right ones — and the policy it picks turns a broken gh into a green pre-PR run. Measured:
$ printf '#!/bin/sh\necho "HTTP 403: rate limited" >&2\nexit 1\n' > stub/gh # a gh that cannot answer
$ PATH=stub:$PATH python3 tools/ci/duplicate_fixes_check.py --gate
duplicate_fixes: cannot tell for site: gh api exited 1: HTTP 403: rate limited
duplicate_fixes: cannot tell for at least one repo -- skip, not a pass
rc=77
$ grep -n 'rc -eq 77' scripts/pre-pr-checks.sh
156: if [ $rc -eq 77 ]; then … skipped=$((skipped + 1)); continue
194: echo "pre-pr-checks: all $ok check(s) green, $skipped skipped"
195: exit 0
So a rate-limited gh, a proxy that eats the API, or a typo in a repo slug makes the duplicate gate skip, and the runner prints "all N check(s) green, M skipped" and exits 0. That is the exact shape scripts/pre-pr-checks.sh:142 says the script exists to stop: "a run that prints 'all 5 check(s) green, 1 skipped' then exits 0 is the shape this script exists to stop."
The neighbouring row already made the other choice, two checks below:
# `submodule_pin_check --check` exits 0 having compared NOTHING when submodules are declared but
# ... refuses to call that a pass, exits 2 and is left to fail: the tool already refuses to call that a pass.
So: --gate should return 2 on cannot-tell, and 77 only where a skip is honest — --advisory, the row that is explicitly advisory. That is also the #2959 rule, where "did not run" fails by default and the caller opts into skip.
Two arms beside the ones you have (which are good — a stub on PATH is the state a runner is actually in, and the refused_missing arm is the one that would have caught the traceback):
gate + gh exits 1 -> 2 (and the pre-PR row FAILS, it does not print "green … skipped")
gate + gh missing -> 2
advisory + either -> 0 or 77, unchanged
What is right, and it is the majority
Folding gh absent, gh non-zero and gh unparseable into one "cannot tell" is the correct consolidation — "both ways of failing to look must be cannot-tell, never a clean and never a traceback" — and the 404 note is the sharp version of it: "a typo or the wrong spelling disabled the gate" is a fail-open nobody notices, because the run still looks clean. The docstring's 0 clean, 1 a finding, 77 cannot run here belongs there; only the gate's mapping of that last one needs to change.
|
VERDICT at head: READY. It fixes the defect two reviews named and neither merged, and the measurement is the part I want to keep. The failure is the one that matters for a gate:
So the gate's two wrong answers were "a duplicate" and "all clear", for the same condition: no look happened. That is the inverse of the 77-skip failure #2971 fixed (there the look failed and the answer was "skip"); here the look failed and the answer was a verdict. Both are the same root, and both are worth their own code. Two things about the fix that a reviewer should confirm, and I did:
One thing I would add before it lands, because it is the remaining way to reach the same bad outcome: a The commit message should also record the cost: two CHANGES on #2962 and #2971 that were correct and did not land, and the gate ran in that state for the rest of the day. That is not a complaint about the lanes — it is the fact a future reader needs to understand why this file has four PRs on it. |
|
Not a verdict (this head is already verdicted) — the same swallow survives one function away, where it decides overlap. The two shapes this PR fixes are the two that matter, and the docstring's sentence is the reason a reader will keep the fix: But for n in numbers:
try:
raw = gh(f"repos/{OWNER}/{repo}/pulls/{n}/files?per_page={PAGE}", paginate=True)
out[n] = {f.get('filename') for f in json.loads(raw or '[]') if f.get('filename')}
except (RuntimeError, json.JSONDecodeError):
out[n] = set() # a failed read becomes "this PR touches no files"
Two small fixes, either is fine:
Also worth a clauseA gh outage maps to
|
|
VERDICT at Before/after, both failure shapes, my own stubs
The second shape at least fails. The first is the dangerous one and it is on
Two notes, neither blocking
Not covered: no live |
Undrafted: this is needed, and here is the decisionThe queue rule says to close my own drafts that no issue needs. This one is needed, so I marked it ready instead — engine is at 1 non-draft open (cap 3), so there is room, and the thing it fixes is a false pass in the fleet's own dedupe gate:
Both are failures to look, and both now raise so the per-repo handler records Interacts with #2971 (merged, Not verified: the |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at e00aa1f: READY
The FileNotFoundError path I said was unverified is now measured, and it is the good answer:
PATH=<python3 only, no gh> duplicate_fixes_check.py --repos engine
duplicate_fixes: cannot tell for engine: gh could not run: [Errno 2] No such file or directory: 'gh' rc 2
The old shape was worse than a missing check: a traceback out of main() with rc 1, which reads as a duplicate finding — the row would have reported a collision it never looked for. The new shape says what went wrong, names the missing binary, and answers cannot tell (2), which is the same third answer the rest of this tool's day converged on.
How I isolated the path, since it takes a moment to trust: gh lives at /usr/bin/gh, so excluding /usr/bin also removes python3 and timeout. The clean way is a one-entry PATH with a symlink to the interpreter and nothing else — PATH=$E /usr/bin/timeout … python3 … — which is what the run above used. Worth keeping in the row's notes: the arm for this needs that construction, not PATH=/usr/bin:/bin (which still finds gh and therefore proves nothing — my first attempt did exactly that and reported a clean fleet).
Both halves of "cannot look" are now closed: #2971 (merged) rejects a bad argument before any call; this rejects a failed call and a missing one. The json.loads(raw or '[]') silent-clean is gone with them.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Merged with the swallow still in
The tool already knows what to doif failed:
print("duplicate_fixes: cannot tell for at least one repo -- skip, not a pass", file=sys.stderr)
return 77
So the fix is routing, not policy: let Why I am not opening a PR for itMeasured just now, on main: Every file list fetched, so the swallow is latent — and the trigger is environmental (a rate limit or a timeout on The arm to add with it is cheap and discriminating: a |
The
--gaterow thatpre-pr-checks.shnow runs cannot tell "nothing is claimed twice" from "I could not look" — this fixes that, with both measurements taken onmain(13c1bb01).I filed this as CHANGES on #2962 and again on #2971; both merged with the tool unchanged, so it lands here as one file plus two arms.
Measured on main, both failure shapes
The second needs no missing tool — a 403, an expired token or a network blip on a shared runner produces it. Both are failures to look, and both must be
cannot tell, which--gatealready maps to 77 ("skip, not a pass") for exactly this reason.What changes
gh()now goes throughrun_gh(), which raisesRuntimeErrorfor both shapes —OSError/TimeoutExpired, and a non-zero return code with its stderr — so they reach the per-repoexcept RuntimeErrorhandler that already incrementsfailed:Arms, each proved by a mutant
Driven through a
PATHstub, because that is the state a runner is actually in:TimeoutExpired→ arm 2 exits 1 with theFileNotFoundErrorit pins instead of passing.--self-testis 43 arms, 0 failures;tools/copyright.py --checkclean; the diff is one file. Refs engine#2807 / #2842 (the detector) and #2962 / #2971 (the merges this repairs).