Skip to content

feat(bin): let firstmate restart itself onto another Claude seat - #18

Merged
max-metaplanet merged 6 commits into
mainfrom
fm/lead-seat-restart
Oct 1, 2026
Merged

max-metaplanet merged 6 commits into
mainfrom
fm/lead-seat-restart

Conversation

@max-metaplanet

Copy link
Copy Markdown
Owner

Intent

Extend Claude seat auto-switching so the primary firstmate itself can move to another seat, not just the new workers it launches.

The design: firstmate tells its crew it is about to restart, starts another claude process on the new seat that becomes the firstmate, then ends the current process - a "kill and resurrect" bootstrap.
Seats are profile directories under the seats root whose contents symlink the shared ~/.claude files, so any seat can resume the same session: the seat is the brain, the sessions and settings are the body.
Crew already launch as CLAUDE_CONFIG_DIR= ... claude.

What Changed

  • Added bin/fm-lead-restart.sh and a bin/fm-seat.sh lead-restart [--to <seat>] [--check] [--persisted] [--launch-command <cmd>] command that moves the primary firstmate to another seat by replacing its process. It checks that the lead is a Claude session and that the destination is signed in. It also works out the session id, pane, and launch command, refusing if any of them can't be established. It sends each live worker a fire-and-forget notice, starts a new claude on the new seat in the same terminal that resumes the same session, and then ends the old process. The watcher process is left running. Without --persisted, the command refuses. The outcome and any recovery command are written to state/.lead-restart.result.
  • bin/fm-lock.sh now records the lock owner's Claude profile and pane in state/.lock-runtime. It also adds handover and handover-clear verbs: a handover is a time-limited reservation in state/.lock-handover that only the outgoing session or the named successor (proven by a nonce) can use, so no third session can take the home during the swap. The logic for these records lives in the new helpers in bin/fm-session-lock-lib.sh. bin/fm-lock.sh status shows both the reservation and the lead's profile. Supporting changes: tmux can now check agent state by pane id (%N), fm-send.sh --fire-and-forget now accepts crewmate and scout tasks, and the persist-open-work contract moved into bin/fm-persist-request-lib.sh, where secondmate restarts also use it.
  • fm-seat.sh status now shows which seat firstmate itself is running on. fm-seat.sh auto now also checks the threshold against firstmate's own seat, runs a --check preflight, and emits one claude-seat: firstmate itself … instruction (or a line naming what blocks the move). A new claude-seat-lead-restart skill, updates to AGENTS.md, docs/claude-seats.md and related docs, shared test fixtures, and tests/fm-lead-restart.test.sh cover all of this.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The fix round addresses F1–F5 correctly: printed agent state is compared, the pane gate is added, blocked lead records are recorded, the lock-record successor check is in place, and the fire-and-forget crew notice has behavioral tests. What remains is minor, but the change kills and replaces the live lead process in the captain's terminal, so it still warrants care.

Testing

I ran the change's targeted suite, tests/fm-lead-restart.test.sh: all 18 tests pass, including the full swap and the stranded outcome in a real tmux on a private socket. I then drove the swap twice by hand in a real Herdr lab session (fm-lab-*, created and torn down through bin/fm-herdr-lab.sh), using a claude-named stand-in lead in a real pane. Each time the result was state=done. The lock moved to a new pid on the beta profile in the same pane (fm-lab-…:w1:p1), resuming lead-session-1. The old pid was gone, the reservation was cleared, and one lead was left running. In the second run the live crew member got the fire-and-forget notice before the swap, and the unreachable crew member was named in the result without blocking it. The pane screen captures show the old lead end and . .lead-restart.launch bring up the successor on seat beta in that same pane. The refusal cases and the automatic trigger passed in the test suite, but only with a faked quota probe and pane probe, so they are not counted as live results. No UI surface is involved; the evidence is CLI and pane transcripts. Only a real signed-in claude --resume was not exercised, because no credential was used.

  • Live validation: ✅ go - 5 of 8 scenarios driven live against the product
