Repository navigation
fix: exit Claude workers with the bare exit word and keep worker shells out of the inbox - #71
Merged
Conversation
…ls out of the inbox Claude task workers launch with --disable-slash-commands, which on Claude Code 2.1.296 unregisters every built-in slash command, so fm-control's /exit printed 'Unknown command: /exit' and exit/relaunch timed out unconfirmed. The bare word exit is handled locally, idle or mid-turn, and never reaches the model. The worker brief now tells workers to reach the steering inbox by absolute path and never cd outside their worktree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Two crew workers are stuck and cannot be restarted through the control plane: "stuck workers, you fix them yourself".
Evidence:
bin/fm-control.sh <id> exit(and sorelaunch) on a Claude Code 2.1.296 worker delivers/exit, the pane answers "Unknown command: /exit", and the control script reportsexit=unconfirmed; the agent did not stop within 30s. The mapping isfm_control_exit_commandinbin/fm-control-lib.sh(claude ->/exit).Second cause: both workers ran
cdinto their own steering inbox dir (state/<id>.inbox, inside the Firstmate home), so the persistent Bash cwd is outside their worktree and the repo PreToolUse hook (resolved from cwd) fails every Bash call; they cannot move inbox messages or recover by themselves.What Changed
fm_control_exit_commandinbin/fm-control-lib.shnow mapsclaudeto the bare wordexitinstead of/exit. Claude task workers launch with--disable-slash-commands, so/exitonly printedUnknown command: /exitandfm-control.sh exit/relaunchended asexit=unconfirmed. The other harnesses keep their existing/exitand/quitmappings, and the control, relaunch and secondmate-restart tests are updated to expect the new command.bin/fm-brief.shwrites into every brief gains one line telling the worker to reach the inbox only by absolute path and nevercdinto it or anywhere else outside its worktree, because the shell's working directory persists and project hooks resolve from it. A new test intests/fm-brief.test.shchecks that line and the absolute inbox path in ship, scout and secondmate briefs.docs/verification/runtime-backends.mdgets a "Claude exit command" record (measured on Claude Code 2.1.296), anddocs/agent-control.mdplus the Claude harness adapter reference now state the bareexitword and link to that record.Risk Assessment
✅ Low: One-line mapping change (claude -> bare
exit) flows through an unchanged submit path that never retypes and still requires a proven-empty composer and the dialog guard, with tests updated consistently; the inbox-cwd half is an advisory brief sentence only, safe to merge with prevention as a follow-up decision.Testing
Drove real Claude Code 2.1.296 workers in a disposable lab home (bin/fm-lab-home.sh) on a private fm-lab tmux socket, using the machine's normal Claude login. Base commit 9695b55 reproduced the reported failure exactly. Target commit 14e03ba stopped the same worker in 5s, stopped a mid-turn worker in 4s, stopped a worker launched by the product's own fm-spawn in 4s, and stopped a Claude started without --disable-slash-commands in 5s.
relaunchon a mid-turn worker whose Bash cwd was inside state/t1.inbox exited it and launched a replacement in the worktree; that replacement handled and acknowledged its inbox message using absolute paths and its pwd stayed in the worktree. The emitted ship brief and secondmate charter both carry the new inbox sentence. Targeted suites tests/fm-control.test.sh and tests/fm-brief.test.sh pass. The lab home, lab tmux server and lab temp dirs were removed; the worktree is clean. No visual artifact: this is a terminal/CLI change, so evidence is pane captures and CLI transcripts. Setup notes: the first relaunch attempts were refused before stopping the agent by the lab's quota-intake gate, then failed after the stop on my own invalid fixture brief; both were fixture issues, fixed by recording a real intake plus a lab model note and scaffolding the brief with bin/fm-brief.sh. The lab tmux server also loaded the user's tmux config, which created extra idle bash sessions inside the lab server only; they were killed with it and the default server was not touched.error: exit-delivered t1 ... agent-state=alive exit=unconfirmed; the agent did not stop within 30s, rc=1 after 38s, pane showsUnknown command: /exit, pane_curren…stopped t1 harness=claude backend=tmux endpoint=fmses:fm-t1, rc=0 after 5s, pane showsAGENT-EXITED rc=0, pane_current_command=bash; a second exit reports `already-stopped…stopped t1 ..., rc=0 after 4s, pane showsAGENT-EXITED rc=0, pane_current_command=bashrelaunched t1 harness=claude from=claude ... endpoint=fmses:fm-t1, rc=0 after 8s; pane showscd -- '<worktree>'then the new agent; 001.msg moved to handled/, inbox-proof.t…--disable-slash-commands;stopped t1 ..., rc=0 after 4s, pane_current_command=bashexitstill stops a Claude launched without --disable-slash-commands (slash commands registered, secondmate-style launch)stopped t1 ..., rc=0 after 5s, pane showsAGENT-EXITED rc=0bin/fm-brief.shin the lab home;tests/fm-brief.test.shpasses (09-fm-brief-test.log)mv, finalpwd= worktree. Single run of model behaviour, so it shows the sentence works here, not that the failure…--setting-sources ''in a throwaway repo that has no PreToolUse hook, so the hook-failure half of the wedge could not be reproduced. Reproducing it needs a lab project that…Evidence: Base commit repro: Unknown command: /exit, exit=unconfirmed
Source: Base commit repro: Unknown command: /exit, exit=unconfirmed
== BASE 9695b55 (old mapping /exit): fm-control.sh t1 exit error: exit-delivered t1 interrupt=not-needed exit-command=delivered agent-state=alive exit=unconfirmed; the agent did not stop within 30s rc=1 after 38s ● Unknown command: /exit == pane_current_command: claudeEvidence: Target commit: same idle worker stops
Source: Target commit: same idle worker stops
== TARGET 14e03ba (new mapping exit): bin/fm-control.sh t1 exit stopped t1 harness=claude backend=tmux endpoint=fmses:fm-t1 worktree=/tmp/fm-lab.69MEIn/wt-t1 rc=0 after 5s ❯ exit AGENT-EXITED rc=0 == pane_current_command: bash == idempotent second exit already-stopped t1 harness=claude backend=tmux endpoint=fmses:fm-t1 rc=0Evidence: Target commit: mid-turn worker stops
Source: Target commit: mid-turn worker stops
Evidence: Target commit: relaunch of a worker stuck in its inbox dir, replacement handles inbox
Source: Target commit: relaunch of a worker stuck in its inbox dir, replacement handles inbox
relaunched t1 harness=claude from=claude model=default effort=default backend=tmux endpoint=fmses:fm-t1 worktree=/tmp/fm-lab.69MEIn/wt-t1 rc=0 after 8s ... ● Bash(echo handled > /tmp/fm-lab.69MEIn/wt-t1/inbox-proof.txt && mv /tmp/fm-lab.69MEIn/state/t1.inbox/001.msg /tmp/fm-lab.69MEIn/state/t1.inbox/handled/ ...) ● Bash(pwd) ⎿ /tmp/fm-lab.69MEIn/wt-t1Evidence: Emitted ship brief with the new inbox sentence
Source: Emitted ship brief with the new inbox sentence
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-brief.sh:451- Second cause in the intent (workercds intostate/<id>.inbox, persistent Bash cwd leaves the worktree, repo PreToolUse hook fails every Bash call) is addressed only by one advisory sentence in the brief. Nothing enforces it: a worker that ignores or forgets the sentence (long session, compaction) reaches the same wedged state, and already-running workers never see the new brief. Recovery now exists becausefm-control relaunchworks again and re-enters the recorded worktree (cd -- <wt>), so this is containment plus recovery, not prevention. A durable fix (e.g. hook resolving from the recorded worktree instead of cwd, or a guard on cwd) would extend the change beyond this diff, so the remedy, not the defect, needs authorization. tests/fm-brief.test.sh:1359 only proves the sentence is emitted, not that the failure is unreachable.bin/fm-brief.sh:451- The new sentence is part of the shared INBOX_SECTION and is also emitted into the secondmate brief (bin/fm-brief.sh:545), which saysnever cd ... anywhere else outside your worktree. A secondmate has no worktree: its brief describesan isolated firstmate homewithprojects/clones it operates (line 517). The term is undefined for that role and could be read as forbidding ordinary movement inside its home. Consider role-neutral wording (your working directory/your home) or a secondmate-specific variant; tests/fm-brief.test.sh:1370 pins the current wording for the secondmate too.bin/fm-control-lib.sh:238- Tradeoff note: the Claude exit text is now a valid shell command. If the agent dies between theemptycomposer read (bin/fm-control.sh:777) and the typed send (bin/fm-control.sh:800),exitlands in the pane's shell and closes the tmux window, where/exitwas a harmless shell error. Window is milliseconds wide, the submit core never retypes (Enter-only retries), a shell pane does not read as composerempty, and relaunch re-creates a gone endpoint, so no action is required.✅ **Test** - passed
✅ No issues found.
error: exit-delivered t1 ... agent-state=alive exit=unconfirmed; the agent did not stop within 30s, rc=1 after 38s, pane showsUnknown command: /exit, pane_curren…stopped t1 harness=claude backend=tmux endpoint=fmses:fm-t1, rc=0 after 5s, pane showsAGENT-EXITED rc=0, pane_current_command=bash; a second exit reports `already-stopped…stopped t1 ..., rc=0 after 4s, pane showsAGENT-EXITED rc=0, pane_current_command=bashrelaunched t1 harness=claude from=claude ... endpoint=fmses:fm-t1, rc=0 after 8s; pane showscd -- '<worktree>'then the new agent; 001.msg moved to handled/, inbox-proof.t…--disable-slash-commands;stopped t1 ..., rc=0 after 4s, pane_current_command=bashexitstill stops a Claude launched without --disable-slash-commands (slash commands registered, secondmate-style launch)stopped t1 ..., rc=0 after 5s, pane showsAGENT-EXITED rc=0bin/fm-brief.shin the lab home;tests/fm-brief.test.shpasses (09-fm-brief-test.log)mv, finalpwd= worktree. Single run of model behaviour, so it shows the sentence works here, not that the failure…--setting-sources ''in a throwaway repo that has no PreToolUse hook, so the hook-failure half of the wedge could not be reproduced. Reproducing it needs a lab project that…bin/fm-lab-home.sh create $LAB+ privatetmux -L fm-labsessionfmses:fm-t1runningclaude --dangerously-skip-permissions --setting-sources '' --strict-mcp-config --disable-slash-commandsBase repro:git archive 9695b55extracted into the lab,FM_HOME=$LAB <base>/bin/fm-control.sh t1 exitagainst the idle workerFM_HOME=$LAB bin/fm-control.sh t1 exit(target) against the same idle worker, then a second time for idempotenceFM_HOME=$LAB bin/fm-control.sh t1 exitagainst a worker mid-turn runningcd $LAB/state/t1.inbox && sleep 300in its Bash toolFM_HOME=$LAB bin/fm-quota-intake.sh record+gate --harness claudein the lab homeFM_HOME=$LAB bin/fm-brief.sh t1 p --mode local-onlyandbin/fm-brief.sh s1 --secondmate --no-projects, emitted briefs inspectedFM_HOME=$LAB bin/fm-control.sh t1 relaunch --note ...against a mid-turn worker whose shell was inside state/t1.inbox, with001.msgwaiting in the inboxFM_HOME=$LAB bin/fm-control.sh t1 exitagainst the replacement worker launched byfm-spawn.sh --relaunchFM_HOME=$LAB bin/fm-control.sh t1 exitagainst Claude started without--disable-slash-commandsbash tests/fm-control.test.shbash tests/fm-brief.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.