Skip to content

feat(bin): recover workers from a crash-stranded no-mistakes gate ref via a fresh branch - #4938

Open
markhomexa wants to merge 3 commits into
kunchenguid:mainfrom
markhomexa:fm/fm-gate-ref-strands-after-crash
Open

markhomexa wants to merge 3 commits into
kunchenguid:mainfrom
markhomexa:fm/fm-gate-ref-strands-after-crash

Conversation

@markhomexa

@markhomexa markhomexa commented Sep 19, 2026 •

Copy link
Copy Markdown

Intent

A pipeline crash strands the validation gate ref, and no supported path recovers it. Hit TWICE on 2026-09-18/19, on two different lanes, hours apart.

After a daemon crash or a killed fix round, the private validation mirror (~/.no-mistakes/repos/.git) keeps the PRE-rebase ref for the branch while custody recovery leaves the worker on the rebased head, so every later no-mistakes axi run dies before its first step with "push to gate: ! [rejected] (non-fast-forward)". The tool's own structured path is a dead end: axi sync --check reports relation=equal, custody_returned, next_action=run_pipeline, and axi sync --recover --keep-local runs as a documented no-op (changed=false) and leaves the ref unmoved. Both workers independently concluded the only ways out were forcing the shared mirror ref or updating the shared daemon, and both correctly refused - that daemon serves every lane on the machine.

The workaround that worked both times: verify with git log --cherry-pick --left-only/--right-only that the stranded ref holds nothing the current head lacks, then re-run on a FRESH branch name, which the mirror accepts as an ordinary new ref.

What Changed

  • Adds bin/fm-nm-stranded-gate.sh, a read-only check that detects a mirror ref left on the pre-rebase tip after a crash. When git rev-list --cherry-pick --left-only shows that every stranded commit is already in HEAD, it prints fresh_branch: and next: lines with the safe fresh-branch remedy. It refuses in three cases: the ref holds commits HEAD lacks (listed as unlanded:), a PR is open on the stranded branch (open_pr:), or it can't prove that no such PR exists. It never fetches, pushes, or writes to the mirror, and it never contacts the daemon. Exit codes: 0 means the remedy is safe, 1 means refused, 2 means an error, 3 means not stranded. tests/fm-nm-stranded-gate.test.sh covers the helper.
  • The no-mistakes brief in bin/fm-dod-lib.sh now covers a push to gate non-fast-forward rejection that axi sync reports nothing to recover from. It gives the helper's absolute path, forbids forcing the mirror ref or touching the daemon, and says how to act on each helper outcome. tests/fm-brief.test.sh checks that no-mistakes briefs name an executable helper path and that direct-PR briefs leave it out.
  • The stuck-crewmate-recovery skill trigger (in the skill and in AGENTS.md) now includes a non-fast-forward gate push refusal. The skill routes that case to the helper, and when the helper refuses it says to preserve the work and escalate. docs/scripts.md lists the new helper.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change adds a read-only helper and brief routing for a stranded gate ref. The fix round does what the user asked: the helper now refuses when a PR is open on the stranded branch or when gh cannot rule one out, and the unlanded-commit refusal is still checked first. It only lists PRs, never changes one, and queries them the same way the existing teardown and pr-check scripts do. A fake gh covers the three cases (open PR, failed query, no PR), and the brief now routes any other helper outcome to rule 7's blocked report.

Testing