Scenario Result Live Evidence
On Herdr, the lead restarts onto seat beta in its own pane, resuming the same session, and the result says done ✅ pass live herdr-lab-lead-restart.transcript.txt and herdr-lab-lead-restart-with-crew.transcript.txt: state=done; lock moved from the old pid to a new pid; .lock-runtime profile=seats/beta, same target w1:p1; su…
On tmux, the lead is replaced in its own pane on the new seat with one lock holder throughout, and the supervision watcher keeps running ✅ pass live tests/fm-lead-restart.test.sh test_the_lead_is_replaced_in_its_own_terminal_with_supervision_unbroken (real tmux on a private socket with real processes)
The crew is told before the swap: each live direct report gets a fire-and-forget notice, and an unreachable one is named in the result without blocking the restart ✅ pass live Herdr run 2: crew1.inbox/001.msg has delivery=fire-and-forget and the restart text; result detail names crew2 as undelivered and still reads state=done. Tmux test: crew_notices=1 was already present w…
--check reports the lead's seat, the destination, the session, the terminal and the replacement command without touching anything ✅ pass live Herdr transcript '--- check:' section; tests/fm-lead-restart.test.sh test_check_establishes_every_part_of_the_move
Adversarial: a replacement that exits at once is reported stranded, not running, and the home is not left reserved ✅ pass live tests/fm-lead-restart.test.sh test_a_replacement_that_never_comes_up_is_reported_stranded (real tmux)
Adversarial: a missing persist gate, an unproven destination login, an unestablished pane or profile, a stale runtime record, a non-holder caller, or an ambiguous argv is refused and leaves the old le… ⏸️ untested no The prior payload did not establish a live result: these refusals ran only in tests/fm-lead-restart.test.sh layer 1 with a faked login probe and a stubbed pane probe, not against a live terminal. To c…
The automatic trigger hands the lead a move once per seat crossing, and a transient blocker does not use up that crossing ⏸️ untested no The prior payload did not establish a live result: this ran only through bin/fm-seat.sh with a fake quota-axi. A real quota threshold crossing needs a real signed-in Claude account on a seat profile.
A real signed-in claude --resume &lt;id&gt; on the new seat comes back as the same session ⏸️ untested no Needs a real signed-in Claude credential on two seat profiles; the validation deliberately never touches production credentials. An operator can confirm it by running `bin/fm-seat.sh lead-restart --to…
Evidence: fm-lead-restart test suite output (includes the real-tmux swap and stranded tests)

Source: fm-lead-restart test suite output (includes the real-tmux swap and stranded tests)

ok - a check establishes the lead's seat, its destination, its session, and the replacement command
ok - without the persist gate nothing is armed and the lead keeps running
ok - a destination that is not proven signed in is refused, undecided included
ok - an unestablished terminal or lead account refuses instead of guessing one
ok - a runtime record that does not name the current lock owner is no evidence
ok - the ambient default profile and the seat the lead already holds are both refused
ok - a session that does not hold this home cannot replace its lead
ok - a launch command is established only when it provably round-trips, and composition leaves exactly one resume
ok - a reservation refuses every session but the one it names, and the successor clears it
ok - a reservation that lapsed holds nothing, so a failed handover cannot wedge a home
ok - the outgoing session still confirms its lock and does not drop its own reservation
ok - only the session holding this home's lock may reserve it for a successor
ok - the detached stage drops the reservation it armed with the nonce it holds, and nothing else can
ok - the lead's own crossing hands over a binding move once per seat, with the persist gate and the exact command
ok - a crossing the lead cannot act on names the blocker instead of offering a restart
ok - a crossing that was blocked hands over the move as soon as it becomes available
ok - the lead is replaced in its own terminal, on the new seat, resuming the same session, with one holder throughout
ok - a replacement that exits at once is reported stranded, not running
# all fm-lead-restart tests passed
Evidence: Herdr lab transcript: lead restart alpha→beta, unreachable crew named in result

Source: Herdr lab transcript: lead restart alpha→beta, unreachable crew named in result

lab session: fm-lab-leadrestart-49646-2615  lab dir: /tmp/fmlr/lab.A47R
lead pane: w1:p1
--- before: lock pid=51969
pid=51969
profile=/tmp/fmlr/lab.A47R/seats/alpha
backend=herdr
target=fm-lab-leadrestart-49646-2615:w1:p1
--- herdr agent get for lead pane:
{"id":"cli:agent:get","result":{"agent":{"agent":"claude","agent_status":"unknown","cwd":"/private/tmp/fmlr/lab.A47R","focused":true,"foreground_cwd":"/private/tmp/fmlr/lab.A47R","pane_id":"w1:p1","revision":0,"state_change_seq":0,"tab_id":"w1:t1","terminal_id":"term_65cb9343858ad1","workspace_id":"w1"},"type":"agent_info"}}
--- check:
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.A47R/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-49646-2615:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.A47R/seats/beta /tmp/fmlr/lab.A47R/hb/claude /tmp/fmlr/lab.A47R/lead.sh --resume lead-session-1
[rc=0]
--- restart:
handover armed (worker 57107)
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.A47R/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-49646-2615:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.A47R/seats/beta /tmp/fmlr/lab.A47R/hb/claude /tmp/fmlr/lab.A47R/lead.sh --resume lead-session-1
this session ends in 2s; the replacement starts in the same terminal on seat beta
[rc=0]
--- result:
state=done
at=1790800394
detail=the firstmate session moved to Claude seat beta in the same terminal, resuming the same session; the restart notice could not be delivered to: crew1
command=CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.A47R/seats/beta /tmp/fmlr/lab.A47R/hb/claude /tmp/fmlr/lab.A47R/lead.sh --resume lead-session-1
launch_file=/tmp/fmlr/lab.A47R/home/state/.lead-restart.launch
--- after: lock pid=59824 (old 51969 alive? no)
pid=59824
profile=/tmp/fmlr/lab.A47R/seats/beta
backend=herdr
target=fm-lab-leadrestart-49646-2615:w1:p1
--- successor argv:
/tmp/fmlr/lab.A47R/hb/claude /tmp/fmlr/lab.A47R/lead.sh --resume lead-session-1
--- lead.log:
lead pid=51969 session=lead-session-1 profile=/tmp/fmlr/lab.A47R/seats/alpha argv=
lead pid=59824 session=lead-session-1 profile=/tmp/fmlr/lab.A47R/seats/beta argv=
--- reservation present? no
--- crew1 inbox:
ls: /tmp/fmlr/lab.A47R/home/state/crew1.inbox: No such file or directory
--- running stand-in leads:
59824 /tmp/fmlr/lab.A47R/hb/claude /tmp/fmlr/lab.A47R/lead.sh --resume lead-session-1
--- pane screen:
teardown rc=0
Evidence: Herdr lab transcript with live crew pane: notice delivered fire-and-forget, pane screen showing same-pane replacement

Source: Herdr lab transcript with live crew pane: notice delivered fire-and-forget, pane screen showing same-pane replacement

lab session: fm-lab-leadrestart-68393-4240  lab dir: /tmp/fmlr/lab.Sqrw
lead pane: w1:p1
--- before: lock pid=69804
pid=69804
profile=/tmp/fmlr/lab.Sqrw/seats/alpha
backend=herdr
target=fm-lab-leadrestart-68393-4240:w1:p1
--- herdr agent get for lead pane:
{"id":"cli:agent:get","result":{"agent":{"agent":"claude","agent_status":"unknown","cwd":"/private/tmp/fmlr/lab.Sqrw","focused":true,"foreground_cwd":"/private/tmp/fmlr/lab.Sqrw","pane_id":"w1:p1","revision":0,"state_change_seq":0,"tab_id":"w1:t1","terminal_id":"term_65cb936a456c31","workspace_id":"w1"},"type":"agent_info"}}
--- crew1 pane w2:p1 agent:
{"id":"cli:agent:get","result":{"agent":{"agent":"claude","agent_status":"unknown","cwd":"/private/tmp/fmlr/lab.Sqrw","focused":false,"foreground_cwd":"/private/tmp/fmlr/lab.Sqrw","pane_id":"w2:p1","revision":0,"state_change_seq":0,"tab_id":"w2:t1","terminal_id":"term_65cb936c6e3cc2","workspace_id":"w2"},"type":"agent_info"}}
--- check:
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.Sqrw/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-68393-4240:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.Sqrw/seats/beta /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/lead.sh --resume lead-session-1
[rc=0]
--- restart:
handover armed (worker 78300)
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.Sqrw/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-68393-4240:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.Sqrw/seats/beta /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/lead.sh --resume lead-session-1
this session ends in 2s; the replacement starts in the same terminal on seat beta
[rc=0]
--- result:
state=done
at=1790800442
detail=the firstmate session moved to Claude seat beta in the same terminal, resuming the same session; the restart notice could not be delivered to: crew2
command=CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.Sqrw/seats/beta /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/lead.sh --resume lead-session-1
launch_file=/tmp/fmlr/lab.Sqrw/home/state/.lead-restart.launch
--- after: lock pid=83131 (old 69804 alive? no)
pid=83131
profile=/tmp/fmlr/lab.Sqrw/seats/beta
backend=herdr
target=fm-lab-leadrestart-68393-4240:w1:p1
--- successor argv:
/tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/lead.sh --resume lead-session-1
--- lead.log:
lead pid=69804 session=lead-session-1 profile=/tmp/fmlr/lab.Sqrw/seats/alpha argv=
lead pid=83131 session=lead-session-1 profile=/tmp/fmlr/lab.Sqrw/seats/beta argv=
--- reservation present? no
--- crew1 pane screen:
'/tmp/fmlr/lab.Sqrw/hb/claude' -c 'echo STAND-IN CREW1 WORKER; while :; do sleep 1; done'

tmp/fmlr/lab.Sqrw
> '/tmp/fmlr/lab.Sqrw/hb/claude' -c 'echo STAND-IN CREW1 WORKER; while :; do sleep 1; done'
STAND-IN CREW1 WORKER

--- crew1 inbox:
001.msg
handled
schema=fm-task-inbox.v1
at=2026-09-30T20:33:50Z
delivery=fire-and-forget
--
The lead first mate is restarting onto another Claude seat (beta). Your own work, seat, and steering inbox are unaffected: carry on, and do not reply to this notice.--- running stand-in leads:
83131 /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/lead.sh --resume lead-session-1
--- pane screen:
export PATH='/tmp/fmlr/lab.Sqrw/fakebin':$PATH; CLAUDE_CONFIG_DIR='/tmp/fmlr/lab.Sqrw/seats/alpha' '/tmp/fmlr/lab.Sqrw/
hb/claude' '/tmp/fmlr/lab.Sqrw/lead.sh'

tmp/fmlr/lab.Sqrw
> export PATH='/tmp/fmlr/lab.Sqrw/fakebin':$PATH; CLAUDE_CONFIG_DIR='/tmp/fmlr/lab.Sqrw/seats/alpha' '/tmp/fmlr/lab.Sqr
w/hb/claude' '/tmp/fmlr/lab.Sqrw/lead.sh'
STAND-IN FIRSTMATE pid=69804 session=lead-session-1 seat=alpha
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.Sqrw/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-68393-4240:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.Sqrw/seats/beta /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/le
ad.sh --resume lead-session-1
[rc=0]
handover armed (worker 78300)
lead seat: alpha
destination seat: beta (/tmp/fmlr/lab.Sqrw/seats/beta)
session resumed: lead-session-1
terminal: herdr fm-lab-leadrestart-68393-4240:w1:p1
replacement command: CLAUDE_CONFIG_DIR=/tmp/fmlr/lab.Sqrw/seats/beta /tmp/fmlr/lab.Sqrw/hb/claude /tmp/fmlr/lab.Sqrw/le
ad.sh --resume lead-session-1
this session ends in 2s; the replacement starts in the same terminal on seat beta
[rc=0]
zsh: terminated  CLAUDE_CONFIG_DIR='/tmp/fmlr/lab.Sqrw/seats/alpha'

tmp/fmlr/lab.Sqrw took 17s
> . /tmp/fmlr/lab.Sqrw/home/state/.lead-restart.launch
STAND-IN FIRSTMATE pid=83131 session=lead-session-1 seat=beta
teardown rc=0
Evidence: Herdr result record
state=done
detail=the firstmate session moved to Claude seat beta in the same terminal, resuming the same session; the restart notice could not be delivered to: crew2
lock-runtime after: profile=.../seats/beta backend=herdr target=fm-lab-leadrestart-68393-4240:w1:p1
successor argv: .../claude .../lead.sh --resume lead-session-1

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • 🚨 bin/fm-lead-restart.sh:489 - The handover stage calls fm_backend_agent_alive as if its exit status meant "alive". It doesn't: bin/fm-backend.sh:991 prints alive/dead/unknown and always returns 0, and every other caller (fm-watch.sh, fm-spawn.sh, fm-fleet-snapshot.sh) reads what it prints. So fm_backend_agent_alive ... &amp;&amp; break passes on the first iteration, and the if ! fm_backend_agent_alive stranded branch at line 493 can never run. Failure path: the old lead is killed and . launch is typed into the pane, but the successor exits right away (bad flag, auth error, pane closed with the process). The stage skips the start check, waits up to CLAIM_WAIT with the reservation live, then writes state=started ("the replacement is running on seat X") and queues no wake. The captain's terminal is left with no firstmate and the result record says it is running. Fix: compare the printed value, e.g. [ &#34;$(fm_backend_agent_alive &#34;$backend&#34; &#34;$target&#34;)&#34; = alive ], at both sites.
  • ⚠️ bin/fm-lead-restart.sh:477 - The stage only proves that the lock anchor pid died before it types . &lt;launch-file&gt; + Enter into the pane. It never checks that the pane went back to a shell. For a trusted Claude session the anchor is CLAUDE_PID, the model-loop process (fm_session_lock_anchor_pid). fm-session-lock-lib.sh itself says this can be a transient helper under a shared daemon, separate from the front-end that owns the pane. If the TUI survives that kill, the launch line goes in as a prompt to the old claude. The (fixed) agent-alive check would then see the old agent and pass. The old session could then reclaim the lock by session id, which the reservation admits. The result would read started/done while firstmate is still on the old seat. Fix: after the kill loop, require the pane's agent state to read dead (a shell) before sending, and record refused/stranded otherwise. The launch argv read from that same pid has the same exposure.
  • ⚠️ bin/fm-seat.sh:847 - auto_lead_trigger records lead=<seat> before it knows whether the move is available. So a transient refusal suppresses the actionable instruction for the rest of that crossing. Example: on the first poll below threshold, the destination's login probe is undecided (quota-axi rate-limited or slow), so fm-lead-restart.sh --check refuses and a one-off "cannot move" line is printed. Every later poll sees reported == seat and returns silently, even once --check would pass. Firstmate then stays on the exhausted seat until it climbs back above the threshold. Fix: record the seat only when the "moves to ... now" instruction is emitted, or key the record on the outcome as well.
  • ⚠️ bin/fm-lead-restart.sh:21 - This contradicts the intent. The intent says: "The design: firstmate tells its crew it is about to restart, starts another claude process on the new seat that becomes the firstmate, then ends the current process". The change deliberately does the opposite: "WHAT DELIBERATELY DOES NOT HAPPEN. Running workers are not told anything and are not moved... a crew notification step would be a message that changes nothing". docs/claude-seats.md says the same ("Running workers are untouched and are told nothing"). The reasoning (durable inbox, logs, and watcher continuity) may be sound, but it drops a step the stated design includes. The user needs to confirm the crew notification can be left out.
  • ℹ️ bin/fm-lead-restart.sh:506 - The claim loop treats "the reservation is gone" as "the successor took the lock". A reservation that simply reached its deadline looks the same. The window is GRACE+EXIT_WAIT+START_WAIT+CLAIM_WAIT, but the stage can also spend up to 10s on the KILL wait plus per-iteration command time. If the exit and start waits run near their limits and the successor never claims, the reservation lapses inside the claim loop and the stage writes state=done. Checking the lock record directly (a live line-1 pid whose .lock-runtime profile equals to_profile) would make 'done' accurate.

🔧 Fix applied.
2 infos still open:

  • ℹ️ bin/fm-lead-restart.sh:528 - The new pane gate is meant to confirm the pane went back to a bare shell before anything is typed into it. It uses fm_backend_agent_alive, but that function prints 'dead' for both a shell pane and a pane that no longer exists (dead|missing) printf &#39;dead&#39; in bin/fm-backend.sh:993). Failure path: the lead was started as the pane's own command, so the pane closes when the process ends. The gate passes, and the stage types . launch at a target that is gone. With the usual %N target the send fails and the result reads stranded 'could not be delivered', which is honest but not the accurate reason. With a session:window target from FM_SUPERVISOR_TARGET, tmux may fall back to another window in that session. Fix: call fm_backend_agent_state and require exactly dead, and treat missing as its own stranded outcome.
  • ℹ️ bin/fm-lead-restart.sh:491 - notify_crew runs before the grace period and before the kill. If the old lead then refuses to exit (the 'refused' branch), the crew has already been told the lead is restarting onto another seat, and nothing corrects that. The notice says to carry on, so nothing breaks, but the crew now holds a false statement. The prescribed ordering ('before the swap') is followed; this is just a note.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 8 scenarios driven live against the product
Scenario Result Live Evidence
On Herdr, the lead restarts onto seat beta in its own pane, resuming the same session, and the result says done ✅ pass live herdr-lab-lead-restart.transcript.txt and herdr-lab-lead-restart-with-crew.transcript.txt: state=done; lock moved from the old pid to a new pid; .lock-runtime profile=seats/beta, same target w1:p1; su…
On tmux, the lead is replaced in its own pane on the new seat with one lock holder throughout, and the supervision watcher keeps running ✅ pass live tests/fm-lead-restart.test.sh test_the_lead_is_replaced_in_its_own_terminal_with_supervision_unbroken (real tmux on a private socket with real processes)
The crew is told before the swap: each live direct report gets a fire-and-forget notice, and an unreachable one is named in the result without blocking the restart ✅ pass live Herdr run 2: crew1.inbox/001.msg has delivery=fire-and-forget and the restart text; result detail names crew2 as undelivered and still reads state=done. Tmux test: crew_notices=1 was already present w…
--check reports the lead's seat, the destination, the session, the terminal and the replacement command without touching anything ✅ pass live Herdr transcript '--- check:' section; tests/fm-lead-restart.test.sh test_check_establishes_every_part_of_the_move
Adversarial: a replacement that exits at once is reported stranded, not running, and the home is not left reserved ✅ pass live tests/fm-lead-restart.test.sh test_a_replacement_that_never_comes_up_is_reported_stranded (real tmux)
Adversarial: a missing persist gate, an unproven destination login, an unestablished pane or profile, a stale runtime record, a non-holder caller, or an ambiguous argv is refused and leaves the old le… ⏸️ untested no The prior payload did not establish a live result: these refusals ran only in tests/fm-lead-restart.test.sh layer 1 with a faked login probe and a stubbed pane probe, not against a live terminal. To c…
The automatic trigger hands the lead a move once per seat crossing, and a transient blocker does not use up that crossing ⏸️ untested no The prior payload did not establish a live result: this ran only through bin/fm-seat.sh with a fake quota-axi. A real quota threshold crossing needs a real signed-in Claude account on a seat profile.
A real signed-in claude --resume &lt;id&gt; on the new seat comes back as the same session ⏸️ untested no Needs a real signed-in Claude credential on two seat profiles; the validation deliberately never touches production credentials. An operator can confirm it by running `bin/fm-seat.sh lead-restart --to…
  • bash tests/fm-lead-restart.test.sh (18 behavior tests, including the full swap and the stranded case in a real tmux on a private socket)
  • Manual Herdr lab run 1: bin/fm-herdr-lab.sh name/provision → stand-in claude lead in its own pane takes the lock through bin/fm-lock.sh → fm-seat.sh lead-restart --to beta --check → fm-seat.sh lead-restart --to beta --persisted → read .lead-restart.result, .lock, .lock-runtime, the successor's argv, the reservation, and the leads left running → fm-herdr-lab.sh teardown
  • Manual Herdr lab run 2: same flow plus a live crew1 worker pane (herdr meta) and a crew2 whose inbox cannot be written; checked crew1's inbox message (delivery=fire-and-forget), the result naming crew2, and a herdr pane read of the lead pane showing the old lead end and the successor start in the same pane
  • Checked after teardown: no leftover fm-lab-leadrestart session in herdr session list, no leftover lab processes, worktree clean
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

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

