Repository navigation
fix(bin): route away-mode GitHub merges through the review ledger and stop phantom required-check holds - #36
Conversation
…eview ledger Under the away record on 2026-10-13 the supervision branch held every pull request that lacked an exact-model attestation instead of steering its worker to run the gate, sent every ask-user finding to the captain, held a fully ready pull request because the review snapshot invented a pending "required checks have not reported" check on a repository with no branch protection, and in the other direction merged a high-stakes pull request through bin/fm-pr-merge.sh with no exact-model attestation. This implements the four-part fix from that investigation. A. The required-check reader (urlencode, plan-gated rules 403, classic protection plus rulesets) moves unchanged from bin/fm-pr-merge.sh into bin/fm-pr-lib.sh as fm_pr_github_* functions taking owner and repo, and bin/fm-pr-review-snapshot.sh uses it when gh prints "no required checks reported": a readable, empty required set records no required checks, while a non-empty or unreadable set keeps the pending placeholder. Merge behaviour is unchanged. B. While the away-posture record exists, bin/fm-pr-merge.sh refuses a GitHub merge unless bin/fm-pr-review.sh merge recorded the current generation's ledger merge decision for the live head (merge-decision writes it only after every review gate passes), so a direct call or a hand-set reviewed head is refused. bin/fm-pr-review.sh release-hold refuses the supervision branch actor in every posture. Attended merges and GitLab are unchanged. C. bin/fm-branch-prompt.sh "Postures" and the away wake tail in .pi/extensions/lib/fm-branch-dispatch.ts name MAIN's standing authority: land a pull request whose ledger passes every gate through bin/fm-pr-review.sh merge, steer a parked worker to supply a missing gate (no init, rebase step skipped, no rebase or force-push, never a merge), and decide ask-user findings under ask-user-authority; the ask-user captain verdict is qualified to the attended posture. D. Matching edits in the afk and pr-review-policy skills, docs/pi-supervision-branch.md, and the merge-path lines in AGENTS.md section 7 and docs/architecture.md that the away gate made incomplete. One-time effect of A: an open review ledger whose bound final disposition digest includes the old "required checks have not reported" placeholder reports "final disposition and evidence have not been posted for the latest review state on this head" at its next checkpoint, until the final disposition is recorded again with bin/fm-pr-review.sh final-disposition. The opt-in credentialed replay test the investigation proposed was not added or run: this change is scoped to the named deterministic tests and adds no new scripts. The deterministic tests cover the PR 218 shape (ready and merged away through the wrapper), the PR 240 shape (refused for the missing exact-model attestation, and refused as a direct away merge), release-hold for the branch actor attended and away, and the prompt and away-tail text. Follow-ups noted in the structure pass: bin/fm-pr-lib.sh is now about 1500 lines and the GitHub forge reads could become their own library; the older fake forge in test_live_collector_keeps_unreported_required_checks_pending duplicates the new write_required_set_fake_gh and was left unchanged as specified.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Reviewer's GuideThe PR closes both away-mode failure paths by routing GitHub merges through a verified review-ledger decision bound to the live head and by making snapshot required-check state reflect the actual branch protection/ruleset configuration, while documenting and testing the expanded but guarded standing authority. Sequence diagram for an away-mode GitHub mergesequenceDiagram
participant Branch as SupervisionBranch
participant Review as bin/fm-pr-review.sh
participant Ledger as ReviewLedger
participant Merge as bin/fm-pr-merge.sh
participant GitHub as GitHub
Branch->>Review: merge task url
Review->>Review: merge-decision
Review->>Ledger: record decision=merge and verified_head
Review->>Merge: invoke guarded merge with reviewed head
Merge->>Ledger: verify current generation decision and head
Merge->>GitHub: gh pr merge --match-head-commit
GitHub-->>Merge: merge result
Merge-->>Branch: report landed or refusal
State diagram for away-mode merge authoritystateDiagram-v2
[*] --> Attended
Attended --> Away: away-posture record exists
Away --> ReviewGate: bin/fm-pr-review.sh merge
ReviewGate --> LedgerDecision: all review gates pass
ReviewGate --> Held: missing gate, red check, or ledger hold
LedgerDecision --> LiveHeadCheck: record verified_head
LiveHeadCheck --> Merged: live head matches
LiveHeadCheck --> Held: direct, hand-set, or stale handoff
Merged --> Away
Held --> Away
Away --> Attended: away record archived
Flow diagram for accurate required-check snapshottingflowchart TD
A[gh pr checks --required] --> B{Reports required checks?}
B -->|Yes| C[Record reported checks]
B -->|No| D[Read pull request base branch]
D --> E[fm_pr_github_read_required_contexts]
E --> F{Read succeeds and set is empty?}
F -->|Yes| G[Record no required checks]
F -->|No| H[Record pending required checks placeholder]
C --> I[Review snapshot]
G --> I
H --> I
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc2b0aa0db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| elif grep -q "^no required checks reported on the '" "$TMP/checks.err"; then | ||
| printf '%s\n' \ | ||
| '[{"name":"required checks have not reported","state":"PENDING","bucket":"pending","link":null}]' \ | ||
| > "$TMP/required.json" | ||
| # gh prints this both when the base requires no checks and when required | ||
| # checks have not reported yet; only a readable, empty required set is the | ||
| # first, and anything else stays one pending required check. | ||
| BASE=$(jq -er '.base.ref | select(type == "string" and length > 0)' "$TMP/core.json" 2>/dev/null) || BASE= | ||
| if [ -n "$BASE" ] && fm_pr_github_read_required_contexts "$OWNER" "$REPO" "$BASE" \ | ||
| && [ "$FM_PR_GITHUB_REQUIRED" = '[]' ]; then |
There was a problem hiding this comment.
Verify the zero-check error before clearing requirements
When no check run exists yet on a PR whose base requires a check, gh pr checks --required emits no checks reported... before applying the required-check filter, as shown in the GitHub CLI v2.96 source. This fallback verifies the required set only for no required checks reported; the following branch still converts no checks reported to [], allowing the review ledger to become ready and record a merge decision before required CI has started. Although fm-pr-merge.sh later refuses the merge, the away workflow can post and attest a falsely ready ledger and then stall, so both diagnostics should use the shared required-set reader.
AGENTS.md reference: AGENTS.md:L237-L238
Useful? React with 👍 / 👎.
… is fixed. Behavior portable parallel 1 comes from an upstream package release, not from this PR's code. ci-2 (Behavior portable serial 4): tests/fm-pi-branch-extension.test.sh checked the away-mode prompt for the phrase "act on them by your own judgment". Part C of this PR rewrote that text in .pi/extensions/lib/fm-branch-dispatch.ts, so it now reads "act on the words by your own judgment", and the test was never updated. CI failed with "the away tail lost the words-execution rule". The rule being checked is that the away prompt must still tell the agent to act on the captain's words, and that one assertion is the only place that checks it; nothing else in the repo still uses the old wording. I updated the assertion to the new phrase and added one check that the prompt contains "MAIN's standing authority needs no words". Both checks read the final prompt text sent to the agent, not source code. The test file passes locally (exit 0, 49 ok lines), including the away-posture case that failed in CI. Two other cases in that file skip locally because the Pi package isn't installed globally here. ci-1 (Behavior portable parallel 1): tests/fm-pi-primary-types.test.sh fails a type check with "Property 'prompt' does not exist on type 'BeforeAgentStartEvent'". The errors are in .pi/extensions/fm-branch-supervision.ts and .pi/extensions/fm-primary-pi-watch.ts, which this PR doesn't touch. CI installs @earendil-works/pi-coding-agent without a pinned version (ci.yml:118 and :222). Version 1.2.0 came out on 2026-10-12, after the last passing runs on 2026-10-10, so CI is now checking against a newer API. It will fail on main too until the extensions are updated for Pi 1.2.0 or CI pins an earlier version. That should be its own change and is outside this PR's scope. Pi isn't installed on this host, so it couldn't be reproduced or fixed here
Intent
Asked on 2026-10-13: after the away session stalled the fleet twice, the captain accepted firstmate's recommendation to "let the scout on the away-mode stalls run now and ship its fix through firstmate's own pipeline" ("let's go with your strong recommendations, i trust you").
The scout report is data/fm-supervision-host-policy-holds/report.md in the firstmate home (read it in full first; it is the specification). Its finding: under the away record the supervision branch held every PR lacking an exact-model attestation instead of steering the worker to run the gate, sent every ask-user finding to the captain, held PR 218 after it was fully ready because the review snapshot invents a pending "required checks have not reported" check on a repo with no branch protection, and in the other direction merged PR 240 through bin/fm-pr-merge.sh without its exact-model attestation. The report's "Proposed change set" has four parts: A (snapshot reads the real required-check set via a shared reader in bin/fm-pr-lib.sh), B (while the away record exists bin/fm-pr-merge.sh refuses a GitHub merge without bin/fm-pr-review.sh merge's recorded ledger merge decision for the live head; release-hold refuses the branch actor), C (prompt and away-tail text naming MAIN's standing authority), D (matching one-line edits in the afk and pr-review-policy skills and docs/pi-supervision-branch.md).
What the report's proposed change set specifies, part by part:
A. The required-check reader in bin/fm-pr-merge.sh (github_urlencode_path_segment, github_branch_rules_unavailable_on_plan, github_read_required_contexts) moves into bin/fm-pr-lib.sh as fm_pr_github_* functions that take owner and repo as arguments; bin/fm-pr-merge.sh calls the library and its merge behaviour is unchanged. In bin/fm-pr-review-snapshot.sh, when gh pr checks --required prints "no required checks reported", the snapshot reads the base branch from the pull request (.base.ref) and calls the shared reader: if the read succeeds and the required set is empty it records no required checks ([]); if the set is non-empty or unreadable it keeps the existing pending "required checks have not reported" placeholder. One-time effect to name in the PR description: open review ledgers whose final-disposition digest includes the placeholder will show "final disposition ... not posted for the latest review state" on their next checkpoint until the final disposition is recorded again.
B. In bin/fm-pr-merge.sh, while the away-posture record exists, for a GitHub merge with a review ledger, the merge is refused unless the reviewed-head handoff (FM_PR_REVIEW_EXPECTED_HEAD) is set and the current ledger generation records merge_decision.decision == "merge" with verified_head equal to that head; bin/fm-pr-review.sh merge-decision writes that only after its ready check passes, so setting the environment variable by hand is not enough. Suggested refusal text: "while the away-posture record exists a GitHub merge goes through bin/fm-pr-review.sh merge, so the current review-ledger generation passes every gate for the live head". Attended behaviour and GitLab do not change. bin/fm-pr-review.sh release-hold refuses the supervision branch actor in every posture (fm_lease_forbid_branch with no away relocation), because away authority never releases a captain hold.
C. bin/fm-branch-prompt.sh: the captain-verdict line "a decision only the captain can make, including every ask-user finding from a validation gate" is qualified to the attended posture (away, only a finding the ask-user-authority policy escalates). In "Postures", after the line saying the record is the captain's away words, a block says MAIN's standing authority needs no words: away, do what MAIN does attended without asking the captain, through the same guarded scripts, whatever the words say or leave out - land a GitHub pull request whose current review-ledger generation passes every gate with bin/fm-pr-review.sh merge (a ledger hold, a task held for the captain, or an unresolved product, rights, spend, destructive, or security-sensitive decision still holds it); when the ledger lacks what the task's parked or finished worker can supply, steer that worker to supply it as routine steering (dispositions with evidence, the posted and recorded final disposition, or for high-stakes work a no-mistakes run on the current head at the policy's exact model with no init - if the repository is not already initialized it stops and reports - the rebase step skipped, no rebase or force-push, then the attestation, a done line, and a park, never a merge); decide each ask-user finding under the ask-user-authority policy and steer the worker with the decision, reporting verdict captain only for a finding that policy escalates, and treating a stop condition written into its own earlier steer as its checkpoint, not a captain instruction; the words add to this set and never subtract from it. The next sentence begins "Beyond that set, no script parses the words". The merge bullet says bin/fm-pr-review.sh merge is the GitHub merge entrypoint while away and bin/fm-pr-merge.sh refuses a GitHub merge under the record without that handoff's recorded ledger merge decision for the live head, remaining the direct GitLab entrypoint, while red or unreported-check merges stay refused away and --allow-red and --allow-missing stay refused under the record. The steering bullet says steering and lifecycle control stay the branch's as in any posture, and a run the words say to abort is aborted. "Never by analogy" becomes "beyond MAIN's standing authority, act only where the words plainly name the event and the action". The --resolve-key, hold-on-doubt, and never-set lines stay unchanged. The away wake tail in .pi/extensions/lib/fm-branch-dispatch.ts mirrors these rules: MAIN's standing authority needs no words (land a ledger-passing pull request through bin/fm-pr-review.sh merge, steer a parked worker to supply a missing gate, decide ask-user findings under the policy); beyond that act on the words only through the guarded scripts, with bin/fm-pr-merge.sh refusing a GitHub merge without that handoff; beyond standing authority, never by analogy, and hold on doubt. The prompt stays a pure function of tracked files.
D. .agents/skills/afk/SKILL.md: replace "any pull request green at its live head may merge (which one the words meant is the branch's reading)" with "a pull request whose review ledger passes every gate merges through bin/fm-pr-review.sh merge under standing authority, and a merge only the words could authorize is the branch's reading of them", and replace the away-merge sentence with "While the away-posture record exists, a GitHub pull request merges only through bin/fm-pr-review.sh merge, so its current ledger generation passes every gate; that merge is standing authority and needs no words, while a merge only the captain's words could authorize is the away session's reading of them and otherwise holds for the return." .agents/skills/pr-review-policy/SKILL.md gains: "While the away-posture record exists, every GitHub merge goes through bin/fm-pr-review.sh merge whatever the policy setting, and bin/fm-pr-merge.sh refuses one that did not." docs/pi-supervision-branch.md: the bin/fm-pr-merge.sh row adds that it refuses a GitHub merge lacking bin/fm-pr-review.sh merge's recorded ledger merge decision for the live head, a new bin/fm-pr-review.sh release-hold row says it is never relocated and refuses the branch actor in every posture, and "Verification" names the new merge and review tests.
Safety boundaries the report requires to hold after the change: no red merge and no merge with an unreported required check while away, with --allow-red and --allow-missing refused away; the snapshot records no required checks only when the shared reader proves the required set empty; captain holds stay (ledger holds refused by the ready check and the merge script, release-hold refuses the branch actor, captain-held tasks and unresolved human decisions still hold); no discards and no destructive or security-sensitive action, with the gate steer forbidding init, rebase, and force-push; the high-stakes exact-model attestation is script-enforced while away; local-only landing still waits for the captain; away authority dies at archive. Out of scope: changes to ask-user-authority, the supervision engine model, attended merge or ledger behaviour, the tracked review policy file, and GitLab.
What Changed
bin/fm-pr-merge.shintobin/fm-pr-lib.shasfm_pr_github_*functions that take owner and repo as arguments. Merge behavior is unchanged. Whengh pr checks --requiredreports "no required checks reported",bin/fm-pr-review-snapshot.shnow reads the PR's.base.refand checks it with the shared reader. It records no required checks only when that set is readable and empty. A non-empty or unreadable set still records the pending "required checks have not reported" placeholder. One-time effect: an open review ledger whose final-disposition digest includes the placeholder will show "final disposition ... not posted for the latest review state" on its next checkpoint, until the final disposition is recorded again.bin/fm-pr-merge.shrefuses a GitHub merge with a review ledger unless both of these hold:FM_PR_REVIEW_EXPECTED_HEADis set.merge_decision.decision == "merge"withverified_headequal to that head.bin/fm-pr-review.sh merge.bin/fm-pr-review.sh release-holdnow refuses the supervision branch actor in every posture (fm_lease_forbid_branch, never relocated). Thebin/fm-lease-lib.shrole partition comments now list this case.bin/fm-branch-prompt.shand the away wake tail in.pi/extensions/lib/fm-branch-dispatch.tsnow say that while away the branch acts under MAIN's standing authority without needing the captain's words. That authority covers:bin/fm-pr-review.sh init/arm)bin/fm-pr-review.sh mergeAGENTS.md,docs/pi-supervision-branch.md,docs/architecture.md,docs/configuration.md,docs/scripts.mdandbin/fm-afk-contract.shcomments were updated to match.tests/fm-pr-merge.test.sh,tests/fm-pr-review.test.sh,tests/fm-branch-supervision.test.shandtests/fm-supervision-host.test.shcover the away merge refusal, release-hold refusal, snapshot required-check handling and prompt text.tests/fm-pi-branch-extension.test.shassertions were updated for the new away-tail text.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The away-merge and release-hold gates both fail closed. The required-check reader moved into the library unchanged and now takes owner and repo as arguments, and the snapshot records no required checks only when that reader proves the set empty. The fix round matches the user's instruction exactly: a ledger-creation and arming item in both prompt surfaces, with no gate relaxed, and
fm-pr-review.sh initandarmhave no branch-actor guard, so the branch can actually run them.Testing
All driven scenarios passed. Part A: required-check snapshot (live against real GitHub) - On this repo's own PR #36, whose base branch has no protection, the base snapshot invents a pending "required checks have not reported" check. The target snapshot records no required checks. - On a real cli/cli PR whose base branch requires 3 checks, the target keeps the pending placeholder. It also keeps it when the protection read is broken. Part B: away merge gate (lab FM_HOME with a real away record) - The branch actor initialized and armed a missing ledger. - Every GitHub merge attempt outside a passingbin/fm-pr-review.sh mergewas refused with the specified text. That covers the direct call, a hand-set handoff,--allow-red, and a merge decision recorded for an earlier head. -fm-pr-review.sh mergerefused the incomplete ledger. It named the missing checkpoint, dispositions, final disposition, and exact-model attestation. -release-holdrefused the branch actor both away and attended. Main could still release the hold. - The read-onlyghwrapper logged zeropr mergecalls and no other mutating call. Part C: generated prompts (base vs target) - The diffs of the generated system prompt and away wake prompt show exactly the intended wording: standing authority, ledger init/arm, the merge handoff, the ask-user qualification, and "beyond standing authority". - The system prompt stays byte-identical across cwd and env. Targeted test files - The five relevant test files ran with 0 failures.fm-supervision-hostwas stopped at the background time limit after 69 passes, including the changed away-tail case. - On this host the tests needed the real node install dir first on PATH, because the mise node shim fails under the tests' fake HOME. This also fails at base, so it is not caused by this change. Not covered live - The positive away merge was not run against real GitHub, because that would merge a real PR. Only the stub-forge test covers it, so it is recorded as untested. - How a live model interprets the prompt was not tested. - The Part D skill and doc edits have no runtime surface. - There is no UI, so there are no screenshots.bash tests/fm-pr-merge.test.sh, which is not live. A live success would merge a real…Evidence: Snapshot on an unprotected real base: base invents a pending required check, target records none
Source: Snapshot on an unprotected real base: base invents a pending required check, target records none
Evidence: Snapshot adversarial: real cli/cli base requiring checks keeps the placeholder (also when the required set is unreadable)
Source: Snapshot adversarial: real cli/cli base requiring checks keeps the placeholder (also when the required set is unreadable)
Evidence: Lab transcript: away entry, branch ledger init/arm, merge refusals B1-B6, release-hold partition C1-C3, gh call log with zero merges
Source: Lab transcript: away entry, branch ledger init/arm, merge refusals B1-B6, release-hold partition C1-C3, gh call log with zero merges
Evidence: Lab review ledger final state (no merge decision recorded; hold released only by main)
Source: Lab review ledger final state (no merge decision recorded; hold released only by main)
Evidence: Generated branch system prompt diff, base vs target
Source: Generated branch system prompt diff, base vs target
Evidence: Generated away wake prompt diff, base vs target
Source: Generated away wake prompt diff, base vs target
Evidence: Generated target away wake prompt
Source: Generated target away wake prompt
Evidence: fm-pr-review test log (empty required set, ready on no-protection base)
Source: fm-pr-review test log (empty required set, ready on no-protection base)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
⏭️ **Rebase** - skipped
Step was skipped.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-branch-prompt.sh:123- While away, a GitHub PR with no review ledger can no longer merge, and nothing tells the away branch how to create one.require_away_review_merge_decision(bin/fm-pr-merge.sh:1144-1155) refuses whenever the ledger file is missing, because REVIEW_LEDGER is a computed path that is set whenever the tracked policy exists, and the away-without-ledger test locks that in.bin/fm-pr-review.sh mergealso dies with 'review ledger is unavailable' when there is no ledger. Only the pr-review-policy skill says to runbin/fm-pr-review.sh init <task> <url>(andarm) afterfm-pr-check.sh, and that is MAIN's step. The branch prompt tells the branch to runbin/fm-pr-check.sh(bin/fm-branch-prompt.sh:53) but never mentions init. The standing-authority list (lines 122-124) only covers steering the worker to supply dispositions, the final disposition, or the attestation, and the worker cannot create the ledger. The same gap is in the away tail at .pi/extensions/lib/fm-branch-dispatch.ts:54. Concrete sequence: a worker opens and reports a PR during the away window; the branch runs fm-pr-check.sh; no ledger is initialized;fm-pr-review.sh mergedies; the branch holds on doubt and reports verdict captain. That is the same stall-until-return this change exists to remove, and before this change a green PR in this state merged. Failing closed in the script is correct, since it protects the exact-model attestation boundary. The fix belongs in the prompt: add 'initialize a missing review ledger with bin/fm-pr-review.sh init <task> <url> and arm' to MAIN's standing-authority set in fm-branch-prompt.sh and the away tail. That adds to the text the intent specifies, so the remedy needs authorization.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-pr-merge.test.sh, which is not live. A live success would merge a real…bin/fm-pr-review-snapshot.sh https://github.com/twilwa/firstmate/pull/36at base 2e07fc7 and target 051aff9 against real GitHub (main unprotected, rules [])bin/fm-pr-review-snapshot.sh https://github.com/cli/cli/pull/14679(trunk requires 3 checks) with onlygh pr checksforced to print the ambiguous 'no required checks reported' message, plus a variant where the branch-protection read returns HTTP 502Lab home viabin/fm-lab-home.sh create;bin/fm-afk-contract.sh enter --words 'keep the lanes running';FM_SUPERVISION_ACTOR=branch bin/fm-pr-review.sh init task-x1 <PR36>andarmAs the branch actor while away: directbin/fm-pr-merge.sh task-x1 <PR36>; the same with a hand-setFM_PR_REVIEW_EXPECTED_HEAD=live head; with--allow-red; with a ledger merge decision recorded for an earlier head; andbin/fm-pr-review.sh merge task-x1 <PR36>on an incomplete ledgerbin/fm-pr-review.sh holdas main, thenrelease-holdas the branch actor away and again afterbin/fm-afk-contract.sh archive; attended directbin/fm-pr-merge.shas main (refused by the ledger hold);release-holdas mainbin/fm-branch-prompt.shandbin/fm-branch-dispatch.mjs wake-prompt --away --readback-file <real lab readback>generated at base and target, then diffed; byte-identity checked across cwd/envbash tests/fm-pr-merge.test.sh(114 ok)bash tests/fm-pr-review.test.sh(27 ok)bash tests/fm-branch-supervision.test.sh(34 ok)bash tests/fm-pi-branch-extension.test.sh(49 ok, 2 skipped: installed Pi package not found)bash tests/fm-supervision-host.test.sh(69 ok, 0 failed, including the changed dispatch away-tail case, before the run was stopped at the background time limit)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.