Skip to content

fix(bin): republish parent metadata after a remote secondmate relaunch - #5583

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/fm5332-remote-relaunch-meta
Sep 26, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/fm5332-remote-relaunch-meta

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #5332.
Implement ready-for-pr issue #5332: a remote second-mate relaunch leaves the parent's record on the old harness, model and effort.
The fix already exists on the captain's fork as merged fork pull requests tiago-peixoto#61 (21e8008, republish the parent's own record after a remote secondmate relaunch) and tiago-peixoto#63 (c12ed36, keep pr= last when a remote relaunch republishes parent metadata). Upstream pull request #5321 was closed and must not be reopened.
After a successful remote relaunch, the parent's record for the mate names the harness, model, and effort the host actually launched, the same way it does after the local relaunch path.
A refused or failed remote relaunch leaves the parent's record untouched.
A record that carries pr= and pr_head= still passes fm_pr_metadata_identity_parse after a remote relaunch, and its armed PR merge poll still validates, because any rewrite must keep the pr= block last.
The parent's record reflects what the host confirms it launched, not what the parent asked for.
The documented operator path in secondmate-provisioning and docs/remote-secondmates.md leads to a correct parent record.
The existing remote relaunch callers, including bin/fm-secondmate-restart.sh and startup liveness, keep working.

What Changed

  • Added bin/fm-remote-secondmate-relaunch.sh. It runs the host-side fm-remote-secondmate-control.sh relaunch through fm-on.sh, then reads the harness, model, and effort back from the route block the host prints. It rewrites the parent's state/<id>.meta under the metadata lock with those values first, and keeps every other line in its original order so any pr= block stays last and fm_pr_metadata_identity_parse still accepts it. If the relaunch fails, is refused, or prints no route confirmation, the parent record is not touched.
  • fm-remote-secondmate-control.sh now includes model= and effort= in its route block. relaunch prints that block at the end, read from the host's republished endpoint record, so a default pin shows up as the value the host actually resolved.
  • bin/fm-secondmate-restart.sh now restarts remote mates through the new wrapper. secondmate-provisioning, docs/agent-control.md, and docs/remote-secondmates.md now point to the wrapper as the way to relaunch a remote mate, and warn against calling relaunch through fm-on.sh directly. The branch adds tests/fm-remote-secondmate-relaunch.test.sh, registers it in fm-test-run.sh, and updates the restart test.

Fixes #5332.

Risk Assessment

✅ Low: The change is a small, well-bounded wrapper that meets every intent criterion. On failure it exits before touching the record, because fm-on's non-zero exit returns and set -e on the host aborts before print_route runs. It reads the identity back from the host endpoint's own record, keeps the pr= block last under the per-record metadata lock, and leaves the restart caller's output parsing and the startup-liveness launch path (which uses the launch verb, not relaunch) unaffected.

Testing

I ran the new regression test, the existing restart test and the full remote lifecycle e2e; all passed. The e2e includes the startup and watch liveness auto-relaunch, so the existing remote relaunch callers still work. I also wrote an operator-style transcript script and ran it against the base commit and the target commit. At base, the documented relaunch path left the parent record stale; at the target, the wrapper records what the host confirmed (not what was requested), keeps pr= last so the PR poll stays valid, leaves the record unchanged on refusal, and refuses local mates. A separate check showed a record with pr=, pr_head= and x_* fields still passes fm_pr_metadata_identity_parse after a relaunch. Every run used a stubbed ssh or the repository's SSH/Herdr fixtures, so no scenario is live. A real remote leg needs a second SSH host running the Firstmate remote job worker, and the host-side relaunch always uses the Herdr session named fm-remote, which the runbook forbids outside fm-lab-* sessions. There is no UI surface, so there are no screenshots.

  • Live validation: ⚠️ inconclusive - 0 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator relaunches a remote mate onto a new harness/model/effort and the parent's state/<id>.meta then names the new runtime ⏸️ untested no Passed with ssh stubbed (demo-fix-e21b3e1.txt vs demo-base-31c47af.txt, tests/fm-remote-secondmate-relaunch.test.sh) but was not driven live. A real remote leg needs a second SSH host running the Firs…
Host resolves 'default' to a configured pin; parent records what the host confirmed, not what it asked for ⏸️ untested no The prior payload did not establish a live result: only stubbed runs passed (demo-fix-e21b3e1.txt, regression test). A live run needs a real remote secondmate host.
Refused remote relaunch leaves the parent's record byte-identical ⏸️ untested no The prior payload did not establish a live result: only a stubbed refusal passed. A genuine refusal needs a real remote secondmate host.
Record with pr= and pr_head= still passes fm_pr_metadata_identity_parse and the armed PR poll still validates after a remote relaunch ⏸️ untested no The prior payload did not establish a live result: the parent-side rewrite and parse ran on real files, but the relaunch came from a stub because there is no real remote host.
Existing caller bin/fm-secondmate-restart.sh restarts a remote mate through the wrapper ⏸️ untested no The prior payload did not establish a live result: tests/fm-secondmate-restart.test.sh passed only over its SSH fixture (fm-secondmate-restart.log). A live run needs a real remote secondmate host.
Startup/watch liveness auto-relaunches a dead remote mate and still works ⏸️ untested no The prior payload did not establish a live result: the lifecycle e2e passed over the repository's fake SSH/Herdr fixtures only. A live run needs a real remote host, and the host-side Herdr session is…
A local mate given to the remote wrapper is refused with guidance to use fm-control.sh ⏸️ untested no The prior payload did not establish a live result: the wrapper CLI was run directly in the demo transcript, but not against a real fleet home.
Documented operator path in secondmate-provisioning and docs/remote-secondmates.md leads to a correct parent record ⏸️ untested no Docs cannot be driven live on their own, and the command they document needs a real remote secondmate host, which the prior payload did not have.
Evidence: Bug reproduced at base 31c47af (parent record stays on pi/gpt-5.6-sol/medium after relaunch)

Source: Bug reproduced at base 31c47af (parent record stays on pi/gpt-5.6-sol/medium after relaunch)

=== checkout: 31c47af
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=pi
model=openai-codex/gpt-5.6-sol
effort=medium
--- last key in record: remote_target

=== operator arms a PR poll (fm-pr-check.sh), then relaunches onto claude default default
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=pi
model=openai-codex/gpt-5.6-sol
effort=medium
pr=https://github.com/example/repo/pull/1
--- last key in record: pr
$ bin/fm-on.sh ios fm-remote-secondmate-control.sh relaunch ios claude default default   (documented path at base)
relaunched ios harness=claude from=pi model=default effort=default backend=herdr endpoint=fm-remote:w1:p2 worktree=/srv/fm-home
schema=fm-remote-secondmate-control.v1
backend=herdr
target=fm-remote:w1:p2
herdr_session=fm-remote
harness=claude
model=claude-opus-5-5
effort=high
rc=0
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=pi
model=openai-codex/gpt-5.6-sol
effort=medium
pr=https://github.com/example/repo/pull/1
--- last key in record: pr
PR poll artifacts: VALID
Evidence: Fixed at e21b3e1 (record takes the host-confirmed claude/claude-opus-5-5/high, pr= stays last, refusal leaves record unchanged)

Source: Fixed at e21b3e1 (record takes the host-confirmed claude/claude-opus-5-5/high, pr= stays last, refusal leaves record unchanged)

