Repository navigation
fix(bin): judge only the checks a pull request's base branch requires - #2
Merged
Merged
Conversation
The merge guard refused every pull request carrying a non-green check, so any repository running an advisory tier - checks that fail on purpose to surface real debt - became permanently unmergeable. GitHub reports required status per check through the rollup's isRequired, which resolves classic branch protection and rulesets together and needs only ordinary repository read access. The branch-protection and rules endpoints do not: a private repository on a free plan answers both with a plan-gated 403, which this script already handles for the merge-queue read. That field only resolves when the query supplies pullRequestNumber, which gh's canned --json statusCheckRollup omits, so this issues its own GraphQL document rather than reusing the rollup already fetched beside it. Verified against cli/cli#14475, where the canned query reports null for all eleven checks while the explicit one reports three required and eight not. A declared required set now narrows what is judged to exactly those checks. A base branch that requires nothing and a read that failed both leave every check judged, because neither establishes what gates and a failed read must never shrink the judged set the way an empty one would. Four answers count as unreadable rather than as a short required set: a failed or unparsable read, an answer describing another head, a truncated context page, and a context carrying no isRequired boolean. Keeping "requires nothing" and "could not read" apart is what stops a field that stops resolving from quietly looking like a branch that gates nothing. Required status is never inferred from a check's name; the name is only the join key back to the rollup, which GitHub itself keys required checks by. Narrowing cross-checks itself against mergeStateStatus, which the forge computes from the same requirements, so a pull request it still reports BLOCKED is refused even when every narrowed check was green. That check is applied only when narrowing, so a base branch that requires nothing keeps exactly the behaviour it has today. Every run now reports which checks it judged and which it ignored, and the verified line no longer claims "every required check green" when it judged every check indiscriminately. Run supersession, the single-name --allow-red waiver and its away-posture refusal, pending-is-not-green, the head binding, and the GitLab path are unchanged.
The required Herdr lane failed on this branch because the pinned Treehouse predated the --root flag that secondmate pool roots depend on, so no secondmate-owned spawn could reach an isolated worktree. d2d718f raises the pin to 2.3.0. This merge only brings that repair onto the branch; no file this branch owns is touched.
…ellCheck 0.11.0 in CI mode (--norc --external-sources, full dataflow over the whole canonical set) flagged SC2178/SC2128 four times in the new github_read_required_checks in bin/fm-pr-merge.sh, on the local variable `names`. Root cause: ShellCheck tracks array-ness by variable NAME across sourced files, and bin/fm-classify-lib.sh:1899 declares `local -a names=()`. That file is reachable only when --external-sources is on, which is why the local no-mistakes lint step (changed-file mode, no --external-sources) passed while CI failed. Fix: renamed the local from `names` to `required_names` at bin/fm-pr-merge.sh:618, 668, 682, 683. 4 lines changed, one file, no behavior change and no new code paths. Verified locally: - shellcheck --norc --external-sources -- bin/fm-pr-merge.sh => exit 0 (reproduced the exact 4 CI warnings before the change). - CI=true bin/fm-lint.sh (full CI parity: whole canonical set + actionlint) => exit 0, "3 workflow files valid". - bash tests/fm-pr-merge.test.sh => exit 0, all cases pass, including the narrowing, BLOCKED cross-check, allow-red waiver, attended-override, supersession, and numeric-owner regression cases. No settled decision was revisited: the BLOCKED cross-check, waiver skip, policy wording, notice arms, and strict all-green for repos declaring nothing required are all untouched
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.
Intent
Fix the merge guard so it judges the checks that actually gate a pull request, rather than refusing on every check that is not green.
What happened, which is the whole context for this ask. ue-frontend pull request 2 adds CI with a deliberate two-tier design: three checks that gate (type-check, lint:blueprint, quality-ratchet) and two jobs that are advisory by design, named "advisory (non-blocking): ...". The advisory ones genuinely fail, on purpose, because they surface real existing debt - including a real build out-of-memory at exit 134 that nobody knew about until this work exposed it. All three gating checks are green.
The captain gave explicit merge authority for that pull request knowing it reads red overall. bin/fm-pr-merge.sh refused it:
error: refusing to merge https://github.com/gkalyan/ue-frontend/pull/2
The worker was then asked to fix the reporting and did: the advisory jobs moved into their own workflows, so the two gating workflows now each report green on their own run conclusion. It deliberately did NOT make the advisory jobs report success, on the grounds that a build reporting pass while it is out-of-memory is a lie in the exact place people look. That judgement was accepted and is not to be revisited.
So the pull request is correct and the guard is what is wrong. The captain is merging that one himself; this task is not about unblocking it. It is about the general defect the incident exposed, in the captain's framing: as it stands, any repository that adopts an honest advisory tier becomes permanently unmergeable by firstmate.
The captain's words authorising this work: "fix the guard, I'll merge PR 2 myself".
What Changed
bin/fm-pr-merge.shnow reads the base branch's required check set from GitHub before judging, via a newgithub_read_required_checksthat issues its own GraphQL document for the rollup'sisRequired(the cannedgh --json statusCheckRollupquery omits thepullRequestNumberargument and returns null). A declared required set narrows judging to exactly those checks, so a red advisory check no longer refuses the merge; a base branch that requires nothing and a read that failed both keep every check judged, and the read is rejected as unreadable when it answers at a different head or a truncated context page.mergeStateStatusfrom the same live view, refusing when the forge still reportsBLOCKEDwhile every narrowed check was green — unless an attended--allow-redwaiver covered a required check or--attended-overrideis in effect, each of which is announced. Narrowed runs print which checks the base requires and which were ignored; runs whose required read failed say so on theverified:/refusal line.tests/fm-pr-merge.test.shcovering narrowing, the three read outcomes, head/pagination/flag rejection,BLOCKEDcross-check and its two bypasses, supersession under narrowing, comma-bearing check names, and all-numeric owner logins;AGENTS.md,docs/architecture.md, and the bearings skill's merge-click ruling now describe green as the required set rather than the rollup's overall colour.Risk Assessment
✅ Low: Well-bounded change that is fail-safe by construction (only a forge-declared required set narrows; stale-head, truncated, unflagged, or failed reads all leave every check judged), cross-checked against GitHub's own mergeStateStatus, and covered by behavioral tests whose fixtures are internally consistent; every previously selected fix is verifiably applied with no over-reach.
Testing
Ran the 13 fixture cases this change owns (all pass) and pinned the new numeric-owner case as a genuine regression — it fails with the typed
-Fflags restored and passes with the shipped-fflags. Then drove the real script end-to-end against five live pull requests on github.com through a shim that forwards reads to the real API and hard-refuses every write, so no pull request state changed andgh pr mergewas never reached. On cli/cli#14035 the guard narrowed to trunk's three required build checks, reported the failing non-requiredlintas "not judged", and refused only on draft/conflict — the ue-frontend incident refusal is gone. On home-assistant/core#182799 it listed dev's eight required checks and refused naming only the required reddocs-missing, ignoring ten non-required non-green contexts. On cli/cli#14475 the BLOCKED cross-check refused a narrowed-green pull request. On #2, whose base declares nothing required, no narrowing notice appeared and both reds were judged. The flag fix itself was proven live on a real all-numeric owner (1337/better-time-picker#4): the pre-fix build emits "could not read which checks master requires, so every check was judged", the shipped build does not. The change is CLI-only, so evidence is CLI transcripts plus the forge's own rollup readouts rather than screenshots. What could not be driven live: the attended--allow-redwaiver and--attended-override --adminmerges of a BLOCKED pull request, and an "advisory (non-blocking): …"-named check that the forge flags required — all three need merge authority on a branch-protected repository, and no repository in this estate has one (ue-frontend is private on a free plan, firstmate's main is unprotected). Those stay fixture-covered.notice: not judged, because trunk does not require them: lint, and the refusal lists only draft/conflict- check 'docs-missing' is not green/error: these checks are not green: docs-missing, with the eight required names listed and no non-required name ment…- every check trunk requires is green, but GitHub still reports mergeStateStatus BLOCKED, so something it requires is unsatisfiednotice:line,error: these checks are not green: Behavior tests (Herdr), Lint(could not read which checks master requires, so every check was judged), the shipped build's does not; real GraphQL rejects `-F own…error: refusing to merge … (could not read which checks master requires, so every check was judged)on a live…--allow-redwaiver on a red required check still merges a pull request GitHub reports BLOCKED, and the bypassed cross-check is announced--attended-override -- --adminstill merges a pull request GitHub reports BLOCKED, with the bypass announcedEvidence: Live read-only merge-guard runs against five real GitHub pull requests, with the forge's own required/red facts for each
Source: Live read-only merge-guard runs against five real GitHub pull requests, with the forge's own required/red facts for each
Evidence: Numeric-owner flag fix, before/after against api.github.com
Source: Numeric-owner flag fix, before/after against api.github.com
Evidence: Targeted run of the 13 narrowing cases, plus the numeric-owner case failing before the fix
Source: Targeted run of the 13 narrowing cases, plus the numeric-owner case failing before the fix
Evidence: Incident-shape narrowing, live on cli/cli#14035
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-pr-merge.sh:629- The required-set read passes owner and repo through gh's typed-F/--fieldflag, which coerces values that look like JSON scalars.-F "owner=$PR_OWNER"sends an integer for an all-numeric GitHub login, and-F "repo=$PR_REPO"sends a boolean/null for a repository literally namedtrue,false, ornull— all legal GitHub names. GraphQL then rejects the variable againstString!, gh exits nonzero,|| return 0leaves FM_PR_GITHUB_REQUIRED_STATUS=unreadable, and the guard silently falls back to judging every check forever in that repository. Concrete sequence: repository1337/ci-tools(numeric owner) with basemaindeclaring required checks type-check and quality-ratchet, plus a redadvisory (non-blocking): build; the required read fails every run, so the merge is refused witherror: refusing to merge <url> (could not read which checks main requires, so every check was judged)— exactly the permanent-unmergeability the intent sets out to fix, restored for those repos with no error naming the real cause. Remedy is mechanical and does not extend the change: use the raw-string flag for the two string variables and keep-Fonly for the Int, i.e.-f "owner=$PR_OWNER" -f "repo=$PR_REPO" -F "number=$PR_NUMBER". The same typed-flag pattern already exists at bin/fm-pr-merge.sh:897 for the post-merge outcome read, where it fails loudly instead of degrading; fixing that line too is optional and outside this change's scope.🔧 Fix applied.
1 info still open:
tests/fm-pr-merge.test.sh:2607- The numeric-owner regression case asserts a full exit-0 merge (|| failplusassert_logged_gh_merge), but the gh mock only emulates gh's typed-flag rejection inside the*isRequired*branch. The post-merge outcome read at bin/fm-pr-merge.sh:897 still sends-F "owner=$PR_OWNER", so with real gh a repository like1337/ci-toolswould merge and then failgithub_read_outcome_with_gh, falling to gh-axi or exiting 1 with "could not read the GitHub pull request outcome after the merge attempt". The assertions this case actually owns — that the required set resolves and narrows for an all-numeric owner, and that nocould not read which checks main requiresline appears — are sound and do fail before the-fchange. The exit-0 / merge-logged part is not evidence about real numeric-owner repositories. No action: you explicitly scoped the post-merge outcome read out of this change ("it fails loudly instead of degrading and is outside this change's scope"), so this is recorded only so the test is not later read as end-to-end proof.🔧 **Test** - 2 issues found → no changes applied ✅
bin/fm-pr-merge.sh:770- Live read of the real incident repo shows gkalyan/ue-frontend main declares NO required checks (github reports isRequired:false for all five contexts on PR 2), so the narrowing never engages there today and the guard still refuses that PR on its two advisory reds. That matches the settled decision to keep strict all-green where the forge declares nothing, but it means the class of repository described in the intent only stops being permanently unmergeable once its base branch actually declares the gating checks via branch protection or a ruleset. No code change implied.-F owner=1337and accepts-f owner=1337, which is exactly the defect the last commit fixes…gh pr view --json statusCheckRollupretur…bash tests/fm-pr-merge.test.sh(repo suite for this file; all 13 required-set cases plus the pre-existing merge-guard cases pass)Drovebin/fm-pr-merge.sh task-x1 https://github.com/gkalyan/ue-frontend/pull/2with the base-commit (d2d718f) script over a ue-frontend-shaped rollup (stubbed gh) — reproduced the exact reported refusalDrove the same invocation with the change under test (stubbed gh) — merges, naming judged and ignored checksDrovefm-pr-merge.sh ... /pull/3with a red required check (stubbed gh) — refusal names only the gating checkDrovefm-pr-merge.sh ... /pull/4with a base branch requiring nothing (stubbed gh) — still refuses on the advisory red (no fail-open)Drovefm-pr-merge.sh ... /pull/6withhasNextPage: true(stubbed gh) — read treated unreadable, every check judgedDrovefm-pr-merge.sh ... /pull/5narrowed-green but mergeStateStatus BLOCKED (stubbed gh) — refusesDrovefm-pr-merge.sh ... /pull/7 --allow-red type-checkon a BLOCKED PR with a red required check (stubbed gh) — merges and announces the bypassed cross-checkDrovefm-pr-merge.sh ... /pull/8 --attended-override -- --squash --adminon a BLOCKED PR (stubbed gh) — merges, forwards --admin, announces the bypassDrovefm-pr-merge.sh ... /pull/9with the required read failing (HTTP 502, injected via the stub) — refuses with the degraded outcome suffixDrovefm-pr-merge.sh ... /pull/11where a check NAMED 'advisory (non-blocking): build' is flagged required by the stubbed forge — still refuses (names do not decide)Drovefm-pr-merge.sh task-x1 https://github.com/1337/ci-tools/pull/10with the pre-fix (ac561e0) script and with the fix (stubbed gh); named-owner control run shows the difference is owner-shape specificLIVE:gh api graphql -f query=<required-set query> -F owner=1337 ...and-f owner=1337 ...against real github.com — Int coercion error vs accepted StringLIVE:gh api graphqlwith the change's exact query against live gkalyan/ue-frontend#2, then re-run through the script's own--jqprogram; contrasted withgh pr view --json statusCheckRollupreporting isRequired nullLIVE: drovefm-pr-merge.shwith a live rollup plus a live required-set read proxied to real gh for gkalyan/ue-frontend#2 (merge call stubbed)🔧 No changes applied.
✅ Re-checked - no issues remain.
notice: not judged, because trunk does not require them: lint, and the refusal lists only draft/conflict- check 'docs-missing' is not green/error: these checks are not green: docs-missing, with the eight required names listed and no non-required name ment…- every check trunk requires is green, but GitHub still reports mergeStateStatus BLOCKED, so something it requires is unsatisfiednotice:line,error: these checks are not green: Behavior tests (Herdr), Lint(could not read which checks master requires, so every check was judged), the shipped build's does not; real GraphQL rejects `-F own…error: refusing to merge … (could not read which checks master requires, so every check was judged)on a live…--allow-redwaiver on a red required check still merges a pull request GitHub reports BLOCKED, and the bypassed cross-check is announced--attended-override -- --adminstill merges a pull request GitHub reports BLOCKED, with the bypass announcedbash tests/fm-pr-merge.test.shrestricted to the 13 required-check-narrowing cases (test_non_required_red_check_no_longer_refuses … test_numeric_owner_still_reads_the_required_set) — all pass at HEAD b601206test_numeric_owner_still_reads_the_required_setre-run with bin/fm-pr-merge.sh:629 reverted to-F owner=... -F repo=...— fails (not ok), so the new case is a real regression testLive read-only run ofbin/fm-pr-merge.sh task-x1 https://github.com/cli/cli/pull/14035through a gh shim that passes reads to the real API and refuses every writeLive read-only run againsthttps://github.com/cli/cli/pull/14475(narrowed green + mergeStateStatus BLOCKED)Live read-only run againsthttps://github.com/home-assistant/core/pull/182799(required checkdocs-missingFAILURE)Live read-only run againsthttps://github.com/gkalyan/firstmate/pull/2(base main declares nothing required)Live read-only run againsthttps://github.com/1337/better-time-picker/pull/4with the shipped-fflags and again with the pre-fix-Fflags, comparing the outcome linegh api graphql -F owner=1337 …vs-f owner=1337 …against api.github.com, showing the realCould not coerce value 1337 to Stringrejectiongh api users/1337confirming an all-numeric GitHub login is a real account shape✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.