Repository navigation
fix: leave worker headroom when entering away mode - #57
Merged
Merged
Conversation
Entry without --spend records the live ordinary-worker count plus a headroom of 5, still never below the existing floor. An explicit --spend is unchanged. The entry read-back states how many new workers can start and warns when none can.
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
Away mode stalled new work three times because of its worker limit: when /afk is entered without --spend, bin/fm-afk-contract.sh (fm_afk_contract_entry_spend_default, ~line 220) records the limit as the current count of every ordinary worker record (idle, parked and finished workers included), never below FM_AFK_CONTRACT_SPEND_DEFAULT=4. So the limit equals the live count and no new worker can start while away. Stalls: 2026-10-14 (limit 4 vs 19 records), 2026-10-31 (two plan checks waited ~40 min), 2026-11-12 (limit 15 = 15 records; five jobs planned for 03:00 UTC waited ~2 h until the captain returned).
The captain: "because of the worker limit I forgot to raise - what can we do about that. this happened several time already."
Approved fix (Q2011 y, 2026-11-12): the default limit becomes the live count plus headroom (about +5, never below the existing floor), and the entry read-back says plainly how many new workers can start, with a warning when none can. "Q2011 y and offer it upstream. use deepseek and grok if safe". This task is the change in this home's firstmate repository; the upstream offer is a separate follow-up task.
What Changed
--spendvalues.Risk Assessment
✅ Low: This is a small, well-tested change to a default value and an entry-only output line. All prior fix-round claims hold in the current code: the room line appears only at entry, headroom is a plain constant, an over-cap home prints "0 (N over the cap)", the warning gives the working remedy, the skill relays the count, and the non-numeric guard is back. The only problem left is a stale comment in fm-spawn.sh.
Testing
Targeted contract tests, real CLI scenarios with prepared durable worker records, baseline stall reproduction, and two authenticated Claude primary runs passed. Print mode resolved the interactive folder-trust blocker without changing trust settings. CLI/chat transcripts provide evidence; no rendered UI changed. Labs were removed and source remained unchanged.
Evidence: CLI scenarios and base-commit stall reproduction
Source: CLI scenarios and base-commit stall reproduction
Evidence: Real Claude primary commands and read-backs
Source: Real Claude primary commands and read-backs
Evidence: Persisted 20-worker default cap
Source: Persisted 20-worker default cap
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-afk-contract.sh:483- The new zero-room warning tells the captain to 'raise the limit with /afk again with --spend', but that doesn't work. While away,/afk --spend Nwith no new words is treated as a refresh (fm_afk_contract_cmd_enter checks for a refresh before it loads standing words), and a refresh ignores --spend. I checked this by hand: entered with 4 live workers and HEADROOM=0 (cap 4, room 0, warning shown), then ranenter --spend 10. It logged 'the expected return and spend cap given with this refresh were not applied; enter new words to replace the mandate', left the cap at 4, and printed the same warning again. The captain gets bad advice exactly when it matters. Fix: say what actually works, e.g. 'send /afk again with new words and --spend <n>'. The tests that pin the current wording need updating too: tests/fm-afk-contract.test.sh:689 and :701..agents/skills/afk/SKILL.md:53- The intent requires that 'the entry read-back says plainly how many new workers can start, with a warning when none can.' The script prints this, but the captain sees firstmate's restatement, not the script output. Step 3 of the skill tells firstmate to relay only 'the expected return, the spend cap, and the one-sentence reach announcement', so the room count and the zero-room warning can be dropped before the captain sees them. That stall-preventing warning is the core of the approved fix. Fix: add the new-worker count, and any warning, to what step 3 says to relay.bin/fm-afk-contract.sh:500- fm_afk_contract_render_spend_room runs inside fm_afk_contract_render_readback, which is used for more than entry. It also runs on refresh, on thereadbacksubcommand, and on every away wake: bin/fm-supervision-host.sh:1109 and docs/pi-supervision-branch.md:585 put the readback verbatim into the away session's wake prompt. So the room count is recomputed live, and once workers fill up, the captain-facing line 'raise the limit with /afk again with --spend' lands in the away agent's prompt as something that looks like an instruction to re-enter /afk with a higher cap. The intent only asks for this on the entry read-back. Decide whether the room line and warning should appear only at entry (render them from cmd_enter, not the shared readback) or on every wake with wording aimed at the away session.bin/fm-afk-contract.sh:481- When the cap is below the live count (an explicit --spend under the count, or workers added after entry), the read-back prints 'new workers that can start: -4' (asserted at tests/fm-afk-contract.test.sh:700). A negative number of workers that can start isn't the plain statement the intent asks for. Fix: print 0 and, if useful, say how far over the cap the home is (e.g. '0 (4 over the cap)'). The test needs updating to match.bin/fm-afk-contract.sh:189- Simplification: the change adds an environment override, FM_AFK_CONTRACT_SPEND_HEADROOM, with input checking and a fallback to 5. The default is written twice, at line 189 and line 233, and the override is documented at :58 and :157. The intent only asks for 'the live count plus headroom (about +5, never below the existing floor)' and never asks for a configurable headroom. A plain constant (FM_AFK_CONTRACT_SPEND_HEADROOM=5, no env read, no validation branch) would do. The tests use the override only to set up the floor case (:672) and the zero-room case (:684). Without it, the zero-room case can use an explicit --spend equal to the live count, and the floor case can be dropped or tested with the constant. Recommend removing the override unless it is wanted.🔧 Fix applied.
7 issues (5 warnings, 2 infos) still open:
bin/fm-afk-contract.sh:483- The new zero-room warning tells the captain to 'raise the limit with /afk again with --spend', but that doesn't work. While away,/afk --spend Nwith no new words is treated as a refresh (fm_afk_contract_cmd_enter checks for a refresh before it loads standing words), and a refresh ignores --spend. I checked this by hand: entered with 4 live workers and HEADROOM=0 (cap 4, room 0, warning shown), then ranenter --spend 10. It logged 'the expected return and spend cap given with this refresh were not applied; enter new words to replace the mandate', left the cap at 4, and printed the same warning again. The captain gets bad advice exactly when it matters. Fix: say what actually works, e.g. 'send /afk again with new words and --spend <n>'. The tests that pin the current wording need updating too: tests/fm-afk-contract.test.sh:689 and :701..agents/skills/afk/SKILL.md:53- The intent requires that 'the entry read-back says plainly how many new workers can start, with a warning when none can.' The script prints this, but the captain sees firstmate's restatement, not the script output. Step 3 of the skill tells firstmate to relay only 'the expected return, the spend cap, and the one-sentence reach announcement', so the room count and the zero-room warning can be dropped before the captain sees them. That stall-preventing warning is the core of the approved fix. Fix: add the new-worker count, and any warning, to what step 3 says to relay.bin/fm-afk-contract.sh:500- fm_afk_contract_render_spend_room runs inside fm_afk_contract_render_readback, which is used for more than entry. It also runs on refresh, on thereadbacksubcommand, and on every away wake: bin/fm-supervision-host.sh:1109 and docs/pi-supervision-branch.md:585 put the readback verbatim into the away session's wake prompt. So the room count is recomputed live, and once workers fill up, the captain-facing line 'raise the limit with /afk again with --spend' lands in the away agent's prompt as something that looks like an instruction to re-enter /afk with a higher cap. The intent only asks for this on the entry read-back. Decide whether the room line and warning should appear only at entry (render them from cmd_enter, not the shared readback) or on every wake with wording aimed at the away session.bin/fm-afk-contract.sh:481- When the cap is below the live count (an explicit --spend under the count, or workers added after entry), the read-back prints 'new workers that can start: -4' (asserted at tests/fm-afk-contract.test.sh:700). A negative number of workers that can start isn't the plain statement the intent asks for. Fix: print 0 and, if useful, say how far over the cap the home is (e.g. '0 (4 over the cap)'). The test needs updating to match.bin/fm-afk-contract.sh:189- Simplification: the change adds an environment override, FM_AFK_CONTRACT_SPEND_HEADROOM, with input checking and a fallback to 5. The default is written twice, at line 189 and line 233, and the override is documented at :58 and :157. The intent only asks for 'the live count plus headroom (about +5, never below the existing floor)' and never asks for a configurable headroom. A plain constant (FM_AFK_CONTRACT_SPEND_HEADROOM=5, no env read, no validation branch) would do. The tests use the override only to set up the floor case (:672) and the zero-room case (:684). Without it, the zero-room case can use an explicit --spend equal to the live count, and the floor case can be dropped or tested with the constant. Recommend removing the override unless it is wanted.tests/fm-afk-contract.test.sh:636- Fix round 1 replaced the environment override with a plain constant,FM_AFK_CONTRACT_SPEND_HEADROOM=5at bin/fm-afk-contract.sh:184, but left one test call behind: the empty-home case still runsFM_AFK_CONTRACT_SPEND_HEADROOM=0 contract "$home" enter .... The script now overwrites that variable when it loads, so the prefix does nothing. The case expects a cap of 5 and 'new workers that can start: 5', which is headroom 5, not 0. A reader will assume headroom is still configurable and will be confused by those numbers. No other tests still use the override; the zero-room case now uses an explicit--spend 15. Fix: delete theFM_AFK_CONTRACT_SPEND_HEADROOM=0prefix at line 636.bin/fm-afk-contract.sh:460-fm_afk_contract_render_spend_roomwas put betweenfm_afk_contract_render_readbackand that function's doc comment. The readback comment says it is a faithful mirror of the record, shown to the captain at entry and to the away session on every wake. It now sits directly above a function that runs only at entry and is not part of the mirror. That is the opposite of what fix round 1 set up when it kept the room line out of the shared readback. Fix: movefm_afk_contract_render_spend_roomand its two-line comment above the readback's comment block, or belowfm_afk_contract_render_readback.🔧 Fix applied.
1 info still open:
bin/fm-spawn.sh:2252- The spend-cap comment above spawn_refuse_if_away_spend_cap still sayslive-workersis 'also the count its entry records as the cap'. That is no longer true: without --spend, entry now records the live count plus FM_AFK_CONTRACT_SPEND_HEADROOM (5), never below the floor of 4 (bin/fm-afk-contract.sh:223-231). The refusal logic itself is still correct, because it refuses when live >= cap and the read-back's room is cap - live. A future reader could, however, take the comment as the rule and bring back the cap == live stall this change fixes. The SPEND CAP header in bin/fm-afk-contract.sh:146-163 was updated; this sibling comment in fm-spawn.sh was left behind. Fix: reword it to say the refusal counts with the samelive-workersimplementation the entry default reads, and that the entry default adds headroom.✅ **Test** - passed
✅ No issues found.
bash tests/fm-afk-contract.test.shpython3 ~/.no-mistakes/evidence/01M77978F36175B7GRV0CDSZPB/drive-contract.pyStarted and inspected interactive Claude on an isolated 120×40 tmux session; encountered folder trust and cleaned up.python3 ~/.no-mistakes/evidence/01M77978F36175B7GRV0CDSZPB/drive-primary.pypython3 ~/.no-mistakes/evidence/01M77978F36175B7GRV0CDSZPB/drive-primary-default.pyExtracted actual primary responses, verified persisted caps, confirmed lab cleanup, and rangit diff --exit-codeandgit status --porcelain.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.