Repository navigation
fix(ci): the detect check skipped a healthy PR — a failed API call is not data - #543
Merged
Merged
Conversation
… not data
The third live attempt at a real landing was refused:
#510 skip its detect jobs failed, so every gate reported skipped
without running — re-run CI before batching
#510 was fine. All three of its detect jobs had completed `success` twenty
minutes earlier and the PR was CLEAN; the `14:18:16` timestamp that looked like
a push was `updated_at` moving when the `merge-bus` label was added.
The check I added in #490 was this:
[ "$(gh api ... --paginate --jq '...|length' 2>/dev/null || echo 0)" != "0" ]
`--paginate` emits one jq result per page and `|| echo 0` appends another on
failure, so a call that emits a page and THEN errors — a secondary rate limit
being the obvious candidate, given how many calls this loop makes per
candidate — yields the two-line string "0\n0", which is `!= "0"`. A healthy PR
is then refused as unverified. This is exactly the defect the pre-flight was
fixed for in #482, reintroduced here one commit later.
Replaced with a `detect_failures` function that reads the status explicitly,
requires one line of three bare integers, and FAILS OPEN on anything else —
consistent with the pre-flight, because `mergeStateStatus == CLEAN` remains the
gate and a rate limit must not block every merge. It also compares `total_count`
against what it fetched, so a commit with more than a page of check-runs says so
instead of answering from a prefix.
Two further traps hit while fixing it, both the same shape as the original:
Whitespace-collapsing is NOT a fix. `"0\n0"` with the newline stripped is
`"00"` — still numeric, still `!= "0"`.
And the function's own warnings went to STDOUT, so `$(detect_failures …)`
captured the warning text along with the count and skipped the PR anyway. A
function whose stdout IS its return value must put diagnostics on stderr. My
isolation test printed the warning and I read it as informational rather than as
contamination; the simulator scenario is what caught it.
Covered by `detect-read-flaky`, which asserts a healthy PR still rides when the
check-runs read emits output and then fails. Mutation-tested both ways: putting
the warnings back on stdout is caught, and restoring the original one-liner is
caught. `detect-died` still skips, so the real guard is intact. Suite now 72
assertions.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The third live attempt was refused, wrongly
#510 was fine. All three detect jobs completed
successtwenty minutes earlier and the PR wasCLEAN. The14:18:16timestamp that looked like a push wasupdated_atmoving when I added themerge-buslabel.The bug, which reads as correct
The check I added in #490:
--paginateemits one jq result per page, and|| echo 0appends another on failure. So a call that emits a page and then errors — a secondary rate limit being the obvious candidate, given how many calls this loop makes per candidate — yields"0\n0", which is!= "0". A healthy PR is refused as unverified.This is precisely the defect the pre-flight was fixed for in #482, reintroduced one commit later. Demonstrated directly:
The fix
A
detect_failuresfunction that reads the status explicitly, requires one line of three bare integers, and fails open on anything else — consistent with the pre-flight, becausemergeStateStatus == CLEANremains the gate and a rate limit must not be able to block every merge. It also comparestotal_countagainst what it fetched, so a commit with more than a page of check-runs says so rather than answering from a prefix.Unit-tested against every shape:
no failures,two failures,truncated,output-then-error,two pages,hard failure,error text on stdout,empty,empty oid. Only a genuine count causes a skip; everything else warns and returns 0.Two more traps, same shape, hit while fixing it
Whitespace-collapsing is not a fix.
"0\n0"with the newline stripped is"00"— still numeric, still!= "0". The same bug in a different hat.The function's own warnings went to stdout, so
$(detect_failures …)captured the warning text alongside the count and skipped the PR anyway. A function whose stdout is its return value must put diagnostics on stderr. My isolation test printed the warning and I read it as informational rather than as contamination — the simulator scenario is what caught it.Verification
detect-read-flakyasserts a healthy PR still rides when the check-runs read emits output and then fails. Mutation-tested both ways: putting the warnings back on stdout is caught, and restoring the original one-liner is caught.detect-diedstill skips, so the real guard is intact.Suite 72 assertions ·
skills-check allexit 0 ·scripts/ci/actionlint.shexit 0.Touches
.github/workflows/, so by its own rule this one is hand-merged.🤖 Generated with Claude Code