✅ **Push** - passed

✅ No issues found.

A seat switch moves only what the next spawn reads, so it has never moved
firstmate: the lead keeps the account its own process launched on while
config/claude-seat drifts away from it. No running Claude Code process can
change credential store, so the lead changes account only by being replaced.

bin/fm-seat.sh lead-restart does that, through bin/fm-lead-restart.sh: another
claude starts on the new seat in the same terminal, resuming the same session,
and the current process ends.

Verified rather than assumed, against the code:

- Running workers need nothing. Steering is a durable inbox, status is a
  durable log, and each task keeps the seat recorded in its own record, so a
  crew notification step would change nothing and none is added.
- The one real worker-facing effect is supervision, and it is handled by not
  touching it. The watcher is a separate process with its own singleton lock and
  is never in the kill, so it is orphaned rather than stopped and keeps its
  beacon; the successor's arm attaches to it instead of starting a second one.
  The cycle count goes one to one.

The guarded pieces:

- The persist gate is the one a second mate's restart already applies. The
  /stow open-record contract now has one owner, bin/fm-persist-request-lib.sh,
  which bin/fm-secondmate-restart-lib.sh composes its request from and the lead
  path states verbatim. The command refuses without --persisted.
- The lock is handed over through a bounded reservation in bin/fm-lock.sh
  (state/.lock-handover). It is armed while the outgoing lead still holds the
  lock, so there is no instant with two holders and none with the home open to a
  third session while line 1 names a dead pid. The outgoing session is admitted
  by its session id and keeps confirming its own lock; the successor is admitted
  by the nonce it is launched with, and that proof is what clears the
  reservation. A lapsed reservation means nothing, so a failed handover cannot
  wedge a home.
