Skip to content

fix(bin): keep a probe's private status-read settings out of the Herdr server it starts - #5622

Closed
aviyashchin wants to merge 3 commits into
kunchenguid:mainfrom
aviyashchin:fm/fm-herdr-env-leak
Closed

aviyashchin wants to merge 3 commits into
kunchenguid:mainfrom
aviyashchin:fm/fm-herdr-env-leak

Conversation

@aviyashchin

Copy link
Copy Markdown

Intent

Fix the status tool. After a fleet snapshot, every new terminal window inherited private status-read settings, so bin/fm-crew-state.sh <id> in those windows read one frozen task's records and reported "no metadata" for every other task.

Observed evidence: the live herdr server --session default process has parent bash bin/fm-crew-state.sh fm-provider-repair. bin/fm-fleet-snapshot.sh crew_state_json runs fm-crew-state.sh with FM_CREW_STATE_META_OVERRIDE, FM_CREW_STATE_STATUS_OVERRIDE (and other FM_*_OVERRIDE values) scoped to that child. The Herdr probe inside it auto-started the Herdr server, which inherited those values. Every pane the server created afterwards, including the captain's Claude session, carried FM_CREW_STATE_META_OVERRIDE=<tmp>/fm-provider-repair.meta. FM_SESSION_START_STAGE_FILE, FM_SESSIONSTART_SUPERVISOR_PID, FM_HOME_SUMMARY_IF_IDLE and FM_HOME_SUMMARY_WORKER_BEST_EFFORT leaked the same way.

What Changed

  • fm_backend_herdr_server_ensure in bin/backends/herdr.sh now removes every FM_*_OVERRIDE and FM_HOME_SUMMARY_PARENT_* variable by pattern before it starts the Herdr server. The old code removed a fixed list of names. It also unsets the call-scoped FM_SESSION_START_STAGE_FILE, FM_SESSIONSTART_SUPERVISOR_PID, FM_HOME_SUMMARY_IF_IDLE, FM_HOME_SUMMARY_WORKER_BEST_EFFORT, FM_CREW_STATE_NO_FORGE, and FM_CREW_STATE_BIN. A read-only probe such as fm-crew-state.sh inside fm-fleet-snapshot.sh can start the server. When that happened, the server passed that probe's frozen FM_CREW_STATE_META_OVERRIDE and similar values to every pane it created later. Documented tuning knobs such as FM_SESSION_START_TIMEOUT, FM_HOME_SUMMARY_FAILURE_REPORT, and FM_CREW_STATE_RUNS_LIMIT still reach panes.
  • docs/herdr-backend.md now lists the settings that are removed at server start and the documented knobs that are kept.
  • A new test, test_server_ensure_scrubs_private_call_scoped_settings, in tests/fm-backend-herdr.test.sh starts the server with those call-scoped settings set. It checks that the call-scoped settings are unset in the server environment and that the documented knobs and unrelated variables are kept.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is confined to the subshell that starts the Herdr server. It removes every FM_OVERRIDE and FM_HOME_SUMMARY_PARENT value, plus the named call-scoped settings from the intent. Documented operator knobs, including FM_HOME_SUMMARY_FAILURE_REPORT, still pass through. The new test runs the real function against a fake server, so it fails without the fix.

Testing

I ran the Herdr backend test file once and it passed, including the new regression test for private call-scoped settings. I also ran a manual before/after reproduction with a fake herdr server that records its startup environment. On base a8572f6 the auto-started server inherited FM_CREW_STATE_META_OVERRIDE=/tmp/snap/fm-provider-repair.meta and the other call-scoped settings named in the intent. Every later pane gets that environment, which is why fm-crew-state.sh &lt;id&gt; read one frozen task. On target a03419f those settings are gone. FM_SESSION_START_TIMEOUT, FM_SESSION_START_QUEUED_LIMIT, FM_SESSION_START_STATUS_TAIL, FM_HOME_SUMMARY_INTERVAL, FM_HOME_SUMMARY_TIMEOUT, FM_HOME_SUMMARY_FAILURE_REPORT, FM_CREW_STATE_RUNS_LIMIT and FM_CREW_STATE_NM_TIMEOUT still reach the server with their values. The trailing --session default routing flag is kept. This change has no UI, so visual evidence does not apply. The worktree is clean.

Evidence: Server environment before/after the fix (fleet-snapshot probe auto-starts Herdr)

Source: Server environment before/after the fix (fleet-snapshot probe auto-starts Herdr)

BEFORE (a8572f6): FM_CREW_STATE_META_OVERRIDE=/tmp/snap/fm-provider-repair.meta, FM_CREW_STATE_STATUS_OVERRIDE, FM_CREW_STATE_NO_FORGE, FM_CREW_STATE_BIN, FM_SESSION_START_STAGE_FILE, FM_SESSIONSTART_SUPERVISOR_PID, FM_HOME_SUMMARY_IF_IDLE, FM_HOME_SUMMARY_WORKER_BEST_EFFORT, FM_HOME_SUMMARY_PARENT_STAMP all inherited by herdr server. AFTER (a03419f): all of those are absent. These remain with their values: FM_SESSION_START_TIMEOUT=300, FM_SESSION_START_QUEUED_LIMIT=7, FM_SESSION_START_STATUS_TAIL=9, FM_HOME_SUMMARY_INTERVAL=90, FM_HOME_SUMMARY_TIMEOUT=11, FM_HOME_SUMMARY_FAILURE_REPORT=5, FM_CREW_STATE_RUNS_LIMIT=50, FM_CREW_STATE_NM_TIMEOUT=25. args=server --session default

# Environment inherited by a 'herdr server' auto-started from a fleet-snapshot crew-state probe

## BEFORE (base a8572f6)
server_ensure rc=0
FM_CREW_STATE_BIN=/tmp/stub
FM_CREW_STATE_META_OVERRIDE=/tmp/snap/fm-provider-repair.meta
FM_CREW_STATE_NM_TIMEOUT=25
FM_CREW_STATE_NO_FORGE=1
FM_CREW_STATE_RUNS_LIMIT=50
FM_CREW_STATE_STATUS_OVERRIDE=/tmp/snap/fm-provider-repair.status
FM_HOME_SUMMARY_FAILURE_REPORT=5
FM_HOME_SUMMARY_IF_IDLE=1
FM_HOME_SUMMARY_INTERVAL=90
FM_HOME_SUMMARY_PARENT_STAMP=s
FM_HOME_SUMMARY_TIMEOUT=11
FM_HOME_SUMMARY_WORKER_BEST_EFFORT=1
FM_SESSIONSTART_SUPERVISOR_PID=4242
FM_SESSION_START_QUEUED_LIMIT=7
FM_SESSION_START_STAGE_FILE=/tmp/stage
FM_SESSION_START_STATUS_TAIL=9
FM_SESSION_START_TIMEOUT=300
HERDR_SESSION=default
args=server --session default

## AFTER (target a03419f)
server_ensure rc=0
FM_CREW_STATE_NM_TIMEOUT=25
FM_CREW_STATE_RUNS_LIMIT=50
FM_HOME_SUMMARY_FAILURE_REPORT=5
FM_HOME_SUMMARY_INTERVAL=90
FM_HOME_SUMMARY_TIMEOUT=11
FM_SESSION_START_QUEUED_LIMIT=7
FM_SESSION_START_STATUS_TAIL=9
FM_SESSION_START_TIMEOUT=300
HERDR_SESSION=default
args=server --session default

