Skip to content

fix(ci): the detect check skipped a healthy PR — a failed API call is not data - #543

Merged
athvin merged 1 commit into
mainfrom
bm/ci-merge-bus-detect-read-safe
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/ci-merge-bus-detect-read-safe

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

The third live attempt was refused, wrongly

#510   skip   its detect jobs failed, so every gate reported skipped
               without running — re-run CI before batching

#510 was fine. All three detect jobs 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 I added the merge-bus label.

The bug, which reads as correct

The check I added in #490:

[ "$(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 "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:

$ v="$( { echo 0; false; } 2>/dev/null || echo 0 )"
value=[0/0]  lines=2  != "0" ? YES -> would skip the PR

The fix

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 be able to 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 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-flaky 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 72 assertions · skills-check all exit 0 · scripts/ci/actionlint.sh exit 0.

Touches .github/workflows/, so by its own rule this one is hand-merged.

🤖 Generated with Claude Code

… 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]>
@athvin
athvin merged commit 1b4668b into main Nov 5, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants