Repository navigation
feat(bin): automatic Claude seat mode with destination headroom and an extra-usage policy - #11
Merged
Merged
Conversation
…an extra-usage policy Seat switching had a trigger but no judgement about where it was switching to: next_seat picked the next seat that was merely logged in, never reading its quota, so it could land on a seat that was nearly empty. The watch also fired once and had to be re-armed by hand, and when a seat's plan quota ran out, work rolled silently into paid extra usage with nothing to stop it. Three controls, each off when absent, each counting percent LEFT: claude-seat-threshold trigger: the ACTIVE seat drops to N% left claude-seat-destination-min a DESTINATION must exceed X% left claude-seat-extra-usage `stop`, or `allow <usd>`, when none qualifies A candidate below the minimum is skipped and named with its measured headroom; a candidate whose quota gives no verdict is skipped as unknown rather than guessed at in either direction; if none qualifies, nothing is switched. With no minimum configured the rotation gate stays login-only and no candidate quota is read at all. The extra-usage policy gates NEW claude dispatch through fm-spawn: `stop` holds once the active seat's plan quota is gone, `allow <usd>` holds once the seat's extra_usage spend reaches the cap, and an unreadable quota holds rather than launching on a guess. A relaunch is never held, because that is recovery of work already under way. --ignore-seat-hold pushes one spawn through without changing the setting. State the limit plainly rather than implying a spend guarantee: firstmate chooses which seat new work starts on and whether it starts, but cannot stop a worker already running from drawing extra usage mid-task. `stop` therefore means stop STARTING work, plus a warning the moment a running worker's seat enters extra usage, sent through the usage warner's notification path. The watch is now a registered repeating check rather than the one-shot condition-action primitive: one crossing fires at most once per seat, and the seat it moves to fires again on its own crossing with nothing re-armed. arm and retire both clear any older one-shot registration so an upgrading home ends with one watch. The usage warner counted percent USED while every seat setting counted percent REMAINING, so the two read as contradicting each other. It now counts percent left too, names both figures on every line it prints so a config carried over from the old reading announces itself, and gains a `threshold <window-id> <percent-left>` setter matching fm-seat.sh's in shape and direction, plus a `notify` action that makes it the one owner of this home's notification path. fm-check-shim-lib.sh factors out the check-shim write, trust binding, and rollback that fm-usage-warner.sh already carried, so the seat watch adds a fourth consumer without a fourth copy.
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
…n extra-usage policy Carried from fork commit c48332b (#11). bin/fm-config-inherit-lib.sh unions the inheritable set again, keeping upstream's newer items beside the two new seat settings. AGENTS.md keeps upstream's pointer and the seat entry is updated in the `operational-home-layout` skill, as for the earlier seat commits. Two resolutions follow from the approved decision to drop the relaunch-pin refusal series and wait for upstream's own PR: docs/configuration.md does not carry this commit's sentence documenting a refused relaunch when the pin does not select the task's recorded seat, because that refusal is not implemented here. Upstream's sentence is kept, with its stale "these three files" corrected to "these files" now that five drive the behaviour. tests/fm-seat.test.sh drops `test_account_pin_and_recorded_seat_refuse_the_relaunch`. The dropped review commits are ancestors of this one, so that test arrived with this pick's side of the conflict while the code it asserts did not, and it would have failed against a branch that deliberately has no such refusal. The two tests asserting a pin-only home and a pin pointing at the seat directory still relaunch are kept: both pass without the refusal and state the behaviour this branch does have.
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
can there be an automated mode ? e.g. at a configurable threshold auto switch to next seat (if next seat has more than X threshold remaining?) probably need a few controls there e.g. a setting that allows it to switch automatically if next seat has more than X remaning and a setting that controls whether to continue and use api usage if theres any available (configuragle limit) or just stop without dipping into any api usage etc
Context. Claude seat switching today (bin/fm-seat.sh, docs/claude-seats.md) has a trigger threshold plus an arm that runs switch --next when the active seat drops to N percent left. But next_seat picks the next seat in list order that is merely logged in - it never reads that seat's quota, so it can switch onto a seat that is nearly empty - and the watch fires once and must be re-armed by hand. Per-seat spend is observable: quota-axi --provider claude --json --full reports, per seat, a window id extra_usage of kind credits with spentUsd and limitUsd; when a seat's plan quota runs out, work rolls silently into paid extra usage.
The three controls wanted: (1) the trigger threshold, which exists - switch when the ACTIVE seat drops to N percent left; (2) destination headroom - only switch to a seat with more than X percent left, skip seats below X, and if none qualifies do not switch; (3) an extra-usage policy for when no seat has headroom - STOP, holding new Claude dispatch rather than starting workers that would run on paid extra usage, or ALLOW up to a configurable dollar cap and then hold. It keeps watching after a switch instead of firing once.
An honest limit to state in the docs: firstmate controls which seat new work starts on and whether new Claude work is dispatched at all. It cannot stop a worker that is already running from drawing extra usage mid-task - that is the organisation's Claude admin setting. STOP therefore means stop starting new work, plus a loud warning the moment any running worker's seat enters extra usage; it is never described as guaranteeing zero spend.
Also: the usage warner (config/usage-warner) counts percent USED while the seat threshold and the quota viewer ("9% session") count percent REMAINING, so the two read as contradicting each other, and the warner has no setter - an operator must know its file path and format. Make every setting count in percent left, and give the warner a setter matching fm-seat.sh threshold in shape and direction.
What Changed
bin/fm-seat.shhas two new settings,destination-min <pct>andextra-usage stop|allow <usd>|off. They are stored in the newconfig/claude-seat-destination-minandconfig/claude-seat-extra-usagefiles, which local secondmate homes inherit. Whendestination-minis set, rotation reads each candidate seat's quota. It only switches onto a seat with more than that percent left, and a seat whose quota can't be read counts as skipped. It names every skipped seat with its headroom, and it refuses to switch if none qualifies. The armed watch now keeps going after a switch: it fires once per seat crossing and keeps checking for a destination while the active seat stays below its trigger. Every quota read is capped byFM_CHECK_TIMEOUT.statusshows all the settings, whether the watch is armed, and whether new dispatch is held right now.bin/fm-spawn.shnow checks the extra-usage policy before a freshclaudespawn. Withstop, or onceallow <usd>reaches its cap (compared against the seat's reportedextra_usagespend), it refuses the spawn and gives the hold reason. A policy that is set also holds dispatch while the quota can't be read. Relaunches are not gated.--ignore-seat-holdpushes a single spawn through without changing any setting. The automatic mode also sends a warning when a seat that a running worker is on enters extra usage.bin/fm-usage-warner.shthresholds now count percent left and cross downward, matching the seat threshold. Warner output shows both figures (e.g.8% left (92% used)). There is a newthreshold <window> <pct>|offsetter, plus anotifyaction thatfm-seat.shuses so the home keeps a single alert path. The arm/disarm logic for check shims moved into a new sharedbin/fm-check-shim-lib.sh. The docs (claude-seats.md,usage-warner.md,configuration.md,AGENTS.md) describe the new controls. They also state thatstoponly stops new work from starting and does not guarantee zero spend. The seat and warner test suites are extended.🤖 Generated with Claude Code
Risk Assessment
blockedmarker re-checks for a destination on every poll, reports once, and cannot ping-pong between seats. Every quota read goes through one bounded helper, and a timed-out read gives no verdict. The hold-reason wording now lives in one place that both the spawn gate andstatususe. The fix round also sources fm-quota-axi-lib in fm-spawn, which the dispatch decision's jq filter needs. The change stays medium risk because it can switch accounts automatically and can hold all new Claude dispatch across the fleet.Testing
I ran fm-seat.sh against real quota-axi in throwaway FM_HOMEs, with no secondmate records, so nothing outside them was touched. The new wake wording showed up live under the stop policy with no qualifying destination, and the repeat poll printed nothing. The watch also switched to a real seat with 97% left, and a rate-limited quota was treated as no verdict. The targeted fm-seat test file passes on the target commit and fails with the old wording restored, but that is a test-suite check, not a live product run. That file stops at its first failure, which is the updated no-headroom test, so the new agreement test itself was not run against the old wording. Once Claude's quota endpoint rate-limited, I could not capture status reporting "allowed" next to the wake line, and I could not get an allow-policy wake. The worktree is clean.
Evidence: Real quota-axi: stop policy, no headroom, new wake wording
Source: Real quota-axi: stop policy, no headroom, new wake wording
claude-seat: default is at 9% left and no seat has enough headroom to switch to; new Claude work will be held once this seat's plan quota runs out, rather than started on paid extra usage. A worker already running is not stopped.Evidence: Real quota-axi: auto switch to a seat with headroom, then silent repeat poll
Source: Real quota-axi: auto switch to a seat with headroom, then silent repeat poll
claude-seat: switched from default at 9% left to seat-max; new workers launch thereEvidence: fm-seat test file with the fix (passes)
Source: fm-seat test file with the fix (passes)
Evidence: fm-seat test file with the old wording (fails)
Source: fm-seat test file with the old wording (fails)
not ok - the wake must name the policy consequence, not just the failed switch (missing: 'will be held once this seat's plan quota runs out')Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 4 issues found → auto-fixed ✅
bin/fm-seat.sh:542- When the trigger is met but next_seat finds no destination, cmd_auto writes fired=<active> and then returns early on every later poll (line 524) until the ACTIVE seat reads back above its threshold. It never calls next_seat again in that time. Example: alpha is at 5% left with threshold 15 and destination-min 30, and beta is at 20%, so there is no destination. Then beta's window resets to 100%. Alpha stays below 15%, so the watch never switches to beta. Withextra-usage stopset, every new Claude spawn stays held on alpha even though a seat with headroom exists. This goes against the intent ('keeps watching', 'switch automatically if next seat has more than X remaining'). Fix: in the no-destination case, keep re-evaluating next_seat on each poll without printing again. For example, record a separateblocked=<active>marker that only silences the repeated 'no seat has headroom' line, whilefiredstays reserved for a switch that actually succeeded or failed. The switch-failed path at line 537 has the same effect.bin/fm-seat.sh:511- cmd_auto runs one quota-axi read per distinct Claude task seat (warn_extra_usage_entry), then the active seat, then one per candidate in next_seat. These run one after another, none has a time limit, and all of them happen inside the watcher's FM_CHECK_TIMEOUT (default 30s, fm-watch.sh:240). The usage warner caps its own read at min(10s, FM_CHECK_TIMEOUT-3) for this reason. fm_seat_quota_json has no cap. With a policy set, several seats, and a slow network, the watcher can kill the pass before it reaches the switch, on every cycle, so the automatic switch silently never happens. Fix: bound each read with the existing fm-timeout-lib helper using a per-pass deadline, and run the trigger/switch path before the extra-usage warning scan so the warning can't use up the switch's budget.bin/fm-seat.sh:389- The change adds a publicfm-seat.sh dispatch-check [--quiet]subcommand, and its comment says 'The dispatch gate bin/fm-spawn.sh consults'. fm-spawn.sh doesn't use it: it calls fm_seat_dispatch_decision directly and has its own second copy of the hold-reason messages (cmd_seat_dispatch_report, bin/fm-spawn.sh:602). No caller uses--quiet. The intent asks for the gate itself, not a separate on-demand CLI. Either remove dispatch-check and --quiet, or have fm-spawn call it and delete the duplicate renderer, so the reason text is defined in one place. At minimum the comment claiming fm-spawn consults it is wrong.bin/fm-usage-warner.sh:339- As the intent requires, config/usage-warner values now mean percent LEFT instead of percent USED, and there is no migration. An existingfive_hour:80(previously 'warn at 80% used') now warns as soon as the window drops to 80% left. This is deliberate and documented, and the first warning shows both figures. Noted only so the operator knows any existing home config must be re-set.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 2 issues found → auto-fixed ✅
bin/fm-seat.sh:719- When the trigger is crossed with no destination andextra-usage stopis set, the watch says 'new Claude work is held rather than started on paid extra usage' even though plan quota still remains. The real run hit this: the default seat was at 11% left, threshold 15. At the same momentfm-seat.sh statussaid 'new Claude dispatch: allowed ... still has 11% of its plan quota left', because the hold only starts once plan quota reaches 0. An operator reading the wake line alongside status sees two answers. Consider wording like 'new Claude work will be held once this seat's plan quota runs out'. The allow-policy message has the same shape.threshold 15,destination-min 30andextra-usage stopare accepted, and stop prints the not-zero-spend caveat.threshold 150,destination-min abcandallow…threshold five_hour 20prints '20% left (which is 80% used)'. 150 is rejected.seven_day offclears. config/usage-warner holds 'five_hour:20'.threshold-reachedexit 0. Status shows 11% left and dispatch allowed. Auto reports no destination and sw…bash tests/fm-seat.test.sh(full seat suite, including the auto-watch, headroom, policy, spawn-gate, quota-budget and recovered-candidate regression cases)bash tests/fm-usage-warner.test.shManual CLI in a throwaway FM_HOME with a fake quota-axi:fm-seat.sh threshold 15,destination-min 30,extra-usage stop, bad inputs (threshold 150,destination-min abc,extra-usage allow,extra-usage allow -5),switch alpha,statusfm-seat.sh autoacross a sequence of quota states: quiet pass, crossing that skips a seat below the minimum, repeat poll, second crossing with no re-arm, no destination, silent repeat, candidate recovers, unreadable active quota, 60s endpoint with FM_CHECK_TIMEOUT=8fm-seat.sh statusshowing HELD vs allowed under stop and underallow 25at $10 and $25 spentfm-spawn.sh gate-demo-1 ... --harness claude(refused by the gate-agent guard before the seat gate)fm-usage-warner.sh thresholdprint/set/reject/clear, plus inspecting config/usage-warnerfm-seat.sh arm/status/retire, and running the generated state/claude-seat.check.sh shim directlyRead-only real quota-axi:fm-seat.sh threshold 15,extra-usage stop,threshold-reached,status,autoon the ambient default login🔧 Fix applied.
✅ Re-checked - no issues remain.
FM_HOME=<throwaway> bin/fm-seat.sh threshold 100; extra-usage stop; threshold-reached; auto; status; auto; extra-usage allow 25; auto; statusagainst real quota-axi (--no-credential-refresh), where the watch switched default→seat-maxFM_HOME=<throwaway> bin/fm-seat.sh threshold 100; destination-min 99; extra-usage stop; auto; status; auto; extra-usage allow 25; auto; statusagainst real quota-axi, the no-headroom casequota-axi --provider claude --no-credential-refresh --full --jsonrun three times, which showed the upstream rate limitbash tests/fm-seat.test.shon target commit 3e73df4: all passedbash tests/fm-seat.test.shwith bin/fm-seat.sh from HEAD~1 (old wording): fails with "missing: 'will be held once this seat's plan quota runs out'"; bin/fm-seat.sh restored afterwards✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Live validation evidence, and its limits
The automatic mode was exercised end to end in a guarded Herdr lab session against a throwaway
FM_HOMEwith synthetic seats, driven by a scriptablequota-axishim. No real credential was read, and neither~/.claude-seatsnor~/.claudewas touched: the seats root was redirected into the lab's own tree. The lab session was torn down through the guarded helper with its fleet-state tripwire verified afterwards.Driven against the real
quota-axi(read-only,--no-credential-refresh, against the ambient default login):arm/status/retireDriven against the
quota-axishim, because reaching these states on real accounts would mean exhausting two real Claude accounts' quota and spending real extra usage:statusreports whether new Claude dispatch is held and whySTOPholds a new dispatch;ALLOWproceeds under its dollar cap and holds once the spend reaches itCovered by the test suite only: the
fm-spawndispatch hold itself - a fresh Claude spawn refused while held,--ignore-seat-holdgetting through, and relaunches and other harnesses never being held. The validation-step agent could not drivefm-spawndirectly, because no-mistakes' own gate-agent guard correctly refuses a pipeline agent from driving a pipeline.tests/fm-seat.test.shandtests/fm-usage-warner.test.shboth pass, along with the adjacentfm-secondmate-harness,fm-spawn-dispatch-profileandfm-trace-context-libsuites.Lab transcript
Guarded Herdr lab run, six scenarios
One migration note for operators
config/usage-warnerdirectives now mean percent left instead of percent used, with no automatic migration. An existingfive_hour:80previously meant "warn at 80% used" and now means "warn at 80% left", so it fires early. The failure direction is safe (it over-warns rather than under-warns) and every warning names both figures, so a carried-over config announces itself the first time it speaks - but it does need re-setting withbin/fm-usage-warner.sh threshold five_hour <percent-left>.