## diff before -> after
1,2d0
< FM_CREW_STATE_BIN=/tmp/stub
< FM_CREW_STATE_META_OVERRIDE=/tmp/snap/fm-provider-repair.meta
4d1
< FM_CREW_STATE_NO_FORGE=1
6d2
< FM_CREW_STATE_STATUS_OVERRIDE=/tmp/snap/fm-provider-repair.status
8d3
< FM_HOME_SUMMARY_IF_IDLE=1
10d4
< FM_HOME_SUMMARY_PARENT_STAMP=s
12,13d5
< FM_HOME_SUMMARY_WORKER_BEST_EFFORT=1
< FM_SESSIONSTART_SUPERVISOR_PID=4242
15d6
< FM_SESSION_START_STAGE_FILE=/tmp/stage
(temp dir: /var/folders/4b/mqh8hr814rn6lcm3639vqnnr0000gn/T/tmp.LDmYl5BV3q)
Evidence: Reproduction script

Source: Reproduction script

#!/usr/bin/env bash
# Reproduce the Herdr server env leak before/after the fix.
# Usage: repro-server-env.sh <worktree>
# Simulates fm-fleet-snapshot.sh -> fm-crew-state.sh fm-provider-repair, whose
# Herdr probe auto-starts the long-lived server. A fake `herdr server` records
# the environment the server (and so every later pane) inherits.
set -u
WT=$1
T=$(mktemp -d)
mkdir -p "$T/base" "$T/fb"
git -C "$WT" archive a8572f6 bin | tar -x -C "$T/base"
cat > "$T/fb/herdr" <<'SH'
#!/usr/bin/env bash
case "${1:-}" in
  status) if [ -e "$MARK" ]; then echo '{"server":{"running":true}}'; else echo '{"server":{"running":false}}'; fi ;;
  server) { env | grep -E '^(FM_|HERDR_SESSION)' | sort; echo "args=$*"; } > "$LOG"; : > "$MARK" ;;
esac
SH
chmod +x "$T/fb/herdr"
run() {  # <label> <root>
  PATH="$T/fb:$PATH" LOG="$T/$1.env" MARK="$T/$1.mark" \
    FM_CREW_STATE_META_OVERRIDE=/tmp/snap/fm-provider-repair.meta FM_CREW_STATE_STATUS_OVERRIDE=/tmp/snap/fm-provider-repair.status \
    FM_CREW_STATE_NO_FORGE=1 FM_CREW_STATE_BIN=/tmp/stub \
    FM_SESSION_START_STAGE_FILE=/tmp/stage FM_SESSIONSTART_SUPERVISOR_PID=4242 \
    FM_HOME_SUMMARY_IF_IDLE=1 FM_HOME_SUMMARY_WORKER_BEST_EFFORT=1 FM_HOME_SUMMARY_PARENT_STAMP=s \
    FM_SESSION_START_TIMEOUT=300 FM_SESSION_START_QUEUED_LIMIT=7 FM_SESSION_START_STATUS_TAIL=9 \
    FM_HOME_SUMMARY_INTERVAL=90 FM_HOME_SUMMARY_TIMEOUT=11 FM_HOME_SUMMARY_FAILURE_REPORT=5 \
    FM_CREW_STATE_RUNS_LIMIT=50 FM_CREW_STATE_NM_TIMEOUT=25 \
    bash -c '. "$0/bin/backends/herdr.sh"; fm_backend_herdr_server_ensure default; echo "server_ensure rc=$?"' "$2"
}
echo "# Environment inherited by a 'herdr server' auto-started from a fleet-snapshot crew-state probe"
echo
echo "## BEFORE (base a8572f6)"; run before "$T/base"; cat "$T/before.env"
echo
echo "## AFTER (target a03419f)"; run after "$WT"; cat "$T/after.env"
echo
echo "## diff before -> after"; diff "$T/before.env" "$T/after.env"
echo "(temp dir: $T)"
Evidence: Herdr backend test file log

Source: Herdr backend test file log