=== checkout: e21b3e1
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=pi
model=openai-codex/gpt-5.6-sol
effort=medium
--- last key in record: remote_target

=== operator arms a PR poll (fm-pr-check.sh), then relaunches onto claude default default
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=pi
model=openai-codex/gpt-5.6-sol
effort=medium
pr=https://github.com/example/repo/pull/1
--- last key in record: pr
$ bin/fm-remote-secondmate-relaunch.sh ios claude default default
relaunched ios harness=claude from=pi model=default effort=default backend=herdr endpoint=fm-remote:w1:p2 worktree=/srv/fm-home
schema=fm-remote-secondmate-control.v1
backend=herdr
target=fm-remote:w1:p2
herdr_session=fm-remote
harness=claude
model=claude-opus-5-5
effort=high
rc=0
--- parent state/ios.meta (harness/model/effort/pr lines):
harness=claude
model=claude-opus-5-5
effort=high
pr=https://github.com/example/repo/pull/1
--- last key in record: pr
PR poll artifacts: VALID

=== refused relaunch leaves record byte-identical
error: unverified remote secondmate harness: notaharness
rc=1
record unchanged: yes

=== local mate refused
error: task l is not a remotely placed secondmate; use bin/fm-control.sh l relaunch instead
rc=1
Evidence: pr/pr_head identity still parses after remote relaunch

Source: pr/pr_head identity still parses after remote relaunch

\### before
window=remote:ios
endpoint_task_id=ios
harness=pi
kind=secondmate
model=m1
effort=medium
remote_host=remote-mac
remote_herdr_session=fm-remote
remote_target=fm-remote:w1:p1
pr=https://github.com/example/repo/pull/7
pr_head=0123456789abcdef0123456789abcdef01234567
x_platform=github
identity_parse: OK url=https://github.com/example/repo/pull/7
$ bin/fm-remote-secondmate-relaunch.sh ios codex default default   (host confirms empty model/effort pins)
relaunched ios harness=codex
schema=fm-remote-secondmate-control.v1
harness=codex
model=
effort=
rc=0
\### after
harness=codex
model=
effort=
window=remote:ios
endpoint_task_id=ios
kind=secondmate
remote_host=remote-mac
remote_herdr_session=fm-remote
remote_target=fm-remote:w1:p1
pr=https://github.com/example/repo/pull/7
pr_head=0123456789abcdef0123456789abcdef01234567
x_platform=github
identity_parse: OK url=https://github.com/example/repo/pull/7
mode=600
.
..
ios.meta
Evidence: Transcript driver script

Source: Transcript driver script

#!/usr/bin/env bash
# Operator transcript: remote secondmate relaunch vs the parent's own record.
# Usage: demo.sh <firstmate-root>
# The SSH boundary is a stub that answers like a host whose relaunch succeeded
# (it resolves "default" to claude/claude-opus-5-5/high), or refuses.
set -u
ROOT=$1
T=$(mktemp -d); H=$T/home; mkdir -p $H/data $H/state $H/config $T/bin
printf -- '- ios - iOS delivery (host: remote-mac; root: /srv/fm; home: /srv/fm-home; scope: iOS; projects: alpha; added 2026-08-01)\n' > $H/data/secondmates.md
seed() {
cat > $H/state/ios.meta <<M
window=remote:ios
endpoint_task_id=ios
worktree=/srv/fm-home
project=/srv/fm
harness=pi
kind=secondmate
mode=secondmate
yolo=off
model=openai-codex/gpt-5.6-sol
effort=medium
home=/srv/fm-home
remote_host=remote-mac
remote_root=/srv/fm
remote_backend=herdr
remote_herdr_session=fm-remote
remote_target=fm-remote:w1:p1
M
chmod 600 $H/state/ios.meta
}
cat > $T/bin/ssh <<'S'
#!/usr/bin/env bash
[ "${MODE:-}" = refuse ] && { echo 'error: unverified remote secondmate harness: notaharness' >&2; exit 1; }
echo 'relaunched ios harness=claude from=pi model=default effort=default backend=herdr endpoint=fm-remote:w1:p2 worktree=/srv/fm-home'
printf 'schema=fm-remote-secondmate-control.v1\nbackend=herdr\ntarget=fm-remote:w1:p2\nherdr_session=fm-remote\nharness=claude\nmodel=claude-opus-5-5\neffort=high\n'
S
chmod +x $T/bin/ssh
printf '#!/usr/bin/env bash\nexit 1\n' > $T/bin/gh; chmod +x $T/bin/gh
export FM_HOME=$H FM_SSH_BIN=$T/bin/ssh
show() { echo "--- parent state/ios.meta (harness/model/effort/pr lines):"; grep -E '^(harness|model|effort|pr|pr_head)=' $H/state/ios.meta; echo "--- last key in record: $(tail -1 $H/state/ios.meta | cut -d= -f1)"; }
echo "=== checkout: $(git -C $ROOT rev-parse --short HEAD)"
seed; show
echo; echo "=== operator arms a PR poll (fm-pr-check.sh), then relaunches onto claude default default"
PATH=$T/bin:$PATH FM_GUARD_GRACE=999999 $ROOT/bin/fm-pr-check.sh ios https://github.com/example/repo/pull/1 >/dev/null 2>&1; show
if [ -x $ROOT/bin/fm-remote-secondmate-relaunch.sh ]; then
  echo '$ bin/fm-remote-secondmate-relaunch.sh ios claude default default'
  $ROOT/bin/fm-remote-secondmate-relaunch.sh ios claude default default; echo "rc=$?"
else
  echo '$ bin/fm-on.sh ios fm-remote-secondmate-control.sh relaunch ios claude default default   (documented path at base)'
  $ROOT/bin/fm-on.sh ios fm-remote-secondmate-control.sh relaunch ios claude default default; echo "rc=$?"
fi
show
( . $ROOT/bin/fm-pr-lib.sh; fm_pr_poll_artifacts_valid $H/state ios $ROOT/bin/fm-pr-poll.sh && echo "PR poll artifacts: VALID" || echo "PR poll artifacts: INVALID" )
if [ -x $ROOT/bin/fm-remote-secondmate-relaunch.sh ]; then
  echo; echo "=== refused relaunch leaves record byte-identical"
  cp $H/state/ios.meta $T/before
  MODE=refuse $ROOT/bin/fm-remote-secondmate-relaunch.sh ios notaharness - -; echo "rc=$?"
  cmp $T/before $H/state/ios.meta && echo "record unchanged: yes"
  echo; echo "=== local mate refused"
  printf 'window=firstmate:fm-l\nendpoint_task_id=l\nharness=codex\nkind=secondmate\n' > $H/state/l.meta
  $ROOT/bin/fm-remote-secondmate-relaunch.sh l claude - -; echo "rc=$?"
fi
rm -rf $T
Evidence: New regression test log

Source: New regression test log

ok - a successful remote relaunch republishes the parent's harness, model, and effort
ok - a remote relaunch records the identity the host confirmed
ok - a refused remote relaunch leaves the parent's record untouched
ok - a local secondmate is refused by the remote relaunch tool
ok - a remote relaunch keeps an already-armed PR poll authenticating
ALL TESTS PASSED
Evidence: Restart caller test log

Source: Restart caller test log

