Repository navigation
fix(bin): stop finished workers filling the away spend cap and apply yolo changes to running ships - #15
Merged
Conversation
…osture changes - fm-spawn.sh: the away spend cap counts only ordinary workers whose current state (fm-crew-state.sh) is still working; done, failed, and decision-parked tasks waiting on a merge, cleanup, or decision hold no slot. Unreadable state still counts, and the recheck under the task-set lock reuses the first reads and recounts records. - fm-project-yolo-apply.sh: new guarded command that applies a project's registered +yolo posture to its live ship tasks in this home, under each task's lifecycle and meta locks; gerrit stays off, an unresolvable registry entry changes nothing, and merge gates are unchanged. - Docs: --spend now reads as concurrent working workers; project-management says to run the apply command after changing a project's posture. - Tests: finished workers do not consume away slots; live tasks follow a changed project posture.
…, split cap tests
…nt dead-backend edge
Owner
Author
Worker notesSkills used: firstmate-coding-guidelines, tdd Regression tests fail with the fix revertedFinal head 374d83d with Before the first commit, the original spend-cap test against base failed with Decisions taken through the review gate
Noticed
Better idea
Also tidied
|
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
"Ooh, we need to fix this ASAP. I mean the overnight runs. This is just bad."
Context: on the night of 2026-10-19 the away session (Claude home, supervision host) stalled after the first batch. Away mode was entered with spend cap 16, meant as 5 active workers on top of 11 old idle task records. Two causes stopped all further work for about 6 hours:
What Changed
bin/fm-spawn.sh: the away spend cap now counts only workers that are still working. A task stops counting iffm-crew-state.shreads it as one of these:A task whose state can't be read still counts. The recheck after the task-set lock reuses the first check's reads. Relaunches stay exempt, and the code comment notes the known edge where a dead backend can let the total go over the cap. The refusal message now reports how many tasks were not counted.
New
bin/fm-project-yolo-apply.sh <project> [<task-id>...]: rewritesyolo=in the project's live ship task metas to match the project's registered+yoloposture, under each task's lifecycle and meta locks. It also rewrites the posture tokens in queued ship backlog notes throughfm-tasks-axi.sh. Busy or unreadable tasks are skipped, the run exits 1, and it is safe to rerun. It is covered by the newtests/fm-project-yolo-apply.test.sh, andtests/fm-branch-supervision.test.shgains spend-cap cases.Docs and skills:
AGENTS.md, theproject-managementandafkskills,fm-afk-contract.sh,fm-project-mode.sh,docs/architecture.md,docs/pi-supervision-branch.mdanddocs/scripts.mdnow describe the new spend-cap semantics, with--spendmeaning how many workers may run at once. They also say to run the apply script right after changing a project's+yolo.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The latest fix round cleanly reverts the R2-1 relaunch-cap machinery exactly as directed (relaunch exemption restored at the top of spawn_refuse_if_away_spend_cap, refusal wording, tests and docs reverted, known dead-backend edge documented), and the kept F1-F3 and per-fixture R2-2 changes remain consistent with the stated overnight-stall intent.
Testing
I ran the two focused suites for this change, tests/fm-branch-supervision.test.sh and tests/fm-project-yolo-apply.test.sh, and both passed. I then replayed the 2026-10-19 incident as CLI transcripts. - Spend cap: with the base fm-spawn.sh, a cap of 4 with 4 finished records and 1 working worker refused every queued spawn ("5 ordinary task(s) are live"). With the fix, 3 spawns were admitted and the 4th was refused once 4 real workers were working, and the refusal named the 4 uncounted finished tasks. - Admitted spawns in the replay: they exit 1 later because the fixture passes no repo argument, the same shape the existing suite uses. That happens after the cap check (fm-spawn.sh:1642 vs ~1939). - Yolo apply:fm-project-yolo-apply.sh adaflipped 3 live ada ship tasks from yolo=off to on. It rewrote the queued ada-4 note token to "yolo on" and appended a posture sentence to ada-5. The other project's live task and queued item were not touched, and the command exited 0. - Environment: the replays needed the same env the suite's tests/lib.sh sets (FM_GATE_REFUSE_BYPASS, FM_TEST_SEAM). Without it the gate shell's NO_MISTAKES_GATE=1 makes fm-spawn refuse early. - Not visual: this is a CLI/shell change with no UI, so there are no screenshots. - Cleanup: the worktree is clean. Removing the scratch dirs in /tmp was denied, so /tmp/fmreplay., /tmp/fmreplay2. and /tmp/fmyolo.* are left behind. They are small and outside the worktree.Evidence: Away spend cap incident replay: base vs fix transcript
Source: Away spend cap incident replay: base vs fix transcript
Evidence: Away spend cap replay script
Source: Away spend cap replay script
Evidence: Project +yolo switch applied to live tasks and queued notes (before/after)
Source: Project +yolo switch applied to live tasks and queued notes (before/after)
Evidence: Yolo switch replay script
Source: Yolo switch replay script
Evidence: fm-branch-supervision suite log
Source: fm-branch-supervision suite log
Evidence: fm-project-yolo-apply suite log
Source: fm-project-yolo-apply suite log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 4 issues found → auto-fixed (3) ✅
bin/fm-spawn.sh:1545-spawn_task_stopped_spendingtreats everystate: parkedandstate: failedresult as "stopped spending". In fm-crew-state.sh, though,parkedcovers any no-mistakes gate (awaiting_approval, fix_review, awaiting_agent), and that includes the common case where the crewmate itself owes the answer and keeps working (responding to review findings, running fixes). Only a gate carrying theask-user: authority decisioncomponent (FM_GATE_HUMAN_DECISION, fm-classify-lib.sh:2474) is waiting on a human. In the same way, a run-stepfailedis reported whether or not the pane is busy, so a worker actively fixing a failed run is also skipped. Concrete case: --spend 5 with 5 ship workers whose pipelines are parked at review with auto-fix findings. The cap counts 0 working, so 5 more spawns go through and 10 workers spend at once while away. The away spend cap no longer bounds spend. Fix: countparkedas stopped only when it comes from the status log (needs-decision) or carries the human-decision component. Treat run-stepfailedas stopped only when the pane is not busy, or keep counting it..agents/skills/project-management/SKILL.md:54- The posture-change procedure only reaches live ship tasks. AGENTS.md section 7 has firstmate record each ship'syoloin the backlog item note at intake and pass it explicitly to the spawn. So queued ship items for the project (the dependent Ada steps in the 2026-10-19 incident) still carry yolo=off in their notes. Once their blockers clear they spawn with --yolo off, and their green PRs again wait for the captain, which is the same failure as intent cause 2. The remedy is a procedure/scope choice (re-resolve yolo from the registry at dispatch, or have the apply step also update queued notes), so it needs the author's decision.bin/fm-spawn.sh:1543- Finished workers whose agent or pane has gone (dead/missing endpoint, worktree gone) read asstate: unknownin fm-crew-state.sh, so they still count against the cap (fail-closed by design). An old idle scout whose report was delivered but whose agent exited, for example after a backend restart, keeps holding an away slot. Part of the 'old idle task records' in the incident could still fill the cap. Worth confirming that this fail-closed trade-off is intended.bin/fm-spawn.sh:1563- Every away spawn now runs fm-crew-state.sh serially for every non-secondmate record, each bounded at 15s (no-mistakes status, backend probes). With around 16 records, one spawn can take tens of seconds, or minutes in the worst case. It is acceptable because it runs only while away and before any lock is held, but stopping early oncelivereaches the cap would bound it.🔧 Fix: Tighten away spend cap and apply yolo to queued ships
3 issues (2 warnings, 1 info) still open:
bin/fm-spawn.sh:1578- The F3 fix lets a record whose tmux/herdr endpoint is proven gone free its away slot. spawn_refuse_if_away_spend_cap still exempts every relaunch ([ "$RELAUNCH" -ne 1 ] || return 0), and its comment says a relaunch "replaces a worker that already counts". That stops being true once dead-endpoint records no longer count. Concrete case: --spend 5, five ship workers on tmux, the tmux server dies (a definitive no-server readsmissing). All five read as gone, so live=0 and five fresh spawns are admitted. firstmate then recovers the original five through fm-control.sh relaunch (fm-spawn --relaunch), which skips the cap, so 10 workers spend while away. The cap no longer bounds concurrent spend. The smallest remedy is to have a relaunch of a record that currently reads as stopped (dead endpoint) count against the cap, or refuse it. That changes when relaunch is refused, so the remedy needs the author's decision.tests/fm-branch-supervision.test.sh:1691- test_away_spend_cap_holds_slots_for_workers_still_owing_work checks only the combined counts (3 working, 3 stopped) across six fixtures, so a wrong classifier with the same totals still passes. For example, the pre-fix behavior for parked and failed (every parked frees, every failed run-step counts) would free ship-gate and ship-asked and keep ship-fixing and ship-failed. Together with scout-gone freed and scout-flaky counted, that again gives live=3 and stopped=3, so the test passes even though an ordinary gate lost its slot and an idle failed run kept one. The fix-round instructions asked for one behavior per case (an ordinary gate holds a slot, a human ask-user gate does not, a busy failed run holds one). Fix: assert per fixture, for example by running the spawn once per fixture (or per pair) with --spend 1 and checking refused or admitted. Then each classification is proven on its own.bin/fm-project-yolo-apply.sh:250- apply_queued reads the item withshow, checks state=queued, then writes withupdate --body-file, all without a backlog lock. A dispatch that starts the item in between gets its now in-flight note rewritten, and the spawn may already have taken the old posture. The window is narrow, and the rerun semantics plus the live-task pass cover most of it. Noted only.🔧 Fix: Count stopped-worker relaunches against away cap, split cap tests
2 issues (1 warning, 1 info) still open:
bin/fm-spawn.sh:1619- The new relaunch cap classifies the task at the moment fm-spawn --relaunch runs. But fm-control's do_relaunch (bin/fm-control.sh:1000-1011) always stops the old agent (do_exit) before it calls fm-spawn --relaunch. By then fm-crew-state reportstmux:dead/missingasbackend target gone, so spawn_task_stopped_spending treats every real relaunch as stopped. The exemption for 'a relaunch of a task that still counts' therefore never applies on the supported path, and the branch can only relaunch through fm-control. Concrete case: away is entered with cap 4 while 5 workers are working (or some states are unreadable and count). firstmate relaunches a stuck working worker X. fm-control kills X's agent, X now reads as stopped, the other workers give live=4>=cap, and fm-spawn refuses. The rollback then reports 'agent stopped but relaunch did not reach replacement launch; no agent is running'. A working worker was destroyed instead of being replaced. Before this fix round, relaunch was always exempt. The test calls fm-spawn --relaunch directly against a live fixture, so it does not model the real kill-then-relaunch order. The remedy is to classify the task (or run the cap check) in fm-control before do_exit and pass that verdict to fm-spawn. That is cross-script work, so it needs the author's decision.bin/fm-spawn.sh:1726- The relaunch cap check runs only once, before any lock: the recheck at line 1726 sits inside the RELAUNCH=0 path, and relaunch takes only its per-task control lock. Two concurrent relaunches of different stopped tasks, or a relaunch racing a fresh spawn whose recheck reuses the cached stopped-id set, can both be admitted with one slot left, so the count goes over the cap. The window is narrow because firstmate normally drives these one at a time. Noted only.🔧 Fix: Restore relaunch exemption from away cap, document dead-backend edge
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-branch-supervision.test.sh(includes test_away_spend_cap_counts_only_working_workers, test_away_spend_cap_holds_slots_for_workers_still_owing_work, test_away_spend_cap_is_rechecked_under_the_task_set_lock, test_quiet_record_never_caps_a_present_captains_spawn) - all ok, exit 0bash tests/fm-project-yolo-apply.test.sh- all 11 cases ok, exit 0Incident replayreplay-away-cap.shagainst base 5d67f6e bin/ (viagit archive) and fixed bin/: away entered with --spend 4, 4 finished scout records + 1 working worker, then 4 sequentialfm-spawn.sh queued-NcallsIncident replayreplay-yolo-switch.sh: ada registered +yolo, 3 live ada ship tasks with yolo=off, queued ada/other ship items, thenfm-project-yolo-apply.sh adawith before/after meta and data/backlog.md✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.