- The successor is relaunched in the same pane with every other flag preserved.
  The lead's own profile and pane are not derivable elsewhere, so the owning
  session records both in state/.lock-runtime bound to the lock's pid, and a
  record naming another pid is no evidence. The launch command is read from the
  running process and accepted only when it provably round-trips; a flattened
  argument vector where a multi-word argument is indistinguishable from two
  arguments refuses and names --launch-command.
- The armed threshold watch asks the same question about the lead's own seat and
  reports that crossing with the exact command rather than acting on it: the
  poll is a separate process and cannot write the lead's conversation down. It
  reports nothing unless the whole move passes preflight, so a crossing with no
  signed-in destination or no established terminal names that blocker instead.
- Claude primary only. Any other harness refuses by name.

What a failure leaves. Every check runs before anything is touched, so a refusal
leaves the previous session running and in charge. After the previous process has
ended there is no going back to it: the stage records the outcome in
state/.lead-restart.result, drops the reservation, and queues a wake. Recovery is
one command in that same terminal, printed in that record and staged as a file to
source, and nothing else is affected because only one process was ever replaced.

Not proven, and not claimed: that a real signed-in `claude --resume <id>` comes
back as that same session. Exercising it needs a credential this work
deliberately never touches. The stand-in reproduces the documented contract
instead - a resume keeps the session id, which is what --fork-session exists to
opt out of - and every other step is proven against real processes.