ok - T1 persist is a gate, and asks for open records and task status only
ok - T2 the mate persists before anything is stopped
ok - T2b an arrived persist answer is resolved before timeout
ok - T2c a reply between the preliminary scan and timeout decision wins
ok - T3 a runtime that cannot prove a restart falls back to the re-read message
ok - T4 every named mate is accounted for, including one this home does not know
ok - T5 a refused restart leaves the mate running and reports an unknown outcome
ok - T8 a local restart re-resolves this home's pin and reports the runtime that came up
ok - native Ultra survives local restart and the remote restart transport
ok - T6 a remote mate restarts through the host-local control plane over the fm-on hop
ok - T7 an unreachable host is reported honestly instead of claimed as reloaded
ok - T9 the persist gate retains its explicitly allocated correlation
ok - T10 pending persist answers are polled as one fleet
ok - T11 post-stop restart failure is never misreported as a nudge
ok - T12 relaunch waits do not block fleet persistence polling
ok - T13 a dead restart worker cannot hang the parent
ok - T14 a result published during reaping is honored
ok - T15 an already-current live mate is named by the update pass and genuinely restarted
ok - T16 an already-current mate with an unprovable runtime keeps the honest nudge path
# all fm-secondmate-restart tests passed
Evidence: Remote lifecycle e2e log (passed, including the liveness auto-relaunch)

Source: Remote lifecycle e2e log (passed, including the liveness auto-relaunch)

