Repository navigation
feat(bin): pace Claude reset-edge releases and pin Firstmate homes to one account - #12
Merged
Merged
Conversation
…account Two independent mechanisms fired on the same clock edge with no account-level admission control anywhere in the stack: Claude Code's per-session auto-continue timer, and firstmate's own dispatch and relaunch paths reading a reset as free headroom. At the reset instant every quota surface reads full while the account is maximally committed, so a whole backlog discharged into a fresh window at once. Release shaping. bin/fm-claude-admission.sh releases at most one firstmate-launched Claude worker per interval onto a credential store the home lists in config/claude-shaped-store, highest priority first. Shaping is armed only while that store carries committed demand and for a horizon after, so an ordinary window is not paced. A withheld launch creates nothing, is held in a durable queue that survives restarts, and is released on its own schedule; the watcher poll wakes firstmate when a slot opens. Nothing is ever cancelled, narrowed, or rerouted, and the pacing is never keyed to how full a window is. Committed demand. The same script publishes a census of live sessions parked for automatic continuation with no later real turn, with each one's measured billable input tokens per turn. quota-array-dispatch reads it beside quota-axi's point-in-time headroom and discounts a shaped candidate in the open; the two readings stay distinct and are never folded into one number. Account binding. The account a worker bills followed whichever session firstmate happened to be in, so a relaunch could move a task between subscriptions. bin/fm-home-identity.sh pins each home to the session and account it was started from; fm-spawn, fm-send, and fm-control refuse every other session, homes are never migrated or merged, and an unreadable pin is repaired deliberately rather than re-derived. A worker records its home's account in its own task metadata and every later relaunch reuses that record, with a default-store binding enforced by unsetting an inherited value rather than by omitting one. A second mate is seeded with its parent's identity, so its own workers stay there too. An unlisted store takes no state, no lock, and no decision, so default and personal Claude launches are byte-for-byte what they were. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hf7z9pt5cBPehNNLr7ptCb
The lab tripwire recorded only the session flagged default, and required that row to be named "default" and to be running. On an operator fleet whose live work runs in named sessions kept strictly separate, "default" is present but stopped, so the lab refused to provision at all - while the sessions actually worth protecting were never in the snapshot, and a passing tripwire proved nothing about them. The snapshot now covers every session except the lab's own, so teardown proves the lab disturbed none of them by name, socket, and running state. That is strictly stronger than watching one row, and it no longer cares which session carries the default flag. The lab session is excluded because it legitimately changes: absent when the tripwire is recorded, present-but-stopped when an owned lab is re-provisioned. Two conditions still refuse rather than record, because a snapshot taken under either proves nothing: no session running, so "unchanged" is vacuous; or more than one session claiming the default flag, so the fleet is ambiguous. The fake Herdr client grows a configurable fleet so these shapes are covered: a stopped default beside running named sessions provisions and tears down, a change to any watched session fails teardown loudly, a vanished session fails, and the two refusal conditions leave no tripwire behind. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hf7z9pt5cBPehNNLr7ptCb
…ay, remote identity
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
Implement recommendations 1 and 2 from the Geris Claude 5-hour usage-spike scout report, scoped exclusively to Claude Code sessions billed through the Herdr geris session / Geris credential, plus the captain's two later clarifications that supersede the original non-goals.
ROOT CAUSE BEING ADDRESSED: a subscription window's reset instant is a synchronization edge. Claude Code's own per-session 'continuing automatically' timer and firstmate's own dispatch/relaunch paths both fire on it, and at that instant every quota surface reads full while the account is maximally committed. 30M tokens discharged in under 9 minutes.
REC 1 - reset-edge release shaping, Geris only. When Geris Claude quota becomes available after a limit reset, release at most one Firstmate-managed waiting Geris worker per 5-10 minute interval, highest-priority eligible work first. Preserve all authorized work in a durable queue and continue it eventually. Never cancel, discard, narrow, or silently reroute work. Do not alter personal/default Claude behavior or any non-Geris Herdr session.
REC 2 - committed-demand accounting, Geris only. Before quota-aware dispatch or relaunch treats Geris headroom as available, count live Geris Claude Code sessions parked for automatic continuation with no later real turn and discount Geris effective headroom/ranking by their measured committed demand. Keep point-in-time quota data and committed demand distinct and inspectable. Do not apply this to personal/default Claude or other providers.
CAPTAIN CLARIFICATION 1 (supersedes the original non-goal only to close the proven cross-session relaunch defect): the account remains bound to the Herdr session, NOT the repository. Anything originally started in Herdr geris must always run with Geris Claude; anything started in Herdr personal must always run with personal Claude. Preserve and use each task's original Herdr session binding on every reset/relaunch instead of inheriting the caller's current session. Do NOT implement repo-based account binding. Regression coverage must prove personal tasks cannot relaunch into geris and geris tasks cannot relaunch into personal.
CAPTAIN CLARIFICATION 2 (strengthened invariant): Geris Firstmate and Personal Firstmate must NEVER mix. Each Firstmate home is durably pinned to its originating Herdr session/account identity; a primary launched from another Herdr session must REFUSE rather than silently reuse or migrate that home. Every ordinary worker and second mate started by a Firstmate inherits that parent session/account identity, records it durably, and every relaunch/recovery/send path uses the recorded identity rather than the caller/current environment. A second mate's own workers stay with that second mate's identity. NO fallback across geris/personal on missing or unreadable identity - refuse instead. Preserve separate homes and all existing work; no migration or destructive cleanup.
CAPTAIN CLARIFICATION 3 (test infrastructure): do not ship on portable coverage alone, and do not start or use the generic default Herdr session, because Personal and Geris must remain strictly separate. Keep geris and personal untouched. Make the smallest in-scope test-infrastructure correction that safely permits a named isolated lab anchored to an already-running named session while proving the other named session remains unchanged, with regression coverage for that safety rule.
DELIBERATE DESIGN DECISIONS a reviewer would not infer from the diff:
VERIFICATION ALREADY PERFORMED (evidence recorded in docs/verification/claude-account-binding.md): live isolated Herdr lab provisioned against the real operator fleet and torn down with the tripwire confirming both named sessions byte-identical; live two-direction refusal proven on the real spawn path; pane-level account binding proven on a private tmux server by reading each launched process's own /proc environ - work-bound task ran with the work store, personal-bound task had no CLAUDE_CONFIG_DIR at all despite the server environment carrying one. Firstmate's own Herdr backend correctly refuses cross-session worker placement, which is why the pane-level half runs on tmux, the verified reference backend; that guard was not worked around.
DELIVERY: open a PR. Do NOT merge - captain approval is required after green CI. Do not use --yes; every gate is decided deliberately, and any ask-user finding is escalated rather than self-answered.
What Changed
bin/fm-claude-admission.sh: an opt-in (per credential store, via a localconfig/claude-shaped-storelist) admission controller that, at a quota reset edge, releases at most one waiting worker per interval from a durable priority queue, and censuses live sessions parked for automatic continuation so quota-aware dispatch and relaunch discount that committed demand from effective headroom. Unlisted stores (including the default personal one) take no state, no lock, and no decision. Malformed evidence refuses (exit 3) only after the request is recorded in the queue, andfm-controlconsults a non-consuming preview before stopping a running agent.bin/fm-home-identity.shand wired it throughfm-spawn,fm-control,fm-send,fm-bootstrap, andfm-remote-secondmate-control: each Firstmate home is durably pinned to the(herdr_session, claude_config_dir)pair that first used it, workers and second mates inherit and record the parent identity, and every relaunch/recovery/send path uses the recorded identity instead of the caller's environment. Mismatches refuse rather than migrate or fall back; a default-store binding is enforced by actively unsetting an inheritedCLAUDE_CONFIG_DIRon the launched pane, which changes the claude launch string for that case.fm-herdr-labsafety tripwire to snapshot every session except the lab's own instead of only the row flagged default, still refusing a fleet with nothing running or with more than one default-flagged session. Addedtests/fm-claude-admission.test.sh,tests/fm-home-identity.test.sh, andtests/fm-remote-secondmate-identity.test.sh, extended the control-relaunch, herdr-lab, secondmate-safety, and spawn-dispatch-profile suites, and documented the behaviour plus the recorded live verification evidence underdocs/.Risk Assessment
Testing
Targeted suites for admission control, home identity, control relaunch, remote secondmate identity, Herdr lab and spawn dispatch all pass, and a manual CLI walkthrough demonstrates the shaped Geris store releasing one worker per interval with the rest held in a durable queue, the committed-demand census published separately, the personal/default store untouched and always admitted, and both geris/personal identity refusals leaving each home's pin intact; the only failure encountered was the secondmate suite tripping on this machine's global git commit-hook template, which passes once a neutral GIT_TEMPLATE_DIR is used.
Evidence: Geris reset-edge admission control CLI walkthrough
Source: Geris reset-edge admission control CLI walkthrough
$ fm-claude-admission.sh demand (shaped Geris store) store=/tmp/geris-demo/geris-store shaped=yes parkedSessions=3 floorInputTokens=730000 sessions{sessionId,parkedAtEpoch,parkedAgeSeconds,turnsObserved,avgInputTokensPerTurn}: geris-session-c,...,120,1,300000 geris-session-b,...,90,1,180000 geris-session-a,...,60,1,250000 $ gate task-urgent-fix --priority 10 admitted: task-urgent-fix (release slot open on .../geris-store with 3 parked session(s) of committed demand) $ gate task-feature --priority 20 withheld: task-feature (a Claude worker was released onto .../geris-store 0s ago; the next release slot opens in 8s) the request is held in .../state/claude-admission/geris-store-.../queue and released when the slot opens; nothing was cancelled $ queue waiting{enqueuedEpoch,priority,taskId,reason}: ...,20,task-feature,feature work ...,30,task-docs,docs pass ...,40,task-chore,cleanup [after one release interval] admitted: task-feature ; task-chore still withheld $ gate personal-task-1 (personal store) admitted: personal-task-1 (store .../personal-store is not shaped by this home) $ queue -> shaped=no (no state, no lock, no decision) $ FM_HOME=<geris-home> HERDR_SESSION=personal fm-home-identity.sh check fm-home-identity: refused: this firstmate home belongs to session geris on Claude store .../geris-store, but the current session is personal on /home/daan/.claude. [exit 3] $ FM_HOME=<personal-home> HERDR_SESSION=geris CLAUDE_CONFIG_DIR=.../geris-store fm-home-identity.sh check fm-home-identity: refused: this firstmate home belongs to session personal on ... [exit 3] Both pins intact afterwards.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-remote-secondmate-control.sh:198- The new home-identity pin breaks remote secondmate steering. cmd_launch (line 172) runs fm-spawn.sh with an explicit HERDR_SESSION="$REMOTE_HERDR_SESSION" (fm-remote), and fm-spawn's newfm-home-identity.sh seed "$PROJ_ABS" "$HOME_PIN_SESSION" ...therefore pins $TARGET_HOME/data/home-identity with herdr_session=fm-remote. cmd_send (line 198) and cmd_key (line 207) invoke fm-send.sh with FM_HOME="$TARGET_HOME" but WITHOUT HERDR_SESSION; nothing in bin/fm-remote-entrypoint.sh or bin/fm-remote-job-worker.sh exports it either, so read_environment_identity resolves ENV_SESSION=default, refuse_mismatch fires, and fm-send's newfm-home-identity.sh ensureguard (bin/fm-send.sh:129) exits 1 before any delivery. Failure sequence: launch a remote secondmate, then send it any message or --key -> "this firstmate home belongs to session fm-remote ... but the current session is default" and the steer never reaches the agent. Fix: set HERDR_SESSION="$REMOTE_HERDR_SESSION" on the cmd_send/cmd_key invocations exactly as cmd_launch already does.bin/fm-claude-admission.sh:559- The fail-closed contract for a malformed durable queue is silently bypassed.head_row=$(sorted_queue | head -n 1) || exit $?takes the exit status ofhead, not ofsorted_queue, so sorted_queue's die_evidence (exit 3 on an unreadable row, priority, or task id) is swallowed: head_row comes back empty and evaluate falls through to DECISION=admit. Verified:f(){ printf 'row\n'; exit 3; }; x=$(f | head -n 1); echo $?prints status=0. Failure sequence: state/claude-admission/<slug>/queue acquires a corrupted row (external edit, truncated filesystem write); the nextgateon a shaped store enqueues, evaluates with an empty head, and admits every launch immediately - the exact reset-edge burst the script exists to prevent - instead of exiting 3 as the header and tests document. The same swallow affects action_queue's<<< "$(sorted_queue)". Fix: capture sorted_queue into a variable (checking its status) before taking the head.bin/fm-claude-admission.sh:671- Shaping can never disarm under sustained traffic, contradicting the stated design decision. Intent: "Shaping is armed only while a shaped store carries committed parked demand, plus a horizon after ... This deliberately keeps ordinary unlimited windows unshaped, so the change is not a permanent rate limit on that account", and docs/configuration.md repeats "stays armed for FM_CLAUDE_DEMAND_HORIZON after the last time it did [carry committed demand]". But action_gate writes ARMED_SINCE whenever DECISION_ARMED=yes, including when armed came from the horizon branch (line 538) rather than from parked>0. Failure sequence: one park event arms the store; parked demand then clears; with defaults (interval 420s, horizon 1800s) any gate call within 30 min refreshes armed-since, so a fleet that spawns or relaunches at least once per horizon stays paced at 1 Claude launch / 7 min indefinitely on an unlimited window. test_shaping_disarms_when_no_demand_remains runs with FM_TEST_HORIZON=0 and cannot catch it. If the sticky arming is intentional, the header and docs need to say so; otherwise the write should be conditioned on parked>0.bin/fm-claude-admission.sh:510- queue_remove interpolates the task id into a grep basic regex:grep -v $'\t'"$id"$'\t'. fm_pr_task_id_valid (bin/fm-pr-lib.sh:97) permits '.', which is a regex wildcard. Failure sequence: tasks "a.c" and "abc" are both queued on a shaped store; releasing or withdrawing "a.c" rewrites the queue without the "abc" row too, so authorized work is dropped from the durable queue with no release and no withdraw - violating the header's "Nothing is ever dropped from the queue except by an explicit withdraw or by being released." Fix: match the id as a literal field (e.g. awk -F'\t' with$3 != id).bin/fm-claude-admission.sh:638- action_demand calls store_is_shaped inside$(store_is_shaped "$store" && echo yes || echo no), so its die_evidence (exit 3 on a config line that is not an absolute path, or an unreadable config file) is confined to the command substitution and the verb printsshaped=noinstead of refusing.demandis data-only, but the misreport is the opposite of the documented fail-closed boundary and would tell a reader that a shaped store is unshaped. Call store_is_shaped outside the substitution and branch on its status.bin/fm-claude-admission.sh:745- action_poll runs the full census (evaluate -> demand_census) on every watcher cycle while anything is queued, and demand_census reads up to FM_CLAUDE_DEMAND_TAIL_BYTES (1 MiB default) from every transcript in the store modified within FM_CLAUDE_DEMAND_MAX_AGE (6 h default). On a busy store that is tens of MiB of reads plus a python3 start per poll interval, for as long as the queue is non-empty - which is precisely the reset-edge window. The header's "silent-and-cheap when nothing waits" is accurate; the loaded case is the expensive one. Noting the bound rather than asking for a change.🔧 Fix: fix admission fail-open, id matching, arming decay, remote identity
3 issues (2 warnings, 1 info) still open:
bin/fm-claude-admission.sh:470- The fix round audited callers of sorted_queue but left the same status-swallow inside the queue helpers:queue=$(read_queue)at lines 470 (sorted_queue), 497 (queue_enqueue) and 509 (queue_remove) discards read_queue's die_evidence exit 3, because the exit only kills the command-substitution subshell and the script runs underset -uwithout-e. Line 484 (queue_has) got the|| exit $?treatment; these three did not. Failure sequence: state/claude-admission/<slug>/queue becomes a symlink or otherwise unreadable (external tamper, permissions, fs error); the nextgateon a shaped store calls queue_enqueue, which sees an empty queue and write_record mv's a single-row file over it - every previously queued authorized request is silently gone - and evaluate's sorted_queue then reads only that one row and returns DECISION=admit. That breaks both named invariants at once: 'Nothing is ever dropped from the queue except by an explicit withdraw or by being released' and the documented fail-closed boundary for unreadable evidence. Fix:queue=$(read_queue) || exit $?at all three sites.bin/fm-control.sh:129- The newfm-home-identity.sh ensureguard is placed before FM_HOME is validated as a directory (fm-control.sh:129 sits above the[ -d "$FM_HOME" ]check at line 133; fm-send.sh:128 sits above its own[ ! -d "$FM_HOME" ]check at line 134). action_ensure creates the record directory (mkdir -p "$FM_HOME/data") and writes the pin, so a stale, mistyped, or relative FM_HOME that previously produced a clean "FM_HOME is not a directory" error now silently materializes <FM_HOME>/data/home-identity - in the current working directory when the value is relative - and pins that phantom home to the calling session. Fix: move the ensure block below the existing FM_HOME directory check in both scripts.tests/fm-remote-secondmate-identity.test.sh:70- write_pin always recordsclaude_config_dir=default, so the new coverage exercises only the-u CLAUDE_CONFIG_DIRbranch of remote_identity_env (bin/fm-remote-secondmate-control.sh:120-123). The other half of the propagated identity - a pin naming an absolute store, which must arrive asCLAUDE_CONFIG_DIR=<path>and satisfy fm-send's ensure comparison after canonicalization - has no executable case, and the test's own control() unsets CLAUDE_CONFIG_DIR so the 'actively removed rather than inherited' claim is not exercised either. A second write_pin case with an absolute store, run with a foreign CLAUDE_CONFIG_DIR in the caller environment, would cover both.🔧 Fix: fail closed on unreadable queue and phantom home pins
3 issues (2 warnings, 1 info) still open:
bin/fm-claude-admission.sh:760- action_poll discards the fail-closed refusal the rest of the file now enforces.sorted=$(sorted_queue) || return 0(line 760) catches sorted_queue's die_evidence exit 3 and returns 0, andstamp="$head:$(read_epoch_record "$LAST_RELEASE")"(line 767) swallows the same status. Failure sequence: state/claude-admission/<slug>/queue becomes a symlink or gains a torn row; everygatecorrectly refuses with exit 3 so nothing is ever released, but the watcher poll - the only automated surface that turns waiting work into acheck:wake - stays silent forever, so firstmate is never told the queue needs repair. The boundary is inconsistent inside the same function:store_is_shapedon line 757 is not in a subshell, so a malformed config/claude-shaped-store DOES exit 3 out of poll. Fix:sorted=$(sorted_queue) || exit $?, and capture read_epoch_record with its status, matching every other verb.tests/fm-control-relaunch.test.sh:897- test_relaunch_keeps_a_personal_task_off_a_work_account asserts a premise it never establishes. Its comment (lines 890-891) says "a work account is sitting in the environment" and $store is created on line 889 then never used, but line 897 runs with FM_TEST_CLAUDE_CONFIG_DIR='' so the caller carries no account at all.assert_not_contains "$launch" "CLAUDE_CONFIG_DIR="therefore passes even if fm-spawn ignored the recorded binding and forwarded the ambient value - there is nothing to forward. The test cannot fail for the defect it names. A conflicting ambient store cannot just be added, because fm-control's identity gate requires caller store == home pin; the reachable setup is to pin the home to $store (herdr_session=default, claude_config_dir=$store), keep the task meta at claude_config_dir=default, and run with FM_TEST_CLAUDE_CONFIG_DIR="$store" - the recorded default binding must still yield-u CLAUDE_CONFIG_DIRand noCLAUDE_CONFIG_DIR=prefix.bin/fm-spawn.sh:1882- The secondmate home-identity seed (lines 1882-1890) runs before the release-shaping gate (lines 1900-1907), so a withheld--secondmateclaude spawn prints "nothing was created and the request is preserved above" after having already written $PROJ_ABS/data/home-identity. The pin is idempotent and identical to what a later successful launch writes, so no state is corrupted, but the message is inaccurate. Both blocks depend only on HOME_PIN_SESSION/HOME_PIN_STORE resolved above, so moving the admission gate ahead of the seed is a straight reorder.🔧 Fix: wake firstmate on poll refusals, fix vacuous relaunch premises
3 issues (1 warning, 2 infos) still open:
bin/fm-claude-admission.sh:784- action_poll routes only sorted_queue (line 776) and the two epoch records (lines 779-780) through poll_refuse. evaluate at line 784 still calls demand_census ascensus=$(demand_census "$STORE") || exit $?, so an unreadable transcript, a torn non-final JSON record, a missing python3, or an unreadable parked count exits 3 with the message on stderr only. bin/fm-watch.sh:711 discards the check's stderr and ignores its status, so FM_CHECK_RESULT is empty and nocheck:wake is appended. Failure sequence: a shaped store holds queued work, one transcript under <store>/projects/*/ becomes unreadable; every gate correctly refuses (exit 3) so nothing is released, and the watcher poll - the only automated surface that turns waiting work into a wake - stays silent forever, so firstmate is never told the store needs repair. Same shape at line 774:store_is_shaped "$store" 2>/dev/null || return 0is not a command substitution, so a malformed config/claude-shaped-store line exits 3 out of poll with stderr sent to /dev/null. This contradicts the block comment added at lines 755-759 ('Every refusal a poll can hit is therefore reported as the one wake line'). Fix: pre-capture the census status the way armed/last are pre-captured (census=$(demand_census "$STORE" 2>&1) || poll_refuse "$?" "$census") and hand it to evaluate, and give store_is_shaped a refusal path naming the config problem by store path (SLUG is not resolved yet at that point).AGENTS.md:113- The check-shim entry still reads 'silent unless a shaped store has waiting work whose release slot is open', but poll_refuse now also emits a wake line for unreadable durable evidence with no open slot. docs/configuration.md:346 describes the same one-line-names-the-task-to-release behavior. Add the evidence-refusal wake to both so a reader can interpret the line.bin/fm-claude-admission.sh:764- poll_refuse composes ~80 characters of preamble ('claude admission: ' + slug + ' holds waiting work that cannot be released; ') before the concrete reason, and fm_cap_line cuts at FM_LINE_CAP_DEFAULT=220. With the new test's own path (/tmp/fm-claude-admission.XXXXXX/unreadablequeue/home/state/claude-admission/<slug>/queue) the line lands ~213 characters, 7 under the cap; any longer TMPDIR (common in CI) truncates the tail, so tests/fm-claude-admission.test.sh:353assert_contains "$out" "is a symlink"fails and the operator gets '... [truncated]' instead of the named problem. Put the reason ahead of the preamble, or pass an explicit larger max for this line.🔧 Fix: route every poll evidence refusal to a wake line
2 issues (1 warning, 1 info) still open:
tests/fm-claude-admission.test.sh:354- The new poll wake-line coverage cannot fail for the defect it was added for. The whole point of the round-4 fix is that bin/fm-watch.sh:713 sends the check's stderr to /dev/null and only keeps its STDOUT (FM_CHECK_RESULT), so a refusal that reaches stderr alone leaves a stuck queue invisible. But the sharedadmission()helper (line 98) ends with"$ADMISSION" "$@" 2>&1, merging both streams into$out. Soassert_contains "$out" "claude admission:"(line 354),assert_contains "$out" "unreadable record"(line 380),assert_contains "$out" "until that is repaired", thehead -n 1leading-line check (line 583), andassert_contains "$out" "not an absolute path"(line 608) would all still pass if poll_refuse's fm_cap_line were changed to write to stderr - which is exactly the silent-forever regression. The tests prove the text is emitted somewhere, not that it is emitted where the watcher reads. Fix: capture stdout only for the poll assertions (e.g. anadmission_stdout()variant that runs with2>/dev/null), and keep the merged helper for the paths that assert die_evidence messages.bin/fm-claude-admission.sh:782- The block comment added at lines 754-762 claims "EVERY refusal reachable from a poll is therefore pre-captured and reported as the one wake line", but two refusals before the store is resolved still exit with stderr only, which the watcher discards.store=$(launch_store 2>/dev/null) || return 0(line 782) swallows launch_store's exit 3 (a non-absolute CLAUDE_CONFIG_DIR, or neither CLAUDE_CONFIG_DIR nor HOME set) and returns silently;resolve_store_state "$store"(line 789) can die_evidence out of store_slug when no shasum/sha256sum is on PATH, exiting 3 with nothing on stdout. In both cases a shaped store holding queued work stays stuck with firstmate never told. Both are pre-STORE_DIR, so poll_refuse already handles that case correctly (it skips the report record and still prints, as the malformed-config path proves) - routing these two through it would make the boundary match the comment. Lower severity than the prior rounds because both causes are environmental rather than data corruption.🔧 Fix: assert poll wakes on stdout, announce pre-store refusals
2 issues (1 warning, 1 info) still open:
bin/fm-spawn.sh:1855- The home-identity guard runs too late on the secondmate path, so a spawn from a foreign Herdr session mutates the child home before refusing. For KIND=secondmate, bin/fm-spawn.sh:1637 fast-forwards the secondmate worktree via ff_target, line 1650 creates $PROJ_ABS/state, and line 1667 runs propagate_secondmate_inheritance (which now also copies the new config/claude-shaped-store, per bin/fm-config-inherit-lib.sh:63) - all beforefm-home-identity.sh ensureat line 1855. Failure sequence: from a session the home does not belong to, run fm-spawn.sh <id> <home> --secondmate; the child home's git HEAD is moved and the wrong parent's local config is written into it, and only then does the identity check refuse with 'this firstmate home does not belong to the current session, and nothing was created' - a claim that is false on that path. The sibling entry points were fixed for exactly this shape in an earlier round (bin/fm-control.sh:129 and bin/fm-send.sh:129 now check immediately after the FM_HOME directory validation). Fix: move theensurecall and the HOME_PIN_SESSION/HOME_PIN_STORE resolution up to just after FM_HOME is resolved (bin/fm-spawn.sh:246), leaving theseedblock where PROJ_ABS exists. Existing coverage (tests/fm-home-identity.test.sh test_spawn_refuses_a_foreign_session_and_creates_nothing) drives an ordinary spawn only, so the secondmate path is unproven.bin/fm-claude-admission.sh:786- The two pre-store poll refusals added this round have no dedupe, so they wake firstmate on every watcher cycle indefinitely. poll_refuse only writes its 'evidence-refusal' report record when STORE_DIR is resolved (bin/fm-claude-admission.sh:770-773), and the launch_store refusal at line 786 and the store_slug refusal at line 793 both fire before resolve_store_state, so each poll re-emits the same wake line. bin/fm-watch.sh:1044-1058 appends a wake and calls wake() for every non-empty check output with no dedupe of its own. Failure sequence: a home that lists a shaped store runs with a relative CLAUDE_CONFIG_DIR (or with neither CLAUDE_CONFIG_DIR nor HOME set, or on a host with no shasum/sha256sum); every FM_CHECK_INTERVAL firstmate is woken with the identical line until a human repairs the environment - burning exactly the agent turns this feature exists to conserve. It also contradicts docs/configuration.md:349 ('the refusal is also reported once per store rather than on every cycle'). Fix: dedupe these two under a home-level marker (the config file exists, so this home is shaping something and a marker under $ADMISSION_ROOT is legitimate), or state the exception in the docs.🔧 Fix: guard identity before any spawn mutation, dedupe poll wakes
2 warnings still open:
bin/fm-spawn.sh:1895- The release-shaping gate runs after the secondmate path has already mutated the child home, so a withheld launch's "nothing was created" is false. For KIND=secondmate, bin/fm-spawn.sh:1661 fast-forwards the child worktree (ff_target), 1673 creates $PROJ_ABS/state, and 1690 runs propagate_secondmate_inheritance - which now also copies config/claude-shaped-store (bin/fm-config-inherit-lib.sh:66) - all before the gate at 1895. Failure sequence: a shaped store is armed and its release slot is spent; a --secondmate claude spawn moves the child home's git HEAD and writes the parent's local config into it, then exits 1 with "error: <id> was not released onto its Claude credential store; nothing was created and the request is preserved above". The block comment added at 1885 ("this point creates no worktree, no endpoint, and no task metadata") is false on this path. Round 3 fixed the identity seed for exactly this shape but only relative to the gate, not relative to the secondmate block above it. Fix: resolve SPAWN_CLAUDE_STORE and run the gate before the secondmate block at 1633 (it needs only HARNESS, the relaunch meta, and HOME_PIN_STORE, all available by then).bin/fm-claude-admission.sh:807- The new pre-store dedupe marker can silence a recurring refusal forever.rm -f -- "$HOME_REFUSAL"(line 807) is only reached once the store is resolved AND shaped; the unshaped branch at line 802 (1) return 0) and the unconfigured-home return leave the marker in place. Failure sequence: a home shaping /work/store with queued work runs with a relative CLAUDE_CONFIG_DIR -> poll_refuse wakes firstmate once and writes .home-evidence-refusal with that reason; the operator repoints CLAUDE_CONFIG_DIR at an unshaped personal store, so the poll returns silently at 802 and the marker is never retired; the same relative value later returns -> poll_refuse matches the stale stamp and exits 3 with empty stdout on every cycle, so the stuck queue on /work/store is never announced. That is the same silent-forever class rounds 4-6 closed elsewhere. Fix: clear HOME_REFUSAL as soon as the pre-store steps succeed (immediately after store_is_shaped returns 0 or 1), not only on the shaped path.🔧 Fix: gate before secondmate mutations, retire stale refusal marker
2 warnings still open:
bin/fm-spawn.sh:1665- The release gate is consuming (action_gate does queue_remove + writes LAST_RELEASE) and round 7 moved it above refusals that still exit 1, with no compensating withdraw anywhere. Below the new boundary and still refusing: secondmate FIRSTMATE_HOME resolution and validate_firstmate_home_for_spawn / secondmate_registry_validate_bindings (bin/fm-spawn.sh:1683-1697), the mkdir/lock failures at 1719-1729, the missing-brief check at 1747, the ship delivery-contract and contradictory-brief refusals at 1858-1890, and the child identity seed at 1924. Failure sequence: a shaped store is armed;fm-spawn.sh fm-x proj --mode direct-PRruns against a brief recordingDelivery contract: mode=no-mistakes. The gate admits, removes fm-x from the durable queue and stamps last-release, then the delivery mismatch exits 1 - so the one release per FM_CLAUDE_RELEASE_INTERVAL is burned by a spawn that created nothing, every legitimately queued worker is delayed a full interval, and fm-x is no longer in the queue that is supposed to preserve it. The same holds for a secondmate whose firstmate home is unregistered and for any missing brief. The boundary comment added at 1633 ('everything above this line is resolution and validation') is not true of the code below it. Fix: hoist the remaining pure-validation refusals above the boundary (or place the gate immediately before the first mutation on each path) rather than placing the gate above validation.bin/fm-claude-admission.sh:806- The relocatedrm -f -- "$HOME_REFUSAL"retires the pre-store dedupe marker before the last refusal that uses it. In action_poll the marker is now removed on shaped_status 0|1 (line 806), butslug=$(store_slug "$store" 2>&1) || poll_refuse "$?" "$slug"(line 809) runs after that and is still pre-store (resolve_store_state has not run, so STORE_DIR is empty and poll_refuse dedupes on HOME_REFUSAL). Failure sequence: a home that shapes a store runs on a host with neither shasum nor sha256sum on PATH; every watcher cycle deletes the marker, store_slug refuses, poll_refuse finds no stamp and emits the wake line again - firstmate is woken with the identical line every FM_CHECK_INTERVAL until a human repairs PATH. That is the repeat the round-7 change was meant to close, and it contradicts docs/configuration.md:349 ('the refusal is also reported once per store rather than on every cycle'). Fix: retire the marker only once every pre-store step has succeeded (after store_slug on the shaped path, and on the unshaped return), not before the last refusal that reads it.🔧 Fix: order spawn refusals before the consuming release gate
2 issues (1 warning, 1 info) still open:
bin/fm-claude-admission.sh:765- The resolved-store half of the poll dedupe is keyed by a CONSTANT stamp, so the "clear-then-recur / a different problem wakes again" invariant that rounds 7-8 closed for the pre-store marker is still broken on the store path.poll_refusesetsstamp=evidence-refusalfor every store-level refusal (line 765) and writes it to $REPORTED (line 784), while the pre-store branch deliberately usesstamp=$reason. $REPORTED is only retired on the admit paths (rm -f -- "$REPORTED"at 686 in action_gate and 722 in action_withdraw, or overwritten with "$head:$last" at 839); action_poll's withhold path returns at 833 without clearing it. Failure sequence A (different problem silenced): a shaped store holds queued work and a transcript under <store>/projects/*/ becomes unreadable -> poll wakes firstmate once and writes $REPORTED=evidence-refusal; the operator repairs the transcript but the release slot is not open yet, so the next poll returns at 833 with the stale marker in place; state/claude-admission/<slug>/queue then gains a torn row -> poll_refuse matches the identical stamp and exits 3 with EMPTY stdout on every cycle. bin/fm-watch.sh:713 discards the check's stderr and ignores its status, so firstmate is never told the queue is stuck and the queued work waits indefinitely - the exact silent-forever class rounds 4-6 were fixed for. Failure sequence B is the same shape without any repair: two distinct evidence problems in a row, only the first announced. Fix: key the store-level stamp by the reason as the pre-store branch does (e.g.stamp="evidence-refusal:$reason"), and retire $REPORTED once a poll gets through every evidence read cleanly, not only when it admits. Coverage: tests/fm-claude-admission.test.sh:337 and :378 each drive a single refusal per fixture, and the census case repairs with FM_TEST_INTERVAL=1 so it lands on the admit path - neither can catch this.bin/fm-spawn.sh:1837- The new phase-boundary comment asserts "a spent release slot always produced a launch", which is stronger than the code can deliver. The gate at 1863-1877 is consuming (queue_remove + LAST_RELEASE), and several non-validation failures still exit 1 below it with no compensating withdraw: the secondmate state mkdir (1903) and inheritance lock (1908-1912), the child identity seed (1946),freshen_spawn_worktree_base(2558), the backend create calls (2165, 2313, 2324, 2336-2349, 2380) and the meta lock (2950). Concretely: tmux's server is gone,fm_backend_tmux_create_taskfails, and the store's one release per FM_CLAUDE_RELEASE_INTERVAL is spent by a spawn that launched nothing while the task is no longer in the durable queue. That residual is inherent - a mutation cannot be validated without mutating - and it is not a regression (the gate previously sat even earlier), so this is a note on the comment's absolute wording rather than a request to move the gate again. Naming the bound ("every REFUSAL precedes the gate; an infrastructure failure after it can still spend a slot") would keep the next change from trusting a guarantee that does not hold.🔧 Fix: key store poll refusals by reason, bound slot guarantee
2 issues (1 warning, 1 info) still open:
tests/fm-claude-admission.test.sh:459- The round-9 code addition - thecase "$(cat -- "$REPORTED")" in evidence-refusal:*) rm -fretire block at bin/fm-claude-admission.sh:833-839 - has no coverage that fails without it. In test_a_different_store_problem_wakes_firstmate_again the clear-then-recur step re-introduces the CENSUS fault (torn.jsonl), but the last stamp written was the SYMLINK reason, so the reasons differ and poll_refuse emits the wake line regardless of whether the retire block exists. Delete the retire block and the test still passes; the assertion "a fault that cleared and recurred must wake firstmate again" therefore cannot fail for the defect it names. Steps 1-3 of the same test are sound (dedupe on repeat, re-wake on a different reason). Fix: make the recurrence the SAME fault that was last reported - repair only the census fault while the queue symlink is the last-reported one, poll cleanly (which must retire the stamp), then re-introduce the symlink and assert the wake line returns. That path fails without the retire block and passes with it.docs/configuration.md:348- docs/configuration.md still says "the refusal is also reported once per store rather than on every cycle, and a refusal that fires before any store could be named is reported once per home the same way". Since round 9 both records dedupe on the concrete PROBLEM, not on the fact of a refusal, so a second, different fault on the same store wakes firstmate again and a cleared fault that recurs is announced. The current wording reads as though one refusal silences the store outright, which is the behavior the change deliberately removed. Add the per-problem qualifier (one sentence per line, plain '-').🔧 Fix: cover the refusal-stamp retirement, document per-problem dedupe
2 infos still open:
bin/fm-claude-admission.sh:848- action_poll pre-captures sorted_queue, armed-since and last-release specifically so their refusals reach stdout through poll_refuse, then calls evaluate, which re-reads all three (bin/fm-claude-admission.sh:530 armed_since, :546 last, :557 sorted_queue) with plain|| exit $?. Only the census is passed in. Consequence is twofold: the durable queue and both epoch records are read twice per poll cycle, and a fault that appears between the pre-capture and the re-read exits 3 with the reason on stderr only, which bin/fm-watch.sh discards - the silent-forever shape rounds 4-6 closed. The window is a few milliseconds so this is a residual, not a reachable defect, but it is removable: pass the already-captured armed/last/sorted values into evaluate the way census already is, and the duplicate I/O and the residual window both go away.tests/fm-claude-admission.test.sh:870- test_a_refusal_after_the_gate_never_spends_the_slot and its comment ("a refusal that lives below the release gate's own position in the file") describe a post-gate refusal, but the delivery mismatch it triggers is emitted at bin/fm-spawn.sh:1784, above the phase boundary at :1820 and above the gate at :1870. The test really proves the phase-1 ordering (a validation refusal never reaches the gate), which is valuable and does fail if the gate is hoisted back above the mismatch. As written the name asserts coverage of the case the phase comment at bin/fm-spawn.sh:1837 explicitly says is NOT guaranteed (an infrastructure failure below the gate can still spend a slot), so a later reader may trust a guarantee no test holds. Rename to reflect that the refusal precedes the gate and drop the "below the gate" comment.✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-claude-admission.test.sh tests/fm-home-identity.test.sh tests/fm-control-relaunch.test.sh tests/fm-remote-secondmate-identity.test.sh tests/fm-secondmate-safety.test.sh tests/fm-spawn-dispatch-profile.test.sh tests/fm-herdr-lab.test.shGIT_TEMPLATE_DIR=/tmp/empty-git-template bin/fm-test-run.sh tests/fm-secondmate-safety.test.sh(re-run after isolating the machine's global pre-commit hook template)Manual walkthrough script drivingbin/fm-claude-admission.sh demand|gate|queueagainst a shaped Geris store with three parked sessions and an unshaped personal storeManual walkthrough drivingbin/fm-home-identity.sh ensure|show|checkfor geris and personal homes, including both cross-session refusal directions and a store-repoint refusalgit status --porcelainto confirm the worktree was left clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.