Ran the two focused test files (the helper's tests and the brief's new test); both passed. Then I drove the helper live against real git bare mirrors and the real gh CLI. First I reproduced the crash symptom: a rebased branch's gate push was rejected as non-fast-forward. The helper recommended <branch>-r2. Following its next: lines produced a push the mirror accepted as a new branch, and the stranded ref was left unchanged. In the adversarial checks the helper refused in each case: unlanded mirror commits, a real open PR (#4935, which stayed open and untouched), a gh auth failure, and gh missing from PATH. I also checked the not-stranded (exit 3) and missing-remote (exit 2) outcomes and captured the rendered worker brief. Every scenario passed. The daemon-backed no-mistakes axi run itself was not driven, because this phase must not init or run another pipeline; a git push to a bare mirror stood in for its first step. There is no UI surface, so no screenshots.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Worker stranded by a crash (gate push rejected non-fast-forward, all mirror commits already in HEAD, no open PR) runs the helper, gets fresh_branch <branch>-r2, follows next: lines, and the mirror acc… ✅ pass live live-stranded-gate-transcript.txt (Scenario 1)
Adversarial: stranded mirror ref holds a commit HEAD lacks -> helper refuses with unlanded: line, no fresh branch, exit 1 ✅ pass live live-stranded-gate-transcript.txt (Scenario 2)
Adversarial: a PR is open on the stranded branch (real PR #4935 via real gh) -> helper refuses, prints open_pr URL, no fresh branch; PR left open and untouched; mirror bytes unchanged ✅ pass live live-stranded-gate-open-pr-transcript.txt (Scenario 3)
Adversarial: open-PR query cannot complete (bad gh auth, or gh not installed) -> helper refuses rather than recommend a fresh branch ✅ pass live live-stranded-gate-open-pr-transcript.txt (Scenarios 4, 4b)
Branch that fast-forwards reports not-stranded (exit 3); a missing no-mistakes remote errors (exit 2) ✅ pass live live-stranded-gate-transcript.txt (Scenarios 5, 6)
A worker brief rendered in no-mistakes mode tells the worker to run the helper by absolute path, never to force the mirror or touch the daemon, and sends refusals and other outcomes to a blocked repor… ✅ pass live rendered-brief-stranded-gate-excerpt.txt; tests/fm-brief.test.sh test_no_mistakes_dod_names_stranded_gate_helper
Re-running an actual no-mistakes axi run against the shared daemon from the fresh branch succeeds ⏸️ untested no This test phase must not init or run another no-mistakes pipeline, and it must not touch the shared daemon, which serves every lane. To verify, a worker can re-run no-mistakes axi run from a fresh b…
Evidence: Live transcript: crash-stranded ref reproduced, fresh-branch remedy accepted by mirror, unlanded-commit refusal, exit 3/2 outcomes

Source: Live transcript: crash-stranded ref reproduced, fresh-branch remedy accepted by mirror, unlanded-commit refusal, exit 3/2 outcomes

== pipeline pushed pre-rebase tip to gate mirror, then crashed

$ git push -q no-mistakes fm/stranded-live-demo
[exit 0]
== custody recovery rebases the worker onto main
== re-run's gate push (what axi run does first):

$ git push no-mistakes fm/stranded-live-demo
To /tmp/stranded-live.ZrTt/mirror.git
 ! [rejected]        fm/stranded-live-demo -> fm/stranded-live-demo (non-fast-forward)
error: failed to push some refs to '/tmp/stranded-live.ZrTt/mirror.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[exit 1]
== Scenario 1: helper with REAL gh (no open PR on origin for this branch)

$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/stranded-live-demo
head: a74e062d26bc5e27b181f5a853d4074d732c260b
mirror: /tmp/stranded-live.ZrTt/mirror.git
mirror_ref: 850e113a5d813e632e5a1bad1bca959843c10666
state: stranded
reason: every mirror-ref commit is already in HEAD; the mirror refuses only the rewritten history
fresh_branch: fm/stranded-live-demo-r2
next: git switch -c fm/stranded-live-demo-r2
next: re-run the same no-mistakes axi run invocation from that branch
[exit 0]
== following the next: lines

$ git switch -c fm/stranded-live-demo-r2
Switched to a new branch 'fm/stranded-live-demo-r2'
[exit 0]

$ git push no-mistakes fm/stranded-live-demo-r2
To /tmp/stranded-live.ZrTt/mirror.git
 * [new branch]      fm/stranded-live-demo-r2 -> fm/stranded-live-demo-r2
[exit 0]
== mirror refs before/after (stranded ref untouched):
850e113a5d813e632e5a1bad1bca959843c10666 commit	refs/heads/fm/stranded-live-demo
850e113a5d813e632e5a1bad1bca959843c10666 commit	refs/heads/fm/stranded-live-demo
a74e062d26bc5e27b181f5a853d4074d732c260b commit	refs/heads/fm/stranded-live-demo-r2
== Scenario 2 (adversarial): stranded ref holds unlanded work

$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/stranded-live-demo
head: a74e062d26bc5e27b181f5a853d4074d732c260b
mirror: /tmp/stranded-live.ZrTt/mirror.git
mirror_ref: c020c41d4dc363f1171780dcdf45f5a4e382ee59
state: refused
reason: the mirror ref holds commits HEAD lacks; a fresh branch would abandon them
unlanded: c020c41d4dc363f1171780dcdf45f5a4e382ee59 task: B only on mirror
next: stop and report blocked with these commits; do not force the mirror or touch the daemon
[exit 1]
== Scenario 3 (adversarial): open PR on stranded branch (real gh, real open PR #4935 head fm/fm-ship-4784)
usage: git cherry-pick [--edit] [-n] [-m <parent-number>] [-s] [-x] [--ff]
                       [-S[<keyid>]] <commit>...
   or: git cherry-pick (--continue | --skip | --abort | --quit)

    --quit                end revert or cherry-pick sequence
    --continue            resume revert or cherry-pick sequence
    --abort               cancel revert or cherry-pick sequence
    --skip                skip current commit and continue
    --[no-]cleanup <mode> how to strip spaces and #comments from message
    -n, --no-commit       don't automatically commit
    --commit              opposite of --no-commit
    -e, --[no-]edit       edit the commit message
    -s, --[no-]signoff    add a Signed-off-by trailer
    -m, --[no-]mainline <parent-number>
                          select mainline parent
    --[no-]rerere-autoupdate
                          update the index with reused conflict resolution if possible
    --[no-]strategy <strategy>
                          merge strategy
    -X, --[no-]strategy-option <option>
                          option for merge strategy
    -S, --[no-]gpg-sign[=<key-id>]
                          GPG sign commit
    -x                    append commit name
    --[no-]ff             allow fast-forward
    --[no-]allow-empty    preserve initially empty commits
    --[no-]allow-empty-message
                          allow commits with empty messages
    --[no-]keep-redundant-commits
                          deprecated: use --empty=keep instead
    --empty (stop|drop|keep)
                          how to handle commits that become empty


$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/fm-ship-4784
head: 1d01c3b05bb6964917cd9a4e04231871d3d6efbb
mirror: /tmp/stranded-live.ZrTt/mirror.git
mirror_ref: fc7060a8ba3ed0e730462ef73e6b12d8693f1e4c
state: refused
reason: the mirror ref holds commits HEAD lacks; a fresh branch would abandon them
unlanded: fc7060a8ba3ed0e730462ef73e6b12d8693f1e4c old tip
next: stop and report blocked with these commits; do not force the mirror or touch the daemon
[exit 1]
== Scenario 4 (adversarial): gh cannot complete (GH_TOKEN invalid, no config)

$ env GH_CONFIG_DIR=/tmp/stranded-live.ZrTt/empty-gh GH_TOKEN=bogus ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/fm-ship-4784
head: 1d01c3b05bb6964917cd9a4e04231871d3d6efbb
mirror: /tmp/stranded-live.ZrTt/mirror.git
mirror_ref: fc7060a8ba3ed0e730462ef73e6b12d8693f1e4c
state: refused
reason: the mirror ref holds commits HEAD lacks; a fresh branch would abandon them
unlanded: fc7060a8ba3ed0e730462ef73e6b12d8693f1e4c old tip
next: stop and report blocked with these commits; do not force the mirror or touch the daemon
[exit 1]
== Scenario 5: not stranded (branch fast-forwards)

$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: ff-demo
head: 56339e826693868b7b9d23ca01de041b98a2318f
mirror: /tmp/stranded-live.ZrTt/mirror.git
mirror_ref: 1d01c3b05bb6964917cd9a4e04231871d3d6efbb
state: not-stranded
reason: HEAD already contains the mirror ref, so a push fast-forwards
[exit 3]
== Scenario 6: no no-mistakes remote

$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
error: no 'no-mistakes' remote in /tmp/stranded-live.ZrTt/repo
[exit 2]
Evidence: Live transcript: refusal on real open PR #4935, gh auth failure, gh missing; mirror fingerprint unchanged, PR still open

Source: Live transcript: refusal on real open PR #4935, gh auth failure, gh missing; mirror fingerprint unchanged, PR still open

== real open PR on origin for head fm/fm-ship-4784:
[{"headRefName":"fm/fm-ship-4784","url":"https://github.com/kunchenguid/firstmate/pull/4935"}]

$ git push no-mistakes fm/fm-ship-4784
To /tmp/stranded-pr.f3bg/mirror.git
 ! [rejected]        fm/fm-ship-4784 -> fm/fm-ship-4784 (non-fast-forward)
error: failed to push some refs to '/tmp/stranded-pr.f3bg/mirror.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[exit 1]
== Scenario 3 (adversarial): stranded branch has an OPEN PR (real gh)

$ ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/fm-ship-4784
head: d1c6e4d20f733ac07bb47107ea9c0b12e8d8d465
mirror: /tmp/stranded-pr.f3bg/mirror.git
mirror_ref: f356dbac036b5fd31537b5fb51790d3c2123b368
state: refused
reason: a PR is open for fm/fm-ship-4784; a fresh branch would open a second PR and orphan it
open_pr: https://github.com/kunchenguid/firstmate/pull/4935
next: stop and report blocked naming this PR; do not force the mirror or touch the daemon
[exit 1]
== Scenario 4 (adversarial): gh query cannot complete (bad token, empty gh config)

$ env GH_CONFIG_DIR=/tmp/stranded-pr.f3bg/empty-gh GH_TOKEN=bogus ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/fm-ship-4784
head: d1c6e4d20f733ac07bb47107ea9c0b12e8d8d465
mirror: /tmp/stranded-pr.f3bg/mirror.git
mirror_ref: f356dbac036b5fd31537b5fb51790d3c2123b368
state: refused
reason: could not prove no PR is open for fm/fm-ship-4784 (gh pr list failed); a fresh branch could orphan it
next: stop and report blocked with this output; do not force the mirror or touch the daemon
[exit 1]
== Scenario 4b: gh not on PATH

$ env PATH=/usr/bin:/bin ~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh
branch: fm/fm-ship-4784
head: d1c6e4d20f733ac07bb47107ea9c0b12e8d8d465
mirror: /tmp/stranded-pr.f3bg/mirror.git
mirror_ref: f356dbac036b5fd31537b5fb51790d3c2123b368
state: refused
reason: could not prove no PR is open for fm/fm-ship-4784 (gh is not installed); a fresh branch could orphan it
next: stop and report blocked with this output; do not force the mirror or touch the daemon
[exit 1]
== mirror byte fingerprint before=1107515146 1153 after=1107515146 1153
== local branches (no fresh branch created):
* fm/fm-ship-4784
  main
== PR still open, untouched:
{"state":"OPEN","url":"https://github.com/kunchenguid/firstmate/pull/4935"}
Evidence: Rendered no-mistakes worker brief excerpt routing to the helper

Source: Rendered no-mistakes worker brief excerpt routing to the helper

101:If a run stops before its first step with `push to gate` rejected as non-fast-forward while `axi sync` reports nothing to recover, a crash stranded this branch's pre-rebase tip in the gate mirror.
102-Never force that mirror ref or touch the daemon; run `~/.no-mistakes/worktrees/a20fe525da72/01M2X250T6NJ3BFF0W896CJKE7/bin/fm-nm-stranded-gate.sh` from your worktree, which owns the safety check.
103-When it prints `fresh_branch:`, follow its `next:` lines; when it refuses, append `blocked:` with its `reason:` and any `unlanded:` commits or `open_pr:` URL, and stop.
104-Any other outcome (not stranded, or an error) goes to rule 7's blocked report with the helper's output.
Evidence: Focused helper test run

Source: Focused helper test run

ok - refuses a fresh branch when the stranded ref holds a commit HEAD lacks
ok - refuses when the stranded ref holds a merge commit
ok - recommends a fresh branch when every stranded commit is in HEAD
ok - fresh branch name increments an -rN suffix and skips taken names
ok - refuses a fresh branch while a PR is open for the stranded branch
ok - refuses a fresh branch when the open-PR query cannot complete
ok - reports not-stranded for equal, fast-forward, and absent mirror refs
ok - exits 2 for a missing remote or detached HEAD

Notes

  • CI has not run yet: both GitHub workflow runs for this PR (CI and Require no-mistakes) are at action_required, held for maintainer approval as fork PRs are. They have zero jobs, so nothing failed. The pipeline's CI step was accepted with no code change, and nothing was auto-fixed on top.
  • This PR is Firstmate's side only. The durable fix belongs upstream in no-mistakes: axi sync --recover should return custody without leaving the gate mirror stranded at the pre-rebase ref. An upstream report has not been filed.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-nm-stranded-gate.sh:143 - The fresh-branch remedy says only git switch -c &lt;base&gt;-rN and 're-run the same no-mistakes axi run invocation'. It never checks for, or mentions, a PR that is already open on origin for the stranded branch. The intent's trigger includes a 'killed fix round', and a CI fix round can run after the pipeline has already pushed the old branch and opened its PR. In that case, following these next: lines makes the pipeline open a second PR from fm/&lt;id&gt;-r2, and the original PR stays open with nothing tracking it. Teardown resolves PRs from the current branch or the recorded pr=, so it never sees the old one. Fixing this means adding PR detection or supersede/close guidance to the remedy, which goes beyond the workaround the intent describes, so the author needs to decide whether the helper or the brief should cover it.
  • ℹ️ bin/fm-dod-lib.sh:290 - The brief tells the worker what to do when the helper prints fresh_branch: (exit 0) or refuses (exit 1). It says nothing for exit 3 (not-stranded) or exit 2 (for example, no no-mistakes remote). A worker whose non-fast-forward push has some other cause would get no direction. A short clause routing those outcomes to the existing rule-7 block report would close the gap.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Worker stranded by a crash (gate push rejected non-fast-forward, all mirror commits already in HEAD, no open PR) runs the helper, gets fresh_branch <branch>-r2, follows next: lines, and the mirror acc… ✅ pass live live-stranded-gate-transcript.txt (Scenario 1)
Adversarial: stranded mirror ref holds a commit HEAD lacks -> helper refuses with unlanded: line, no fresh branch, exit 1 ✅ pass live live-stranded-gate-transcript.txt (Scenario 2)
Adversarial: a PR is open on the stranded branch (real PR #4935 via real gh) -> helper refuses, prints open_pr URL, no fresh branch; PR left open and untouched; mirror bytes unchanged ✅ pass live live-stranded-gate-open-pr-transcript.txt (Scenario 3)
Adversarial: open-PR query cannot complete (bad gh auth, or gh not installed) -> helper refuses rather than recommend a fresh branch ✅ pass live live-stranded-gate-open-pr-transcript.txt (Scenarios 4, 4b)
Branch that fast-forwards reports not-stranded (exit 3); a missing no-mistakes remote errors (exit 2) ✅ pass live live-stranded-gate-transcript.txt (Scenarios 5, 6)
A worker brief rendered in no-mistakes mode tells the worker to run the helper by absolute path, never to force the mirror or touch the daemon, and sends refusals and other outcomes to a blocked repor… ✅ pass live rendered-brief-stranded-gate-excerpt.txt; tests/fm-brief.test.sh test_no_mistakes_dod_names_stranded_gate_helper
Re-running an actual no-mistakes axi run against the shared daemon from the fresh branch succeeds ⏸️ untested no This test phase must not init or run another no-mistakes pipeline, and it must not touch the shared daemon, which serves every lane. To verify, a worker can re-run no-mistakes axi run from a fresh b…
  • bash tests/fm-nm-stranded-gate.test.sh (8 behavior tests, fake gh, all ok)
  • bash tests/fm-brief.test.sh (new test_no_mistakes_dod_names_stranded_gate_helper ok)
  • Live repro: bare mirror as no-mistakes remote, pushed the pre-rebase tip, rebased onto an advanced main, real git push rejected non-fast-forward, ran helper with the real gh against kunchenguid/firstmate, ran git switch -c &lt;branch&gt;-r2 and pushed; mirror accepted the new ref and the stranded ref was unchanged
  • Live adversarial: rewrote the mirror ref to include a commit HEAD lacks -> helper refused with unlanded: line, exit 1
  • Live adversarial: stranded branch named fm/fm-ship-4784, which has real open PR #4935 -> real gh query, helper refused with open_pr URL, exit 1; PR still OPEN afterwards; mirror byte fingerprint identical; no fresh branch created
  • Live adversarial: bogus GH_TOKEN plus empty GH_CONFIG_DIR, and gh removed from PATH -> both refused with 'could not prove no PR is open'
  • Live: fast-forwardable branch -> not-stranded exit 3; missing no-mistakes remote -> error exit 2
  • Rendered a real no-mistakes brief with bin/fm-brief.sh --mode no-mistakes and captured the stranded-gate guidance, which names the helper by absolute path
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…workers to a safe fresh-branch remedy

Add bin/fm-nm-stranded-gate.sh, a read-only check that compares the gate
mirror's ref for the current branch with HEAD by cherry-pick equivalence and
prints the fresh-branch command only when the mirror ref holds nothing HEAD
lacks; any unlanded commit, including a merge, is refused. The no-mistakes
Definition of done points workers at it, and stuck-crewmate-recovery tells
firstmate how to treat a refusal.
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.

1 participant