ok - overlapping remote home provisioning serializes through publication and rollback
ok - remote seed rollback preserves serialized competing routes
ok - unknown readiness preserves its route and brief for reconciliation
ok - remote seeding checks, repairs, and re-checks readiness, then stops on a remaining gap
ok - remote seeding proceeds once the repair closes every gap
ok - remote seeding provisions a supplied origin without touching the primary project tree
ok - remote provisioning re-validates a supplied origin at the receiving host
ok - seeding carries bitbucket, self-hosted, and scp-like origins through to the remote clone
ok - remote seed registers the route and provisions the whole home and project clone on that host
ok - remote inheritance rejects incomplete and superseded payload generations
ok - mixed local and remote routes validate without migration
ok - remote spawn launches on the remote-local backend and records a host-qualified route
ok - legacy and mismatched remote endpoints fail closed before backend access
ok - non-herdr remote endpoints are refused without changing either route
ok - remote spawn serializes inheritance through launch publication
cannot retire terminal source; it remains registered: remote-reply-ios
ok - marked send and routed reply complete through the existing parent correlation owner
cannot retire terminal source; it remains registered: remote-reply-ios
ok - partial remote inheritance retains reread intent through bootstrap convergence
ok - config push and bootstrap serialize remote inheritance convergence
cannot retire terminal source; it remains registered: remote-reply-ios
ok - remote inherited config retains and retries a failed live reread nudge
cannot retire terminal source; it remains registered: remote-reply-ios
cannot retire terminal source; it remains registered: remote-reply-ios
cannot retire terminal source; it remains registered: remote-reply-ios
ok - fleet snapshot projects mixed local and remote structured state
ok - remote update imports and fast-forwards the persistent home on its configured host
ok - the remote restart verb delegates to the host-local control plane and refuses before stopping anything
ok - startup repairs remote readiness before probing without relaunching
ok - watch liveness: a dead remote secondmate is auto-relaunched on its own host with one wake
ok - watch liveness: an unreachable remote secondmate is probed, preserved, and never failed over
ok - the host-local state read steps around a stale shadowing herdr client
ok - startup reports alive legacy backends without changing their routes
ok - unreachable no-ledger remote state remains explicit with no local respawn or failover
cannot retire terminal source; it remains registered: remote-reply-ios
ok - remote retirement refuses child work, then removes only its own endpoint while a shared-session sibling survives
ALL TESTS PASSED
- Outcome: ⚠️ 2 issues (1 warning, 1 info) across 1 run (13m54s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-remote-secondmate-relaunch.sh:76 - After a successful relaunch the wrapper refreshes only harness=, model= and effort= in the parent record. The route block it already parses also carries target= (and traceparent=), but the parent's remote_target= is left as it was at launch. bin/fm-fleet-snapshot.sh:770 reads remote_target to show a remote mate's endpoint. If the host-local fm-control relaunch opens a new Herdr pane, the snapshot keeps showing the pre-relaunch pane. This is pre-existing and outside the stated intent (which names only harness, model and effort), so no change is required here. Note that docs/remote-secondmates.md:247 says the wrapper republishes the route metadata 'the same way launch already records a fresh route', which slightly overstates what it refreshes.
⚠️ **Test** - 2 issues (1 warning, 1 info)
  • ℹ️ Nothing here ran against a real remote host. A real remote leg needs a second SSH host running the Firstmate remote job worker, and the host-side Herdr session is always named fm-remote, which the runbook does not allow outside fm-lab-* lab sessions. All evidence uses a stubbed ssh or the repository's own SSH/Herdr fixtures.
  • ⚠️ live validation verdict: inconclusive (0 of 8 scenarios were driven live against the product); untested: Operator relaunches a remote mate onto a new harness/model/effort and the parent's state/<id>.meta then names the new runtime, Host resolves 'default' to a configured pin; parent records what the host confirmed, not what it asked for, Refused remote relaunch leaves the parent's record byte-identical, Record with pr= and pr_head= still passes fm_pr_metadata_identity_parse and the armed PR poll still validates after a remote relaunch, Existing caller bin/fm-secondmate-restart.sh restarts a remote mate through the wrapper, Startup/watch liveness auto-relaunches a dead remote mate and still works, A local mate given to the remote wrapper is refused with guidance to use fm-control.sh, Documented operator path in secondmate-provisioning and docs/remote-secondmates.md leads to a correct parent record
  • Live validation: ⚠️ inconclusive - 0 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator relaunches a remote mate onto a new harness/model/effort and the parent's state/<id>.meta then names the new runtime ⏸️ untested no Passed with ssh stubbed (demo-fix-e21b3e1.txt vs demo-base-31c47af.txt, tests/fm-remote-secondmate-relaunch.test.sh) but was not driven live. A real remote leg needs a second SSH host running the Firs…
Host resolves 'default' to a configured pin; parent records what the host confirmed, not what it asked for ⏸️ untested no The prior payload did not establish a live result: only stubbed runs passed (demo-fix-e21b3e1.txt, regression test). A live run needs a real remote secondmate host.
Refused remote relaunch leaves the parent's record byte-identical ⏸️ untested no The prior payload did not establish a live result: only a stubbed refusal passed. A genuine refusal needs a real remote secondmate host.
Record with pr= and pr_head= still passes fm_pr_metadata_identity_parse and the armed PR poll still validates after a remote relaunch ⏸️ untested no The prior payload did not establish a live result: the parent-side rewrite and parse ran on real files, but the relaunch came from a stub because there is no real remote host.
Existing caller bin/fm-secondmate-restart.sh restarts a remote mate through the wrapper ⏸️ untested no The prior payload did not establish a live result: tests/fm-secondmate-restart.test.sh passed only over its SSH fixture (fm-secondmate-restart.log). A live run needs a real remote secondmate host.
Startup/watch liveness auto-relaunches a dead remote mate and still works ⏸️ untested no The prior payload did not establish a live result: the lifecycle e2e passed over the repository's fake SSH/Herdr fixtures only. A live run needs a real remote host, and the host-side Herdr session is…
A local mate given to the remote wrapper is refused with guidance to use fm-control.sh ⏸️ untested no The prior payload did not establish a live result: the wrapper CLI was run directly in the demo transcript, but not against a real fleet home.
Documented operator path in secondmate-provisioning and docs/remote-secondmates.md leads to a correct parent record ⏸️ untested no Docs cannot be driven live on their own, and the command they document needs a real remote secondmate host, which the prior payload did not have.
  • bash tests/fm-remote-secondmate-relaunch.test.sh (new regression test: confirmed, host-resolved, refused, local-refused, and armed-PR-poll cases)
  • bash tests/fm-secondmate-restart.test.sh (existing restart caller, now routed through the wrapper for remote mates)
  • bash tests/fm-remote-secondmate-lifecycle-e2e.test.sh (real fm-on, remote entrypoint, job worker and control scripts over the repository's SSH/Herdr fixtures; includes the startup and watch liveness auto-relaunch)
  • $E/demo.sh &lt;base worktree at 31c47af&gt;: operator transcript showing the documented fm-on relaunch path leaving the parent record stale (bug reproduced)
  • $E/demo.sh &lt;this worktree at e21b3e1&gt;: same transcript through bin/fm-remote-secondmate-relaunch.sh showing the record updated from the host's confirmation, PR poll still valid, refused relaunch leaving the record untouched, local mate refused
  • Manual check: a record with pr=, pr_head= and x_platform= passed through the wrapper, then fm_pr_metadata_identity_parse run on it before and after, plus file mode and no leftover temp files
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A host-local relaunch rewrote only the far endpoint, so this home kept the old harness, model, and effort, and appending those keys after pr= broke pull-request poll authentication.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Verdict: Diff reviewed (bin/fm-remote-secondmate-relaunch.sh wrapper + route block model/effort + restart caller). Author body Fixes #5332 verified against ready-for-pr #5332 (parent state/<id>.meta stayed on old harness/model/effort after documented remote relaunch). contract-class: restore — local relaunch already rewrites parent metadata; remote relaunch path was the broken twin; no new default-on surface.

VISION: (1) One interface — aligns (record honesty). (2) Authority explicit — aligns (no new grant). (3) Scripts/agents — aligns (deterministic metadata rewrite). (4) Restart non-event — aligns (parent record matches host). (5) Delegation spine — aligns. (6) Fleet outlives vendor — aligns (Herdr/SSH fixtures unchanged). (7) Scope — aligns (bin/docs/tests only). Aligns overall.

Attestation: MATCH e21b3e17bdec8d25c61a05011c6475565e690831. workflow-zero: yes. CI: in_progress CI 36066463973; NM SUCCESS 36066464041. Waiting on: CI green.

@tiago-peixoto

Copy link
Copy Markdown
Contributor Author

Friendly nudge: head e21b3e17 is mergeable against current main and all CI checks pass. Happy to adjust anything if needed.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Verdict: Re-reviewed after author nudge (2026-09-26). Diff is the parent-side wrapper + route-block model/effort + restart caller. Author body Fixes #5332 verified against ready-for-pr #5332 (documented fm-on relaunch left parent state/<id>.meta on the old harness/model/effort; local relaunch already rewrote). Tip vs main ef595d8d4536: wrapper absent on main; restart still calls host relaunch directly — still broken. contract-class: restore.

VISION (per rule):

  • One captain, one interface — aligns (record honesty after remote relaunch).
  • Authority is explicit — aligns (no new grant; documents the operator path).
  • Scripts own the mechanics — aligns (deterministic metadata rewrite under lock; keeps pr= last).
  • A restart is a non-event — aligns (parent record matches host-confirmed runtime).
  • Delegation with a spine — aligns.
  • The fleet outlives any vendor — aligns (Herdr/SSH fixtures unchanged).
  • Scope — aligns (bin/docs/tests only).

Aligns overall. Attestation MATCH. CI green / CLEAN. Auto-merging squash.

@kunchenguid
kunchenguid merged commit e789e52 into kunchenguid:main Sep 26, 2026
20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this.

zachlandes added a commit to zachlandes/firstmate that referenced this pull request Sep 26, 2026
…used two of them, and both are now fixed. 1. **fm-live-gate.test.sh (shard 7), caused by this PR.** Rule it broke: every guard in the live-harness family has to start with the shared `fm_live_gate`, so that `FM_LIVE=0` switches them all off together. The new `tests/fm-calm-branch-outcomes-live-e2e.test.sh` used its own on/off check and its own pi/tmux checks instead. I replaced those with `fm_live_gate opt-in FM_CALM_BRANCH_OUTCOMES_LIVE_E2E pi tmux`, which keeps the "refuse to pass having checked nothing" behaviour when the guard is asked to run. It was the only file in this diff with its own gate. `tests/fm-live-gate.test.sh` now passes: all 40 live guards skip together under `FM_LIVE=0`. 2. **fm-pi-branch-responsiveness-live-e2e.test.sh (shard 6), caused by this PR.** Rule it broke: any test that copies `fm-branch-supervision.ts` into a fixture must also copy every `./lib` file it imports. This PR added an import of `./lib/fm-calm-branch-outcomes.ts`, but the fixture didn't copy that file, so Pi couldn't load the extension and its TUI never drew. I checked every test that copies the extension. The same gap was in `tests/fm-pi-branch-live-e2e.test.sh`, which CI didn't catch because it only runs when asked, so I fixed both. `fm-pi-codex-native` loads the extension straight from the repo, so it needed no change. The responsiveness guard now passes locally against the real Pi 0.87.1: "ok - supervision outcome delivery keeps the real Pi 0.87.1 TUI echoing keystrokes at its unloaded floor". 3. **fm-remote-secondmate-relaunch.test.sh (shard 6), not caused by this PR.** It fails with "could not arm the PR poll fixture for the relaunch-ordering test". That part of the test was added upstream in e789e52 (kunchenguid#5583). It fails the same way when run on a clean export of the base commit ea7c7f7, with none of this branch's changes, and this PR touches nothing it uses. I made no change for it. While debugging number 3, a temporary `sed` edit I made emptied `bin/fm-pr-check.sh` in the worktree. I restored it with `git checkout`, and it is not part of the changes. Also checked: `shellcheck -x` is clean on the three changed test files, and `tests/fm-calm-branch-outcomes.test.sh` still passes
ashkonmousavi added a commit to ashkonmousavi/firstmate that referenced this pull request Sep 26, 2026
* fix(bin): report a Lavish source armed only after its listener is running (#5566)

* fix(bin): report a Lavish source armed only after its listener is running

Registration alone was treated as ready, so arm could succeed before anything was collecting from the board.

* no-mistakes(review): Guard Lavish arm launches, keep retire refusals, report live prior listener

* no-mistakes(review): Keep polling through window before reporting a still-live prior listener

* test: wait for a capture's claim to drop before the next arm

The result is stored before the runner exits, so a re-arm in that gap was meeting a live claim.

* no-mistakes(document): Record Lavish arm readiness evidence in verification doc

* no-mistakes(ci): Both failures were caused by this PR, and both are fixed with test-only edits. Lint 2 (ShellCheck SC2034): this branch removed the only use of `reply_id` (a `start "$reply_id"` call) from tests/fm-procevent.test.sh, which left the assignment at line 1450 unused. I deleted that assignment. It was the only `reply_id` in the file. ShellCheck is now clean on both test files. Behavior portable serial 4: the failing test was tests/fm-bearings-board.test.sh, in the check "registration consumed its answer before the any-origin binding existed". I reproduced it locally: the hold was still `state: queued` when the test checked it. - What must hold: the test's check that the hold is closed must run after the listener has captured the answer. - Why it broke: the test used a stand-in adapter that ran `fm-procevent.sh start` in the foreground after `arm`, so capture finished before build returned. On this branch, `arm` starts the listener itself in the background, so the real listener captures the answer and closes the hold a moment after build returns. - Fix: removed the now-redundant stand-in adapter, the copied runtime directory, and its extra environment variables. The test now runs the real build through the existing `run_board` helper and waits up to about 10s for the hold to reach `state: done`. The checks that follow are unchanged: `Resolution mode: answered` and the any-origin binding. - Other tests: this was the only test in the file that stood in for the adapter this way. The shard's other pure-contract-unit test (tests/fm-trace-context-lib.test.sh) passed unchanged. Verification: - tests/fm-bearings-board.test.sh passed 3 times in a row via bin/fm-test-run.sh, all 18 checks, about 53s per run. - tests/fm-procevent.test.sh was not rerun, because the lint fix only removed an unused assignment

* fix(bin): stop repeating unknown-wake escalations that were already delivered (#5599)

* fix(bin): acknowledge a delivered unknown-wake escalation

The same unrecognized wake was escalated again after it had already been handled, because delivery never recorded that identity.

* no-mistakes(review): Scope unknown-wake acknowledgements to one away session

* no-mistakes(review): Clear delivered digest when unknown-wake ack write fails

* no-mistakes(review): Limit unknown-wake suppression to acknowledged lines

* no-mistakes(document): List unknown-wake ack file among away-session artifacts

* fix(bin): keep a stated default-key retraction from cancelling a keyless wait (#5587)

* fix(bin): keep a stated default retraction from cancelling a keyless wait

A resolved line that names the shared default decision bucket was closing the keyless live wait that only prints as that same key. Keyless self-retraction still closes the keyless wait.

* no-mistakes(review): Keep declared waits standing past foreign-key resolved lines

* no-mistakes(review): Bound declared-wait read and share one decision-key parser

* no-mistakes(document): Document supervisors' key-aware declared-wait read

* fix(bin): terminate a remote job worker that lost ownership on TERM (#5544)

* fix(bin): terminate a remote job worker that lost ownership when it receives TERM

A serving worker whose lock directory is gone can no longer quarantine shutdown, and resuming service publishes a false ready heartbeat. Exit after stopping only that worker's own command tree, without removing a replacement owner's lock.

* no-mistakes(review): Check worker lock ownership before publishing shutdown quarantine

* no-mistakes(document): Correct worker shutdown comment on replacement-owned lock

* fix(bin): keep an ousted remote job worker off the replacement quarantine

Shutdown can lose the lock after the first ownership check and before it
writes or clears quarantine. Bind both operations to the directory object
this process still owns so a replacement's quarantine stays untouched.

* no-mistakes(review): Make ousted-worker shutdown test reliably reach quarantine clear

* no-mistakes(document): Reattach worker_shutdown doc comment to its function

* no-mistakes(ci): Fixed the failing check (Behavior portable serial 7) with a test-only change to the stall test in tests/fm-remote-job.test.sh. Product code is unchanged; no other test changed. Cause: after the decoy dies, both workers run the same check-exists, read, delete sequence on the job records. On the CI runner the replacement deleted a record between the ousted worker's check and its read. The ousted worker exited 125, and because the file runs under set -e the unguarded `wait` ended the test with 125. The exit trap then killed the replacement, which produced the "Killed" line. Reproduction: a temporary 0.3 s delay between the check and the read, applied to the ousted worker only, made the committed test fail exactly as in CI (exit 125 and the "Killed" line). The new test passed with the same delay. The delay is reverted, along with a similar debug hook that the timed-out attempt had left in bin/fm-remote-job-worker.sh. Test changes: - The replacement is frozen (and confirmed stopped) before the decoy is killed and resumed only after the ousted worker exits, so only one worker touches the job records at a time. - The ousted worker is stopped only once its quarantine exists and its lane is reaped, which places it inside its stop loop. - Every fixed poll loop is now a wait on a named condition with a 30 s deadline and an explicit failure message. Exit detection also handles zombies. - The exit trap kills and waits for the decoy and both workers on every path. - A non-zero exit from the ousted worker now fails with its exit code and stderr instead of silently ending the file. The test still proves that the resumed ousted worker exits 0 and leaves the replacement's lock, quarantine contents and quarantine inode unchanged. Verification: the full test file passed four times on its own and three times under nice -n 10 with four busy-loop CPU hogs; bin/fm-lint.sh passes. Changes are not committed

* no-mistakes(ci): I fixed the failing check (Behavior portable serial 7) by changing only the stall test in tests/fm-remote-job.test.sh. Product code is unchanged. **What failed:** "an ousted worker in shutdown leaves the replacement quarantine untouched" failed on CI with the ousted worker exiting 125 ("could not stop the active command tree"). **Why:** during shutdown, the worker retries the still-running decoy command group a fixed 100 times, 0.01 s apart, then gives up and exits 125. The test tried to freeze the worker partway through those retries by sending SIGSTOP from outside. On a slow runner the retries ran out before the stop arrived, so the worker had already given up. The invariant is that the test must hold the ousted worker inside that retry loop until the replacement owns the lock. That was the only place the test depended on timing. The other waits already watch for a named state change with a 30 s deadline. **Fix:** - The ousted worker now starts with a small `sleep` wrapper at the front of its PATH, and the SIGSTOP race is gone. - The wrapper only holds a `sleep` called directly by that worker's own process (it checks its parent pid against a hold file) while its quarantine file exists. - The only such `sleep` is the first retry in the shutdown stop loop, so the worker waits there as long as needed. - The wrapper writes a marker when it starts holding. The test waits for that marker, then hands the lock to the replacement, freezes the replacement, and kills the decoy. - The test releases the worker by deleting the hold file. Deleting the whole temp directory also releases it, so a failed run cannot leave the wrapper looping. - A process leak: the test overwrites the job's command-group record with the decoy, so no worker ever stopped the job's real command. `fm-hold-job.sh` and its `sleep 30` stayed running for up to 30 s after the test. The test now records that group before overwriting it and kills it at the end of the test and in the exit cleanup. - The test still asserts the same things: the ousted worker exits 0, and the replacement's lock, quarantine contents and quarantine inode are unchanged. **Verification:** - The full file passed twice on its own, twice under `nice -n 10` with six busy-loop CPU hogs, and twice more after the leak fix. - `pgrep` found no leftover processes afterwards. - With the worker from just before the fix commit (cf45cb6^), the test still fails with "the ousted worker wrote or cleared the replacement quarantine during shutdown", so it still proves the fix. - `bin/fm-lint.sh` passes. - I did not reproduce the CI failure locally. The cause comes from the fixed retry limit and the CI error message. The changes are not committed

* no-mistakes(ci): I changed only the stall test ("an ousted worker in shutdown leaves the replacement quarantine untouched") in tests/fm-remote-job.test.sh. Product code is unchanged, and so is every other test. **Invariant:** the pid written to the job's group record must be a process-group leader whose group dies when that one process is killed. Otherwise the worker's bounded stop loop never sees the group die, gives up, and exits 125 ("could not stop the active command tree") before it reaches the lost-ownership exit. The decoy is the only place in this test that depends on this. **Fix:** - The decoy used to be `set -m; sleep 30 &`. It now starts as `perl -MPOSIX=setsid -e 'setsid() >= 0 or exit 1; exec @ARGV' sleep 30 &`, which gets its own session and group without shell job control. tests/fm-procevent.test.sh already uses the same idiom. - The test now waits, with the file's usual 30 s deadline and a named failure, until `ps -o pgid=` of the decoy equals its pid before writing it into the group record. This way the worker can never read the record before `setsid` has run. - The existing steps are unchanged: the test kills the decoy, reaps it with `wait` before releasing the hold file, and the exit trap still kills and reaps the decoy and both workers. - The assertions are unchanged: the ousted worker exits 0, and the replacement's lock pid, quarantine text and quarantine inode stay the same. **Cleanup:** I reverted a debug `printf` hook that the timed-out previous attempt had left in bin/fm-remote-job-worker.sh, and deleted its untracked `.tmp-repro/` directory. Neither was committed. **Verification:** - The full tests/fm-remote-job.test.sh passed twice normally and once under `setsid -w` with stdin from /dev/null (no controlling terminal). - `bin/fm-lint.sh` passes. - No leftover `sleep 30` processes afterwards. **Not reproduced:** I could not reproduce the CI failure locally. On this host `set -m` made the decoy its own group leader even without a controlling terminal, so the cause on the runner is not confirmed. The change removes the test's reliance on shell job control, as the user asked. Changes are not committed

* no-mistakes(ci): I changed only the stall test ("an ousted worker in shutdown leaves the replacement quarantine untouched") in tests/fm-remote-job.test.sh. Product code is unchanged, and so is every other test. **Invariant:** the group record the ousted worker checks in its stop loop must stay the job's own command group, and the test must stop that group before it releases the hold. Otherwise the bounded retry keeps seeing a live group, gives up, and exits 125 ("could not stop the active command tree") before it reaches the lost-ownership exit. The test overwrote this record in one place (the decoy) and stopped the group in one place (killing the decoy); both are changed. **Fix:** - I removed the setsid decoy and the overwrite of `.claim/group`. The record keeps the job's real command group, which the test still saves as `STALL_JOB_GROUP`. - The two-line `group_start` stays. It is still needed: without it the worker kills the real group on its first pass, before the replacement takes over, so the hold would never matter. - The `sleep` wrapper that holds the worker at its first stop-loop retry is unchanged. - After the replacement owns the lock, its quarantine is planted and it is frozen, the test runs `kill -KILL -- -$STALL_JOB_GROUP`. It then waits, with the file's usual 30 s deadline and a named failure, until `kill -0` on the group fails. Only then does it remove the hold file. The worker therefore always sees its own command already stopped and never races its retry budget. - The exit trap still kills the saved command group if the test fails. It can't `wait` on that group because the group is not a child of the test shell. The decoy variable and its cleanup entry are gone. - The assertions are unchanged: the ousted worker exits 0, and the replacement's lock pid, quarantine text and quarantine inode stay the same. **Verification:** - The full tests/fm-remote-job.test.sh passed twice normally. - It passed once under `setsid -w` with stdin from /dev/null (no controlling terminal). - It passed once under `nice -n 10` with six busy-loop CPU hogs. - With the worker from before the fix (cf45cb6^), the test still fails with "the ousted worker wrote or cleared the replacement quarantine during shutdown", so it still proves the fix. - No `fm-hold-job` or `sleep 30` processes were left afterwards. - `bin/fm-lint.sh` passes. **Not reproduced:** I couldn't reproduce the CI failure locally; the decoy version also passed on this host. So I can't confirm why the decoy group stayed alive on the runner. The new wait turns any leftover live group into a clear named failure instead of an exit 125. The changes are not committed

* fix(bin): keep a dead command group dead on bash 5.2

A bare return inside the liveness check drops the failing kill status when the check runs in a conditional, so shutdown keeps treating a stopped group as alive and exits 125.

* no-mistakes(review): Use bash 3.2 fd syntax and fix trap return comments

* docs: make configuration settings easier to find and understand (#5589)

* docs: make configuration settings easier to find and understand

* no-mistakes(review): Restore dropped qualifiers and fix misplaced config doc labels

* no-mistakes(review): Restore three dropped qualifiers in configuration reference

* fix: limit project memory edits to factual corrections (#5636)

* fix: bound worker edits of project AGENTS.md/CLAUDE.md to factual corrections

These files are loaded into every agent session of a project, so additions
should be a deliberate human choice rather than automated task output. The
ship brief's project-memory section and AGENTS.md section 6 previously invited
workers to record durable knowledge, which let project AGENTS.md files accrete
detail the codebase or README already carries. Workers now edit only to fix
factually wrong content - including content their own change made wrong - and
fm-ensure-agents-md.sh runs only alongside such a correction. Stow no longer
routes project-memory additions through ship tasks, and the generated skeleton
no longer invites discovery-driven additions.

* no-mistakes(review): Stop running fm-ensure-agents-md.sh on memory-file corrections

* no-mistakes(document): Clarify manual project-memory initialization and remove duplicate guidance

* feat: permit gate lifecycle calls against disposable lab homes (#5635)

* fix(bin): let gate agents drive lifecycle against marked lab homes

Part 2 of the #5615 split. A no-mistakes gate agent runs inside a
checkout carrying the fleet-captain identity, so fm-gate-refuse-lib
refuses fleet mutation on the gate signal. That refusal was absolute,
which kept gate validation from ever exercising the real lifecycle.

Stamp a disposable lab FM_HOME with a .fm-lab-home marker file that
only bin/fm-lab-home.sh writes, and only onto a fresh empty dir, so
no call path can mark a populated real home. fm_refuse_if_gate_agent
then permits lifecycle only when FM_HOME carries the marker and is
driven through its stock layout - any FM_*_OVERRIDE relocation stays
refused so part of the "lab" cannot be split back onto the real fleet.
The threat model is a confused agent touching the real fleet, not
deliberate forgery, so the marker is a plain token file rather than a
bound record. FM_GATE_REFUSE_BYPASS is unchanged: it still serves the
test harness, which cannot mark hundreds of temp homes.

Teardown's slot-ownership scan compared state-dir paths textually
while fm_firstmate_root_home canonicalizes, so a lab home under a
symlinked TMPDIR scanned its own record twice and self-collided;
compare file identity (-ef) instead.

* no-mistakes(review): Refuse unlistable lab homes and hardlinked slot records

* no-mistakes(review): Mint lab markers only on verified-empty fresh dirs

* no-mistakes(document): Clarify lab-home gate documentation and comment contracts

* no-mistakes(document): Clarify lab-home gate documentation and remove stale claims

* no-mistakes(document): Clarify gate lab-home documentation and boundary wording

* fix(bin): evict a watcher whose beacon stalls past a hard bound instead of refusing every re-arm (#5594)

* fix(bin): replace a watcher whose beacon stalls past a hard bound instead of refusing every re-arm

A fleet watcher that is alive but whose liveness beacon has gone stale could
never be replaced: every re-arm was refused because the lock holder was a live
pid, and the holder was never evicted because it was not dead. Add
FM_WATCHER_STALL_BOUND (default 3x the stale grace): below it the refusal is
unchanged; at or past it the arm re-verifies the holder against the lock's
recorded identity, sends TERM, waits boundedly, and takes the lock the normal
way, ledgering a stalled-holder-replaced row. A holder that survives TERM keeps
the old refusal.

Fixes #4400

* no-mistakes(test): poll for replacement message to fix watcher-lock test flake

* no-mistakes(document): document FM_WATCHER_STALL_BOUND in config inventory

* fix(pi): hide queued Firstmate inputs under Calm only when the session can keep them (#5563)

* fix(pi): hide queued Firstmate notifications under Calm only when the session can keep them

Calm now keeps authenticated Firstmate operational inputs out of Pi's queued-message
listing, but only after proving the live session exposes every member needed to keep
them across Escape. A session missing any of them keeps stock rows and Escape and shows
one generic warning. Escape and the dequeue key return only captain-authored messages to
the editor and re-queue hidden notifications in order; after an abort that kept any in
Pi's agent queue, the adapter starts the delivery turn itself because Pi 0.87.1 does not
continue an aborted run. Compaction-held notifications stay with Pi's compaction flush and
never start or announce a turn.

Fixes #1588

* docs(calm): record Pi 0.87.1 queued-row retention verification

* no-mistakes(review): Deliver kept Calm notifications after tree-navigation aborts too

* no-mistakes(review): Defer Calm notification turn until tree navigation finishes

* no-mistakes(lint): Silence SC2016 for literal JavaScript in queue-retention e2e test

* fix(bin): refuse teardown when a required source disappears (#5548)

* fix(bin): refuse teardown when a required source disappears

A missing sibling was sourced after cleanup had started, so Bash 3.2
exited 0 from the EXIT trap and Bash 5 continued and reported success.

* no-mistakes(review): Remove unused FM_TEST_ONLY hook from teardown tests

* no-mistakes(review): Check task backend sources before any teardown cleanup

* test(gotmp): give teardown fixtures every tmux adapter sibling

Teardown now refuses when a sibling the recorded backend's adapter sources
is missing, so the fake bin must carry fm-session-lock-lib.sh,
fm-agent-process-lib.sh and fm-gemini-lib.sh.

* docs: make supervision-host easier to read (#5605)

Restructure the supervision host doc's prose into shorter sections, lists,
and tables without changing documented behavior. Every original heading,
anchor, identifier, number, quoted string, and link target is preserved.

* docs: make the Herdr backend guide easier to read (#5606)

* docs: make herdr-backend easier to read

Restructure the Herdr backend doc's prose into shorter sections, lists, numbered procedures, and tables without changing documented behavior. Every original heading, anchor, fenced code block, link target, and documented fact is kept.

* no-mistakes(document): Restore composer-proof reason and complete Herdr topic table

* docs: make pi-supervision-branch easier to read (#5607)

Restructure the prose into sections, lists, and tables without changing
documented behavior. Every original heading and anchor, inline-code span,
link target, number, and quoted string is kept, and each sentence sits on
its own line. Adds a topic navigation table and short subsections under
the existing headings.

* docs: make watcher-continuity easier to read (#5608)

* docs: make watcher-continuity easier to read

Restructure the prose into sections, lists, and tables without changing documented behavior. Every original heading, anchor, identifier, link target, and number is kept.

* no-mistakes(review): Fix actor and supervision-host scope in watcher-continuity doc

* no-mistakes(review): Make readiness TERM and retry conditional on unready successor

* docs: make sessionstart-nudge easier to read (#5609)

* docs: make sessionstart-nudge easier to read

Restructure the prose into sections, lists, and tables without changing documented behavior. Every original heading, inline-code span, link target, number, and fact is preserved, and a harness-to-tier table now sits near the top.

* no-mistakes(review): Drop helm glossary line and dedupe exit-code lead-in

* docs: make captain-hold-lifecycle easier to read (#5610)

* docs: make captain-hold-lifecycle easier to read

Restructure the captain-hold lifecycle prose into sections, lists, and tables without changing documented behavior. Every original heading, anchor, identifier, number, quoted string, and link target is kept.

* no-mistakes(review): Fix verification record subjects and grouping headings

* no-mistakes(review): Clarify task-body read-back cases belong to the suite

* docs: make remote-secondmates easier to read (#5612)

* docs: make remote-secondmates easier to read

Restructure the remote second mates prose into sections, lists, numbered procedures, and tables without changing documented behavior. Every original heading, anchor, fenced code block, identifier, link target, and qualifier is preserved.

* no-mistakes(review): Merge remote-home table cell into one sentence

* no-mistakes(review): Tighten readiness lead-in, restore causal link, fix dangling reference

* fix(bin): bound the away digest and log why a delivery failed (#5554)

* fix(bin): bound the away digest and log why a delivery failed

The away daemon joined every buffered escalation into one unbounded
digest. A start-up catch-all span can exceed what one transport argument
carries (tmux rejects the send-keys command; Linux refuses to exec any
argument above 131,071 bytes, which is how herdr receives it), so the
initial send failed on every housekeeping pass and was logged as an
unconfirmed Enter with text possibly in the composer.

escalate_flush now builds the injected digest under a fixed byte budget:
each event is cut at a UTF-8 boundary with an omitted-bytes marker, the
joined events stop with a "+K more event(s)" tail, and a bounded digest
names a state/.subsuper-digests/ file that keeps every buffered event
verbatim. The buffer itself is untouched, so the return catch-up stays
complete.

The tmux submit core and the herdr literal send now replay the
transport's stderr on failure, and inject_msg logs the failing stage
(initial send versus Enter confirmation) with the byte count and that
stderr. The wedge alarm line and marker carry the last failure reason.

Fixes #4382

* no-mistakes(review): Drop digest pruning; label send-failed as send-or-Enter stage

* no-mistakes(review): Keep digest full text once submit ran; reuse on retry

* no-mistakes(lint): Count digest files with find instead of ls

---------

Co-authored-by: firstmate-oss <[email protected]>

* test: add a gated harness seam and stabilize lifecycle fixtures (#5638)

* feat(tests): add FM_TEST_SEAM launch seam and gate lab-primary recipe

Part 1 of the #5615 split: the pieces that let the no-mistakes pipeline
live-validate firstmate changes, without the gate-refusal rescoping.

- bin/fm-afk-launch.sh: FM_TEST_HARNESS pins the detected harness only
  alongside the FM_TEST_SEAM=1 marker test suites set, so a leaked variable
  in a real primary's environment stays inert and unknown tokens fall
  through to real detection.
- tests/lib.sh: export FM_TEST_SEAM=1 for every suite.
- .no-mistakes.yaml: per-harness recipe for running a real fixture primary
  from a gate run - a plain mktemp lab FM_HOME on a private tmux socket,
  with FM_GATE_REFUSE_BYPASS=1 scoped to it and NO_MISTAKES_GATE scrubbed.
- tests/fm-wake-queue.test.sh: stop the owned watcher fixture with KILL and
  clear its lifecycle state so the next leg starts clean; TERM could leave
  bash waiting in a child on some runners.
- tests/fm-remote-secondmate-lifecycle-e2e.test.sh: wait for the liveness
  lock holder's post-acquire marker instead of the lock dir, which is
  published before the claim finishes.

* no-mistakes(review): Scrub lab home overrides and require FM_TEST_SEAM separately

* no-mistakes(document): Clarify test seam and disposable lab bypass documentation

* no-mistakes(document): Clarify lab isolation and test-seam documentation

* no-mistakes(ci): Fixed the CI failure: test cleanup killed the remote worker child but left its supervisor able to restart it during fixture removal. Cleanup now stops the worker tree. The lifecycle test passed locally; ShellCheck and diff checks passed

* fix(bin): refuse watchers from disposable checkouts and exit when the home is gone (#5552)

* fix(bin): refuse watchers from disposable checkouts and exit when the home is gone

Fixes #321
Fixes #4760

A watcher armed from a disposable no-mistakes validation checkout under
.no-mistakes/worktrees/ outlived the validation step and kept writing the
real home's state, and a running watcher never noticed when its home,
state directory, or code root disappeared. The arm now refuses from such
a checkout with the typed failure line, the watcher checks once per poll
that its home, state directory (or its own lock holder record), and bin
directory still exist and exits with a logged reason scoped to itself,
and the shared test helpers reap every watcher a suite armed for a
temporary home through the home-scoped stop.

* no-mistakes(lint): fix SC1007 by assigning empty string in watch-arm test

* no-mistakes(ci): Found and fixed a genuine, reproducible hang introduced by this branch's test-watcher reaper, which is what killed both CI checks (serial-2 cancelled at the 30-min cap; Lint 2 exit 143 = the suite's own TERM-trap code). Root cause: test_drain_asserts_watcher_liveness (tests/fm-wake-queue.test.sh) fabricates a .watch.lock whose pid is the test runner's own $$ with the runner's real identity, to make the drain believe a live watcher exists. The new make_case tracking registers that state dir for reaping, so at fm_test_cleanup the new fm_test_reap_watchers drives fm-watch-arm.sh --stop; its identity check matches (the fixture recorded the runner's identity) and it kill -TERMs the test runner. tests/lib.sh:231 is `trap 'fm_test_cleanup; exit 143' TERM`, so the TERM re-enters cleanup -> reap -> kills $$ again -> infinite loop until the runner cap. I reproduced this locally: the suite ran all tests then looped forever in cleanup spawning fm-watch-arm.sh --stop against a lock naming its own PID. Fix (tests/lib.sh, +5 lines): in fm_test_reap_watchers, skip any tracked lock whose pid equals our own $$ before driving --stop. This is the single shared reap boundary; seven $$-self-lock fixtures across four test files are all covered by the one guard, and real armed watchers (pid != $$) are still reaped. Invariant: the test reaper must only signal real armed watcher processes, never the test runner itself. Verified locally: tests/fm-wake-queue.test.sh -> EXIT 0 (63 ok, no hang); tests/fm-watch-arm.test.sh -> EXIT 0 (21 ok, including test_reaper_stops_a_tracked_watcher, confirming the guard does not over-skip). Lint 2's exit 143 was the same shard/cap signature; a fresh CI run on this new commit will re-evaluate it

---------

Co-authored-by: firstmate-oss <[email protected]>

* fix(bin): surface unrecognized status prefixes instead of reading them as silence (#5588)

* fix(bin): surface an unrecognized status prefix instead of dropping it

A parked or holding declaration, and a verb whose correlation token did not parse, never became an event, so the supervisor still saw the earlier line.

* no-mistakes(review): Require verb-shaped unrecognized status prefixes, add continuation tests

* no-mistakes(document): Document unrecognized status prefix escalation in afk skill

* no-mistakes(ci): I reproduced the "Behavior portable serial 6" failure locally and fixed it by changing the test data in one test. No product code changed. **What failed:** `tests/fm-session-start.test.sh`, in `test_orphan_status_logs_are_printed`, with "matched status log was printed 2 times". **Why:** the test writes status lines with made-up prefixes, `matched: surfaced once` and `orphan: step N`. The test only uses them as placeholder text. It checks that the session-start digest prints each task's status tail exactly once. This PR (#4763) deliberately makes an unrecognized one-word lowercase prefix a status event. So those lines now surface as captain-relevant events, and the wake queue's STATUS OUTCOME BACKSTOP section prints them a second time. The code under review is behaving as the issue asks. Only the test's placeholder data had become meaningful. **Rule the test depends on:** its status lines must not be captain-relevant, so the digest is the only place they are printed. Both lines in this test broke that rule. The orphan line would have failed the same count check right after the matched line did. **Fix:** in that test only, I switched both lines to the recognized, non-captain verb `working:`: `working: surfaced once` and `working: orphan step 1..6`. I updated the matching assertions and counts to use the new text. What the test checks is unchanged: orphan logs are labelled, the tail is bounded, the log path is printed, and each tail appears once. **Verification:** before the fix, the test failed locally the same way as in CI. After it, `bash tests/fm-session-start.test.sh` reports "all assertions passed

* no-mistakes(review): Detect unrecognized prefixes on unstamped lines; share verb list

---------

Co-authored-by: Kun's firstmate <[email protected]>

* fix(bin): report the failing item when remote inheritance fails (#5658)

Fixes #5295

Session start now reports a remote inheritance failure using the
push's own error line instead of the first unchanged item that
happened to print before it, and the shared captain preferences
header check now names the first required phrase it did not find,
on both the local and remote inheritance paths.

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads (#5657)

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads

pi-code loads the tracked Claude settings but has no asyncRewake, so it
awaits every Stop hook; without a stand-down the auto-arm runs
synchronously inside Pi's turn end and holds it open for the declared
multi-hour timeout. Stand down when the payload's transcript_path
contains a /.pi/ path component, the same discriminator the closed-but-
unmerged fix in #3352 used, with an explicit string-type check on the
jq filter.

Fixes #3343

* no-mistakes(document): document pi-code stand-down in harness integrations reference

* fix(bin): match whole multi-word project names in the registry lookup (#5659)

* fix(bin): match whole multi-word project names in the registry lookup

bin/fm-project-mode.sh matched a registered project name against only the
first whitespace-delimited token of a registry row, so a name containing a
space never matched, silently defaulting the project to no-mistakes off
instead of its declared posture.

The lookup now matches the whole registered name against the raw line text,
so a name is compared literally (never as a regex) and a name that is a
leading prefix of another registered name still resolves to its own row.

* no-mistakes(document): docs already accurate for multiword registry name match

* chore: drop accidental empty err file

Co-authored-by: Kun Chen <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Kun Chen <[email protected]>

* fix(bin): classify shell stdin payloads after -s operands (#5546)

* fix(bin): classify the stdin program of `bash -s` with operands in the arm policy

With -s, sh/bash/zsh read the program from stdin even when operands follow;
the operands are only positional parameters. The arm policy treated the first
operand as a script path, so heredoc and here-string payloads were never
classified and a hidden bin/fm-watch.sh execution was allowed.

A protected path in the operand position still fails closed as before.

Fixes #1489

* no-mistakes(document): Clarify stdin shell operand documentation

*