tests/fm-lead-restart.test.sh drives the real scripts: the establishment
refusals and the reservation against real claude-named processes, and the whole
swap in a real tmux on a private socket, where one lead before and one lead
after must be in the same pane, on the new profile, resuming the same session,
with a cycle started inside the outgoing lead's tree still alive afterwards.
The lead restart and the seat command both need the seat NAME a profile
directory belongs to, which is the inverse of fm_seat_config_dir and belongs
beside it rather than in two copies.
…ies out

The watch reported the lead's seat crossing and left the move to be asked for.
That is report-only: the captain set the threshold, so the threshold firing is
the instruction, and firstmate acts on it like any other actionable check result.

The watch still hands the move over rather than performing it, and that is about
which process can do it, not about who decides: the poll runs in a separate
process and cannot write the lead's conversation down, which the persist gate
requires first. What changes is that the handover is now binding.

- The wake line says so itself and stays self-sufficient with no skill loaded:
  it states that firstmate moves now, on this wake, without asking the captain,
  names the skill that owns the handling, and orders the persist step before the
  command.
- .agents/skills/claude-seat-lead-restart owns that handling: the standing
  authority and its exact scope, the persist step, what to do with a refusal,
  that nothing follows once the command arms, and the recovery half for a
  `check: lead-restart` wake whose swap did not complete. It also states that
  the away and quiet postures do not change it, because a seat runs out of quota
  whether or not the captain is present.