ok - fm_backend_herdr_version_check: accepts the current protocol (14)
ok - fm_backend_herdr_version_check: refuses an old protocol loudly
ok - fm_backend_herdr_version_check: refuses loudly when herdr is not installed
ok - fm_backend_herdr_workspace_label: a primary home (no marker) resolves to 'firstmate'
ok - fm_backend_herdr_workspace_label: a secondmate home (.fm-secondmate-home) resolves to '2ndmate-<id>'
ok - fm_backend_herdr_workspace_label: trims whitespace around the marker's secondmate id
ok - fm_backend_herdr_workspace_label: an empty marker file falls back to the primary label 'firstmate'
ok - fm_backend_herdr_workspace_label: two different secondmate homes get two different, non-colliding labels
ok - fm_backend_herdr_cli: sets HERDR_SESSION AND appends a trailing --session flag on every call
ok - herdr client selection: a live pane behind a stale shadowing client reads alive
ok - herdr recovery-grade read: a stopped server means missing there, and nowhere else
ok - herdr stale registration: a shell-only pane with a lingering Pi record is agent-free with an explicit reason
ok - herdr stale registration: no registered status can outrank a shell-only process view
ok - herdr stale registration: a registered agent with a live Pi foreground process still reads alive
ok - herdr stale registration: only a shell-only pane demotes a registration
ok - herdr stale registration: a transient prompt helper settles into stale-agent instead of reading live
ok - herdr stale registration: an exhausted settle window still reads a non-shell foreground as live
sh: line 1: 24999 Terminated: 15          '/private/var/folders/4b/mqh8hr814rn6lcm3639vqnnr0000gn/T/fm-backend-herdr-tests.fAqewx/stale-reg-descendant-bin/pi' 300
ok - herdr stale registration: an agent process outside the foreground group still counts as alive
sh: line 1: 25783 Terminated: 15          '/private/var/folders/4b/mqh8hr814rn6lcm3639vqnnr0000gn/T/fm-backend-herdr-tests.fAqewx/stale-reg-spaced-bin/Application Support/Some Dir/pi' 300
ok - herdr stale registration: the descendant walk reads a spaced executable path whole
ok - herdr stale registration: an unreadable process view refuses instead of guessing either way
ok - herdr stale registration: an empty foreground list over a real shell is not unreadable, it settles via the descendant walk
ok - herdr stale registration: presentation reclaim never closes a stale-registration pane
ok - herdr stale registration: busy_state proves a working record at process level before reporting busy
ok - herdr client selection: one selected client is reused per process
ok - herdr client selection: selected clients remain scoped to their session
ok - herdr client selection: only protocol_mismatch triggers reselection; other failures pass through untouched
ok - herdr client selection: the happy path makes no extra call
ok - herdr client status: .server.compatible, legacy protocol equality, unknown, and stopped shapes all normalize
ok - fm_backend_herdr_launcher_identity: a firstmate not running inside herdr has no launcher workspace to inherit
ok - fm_backend_herdr_launcher_identity: HERDR_ENV=1 without a pane id selects the backend but binds no parent
ok - fm_backend_herdr_launcher_identity: resolves the launcher's exact workspace even when a same-labeled workspace sorts first
ok - fm_backend_herdr_launcher_identity: refuses a launcher pane that names a different herdr session
ok - fm_backend_herdr_launcher_identity: refuses a claimed pane without exact server identity
ok - fm_backend_herdr_launcher_identity: refuses a launcher pane whose injected socket belongs to another herdr server
ok - fm_backend_herdr_launcher_identity: refuses when the launcher's own pane no longer resolves
ok - fm_backend_herdr_launcher_identity: refuses when the launcher's pane and tab disagree about their workspace
ok - fm_backend_herdr_launcher_identity: refuses when the launcher's workspace is gone from its own session
ok - fm_backend_herdr_workspace_ensure: places a worker in the launcher's exact workspace, not the first same-labeled one
ok - fm_backend_herdr_workspace_ensure: refuses to guess between two same-labeled home workspaces
ok - fm_backend_herdr_workspace_ensure: a --secondmate container resolves that home's own workspace, not the launcher's
ok - fm_backend_herdr_container_ensure: surfaces the exact ambiguous-placement refusal instead of a generic failure
ok - fm_backend_herdr_container_ensure: version-gates, starts the server, ensures the firstmate workspace, echoes session:workspace_id + the seeded default tab id
ok - fm_backend_herdr_server_ensure: scrubs home and harness identity without disturbing unrelated environment or session routing
ok - fm_backend_herdr_server_ensure: scrubs call-scoped status-read and session-start settings but keeps documented knobs
ok - fm_backend_herdr_container_ensure: reuses an existing firstmate workspace without recreating it, and reports no seeded default tab (adopted, not created)
ok - fm_backend_herdr_container_ensure: workspace create passes --no-focus
ok - fm_backend_herdr_container_ensure: creates the workspace under the SECONDMATE home's own label, not 'firstmate'
ok - fm_backend_herdr_create_task: prunes exactly the seeded default tab container_ensure identified, once the first real task tab exists
ok - herdr repeated spawn/teardown: one persistent firstmate workspace reused, zero orphans, default tab pruned, create ran once
ok - fm_backend_herdr_create_task: an ADOPTED workspace's pre-existing tab is never pruned (the created-vs-adopted gate)
ok - fm_backend_herdr_create_task: the label-collision startup-workspace scenario (2026-07-02 incident) leaves the captain's live tab untouched
ok - fm_backend_herdr_workspace_prune_seeded_default_tab: refuses to close the seeded default tab when its pane reports a working agent (defense in depth)
ok - fm_backend_herdr_create_task: refuses a duplicate tab label (herdr's own tab create has no uniqueness check)
ok - fm_backend_herdr_create_task: a same-labeled tab with a live (even idle) registered agent still refuses exactly as before
ok - fm_backend_herdr_create_task: scans every same-labeled tab and refuses if any duplicate is live
ok - fm_backend_herdr_create_task: closes and replaces a same-labeled tab whose pane is dead (pane_not_found)
ok - fm_backend_herdr_create_task: closes and replaces a same-labeled tab whose pane is alive but hosts no registered agent (a restored plain shell)
ok - fm_backend_herdr_create_task: closes every confirmed same-labeled husk only after creating the replacement
ok - fm_backend_herdr_create_task: refuses success when a preexisting husk tab remains after replacement
ok - fm_backend_herdr_create_task: refuses (fail-safe) rather than guessing when the duplicate's agent state cannot be classified confidently
ok - fm_backend_herdr_create_task: creates the replacement tab BEFORE closing the husk tab, never the reverse
ok - fm_backend_herdr_create_task: creates a tab and parses tab_id/pane_id from the JSON response, prunes nothing when no seeded tab id is given
ok - fm_backend_herdr_create_task: tab create passes --no-focus
ok - herdr presentation: a home that set nothing gets the projection by default at or above the floor
ok - herdr presentation: an unconfigured home below the floor falls back flat with one naming warning
ok - herdr presentation: an unreadable client release falls back flat instead of guessing
ok - herdr presentation: a deliberate opt-in is never silently downgraded below the floor
ok - herdr presentation: an explicit off opts the home out
ok - herdr presentation: an unrecognized value warns and follows the default instead of failing a spawn
ok - herdr presentation: the below-floor warning is one per home per release, not one per spawn
ok - herdr presentation: warning marker publication is atomic, symlink-safe, and fails visible
ok - herdr presentation: client and selected server floors compose conservatively without overriding explicit opt-in
ok - herdr presentation floor: every measured release, and each signal alone, classifies correctly
ok - herdr presentation floor: either signal alone can carry an above verdict, and each

... [8339 bytes truncated] ...

t row below a stale bordered decorative box still wins (not misread as the box's own row)
ok - fm_backend_herdr_composer_state: claude's dim prompt-suggestion ghost (the overnight wedge shape) reads empty
ok - fm_backend_herdr_composer_state: real typed text on the same claude prompt row still reads pending
ok - fm_backend_herdr_composer_state: grok's dark-truecolor placeholder (the TRUECOLOR gap) reads empty
ok - fm_backend_herdr_composer_state: grok's real bright typed input still reads pending
ok - fm_backend_herdr_composer_state: a real-codex unbordered '›' prompt row reads empty
ok - fm_backend_herdr_composer_state: a faint real-codex ghost suggestion reads empty
ok - fm_backend_herdr_composer_state: non-faint codex prompt text still reads pending
ok - fm_backend_herdr_wait_for_working: reports 'busy' immediately on the first poll, without spending the rest of the budget
ok - fm_backend_herdr_wait_for_working: a slow transition landing on a later sample within one window is still caught (robust against the 'slow transition' failure direction)
ok - fm_backend_herdr_wait_for_working: spreads six samples across the full budget endpoint without a final trailing sleep
ok - fm_backend_herdr_send_text_submit: applies the herdr minimum confirmation budget before polling agent-state
ok - fm_backend_herdr_wait_for_working: reports 'idle' (readable, genuinely not yet working) when 'busy' never appears
ok - fm_backend_herdr_wait_for_working: reports 'unknown' (a hard read failure, not a timing race) only when EVERY poll in the window fails
ok - fm_backend_herdr_wait_for_working: treats blocked as submit-active for confirmation without changing watcher busy-state semantics
ok - fm_backend_herdr_send_text_submit: reports 'empty' once agent_status reports working after one Enter, without ever reading the composer
ok - fm_backend_herdr_send_text_submit: reports 'pending' when agent_status stays idle and the composer still holds unsent text after retried Enters (swallowed)
ok - fm_backend_herdr_send_text_submit: a slash-command popup's placeholder fill on Enter #1 never flips agent_status to working, so it does not short-circuit as submitted; Enter #2 is retried and lands it
ok - fm_backend_herdr_send_text_submit: a post-Enter blocked state confirms delivery without retrying into the prompt
ok - fm_backend_herdr_send_text_submit: native working + proven pending after retries reports empty (queued Enter)
ok - fm_backend_herdr_send_text_submit: a failed Enter cannot borrow preexisting working state as queued-delivery proof
ok - fm_backend_herdr_send_text_submit: a failed Enter cannot borrow a later native transition as delivery proof
ok - fm_backend_herdr_send_text_submit: idle native agent-state plus empty composer reports empty (landed Claude turn)
ok - fm_backend_herdr_send_text_submit: idle native baseline uses a rendered busy footer to confirm a queued Enter
ok - fm_backend_herdr_composer_state: cursor's mid-turn placeholder-plus-busy-token row reads pending (why delivery needs a separate signal)
ok - fm_backend_herdr_rendered_busy_state: busy/idle/unknown from the rendered footer, with an unreadable pane never reading idle
ok - fm_backend_herdr_send_text_submit: a rendered-footer idle-to-busy transition confirms delivery when native agent-state never reports idle
ok - fm_backend_herdr_send_text_submit: an already-busy footer baseline is never accepted as proof that this Enter landed
ok - fm_backend_herdr_send_text_submit: confirms submission via native agent-state alone, immune to a codex-style dynamic idle-tip composer that would have misread as 'pending' under the old composer-based confirmation
ok - fm_backend_herdr_composer_state: a faint real-codex dynamic idle-tip composer row reads empty
ok - fm_backend_composer_state (herdr): the pre-injection empty-box guard still refuses a genuinely non-empty composer, unaffected by the submit-confirmation change
ok - fm_backend_herdr_send_text_submit: a slow transition landing on a later sample within one Enter's budget is confirmed WITHOUT sending a needless extra Enter
ok - fm_backend_herdr_send_text_submit: reports 'send-failed' when the literal send-text call itself errors
ok - fm_backend_herdr_send_text_submit: reports 'unknown' when the post-Enter agent-get read fails (never retries past an unreadable target)
ok - fm_backend_herdr_send_text_submit: an unreadable composer stops Enter retries after native status stays idle
ok - fm_backend_herdr_send_text_submit: a 1500-character payload a Claude composer still holds is submitted whole
ok - fm_backend_herdr_send_text_submit: a long payload whose Claude composer kept only the tail is not submitted, is cleared, and reports send-failed
ok - fm_backend_herdr_send_text_submit: a refused suffix whose clear cannot be verified reports unknown, not send-failed
ok - fm_backend_herdr_send_text_submit: a refused 480-character suffix wrapped over five rows is cleared one row per Ctrl+U and reports send-failed
ok - fm_backend_herdr_send_text_submit: after a refused suffix is cleared, a resend starts from an empty Claude composer and submits only the message
ok - fm_backend_herdr_send_text_submit: a Claude composer holding leftover text is refused before anything is typed
ok - fm_backend_herdr_send_text_submit: a matching head in the transcript does not prove the current composer
ok - fm_backend_herdr_send_text_submit: an away-mode digest and a marked steer are submitted when Claude's read-back only drops U+2063
ok - fm_backend_herdr_send_text_submit: dropping U+2063 does not let a marked digest missing its head be submitted
ok - fm_backend_herdr_send_text_submit: a lone paste placeholder still submits the full long payload
ok - fm_backend_herdr_send_text_submit: a lone multi-line paste placeholder still submits the long multi-line payload
ok - fm_backend_herdr_send_text_submit: a paste placeholder followed by a literal remainder is not submitted and is cleared
ok - fm_backend_herdr_send_text_submit: three paste placeholders with no literal remainder submit the long payload
ok - fm_backend_herdr_send_text_submit: non-Claude and unidentified panes keep the pre-proof type-then-Enter behavior
ok - fm_backend_validate: herdr is a known backend (P2)
ok - fm_backend_busy_state: tmux (no native primitive) always reports unknown, preserving the P1 regex-only path
error: unknown backend 'bogus' (known: tmux herdr zellij orca cmux)
ok - fm_backend_composer_state dispatches every backend to its named thin classifier, unknown for unrecognized backends
ok - fm-peek/fm-send: explicit stale targets matching metadata use the recorded backend
ok - fm_backend_herdr_normalize_event routes through the shared record with an empty from_status
ok - fm_backend_herdr_escalation_marker keys the dedupe marker exactly like the watcher's .stale-<key>
ok - fm_backend_herdr_apply_transition: blocked dedupe starts only after explicit commit
ok - fm_backend_herdr_apply_transition: a working edge clears the marker so the next ->blocked re-escalates
ok - fm_backend_herdr_clear_transition removes task-owned dedupe state
ok - fm_backend_herdr_apply_transition: idle/done (defer) and unknown/empty (fallback) take no fast action
ok - fm_backend_herdr_wait_transition: a home with no herdr panes falls back to polling (rc 2)
ok - fm_backend_herdr_wait_transition: below-capability protocol/schema falls back to polling (rc 2)
ok - fm_backend_herdr_wait_transition: reconnect level-reconcile returns an uncommitted blocked pane
ok - fm_backend_herdr_wait_transition: subscribes before reconnect level-reconcile
ok - fm_backend_herdr_wait_transition: a still-blocked, already-escalated pane is not re-delivered on reconnect
ok - fm_backend_herdr_wait_transition: a streamed ->blocked edge returns the record sub-poll
ok - fm_backend_herdr_wait_transition: streamed working clears the marker, idle/done are deferred (clean timeout)
ok - fm_backend_herdr_wait_transition: a reader/subscribe failure falls back to polling (rc 2)
ok - fm_backend_herdr_wait_transition: Bash 3.2-safe bad-ack path closes fd 9 and removes its FIFO
ok - fm_backend_herdr_wait_transition: stock macOS Bash clean timeout closes fd 9 and returns 1

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • ⚠️ bin/backends/herdr.sh:1669 - The prefix scrub goes further than the intent. The intent names these call-scoped variables: FM_CREW_STATE_META_OVERRIDE, FM_CREW_STATE_STATUS_OVERRIDE, the FM_OVERRIDE values, FM_SESSION_START_STAGE_FILE, FM_SESSIONSTART_SUPERVISOR_PID, FM_HOME_SUMMARY_IF_IDLE and FM_HOME_SUMMARY_WORKER_BEST_EFFORT. The patterns FM_CREW_STATE_*|FM_SESSION_START_*|FM_HOME_SUMMARY_* also remove documented runtime knobs listed under 'Environment variables' in docs/configuration.md (lines 1184-1230): FM_SESSION_START_TIMEOUT, FM_SESSION_START_QUEUED_LIMIT, FM_SESSION_START_STATUS_TAIL, FM_HOME_SUMMARY_INTERVAL, FM_HOME_SUMMARY_TIMEOUT, FM_CREW_STATE_NM_TIMEOUT and FM_CREW_STATE_RUNS_LIMIT. Example: an operator exports FM_SESSION_START_TIMEOUT=300, then fm-spawn.sh or fm-afk-launch.sh auto-starts the Herdr server. Every pane that server creates, including the captain session, falls back without warning to the 120s default. Before this change that value was inherited. Before this change these knobs also passed through the fixed-name unset list. docs/configuration.md does not mention this Herdr exception. Decide which option you want. Option 1: keep the FMOVERRIDE prefix and scrub only the call-scoped names: FM_SESSION_START_STAGE_FILE, FM_SESSIONSTART_SUPERVISOR_PID, the FM_HOME_SUMMARY_IF_IDLE/WORKER_BEST_EFFORT/PARENT*/FAILURE_REPORT group, FM_CREW_STATE_NO_FORGE and FM_CREW_STATE_BIN. Option 2: keep the broad prefixes deliberately and document in configuration.md that these knobs do not reach panes of a Herdr server that Firstmate auto-starts.
  • ℹ️ bin/backends/herdr.sh:1662 - The fix applies only when the server starts. An already-running server is reused unchanged. The live herdr server --session default from the evidence, whose parent is fm-crew-state.sh fm-provider-repair, keeps passing FM_CREW_STATE_META_OVERRIDE and the other leaked values to new panes until someone restarts it. This is expected and needs no code change. The operator must restart that server once after deploy before fm-crew-state.sh &lt;id&gt; works in new windows.

🔧 Fix: Scrub only call-scoped Herdr settings, keep documented knobs
1 info still open:

  • ℹ️ bin/backends/herdr.sh:1668 - FM_HOME_SUMMARY_FAILURE_REPORT is removed by name as if it were call-scoped, but no code sets it for a single call. It is only read, at bin/fm-bootstrap.sh:1482. docs/configuration.md:1197 also lists it as an operator setting (default 2). Example: an operator exports FM_HOME_SUMMARY_FAILURE_REPORT=5 and a probe auto-starts the Herdr server. The captain pane's session-start then silently uses the default of 2. This follows the round-1 instruction, which named it in the scrub list. The same instruction also says documented operator knobs must still reach panes, so the two parts conflict for this variable. Decide whether to keep scrubbing it or remove it from the unset list. Then update the matching assertion in tests/fm-backend-herdr.test.sh and the docs/herdr-backend.md sentence. Impact is small: only the threshold for reporting failures in the home-summary line changes.

🔧 Fix: Pass FM_HOME_SUMMARY_FAILURE_REPORT through to Herdr panes
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-backend-herdr.test.sh: whole Herdr backend test file, exit 0. Includes the new test_server_ensure_scrubs_private_call_scoped_settings and the existing test_server_ensure_scrubs_home_and_harness_identity.
  • bash /Users/aviyashchin/.no-mistakes/evidence/01M3B8ME6SED3HH0V112CENM5T/repro-server-env.sh &lt;worktree&gt;: before/after reproduction. The script calls fm_backend_herdr_server_ensure default from base a8572f6 (extracted with git archive) and from target a03419f. The caller environment copies the fleet-snapshot fm-crew-state.sh fm-provider-repair probe plus operator tuning knobs. A fake herdr server records the environment it inherits.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…r server it starts

A fleet snapshot runs fm-crew-state.sh with FM_CREW_STATE_META_OVERRIDE and related call-scoped settings. When that read-only probe was the first call to need the Herdr server, the server inherited those values and passed them to every later pane, so crew-state in new windows read one frozen task's records.

The server start already removed a fixed name list; it now also removes every FM_*_OVERRIDE and the FM_CREW_STATE_*, FM_SESSION_START_*, FM_SESSIONSTART_*, and FM_HOME_SUMMARY_* families by prefix. Scrubbing at the single server-start owner covers every probe and session-start path that can start a server, which is smaller than making each read-only caller avoid starting one.
@aviyashchin aviyashchin closed this by deleting the head repository Oct 8, 2026
andrewesweet added a commit to andrewesweet/firstmate that referenced this pull request Oct 17, 2026
bin/fm-crew-state.sh honours FM_CREW_STATE_META_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE only when the override's basename is the requested task's own .meta or .status file name.
An override naming a different task, for example one inherited through a server started inside another task's snapshot child, falls through to the task's own records under the state directory.
A snapshot's own override, which names the task it was captured for, is still honoured.
This is complementary to kunchenguid#5622, which keeps the overrides out of the Herdr server launch: whatever path leaks an override, the reader never trusts one that names a different task.
Regression tests cover a mismatched override being ignored and a matching one being honoured.
kunchenguid pushed a commit that referenced this pull request Oct 17, 2026
* Guard fm-crew-state overrides by task-name basename

bin/fm-crew-state.sh honours FM_CREW_STATE_META_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE only when the override's basename is the requested task's own .meta or .status file name.
An override naming a different task, for example one inherited through a server started inside another task's snapshot child, falls through to the task's own records under the state directory.
A snapshot's own override, which names the task it was captured for, is still honoured.
This is complementary to #5622, which keeps the overrides out of the Herdr server launch: whatever path leaks an override, the reader never trusts one that names a different task.
Regression tests cover a mismatched override being ignored and a matching one being honoured.

* no-mistakes(review): Make metadata override tests behaviorally distinct
max-metaplanet added a commit to max-metaplanet/firstmate that referenced this pull request Oct 19, 2026
* feat(herdr): opt-in project groups with status tags and a sorted agents view (kunchenguid#7434)

* feat(herdr): opt-in project groups with status tags and a sorted agents view

Add config/herdr-project-groups (absent or off: unchanged behavior). When on,
Firstmate tags each Herdr task pane, and its own projected workspace, with
display-only fm_group/fm_state/fm_task/fm_sort tokens, sets a Herdr agents
view sorted by group then status (needs-captain, problem, running, done), and
places a new projected task at the end of its own group inside the parent
block with the same single verified move as before.

The watcher reconciles tags once per poll and a spawn tags its task at once;
bin/fm-herdr-groups.sh also previews (plan), clears, and prints or appends
suggested sidebar rows with a backup. The agents view helper needs python3.
The only test-runner change is the serial weight hint for the new suite.

* docs(herdr): record the live lab check of project groups

The four hand checks for tags, the sorted agents view, placement at the
end of the group, and clear passed against a real Herdr 0.9.5 server
(protocol 22) in a guarded lab session.

* docs(herdr): align project group verification notes with the live check

* fix(bin): pin LC_ALL=C for remote job process identity reads (kunchenguid#7410)

ps -o lstart= renders in the caller's locale, so a lock or claim owner
recorded under one locale (de_DE renders "Di Okt 13 ...") failed identity
verification under another, was declared dead, and a second worker split
the queue: two serve loops reclaimed and reaped each other's live jobs,
which vanished mid-claim and failed staged jobs with exit 125 and no
output. Pin LC_ALL=C in fm_remote_job_process_start and pin the
cross-locale invariant with a regression test.

Co-authored-by: researchworldwide2026 <[email protected]>

* fix(opencode): ignore child stdin EPIPE in guard and encoder (kunchenguid#7447)

* fix(bin): ignore crew state overrides for other tasks (kunchenguid#5881)

* Guard fm-crew-state overrides by task-name basename

bin/fm-crew-state.sh honours FM_CREW_STATE_META_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE only when the override's basename is the requested task's own .meta or .status file name.
An override naming a different task, for example one inherited through a server started inside another task's snapshot child, falls through to the task's own records under the state directory.
A snapshot's own override, which names the task it was captured for, is still honoured.
This is complementary to kunchenguid#5622, which keeps the overrides out of the Herdr server launch: whatever path leaks an override, the reader never trusts one that names a different task.
Regression tests cover a mismatched override being ignored and a matching one being honoured.

* no-mistakes(review): Make metadata override tests behaviorally distinct

* fix(bin): re-anchor a Claude session's lock so /clear keeps ownership (kunchenguid#7415)

* fix(bin): re-anchor a Claude session's lock so /clear keeps ownership

A same-session confirmation over a live lock line 1 outside the current
harness ancestry now rewrites line 1 to the session's CLAUDE_PID anchor
under the claim lock, so a later /clear re-key in the same process is
still proven by ancestry instead of being refused as a foreign owner.

Fixes kunchenguid#6820

* fix(bin): move task leases with a session-lock re-anchor

A same-session re-anchor rewrote lock line 1 off a live pid while task
leases still named that pid, so a lease held by main or the supervision
branch read as stale and the other actor could claim the task. The
re-anchor now takes the lease-command lock after the claim lock and,
in the same critical section as the line-1 write, rewrites leases
recorded against the old pid to the new anchor (fm_lease_rekey_holder).
If the lease-command lock stays busy past a short bound, the
confirmation keeps line 1 as before and a later acquisition re-anchors.

The foreign-owner reproduction now asserts the re-anchor contract: the
same trusted id from a live process outside the owner's ancestry moves
line 1 onto that process's CLAUDE_PID, and a different id is refused
against it afterwards. The ancestry membership loop is shared through
one session-lock lib helper.

The earlier commit dropped the ancestry suite's dead-front-end reclaim
phase; that coverage lives in the existing reclaim tests
(test_verified_reclaim_keeps_new_sidecar and the Stop auto-arm's
test_reclaims_stale_session_lock_before_arming).

* fix(bin): record the lock holder for a lease pinned before a re-anchor

The supervision host pins FM_LEASE_HOLDER_PID to lock line 1 at the
start of each engine turn. A same-session re-anchor inside that turn
moved line 1 to a new pid while the pinned holder stayed alive, so a
later claim or same-actor refresh in the turn recorded the old pid and
the lease read stale, letting main claim the branch's task.

A claim now records the live line 1 when the pinned holder is alive but
is no longer line 1. Another session takes the lock only from a dead
owner, so that state comes from a re-anchor; a dead pin is still
recorded as before and its lease stays stale.

* no-mistakes(review): Move auto-arm rewake session pid with lock re-anchor

* no-mistakes(review): Align startup-network downgrade test and lock-rewrite comment

* no-mistakes(review): Correct lock takeover and re-anchor signal-window comments

* no-mistakes(review): Record re-anchor rewake and pinned-claim verification evidence

* no-mistakes(document): Update network-checks diagnostic for re-anchored lock holder

* feat: support version URLs for watched tool updates (kunchenguid#7449)

* feat(bin): watch a tool's published version through version_url

A watched tool whose CLI never announces its own updates can name a version_url; the document is fetched read-only inside the probe bound, its first dotted number is the published version, and an update is reported when that is newer than the version PATH resolves. Claude Code is the shipped example entry.

* no-mistakes(review): Compare published versions against newest installed tool copy

* no-mistakes(document): Clarify watched-tool version URL documentation

* fix(pi): keep a live session's extension markers when a nested Pi command loads them (kunchenguid#7287)

* fix(pi): keep a live session's extension markers when a nested Pi command loads them

A short-lived Pi command started from inside a live session, such as the
`pi --help` capability probe, auto-loads the two primary extensions. Both
treated the session lock as owned because an ancestor holds it, so the child
rewrote `.pi-watch-extension-loaded` and `.pi-turnend-extension-loaded` with
its own pid and exited. Session start then rejected the markers and printed a
false `PI_WATCH_EXTENSION: not loaded` alarm.

Before writing, each extension now reads the marker's pid and leaves the
marker untouched when that pid is a live strict ancestor of the current
process. A missing marker, a dead pid, the current pid, or a live pid outside
the ancestry still writes as before, so a fresh start and a relaunch over a
dead session bind unchanged. Lock ownership and the reader are untouched.

Fixes kunchenguid#5202.

* fix(tests): drop apostrophes from the nested-load marker heredocs so stock Bash 3.2 parses them

* fix: reclaim orphaned Claude auto-arm claims (kunchenguid#5939)

* fix(bin): supersede an orphaned Claude auto-arm claim after a session restart

An auto-arm claim is open only while its owner still descends from the session-lock pid.
A hook whose session exited mid-cycle stays alive with no parent to receive its exit 2, so deferring to its claim left the home unsupervised until the next session turn.
The replacement session's first Stop now takes the next generation, attaches to the running watcher, and delivers the wake itself, while the orphan goes silent.
A claim with no readable numeric session lock is never open.

* no-mistakes(review): accept pid-1 ancestor and session-id-matched autoarm claims

* no-mistakes(review): pin autoarm session-id claim signal to lock holder pid

* no-mistakes(review): exercise real lock recovery in orphan supersession tests

* no-mistakes(review): record lock-holder pid-identity instead of bare pid

* no-mistakes(document): complete autoarm claim-open coverage list

* no-mistakes(ci): Greptile finding ci-1 (hidden session-lock dependency in bin/fm-wake-lib.sh) fixed. Invariant: every function fm-wake-lib.sh calls must either be defined in that file or explicitly loaded by it before the call, so a caller sourcing only the wake library cannot silently degrade. Violating sites in the changed area: fm_autoarm_claim_open's fm_session_lock_recorded_session_id call, and the sibling writer fm_autoarm_claim_next's fm_session_lock_trusted_session_id call (which would otherwise silently omit the two new ledger fields). Both fixed at one shared boundary: a new lazy loader _fm_wake_require_session_lock (bin/fm-wake-lib.sh:38), matching the file's existing _fm_wake_require_classify/_fm_wake_require_timeout idiom, invoked immediately before each call. Lazy rather than top-level source so the ~40 scripts sourcing the wake library pay no harness-identity machinery cost; no circularity (fm-session-lock-lib.sh sources only fm-cursor-lib.sh). No new behaviour, state, or fallback. Verification: sourcing only fm-wake-lib.sh, a claim with broken ancestry plus matching sidecar id and matching recorded lock-holder identity now reads OPEN and the session-lock library is loaded on demand; ordinary descent path unaffected. Suites tests/fm-claude-stop-autoarm.test.sh, tests/fm-turnend-guard.test.sh, tests/fm-wake-queue.test.sh all pass; shellcheck -S warning reports only the pre-existing SC2034 present on HEAD. tests/fm-session-lock-ancestry.test.sh fails its final case ("the pty-host was not reparented to init after the daemon ended") identically with the change reverted, so that failure is a pre-existing WSL environment behaviour, not caused by this fix

* no-mistakes(document): Clarify auto-arm claim documentation

* feat(bin): add Polytoken crewmate/scout worker adapter (kunchenguid#7321)

* wip: polytoken worker adapter (detection, launch, wiring, control, composer; tests mid-iteration)

* feat: verify the polytoken worker adapter (crewmate + scout)

Add polytoken 0.8.19 as a verified crewmate/scout adapter on the
captain-approved TUI-pane-plus-REST hybrid: the pane keeps inspection
and backend parity while the control verbs ride the session daemon's
typed REST API.

Detection is ancestry alone on the anchored polytoken comm (a tool
subprocess's parent is the session daemon, verified live), with the
launch boundary clearing every foreign ORCA_/FM_ marker plus the fixed
harness-identity set. The launch generates the per-task worker config
dir (mirrored operator config with the unattended permission posture
enforced, because a project config.yaml fully replaces the global
config), the worker role-contract facet (no model pin, delegation and
facet switching denied at the tool registry), and the worktree hook
layer binding the verified busy pair - pre_user_prompt and
pre_model_turn open, stop closes - to a no-argv generated writer. The
readiness gate binds the session id, port, and credential into task
metadata through sessions --format json and fails loudly on any
first-start dialog, because the license terms are a blocker by captain
decision and --accept-license-terms is never passed.

Interrupt is POST /turn/cancel with its typed settle (the TUI has no
interrupt chord, so no key is ever improvised), exit is /quit, and a
cancelled turn's busy close is written by the control plane because no
stop hook fires. The composer is the verified separated shape with
polytoken as its second owner, and Enter mid-turn queues, so the
busy-queued conversion applies. Crewmate and scout only: a secondmate
launch is refused, and a project's own .polytoken/hooks.json is refused
rather than clobbered.

* no-mistakes(review): Fix polytoken launch flag order, token argv, live guard

* no-mistakes(document): Correct polytoken REST doc comment and token-on-stdin invariant

* no-mistakes(lint): Silence intentional SC2016 in polytoken live guard treehouse shim

* no-mistakes(review): Retire polytoken pool wiring, drop FIFO config, test env clearing

* no-mistakes(review): Scope polytoken teardown wiring removal to untracked polytoken files

* no-mistakes(review): Refuse existing polytoken hook layer before writing any wiring

* no-mistakes(document): Note teardown as consumer of harness wiring-path table

* no-mistakes(review): Retire only firstmate-generated polytoken worktree wiring

* no-mistakes(review): Guard polytoken hook layer before relaunch cleanup arms

* no-mistakes(document): Note relaunch also skips git-tracked wiring paths

* test: stub polytoken in the refused-relaunch fixture

The refused relaunch onto polytoken resolves the polytoken binary before
its hook-layer refusal, so the case failed on CI hosts without the real
CLI installed. A no-op stub on the fixture PATH stands in; it is never
launched.

* no-mistakes(review): Guard polytoken interrupt close; refuse whitespace hook paths

* no-mistakes(review): Snapshot busy record after cancel settles before idle close

* no-mistakes(review): Guard interrupt close with pre-cancel snapshot and sync recheck

* no-mistakes(test): Clear inherited AGENT at the polytoken launch boundary

* no-mistakes(document): Document guarded polytoken interrupt close and whitespace refusal

* test: preserve Polytoken hook refusal coverage with explicit pins

* no-mistakes(review): Refuse invalid Polytoken relaunch profiles before stopping the worker

* no-mistakes(document): Document Polytoken relaunch refusals before stopping the worker

* fix: scope worker wiring cleanup to Polytoken

* fix(bin): point Polytoken workers away from tool_flow for the task directory

Polytoken 0.9.0 offers no launch-time path grant: tool_flow's file_read
refuses the Firstmate task directory while the direct file tools reach it
under the generated bypass matcher. The worker facet now says so, and the
verification record carries the live evidence.

* fix(bin): leave the pool as found when a fresh spawn fails

A fresh spawn that fails and leaves no task record now closes the endpoint
it opened before its launch was delivered, so the shell whose treehouse get
leases the slot ends and the pool gets the slot back. It also removes the
harness wiring, task temp root, and staged launch file it wrote, and drops
its slot claim under a retaken project lock after metadata publication.

* no-mistakes(review): Stop pre-launch refusals pointing at windows abort cleanup closes

* fix(bin): scope failed-spawn cleanup and the Running-for busy row to Polytoken

The failed-spawn pool cleanup and the Running-for busy row now apply only to
Polytoken, so every other harness keeps main's abort behavior, header text,
operator messages, and harness-less busy union. Tests prove the Polytoken
path cleans up and a non-Polytoken refused launch behaves as on main.

* no-mistakes(review): Scope submit-core busy reads to Polytoken pane identity

* no-mistakes(review): Stop polytoken treehouse isolation refusal pointing at closed window

* test: track the spawned window in the Polytoken harness tmux stand-in

Main now requires exact tmux window membership before sending keys
(aa9ab04), and the Polytoken harness stand-in listed no windows, so the
merged spawn could never deliver Enter. Record the created window, list
it, and forget it on kill, as tests/fixtures.sh does.

* no-mistakes(document): Scope fresh-endpoint abort comment to Polytoken spawns

* no-mistakes(ci): Lint 1 (ci-3) was caused by this PR, and I fixed it. Commit d18014e added the in_polytoken_submit_pane() subshell helper to tests/fm-polytoken-harness.test.sh. That helper sources bin/fm-tmux-lib.sh without the `# shellcheck source=/dev/null` line that every other source in the file carries (lines 55-63 and 200). With --external-sources, ShellCheck followed the library into the subshell and flagged `local pid=$!` at line 690 as SC2031. The fix is that one missing line, added above the source at line 318. After the fix, `shellcheck -x` reports nothing on the file, `bin/fm-lint.sh tests/fm-polytoken-harness.test.sh` passes with full extended analysis, and the Polytoken harness test passes. Behavior portable serial 2 (ci-1) and serial 5 (ci-2) failed in timing-sensitive tests this PR does not touch, so I made no code change for them. I reran both test files in full on this branch on macOS, and both passed (rc=0, no failures). tests/fm-supervision-host.test.sh passed, including the 'host-only transition veto changed Pi's existing offer rule' check that failed in CI. tests/fm-remote-secondmate-lifecycle-e2e.test.sh passed, including 'watch liveness: a dead remote secondmate is auto-relaunched on its own host with one wake'. Main's own recent CI runs (38950070853, 38719784765) also failed on different timing assertions in these serial shards. Together that points to runner flakes rather than a defect in this change

* no-mistakes(review): Retake per-id spawn lock before Polytoken abort deletions

* no-mistakes(document): Document per-id lock guard on Polytoken abort cleanup

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

* Fix away branch relaunch admission (kunchenguid#7444)

* fix(bin): show reported checks when a pull request's base requires none (kunchenguid#7450)

Port the reported-check fallback and regressions from df60538. Preserve required-only reporting when required checks exist and refuse failed fallback reads.

* fix: support durable per-secondmate account pins (kunchenguid#7452)

* fix(tests): clean read-only relaunch fixtures

Use the shared fixture cleanup so generated read-only Git hook directories do not leave permission errors and temporary trees behind.

* fix(accounts): support durable per-secondmate account pins

Resolve optional primary-home secondmate account files through the worker pin parser and checks. Preserve existing defaults when no override exists and re-read the selected pin on spawn, relaunch, and recovery.

* no-mistakes(review): Name the rejected pin file in account refusals

* no-mistakes(document): Document per-secondmate account pins in relaunch and layout docs

* feat(bin): consult operator evidence guards before wedge escalation (kunchenguid#6958)

* feat(watch): consult opt-in operator guards before a wedge escalation

Add config/wedge-evidence-guards, an opt-in list of operator-owned guard
executables that the watcher's at-threshold wedge branch consults after the
wait evidence, worktree-write probe and dead-endpoint probe. A CRITICAL
answer defers one window at a time, capped by FM_WEDGE_GUARD_DEFER_MAX
consecutive deferrals recorded beside the other wedge-window records, and
the escalation that ends a capped run names the guard and its reason.
Timeouts, failures, malformed output, UNKNOWN and WARNING fail open, and an
untrusted config or guard is never run. With the config absent the ladder is
unchanged.

Refs kunchenguid#6919

* no-mistakes(document): Document wedge-evidence-guards in home layout index

* no-mistakes(document): Align jev-guards CRITICAL verdict with bounded deferral

* fix(bin): make inbox listing succeed when the inbox is empty (kunchenguid#7460)

* fix(bin): make the brief's inbox listing succeed on an empty inbox

The worker brief told crewmates to list the inbox with a bare *.msg glob.
On an empty inbox that glob fails: bash ls exits 2 and zsh aborts with
'no matches found'. Use find piped to sort -V so the listing is silent on an
empty or absent inbox and keeps numeric order past 999.

Refs kunchenguid#7244

* no-mistakes(review): Make relaunch note inbox listing safe when empty

* fix: bound remote secondmate convergence and preserve owed re-reads (kunchenguid#7394)

* fix(bin): fit remote second-mate convergence inside the startup network bound

The deferred startup network stage (120s) timed out once four second mates
were remote: the mates already converge concurrently, but each mate's
inheritance push sent its fifteen allowlisted items one SSH round trip after
another, so a single mate's convergence took 64-76s after a ~16s liveness
pass.

- fm-remote-inherit-push.sh validates and snapshots every item locally first,
  so a local refusal now sends nothing, then sends the items up to
  FM_REMOTE_INHERIT_PUSH_JOBS (default 4) at a time and replays their output in
  allowlist order. A failed item still fails the push with its own error, and
  no further item is started after it. The receiver is unchanged: each item is
  its own file and generation record, and the host's job worker still runs one
  home's commands one at a time.
- fm-bootstrap.sh gives each remote mate's convergence its own budget,
  FM_SECONDMATE_CONVERGENCE_TIMEOUT (default 75s). A mate whose sync or push
  hits it is reported as that mate's SECONDMATE_SYNC skip and keeps its retry
  marker, instead of holding the whole stage past its bound.

* fix(bin): nudge a remote second mate to re-read only when something changed

Each remote convergence attempt records its retry marker before it starts,
so a sweep cut off by the startup network bound or failing before any change
left a marker that made the next session start nudge every remote mate even
though its instructions and inherited files were unchanged. The marker now
records whether a re-read is owed, set only once an attempt actually changed
the home, and a tracked-file sync that moved nothing under AGENTS.md, bin/,
or .agents/skills/ no longer counts as a change.

* fix(bin): keep a remote mate's re-read owed when its convergence is cut short

A convergence step stopped by the per-mate budget loses its output, so a
push that had already applied an item reported nothing and left the retry
marker with no re-read owed; the next start then saw every item unchanged
and never told the mate to re-read. A step cut off by the budget now marks
the re-read owed, and so does a failed push whose output shows items it had
already pushed or removed.

The lifecycle e2e suite runs every remote leg through the real entrypoint
and job worker on the test machine, so it now gives convergence ample time;
the budget's own behavior is pinned in fm-bootstrap-network-parallel, whose
budget and failure cases are also made independent of machine load.

* no-mistakes(review): Keep re-read owed on partial or unknown completion

* no-mistakes(review): Persist owed re-read when killed mid-mutation

* no-mistakes(document): Fix stale remote re-read owed docs

* test: send inherited items one at a time in the remote lifecycle e2e fixture

Behavior portable serial 5 failed on the watcher auto-relaunch leg of
tests/fm-remote-secondmate-lifecycle-e2e.test.sh after the inheritance push
started overlapping its sends. Across 14 recent main CI runs that suite's
remote-spawn leg took 30.8-35.6s and the watcher leg 27.3-34.5s, already close
to its 30s wait; on the PR run remote spawn took 42.1s, well outside that range,
while legs that push nothing were only 5-10% slower. The watcher relaunch is a
remote spawn, and the only changed code on that path is the inheritance push.

This fixture's transport has no network latency and its job worker runs one
home's commands one at a time, so overlapping sends cannot hide any round trip
there and only add submission overhead to every remote spawn. The suite now
sends one item at a time, as it did before; the overlapped scheduler stays
covered by tests/fm-bootstrap-network-parallel.test.sh, and the production
default of four is unchanged. The watcher leg's failure now also prints the
watcher's output.

* no-mistakes(document): Clarify remote re-read obligations and consolidate documentation

* fix(bin): record a remote mate's re-read as owed before convergence can change its home

A live run against a real remote second-mate home showed the owed re-read
still lost when the startup network bound stopped the stage. That bound
stops it the way `timeout -k 1` does: TERM to the stage's process group, then
KILL one second later. Bash defers a TERM trap while the convergence worker
waits in a command substitution, and the remote call runs in its own timed
process group, so the KILL landed before the trap could record the re-read.
The remote home had already applied the change, the next start saw every item
unchanged, sent nothing, and deleted the marker, so the mate was never told
to re-read.

Bootstrap convergence and config-push now write the record owed before any
remote step can change the home, and write it back only after the attempt has
reported: removed after confirmed unchanged convergence or a successful send,
and back to owed=0 when a failed attempt's outcome proves nothing changed. A
kill at any point therefore leaves the re-read owed. The TERM/INT traps are
gone. The kill regression now sends TERM and then KILL one second later, as
the startup bound does; it fails on the previous head and passes here.

* no-mistakes(document): Clarify convergence timeout scope and consolidate reread documentation

* fix: require positive daemon running status in crew-state (kunchenguid#7317)

* fix(tests): stabilize supervision host drain and offer fixtures (kunchenguid#7467)

* fix(bin): refuse spawn into a project with an unborn HEAD (kunchenguid#6987)

* fix(bin): refuse spawn into a project with an unborn HEAD

Spawn into a repository with no commit waited 60s for treehouse and then reported that the worktree was the spawning project itself, never naming the cause. Refuse before the wait and name the unborn HEAD and the remedy. The project-management skill now states that a new local repository needs a first commit.

* docs(skills): tell the captain a new project needs a first commit

The Create a project step no longer reads as firstmate committing into the project. It states that spawn refuses an unborn HEAD and that the captain is told the project needs a first commit.

* test: give spawn fixtures a first commit for the unborn-HEAD refusal

* no-mistakes(review): Commit foreign consent fixture so spawn guard passes

* feat(bin): add GitLab --allow-no-pipeline merge waiver and close backlog items for GitLab MRs (kunchenguid#7462)

* feat(bin): add an attended GitLab --allow-no-pipeline merge waiver

A GitLab repository that deliberately runs no merge request pipeline could
never be merged through fm-pr-merge.sh: the guard requires a successful head
pipeline at the current head, and GitLab has no per-check waiver.

--allow-no-pipeline waives only the pipeline condition, and only when GitLab
reports head_pipeline as present and null. A failed, running, canceled, or
stale pipeline still refuses, every other condition (open, mergeable
detailed_merge_status, no conflicts, discussions resolved) still holds, and
the verified head is still passed to glab as --sha. The flag is attended-only
(refused while the away-posture record exists), GitLab-only, and takes no
value; without it the default refusal is unchanged.

* fix(bin): close a GitLab merge request task's backlog item with a note

tasks-axi accepts a --pr link only as a GitHub or Forgejo pull request, so
after a GitLab merge request landed, teardown could never complete the
backlog Done transition and left the close pending forever.

Extend the existing Gerrit carve-out in fm_backlog_done and
fm_backlog_retain, and the captain-hold answer replay that shares it, to
record a GitLab merge request URL as a "GitLab merge request <url>" note,
until tasks-axi accepts GitLab merge request URLs. GitHub and Forgejo pull
requests are still recorded as pr links.

* no-mistakes(document): Note GitLab --allow-no-pipeline waiver in merge-watch record

* no-mistakes(review): Order seat-pin test before footer; drop duplicate mate assignment

* no-mistakes(test): Fix herdr-groups test socket paths on macOS

* no-mistakes(document): Document account pin superseding recorded Claude profile on relaunch

* no-mistakes(ci): Fixed two failing tests in the portable serial shards, plus one doc line. The "PR must be raised via no-mistakes" check needs no code change. 1. Shard 12, `tests/fm-control-relaunch.test.sh`, "an unpinned replacement must launch exactly as before": a real merge conflict, reproduced locally. - **Cause:** when a Claude account pin applies, the fork saves the pin's directory as the task's recorded Claude profile (`claude_seat`). A relaunch without `--seat` reuses that recorded profile. So after the pin was removed, the replacement still launched under the old pin directory (`CLAUDE_CONFIG_DIR=<old pin>`). - **Rule that must hold:** a Claude profile recorded only because of a pin must not outlive the pin. - **Where it applies:** both places that read the recorded Claude profile on relaunch. - `bin/fm-spawn.sh`: the launch owner sets `RELAUNCH_SEAT`. - `bin/fm-control.sh` (`resolve_relaunch_profile`): checks the profile before the old agent is stopped. - **Fix:** both now ignore a recorded `claude_seat` that equals the task's recorded `account` (the pin's directory). - **What stays the same:** profiles chosen with `--seat` are still kept. An active pin still overrides the recorded profile, and a changed pin is still followed. - **Docs:** updated the matching line in `docs/agent-control.md`. 2. Shard 8, `tests/fm-watch-triage-delivery.test.sh`, "re-arm 4 never captured the pane": a flaky test, not caused by this change. - **Cause:** the fake `tmux` empties its tick counter file and then rewrites it. Stopping the watcher doesn't stop that child process, so the test sometimes read an empty file (`[: : integer expression expected`). - **Fix:** the fake now writes to a temp file and renames it into place, so the counter is never read empty. 3. "PR must be raised via no-mistakes": fails because the attestation records that the test step was approved over a failing test command (exit 124). The user already declined fixing that in test round 2, so no code change is warranted. It stays red until `test.allow_approve_over_failure` is set in the default-branch `.no-mistakes.yaml`, or until the PR is re-attested. **Verification:** run locally on macOS with `CLAUDE_CONFIG_DIR` unset. These files passed with no failures: `fm-control-relaunch`, `fm-watch-triage-delivery`, `fm-seat`, `fm-worker-account`, `fm-worker-account-live-e2e`. `shellcheck -x -S warning` is clean on the changed scripts. I didn't rerun the other serial shards

* no-mistakes(test): Keep recorded Claude seat separate from account pin

---------

Co-authored-by: Sebastian <[email protected]>
Co-authored-by: joergspoerl <[email protected]>
Co-authored-by: researchworldwide2026 <[email protected]>
Co-authored-by: Andrew Sweet <[email protected]>
Co-authored-by: Liam Sarsfield <[email protected]>
Co-authored-by: Tiago <[email protected]>
Co-authored-by: sjennings <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Harsha <[email protected]>
Co-authored-by: Konner Moshier <[email protected]>
Co-authored-by: Tim Kleinschmidt <[email protected]>
Co-authored-by: Arthur Cruz <[email protected]>
Co-authored-by: Robert Christensen <[email protected]>
Co-authored-by: Muhammad Syarifudin <[email protected]>
witt3rd added a commit to witt3rd/firstmate that referenced this pull request Oct 21, 2026
* feat: let a home declare authoritative external memory tiers (#6608)

* docs: let a home declare authoritative external memory tiers

AGENTS.md section 6 routed durable knowledge only to firstmate-local files,
so a home whose captain keeps reasoning and facts in external stores had no
tracked rule keeping those stores authoritative over the per-machine data/
cache. Add a generic home-declared Memory l