Skip to content

fix(ci): the merge bus needs actions: read, and must not read a 403 as data - #482

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

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

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

The first live bus run failed. This is why.

gh: Resource not accessible by integration (HTTP 403)
gh: Not Found (HTTP 404)

It died in the build step having created nothing — no branch, no bus PR, no merges.

Root cause: declaring a permissions: block sets every scope you don't name to none. The bus named contents: write and pull-requests: write only — but both the starvation pre-flight and the verdict classification read /actions/runs to count executed steps, and neither had actions: read.

Nothing offline could have caught this. The simulator stubs gh, so token scopes are never exercised. This is exactly why this repo insists a gate be observed working rather than reasoned about — the mutation-tested suite passed 45/45 against a workflow that could not make a single API call.

The 404 was the more interesting half

gh put its error text on stdout as well as stderr, and the pre-flight interpolated the call straight into the loop:

for rid in $(gh api ".../actions/runs?status=completed&per_page=5" --jq '.workflow_runs[].id'); do

So the error became the word list, and the next request went to /actions/runs/gh:/jobs — hence the 404 on a garbage run id. A failed API call is not data. The status is now checked explicitly, run ids and step counts are both verified numeric, and an unreadable API is treated as unknown rather than as an answer.

The two failure modes are deliberately asymmetric

The pre-flight fails open. It only saves a wasted batch during an outage, so letting a permissions hiccup block every merge would be the worse trade. It warns and proceeds.

The verdict step fails closed. With the API unreadable, executed stays 0 — which would have relabelled a genuinely red batch as starved, suppressing the bus-failed label and the member comments, and sending everyone to check their billing instead of the diff. Claiming starvation now requires evidence rather than the absence of it.

That second one was a latent bug independent of the 403, and it would have been actively misleading the first time a real batch went red during any API hiccup.

Verification

Two new simulator scenarios, preflight-blind and verdict-blind, both mutation-tested back to the original code. Suite is now 56 assertions, all passing.

Getting there took two corrections worth recording:

  1. The stub first emitted the 403 on stderr only — a tidier failure than the one that actually happened. The naive code passed against it. Fixed by emitting on stdout too, as the real gh did.
  2. The mutation first kept the numeric guard that absorbs the garbage, so it still passed. Fixed by reverting to the genuinely original code.

Only then did the mutant get caught — on never requested a garbage run id, reproducing the production 404 precisely. A scenario that does not reproduce the real failure proves nothing about the fix.

Ladder status

Rung Result
1. dry run, nothing labelled ✅ live
2. dry run with a candidate ✅ live — #467 RIDE, nothing created
3. real landing ❌ this bug; retry after this merges

🤖 Generated with Claude Code

… as data

The first live bus run died in the build step with

    gh: Resource not accessible by integration (HTTP 403)
    gh: Not Found (HTTP 404)

having created nothing. Declaring a `permissions:` block sets every scope you do
not name to `none`, and the bus names only `contents: write` and
`pull-requests: write` — so the starvation pre-flight and the verdict
classification, both of which read `/actions/runs` to count executed steps, had
no `actions: read` and got a 403.

Nothing offline could have caught it: the simulator stubs `gh`, so token scopes
are never exercised. This is the live ladder earning its keep, and the reason
the repo insists a gate be observed working rather than reasoned about.

The 404 was the more interesting half. `gh` put its error text on stdout as well
as stderr, and the pre-flight interpolated the call straight into
`for rid in $(gh api ...)` — so the error became the loop's word list and the
next request went to `/actions/runs/gh:/jobs`. A FAILED API CALL IS NOT DATA:
the status is now checked explicitly, run ids and step counts are both verified
numeric, and an unreadable API is treated as unknown rather than as an answer.

The pre-flight fails OPEN on an unreadable API, deliberately — it only saves a
wasted batch during an outage, so letting a permissions hiccup block every merge
would be the worse trade. The verdict step fails the other way, and that
asymmetry is the point: with the API unreadable, `executed` stays 0, which would
have relabelled a genuinely RED batch as `starved` — suppressing the
`bus-failed` label and the member comments, and sending everyone to look at
their billing instead of the diff. Claiming starvation now requires evidence
rather than the absence of it.

Two simulator scenarios cover these, `preflight-blind` and `verdict-blind`, and
both were mutation-tested back to the original code. Getting there took two
passes worth recording: the stub first emitted the 403 on stderr only, which is
a tidier failure than the one that happened, and the mutation first kept the
numeric guard that absorbs the garbage. A scenario that does not reproduce the
real failure proves nothing about the fix. Suite now 56 assertions.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 6d1e525 into main Nov 5, 2026
36 checks passed
athvin added a commit that referenced this pull request Nov 5, 2026
… not data (#543)

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: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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