- AGENTS.md section 13 carries only the load trigger; docs/claude-seats.md and
  docs/configuration.md drop their report-only wording.

Also fixed, found while testing this: bin/fm-lock.sh dropped the handover
reservation before publishing the new owner's runtime record, so the stage read
the swap as complete while that record was still missing. The reservation is now
dropped last, which is what makes its disappearance mean the whole acquisition
landed.

The suite pins the wake as an instruction rather than an option, and
bin/fm-test-run.sh maps the new paths so a change to the seat, lock, or lead
restart selects this suite.
@max-metaplanet
max-metaplanet merged commit e73254a into main Oct 1, 2026
40 of 42 checks passed
max-metaplanet added a commit that referenced this pull request Oct 6, 2026
* feat(bin): let firstmate move itself to another Claude seat

A seat switch moves only what the next spawn reads, so it has never moved
firstmate: the lead keeps the account its own process launched on while
config/claude-seat drifts away from it. No running Claude Code process can
change credential store, so the lead changes account only by being replaced.

bin/fm-seat.sh lead-restart does that, through bin/fm-lead-restart.sh: another
claude starts on the new seat in the same terminal, resuming the same session,
and the current process ends.

Verified rather than assumed, against the code:

- Running workers need nothing. Steering is a durable inbox, status is a
  durable log, and each task keeps the seat recorded in its own record, so a
  crew notification step would change nothing and none is added.
