Repository navigation
feat(bin): add park/unpark control verbs to suppress watcher loops on stopped seats - #7045
RooseveltAdvisors wants to merge 4 commits into
Conversation
Add park and unpark verbs to the lifecycle control plane for stopped seats with unlanded work. Suppress watcher endpoint probing when parked by default in fm_backend_target_of_meta without removing the endpoint record or touching unlanded commits. Report state: parked in fm-crew-state and preserve full target resolution under --include-parked for snapshots and teardown. Preserve authoritative unlanded-work refusal in fm-teardown.
… parked on relaunch
…his PR's new test, tests/fm-parked-seat.test.sh. ShellCheck reported SC2034 ("variable appears unused") for FM_HOME, STATE and SCRIPT_DIR. Those three are set inside a subshell and then read by the fm-watch.sh script it loads, but ShellCheck is told not to follow that script (source=/dev/null), so it cannot see them being used. The rule that should hold is that every place in the test which sets variables for the loaded watcher is lint-clean. There are three such places, at the former lines 169, 182 and 195. CI only flagged the one at line 195, but I fixed all three the same way: a `# shellcheck disable=SC2034 # read by the sourced watcher at call time` comment above each, the same style used in tests/fm-parent-channel-scan-exclusion.test.sh:284. No behavior changed. Checks run: - `bin/fm-lint.sh tests/fm-parked-seat.test.sh` (the project linter, ShellCheck 0.11.0 with extended analysis) passes. - `shellcheck -x` on the file passes. - `bash tests/fm-parked-seat.test.sh` passes both of its tests. I did not act on the separate "Behavior portable serial 2" item. That check was cancelled without a result; nothing in the code caused it, and it needs your decision, not a code fix
|
Speaking as Kun's firstmate: thank you, @RooseveltAdvisors. A stopped seat that keeps raising stale wakes is real noise, and the live drive is thorough (8/9). This is my first stamp. I read head Contract-class: opt-in. Nothing parks unless someone runs VISION: One captain: aligns (less noise, and crew-state shows Because this is a new control-plane primitive with overlapping proposals, Kun decides whether this shape is the one to adopt. That decision comes once CI is green. Two notes would help him: how this relates to #6692 and #6191, and whether Status: waiting on CI (rerun), then Kun (merge-or-leave). |
|
A concrete use case for this, from ordinary operation, in case it helps the merge-or-leave call. Situation. A home runs several persistent second mates on one provider. That provider's weekly quota ran out mid-week, so every second mate was idle, unable to work, and still costing quota on each supervision wake. The operator wanted to stop them all, keep their homes and backlogs intact, and start them again when capacity returned. That is the full-fleet-stop case #7019 describes. What happens on main today (read on
So an operator who needs a durable stop today has to reuse a crash-loop record for a purpose it was not designed for, and still loses the stop at the next session start. An explicit A natural follow-up, not needed for this PR: waking a parked second mate automatically when work is routed to it, for example when |
Intent
Add supported parked-seat record to suppress stale loop on stopped seats
What Changed
parkandunparkverbs to thebin/fm-control.shallowlist.parkstops the agent if it is running. It then writesparked=1,parked_at, and an optionalparked_noteto the task meta under the meta lock and publishes the update atomically. It also clears the endpoint's stale, hash, paused, writing, and subsuper markers. The worktree, unlanded commits, and the endpoint record are left as they are.unparkremoves the parked fields.--note/--note-filenow work withparkas well asrelaunch.fm-watch.shprobing loops (recorded_windows, secondmate wake-stall, and secondmate liveness ticks) and by thefm-bootstrap.shsecondmate liveness sweep. This stops the stale-loop behaviour and auto-relaunch on parked seats.fm-crew-state.shnow reports aparkedstate, plus the note if one was given.fm-spawn.shtreats the parked keys as spawn-owned, so they are dropped on relaunch and a relaunched task starts unparked.docs/agent-control.md,docs/architecture.md, anddocs/scripts.mdto cover the new verbs. Addedtests/fm-parked-seat.test.shand extended the control, relaunch, and crew-state tests.🤖 Generated with Claude Code
Risk Assessment
Testing
Each live scenario ran in its own throwaway lab home with a private tmux server. They used the real fm-control park/unpark, fm-watch, fm-crew-state, fm-teardown and secondmate_liveness_tick code. One run used a real Claude CLI seat. Every live scenario produced its expected result. This includes a before-and-after control that a run without the fix would fail: unparked stopped seats raise a stale wake, parked ones do not, and unparking brings the wake back. The fm-spawn --relaunch path was not driven live, so that scenario is untested. Its focused test, which uses a stubbed tmux, passes. The four targeted test files also pass. All lab homes were removed. So were the CLAUDE.md edit and the .codegraph/ folder that an auto-index hook added to the worktree. There is no UI surface, so the evidence is CLI transcripts.
Evidence: Live drive: park/watch/crew-state/unpark/teardown on stopped tmux seats
Source: Live drive: park/watch/crew-state/unpark/teardown on stopped tmux seats
Evidence: Live drive: park a running real Claude CLI seat
Source: Live drive: park a running real Claude CLI seat
Evidence: Live drive: secondmate liveness tick skips parked mates
Source: Live drive: secondmate liveness tick skips parked mates
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:5188- A relaunch that does not go through fm-control keepsparked=1on the task, so a live agent ends up hidden from supervision.preserve_relaunch_metacopies every key it does not own, andparked,parked_atandparked_noteare not in its owned list. Onlyfm-control relaunchclears the flag afterwards (fm-control.sh:1163). Example: an operator runsfm-control t1 parkand later resumes the seat with the documentedfm-spawn.sh t1 --relaunch(docs/agent-control.md:88). The new agent is alive, but the record still saysparked=1. As a result, fm-watchrecorded_windows(fm-watch.sh:821) never probes it for stale or wedge,fm-crew-statereportsstate: parked,fm_busy_classify_metareturnsunknown no-target, andfm-sendrefuses with 'no backend target recorded'. The secondmate liveness auto-relaunch has the same problem:fm_secondmate_liveness_relaunchcalls fm-spawn the same way (fm-secondmate-liveness-lib.sh:291). It is worse there, becausesecondmate_liveness_tick(fm-watch.sh:1066-1080) never checksparked. The fallback towindow(liveness-lib:216) reads the stopped secondmate as dead and auto-relaunches it on the next tick, which undoes the park. Fix: addparked parked_at parked_noteto the owned keys inpreserve_relaunch_meta, so any fresh launch clears the flag, and skipparked=1metas insecondmate_liveness_tickand in the bootstrap sweep (fm-bootstrap.sh:754).bin/fm-backend.sh:363-fm_backend_target_of_metais a shared helper, and the change makes it return an empty target for every parked task by default. Only five call sites opt back in with--include-parked. That suppression was meant for the watcher's probe loop, but it now also silently changes non-watcher callers. (1) fm-busy-lib.sh:1197fm_busy_classify_metareturnsunknown no-target. Sofm-control <parked-id> exitagainst an agent that is alive and busy (for example one revived as described in F1) skips the interrupt-first branch at fm-control.sh:694 and types the exit command into a busy turn. (2) fm-send.sh:366/405/1019 refuse with a misleading 'no backend target recorded in meta' instead of saying the seat is parked. (3) fm-spawn.sh:3595 refuses a Herdr re-dispatch with 'existing metadata has no endpoint'. (4) fm-watch.sh:1017 hands an empty target tosecondmate_in_active_turnandsecondmate_ring_to_drain. Others: fm-supervise-daemon.sh:594/1389, fm-pending-reply-lib.sh:1635, fm-procevent.sh:865, fm-crew-state.sh:322. Fix: keep the helper's default unchanged and apply theparked=1skip only where the intent needs it, in fm-watchrecorded_windowsand the stale and wedge loops. That also removes the need for the--include-parkedflag and its order-insensitive argument parsing.tests/fm-parked-seat.test.sh:313- The test that runs the real watcher only proves an absence, and the same absence would hold with no fix at all. The watcher runs for 0.5s with FM_POLL=0.05, then the test asserts that no.stale-*marker or 'stale:' line appeared. Stale detection needs the pane hash to stay unchanged across a much longer time threshold, so an unparked stopped seat would also produce nothing in 0.5s. The assertion passes with the fix and would pass without it. Either remove this part, or reproduce the failure: stage an aged.hash-/.stale-since-marker so an unparked seat does emit a stale wake within the run, then show that the parked seat does not. The test also duplicatestest_park_and_unparkin tests/fm-control.test.sh:1177 andtest_parked_seat_in_metadatain tests/fm-crew-state.test.sh:1015.bin/fm-control.sh:1163-do_relaunchnow callsupdate_meta_parked 0afterjournal_write complete, on every relaunch, including tasks that were never parked. That adds an extra locked read and rewrite of the metadata each time. If that rewrite fails,diemakes the command exit non-zero after the replacement agent is already live and the journal already says complete, so a successful relaunch is reported as a failure. Fix: only rewrite whenparked=1is present. Better still, rely on the spawn-side clear from F1 and drop this call.🔧 Fix applied.
5 issues (1 error, 2 warnings, 2 infos) still open:
bin/fm-spawn.sh:5188- A relaunch that does not go through fm-control keepsparked=1on the task, so a live agent ends up hidden from supervision.preserve_relaunch_metacopies every key it does not own, andparked,parked_atandparked_noteare not in its owned list. Onlyfm-control relaunchclears the flag afterwards (fm-control.sh:1163). Example: an operator runsfm-control t1 parkand later resumes the seat with the documentedfm-spawn.sh t1 --relaunch(docs/agent-control.md:88). The new agent is alive, but the record still saysparked=1. As a result, fm-watchrecorded_windows(fm-watch.sh:821) never probes it for stale or wedge,fm-crew-statereportsstate: parked,fm_busy_classify_metareturnsunknown no-target, andfm-sendrefuses with 'no backend target recorded'. The secondmate liveness auto-relaunch has the same problem:fm_secondmate_liveness_relaunchcalls fm-spawn the same way (fm-secondmate-liveness-lib.sh:291). It is worse there, becausesecondmate_liveness_tick(fm-watch.sh:1066-1080) never checksparked. The fallback towindow(liveness-lib:216) reads the stopped secondmate as dead and auto-relaunches it on the next tick, which undoes the park. Fix: addparked parked_at parked_noteto the owned keys inpreserve_relaunch_meta, so any fresh launch clears the flag, and skipparked=1metas insecondmate_liveness_tickand in the bootstrap sweep (fm-bootstrap.sh:754).bin/fm-backend.sh:363-fm_backend_target_of_metais a shared helper, and the change makes it return an empty target for every parked task by default. Only five call sites opt back in with--include-parked. That suppression was meant for the watcher's probe loop, but it now also silently changes non-watcher callers. (1) fm-busy-lib.sh:1197fm_busy_classify_metareturnsunknown no-target. Sofm-control <parked-id> exitagainst an agent that is alive and busy (for example one revived as described in F1) skips the interrupt-first branch at fm-control.sh:694 and types the exit command into a busy turn. (2) fm-send.sh:366/405/1019 refuse with a misleading 'no backend target recorded in meta' instead of saying the seat is parked. (3) fm-spawn.sh:3595 refuses a Herdr re-dispatch with 'existing metadata has no endpoint'. (4) fm-watch.sh:1017 hands an empty target tosecondmate_in_active_turnandsecondmate_ring_to_drain. Others: fm-supervise-daemon.sh:594/1389, fm-pending-reply-lib.sh:1635, fm-procevent.sh:865, fm-crew-state.sh:322. Fix: keep the helper's default unchanged and apply theparked=1skip only where the intent needs it, in fm-watchrecorded_windowsand the stale and wedge loops. That also removes the need for the--include-parkedflag and its order-insensitive argument parsing.tests/fm-parked-seat.test.sh:313- The test that runs the real watcher only proves an absence, and the same absence would hold with no fix at all. The watcher runs for 0.5s with FM_POLL=0.05, then the test asserts that no.stale-*marker or 'stale:' line appeared. Stale detection needs the pane hash to stay unchanged across a much longer time threshold, so an unparked stopped seat would also produce nothing in 0.5s. The assertion passes with the fix and would pass without it. Either remove this part, or reproduce the failure: stage an aged.hash-/.stale-since-marker so an unparked seat does emit a stale wake within the run, then show that the parked seat does not. The test also duplicatestest_park_and_unparkin tests/fm-control.test.sh:1177 andtest_parked_seat_in_metadatain tests/fm-crew-state.test.sh:1015.bin/fm-control.sh:1163-do_relaunchnow callsupdate_meta_parked 0afterjournal_write complete, on every relaunch, including tasks that were never parked. That adds an extra locked read and rewrite of the metadata each time. If that rewrite fails,diemakes the command exit non-zero after the replacement agent is already live and the journal already says complete, so a successful relaunch is reported as a failure. Fix: only rewrite whenparked=1is present. Better still, rely on the spawn-side clear from F1 and drop this call.bin/fm-crew-state.sh:237- The crew-state label always saysseat parked with unlanded workfor anyparked=1record, butfm-control park(bin/fm-control.sh:1262-1271) never checks whether the worktree actually has unlanded commits. Example: park a task whose branch is already merged.fm-crew-statethen reportsstate: parked · source: none · seat parked with unlanded work, which is a wrong claim to the operator. Fix: change the detail toseat parked. The note suffix can stay. The same wording is asserted in tests/fm-crew-state.test.sh:1025 and is also used in the docs row docs/agent-control.md:38.✅ **Test** - passed
✅ No issues found.
Lab home (bin/fm-lab-home.sh create) + private TMUX_TMPDIR tmux server, real stopped seat panes fmses:fm-t1/fm-t2, run realbin/fm-watch.sh(FM_POLL=1) before and afterbin/fm-control.sh t1 park --note ...bin/fm-crew-state.sh t1/t2on parked vs unparked seatsbin/fm-control.sh t2 parkthen 3 real watcher runs with both seats parked (blocked 12s with no wake, no probe markers)bin/fm-control.sh t1 unparkthen real watcher run surfacesstale: fmses:fm-t1againAdversarial:fm-control t1 unpark --note x(rc=1) andfm-control t1 bogus(rc=2)bin/fm-teardown.sh t1on parked seat with unlanded commit -> REFUSED, worktree and HEAD intactRealclaudeCLI seat in lab tmux:bin/fm-control.sh c1 park --note 'hold for review'-> exit_result=stopped, pane back to bash, window kept, parked=1, markers cleared, crew-state parkedSourced realsecondmate_liveness_tickin lab with relaunch budget 0: parked sm1 skipped, unparked sm2 bound; afterfm-control sm1 unparksm1 enters the relaunch pathbash tests/fm-parked-seat.test.shbash tests/fm-control-relaunch.test.sh(incl. test_spawn_relaunch_clears_the_parked_record)bash tests/fm-crew-state.test.shbash tests/fm-control.test.sh(incl. test_park_and_unpark)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.