- The one real worker-facing effect is supervision, and it is handled by not
  touching it. The watcher is a separate process with its own singleton lock and
  is never in the kill, so it is orphaned rather than stopped and keeps its
  beacon; the successor's arm attaches to it instead of starting a second one.
  The cycle count goes one to one.

The guarded pieces:

- The persist gate is the one a second mate's restart already applies. The
  /stow open-record contract now has one owner, bin/fm-persist-request-lib.sh,
  which bin/fm-secondmate-restart-lib.sh composes its request from and the lead
  path states verbatim. The command refuses without --persisted.
- The lock is handed over through a bounded reservation in bin/fm-lock.sh
  (state/.lock-handover). It is armed while the outgoing lead still holds the
  lock, so there is no instant with two holders and none with the home open to a
  third session while line 1 names a dead pid. The outgoing session is admitted
  by its session id and keeps confirming its own lock; the successor is admitted
  by the nonce it is launched with, and that proof is what clears the
  reservation. A lapsed reservation means nothing, so a failed handover cannot
  wedge a home.
- The successor is relaunched in the same pane with every other flag preserved.
  The lead's own profile and pane are not derivable elsewhere, so the owning
  session records both in state/.lock-runtime bound to the lock's pid, and a
  record naming another pid is no evidence. The launch command is read from the
  running process and accepted only when it provably round-trips; a flattened
  argument vector where a multi-word argument is indistinguishable from two
  arguments refuses and names --launch-command.
- The armed threshold watch asks the same question about the lead's own seat and
  reports that crossing with the exact command rather than acting on it: the
  poll is a separate process and cannot write the lead's conversation down. It
  reports nothing unless the whole move passes preflight, so a crossing with no
  signed-in destination or no established terminal names that blocker instead.
- Claude primary only. Any other harness refuses by name.

What a failure leaves. Every check runs before anything is touched, so a refusal
leaves the previous session running and in charge. After the previous process has
ended there is no going back to it: the stage records the outcome in
state/.lead-restart.result, drops the reservation, and queues a wake. Recovery is
one command in that same terminal, printed in that record and staged as a file to
source, and nothing else is affected because only one process was ever replaced.

Not proven, and not claimed: that a real signed-in `claude --resume <id>` comes
back as that same session. Exercising it needs a credential this work
deliberately never touches. The stand-in reproduces the documented contract
instead - a resume keeps the session id, which is what --fork-session exists to
opt out of - and every other step is proven against real processes.

tests/fm-lead-restart.test.sh drives the real scripts: the establishment
refusals and the reservation against real claude-named processes, and the whole
swap in a real tmux on a private socket, where one lead before and one lead
after must be in the same pane, on the new profile, resuming the same session,
with a cycle started inside the outgoing lead's tree still alive afterwards.

* refactor(bin): give profile-to-seat naming one owner in fm-seat-lib.sh

The lead restart and the seat command both need the seat NAME a profile
directory belongs to, which is the inverse of fm_seat_config_dir and belongs
beside it rather than in two copies.

* feat(agents): make the lead's own seat crossing a move firstmate carries out

The watch reported the lead's seat crossing and left the move to be asked for.
That is report-only: the captain set the threshold, so the threshold firing is
the instruction, and firstmate acts on it like any other actionable check result.

The watch still hands the move over rather than performing it, and that is about
which process can do it, not about who decides: the poll runs in a separate
process and cannot write the lead's conversation down, which the persist gate
requires first. What changes is that the handover is now binding.

- The wake line says so itself and stays self-sufficient with no skill loaded:
  it states that firstmate moves now, on this wake, without asking the captain,
  names the skill that owns the handling, and orders the persist step before the
  command.
- .agents/skills/claude-seat-lead-restart owns that handling: the standing
  authority and its exact scope, the persist step, what to do with a refusal,
  that nothing follows once the command arms, and the recovery half for a
  `check: lead-restart` wake whose swap did not complete. It also states that
  the away and quiet postures do not change it, because a seat runs out of quota
  whether or not the captain is present.
- AGENTS.md section 13 carries only the load trigger; docs/claude-seats.md and
  docs/configuration.md drop their report-only wording.

Also fixed, found while testing this: bin/fm-lock.sh dropped the handover
reservation before publishing the new owner's runtime record, so the stage read
the swap as complete while that record was still missing. The reservation is now
dropped last, which is what makes its disappearance mean the whole acquisition
landed.

The suite pins the wake as an instruction rather than an option, and
bin/fm-test-run.sh maps the new paths so a change to the seat, lock, or lead
restart selects this suite.

* no-mistakes(review): Harden lead restart handover and notify crew before swap

* no-mistakes(document): Clarify lead-restart skill: started outcome queues no wake

* no-mistakes(lint): Make fm-lead-restart test shellcheck-clean
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