Repository navigation
fix(daemon): refuse to arm away mode when the primary is not tmux/herdr-hosted - #31
Merged
Merged
Conversation
sKeLe100
force-pushed
the
fm/afk-delivery-unreachable
branch
2 times, most recently
from
August 27, 2026 04:42
bb7850a to
fb9113d
Compare
…osted A non-tmux, non-herdr primary caused the daemon to fall back to a guessed firstmate:0 tmux session at arm time; if a same-named session happened to exist, escalations were typed into it silently and swallowed by the composer guard (confirmed root cause of an 8-hour away-mode run on 2026-08-22 that delivered nothing). There is no verified delivery path for that case, so refuse loudly at arm time instead.
…confirmed Moves the tmux/herdr host check ahead of the away-mode flag write in fm-afk-start.sh so a refusal never leaves state/.afk set with no daemon alive (a review finding on the daemon's own FALLBACK refusal).
…ver daemon refusal directly
FM_SUPERVISOR_BACKEND alone does not supply a target, so accepting it in fm_afk_host_confirmed let state/.afk be written even though the daemon's own target_source logic would then hit FALLBACK and refuse - reproducing the dead-flag condition this fix exists to remove.
sKeLe100
force-pushed
the
fm/afk-delivery-unreachable
branch
from
August 27, 2026 08:50
50c6126 to
82e1e30
Compare
sKeLe100
added a commit
that referenced
this pull request
Nov 23, 2026
… to fork contracts Test-only adaptations found in CI triage. No production code changes. - fm-stow-guard: run a staged copy of the guard from each fixture root's bin/, because the fork's primary-scope check (#22) keys on the guard's physical location; same pattern as fm-sessionstart-nudge. - fm-backend-t3code: give codex spawns an explicit --effort (the fork refuses a codex launch without one), and give the native-restart case a fake tmux pane so the fork's pre-arm host check (#31) passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Away mode cannot deliver escalations to a non-tmux primary session. Root cause: the /afk daemon (bin/fm-supervise-daemon.sh) auto-discovers an injection target by window NAME only, never confirming the target actually hosts the live primary session. When the primary Claude session is not inside tmux, the daemon falls back to a bare shell (e.g. firstmate:0) and silently types escalations into an empty prompt nobody reads for hours while /afk still reports success. Required fix: at /afk arm time, detect that the resolved delivery target does not host the live primary session and REFUSE to arm with a plain captain-facing message, rather than arming into a dead target. If a workable delivery path exists for a non-tmux primary, implement it; otherwise state plainly at arm time that away mode is unavailable in this configuration. Do NOT relax the composer guard in any way - it is the only reason those 8 hours of escalations were not typed into a random shell. Acceptance: arming /afk from a non-tmux primary either establishes a genuinely working delivery path or refuses loudly at arm time; a tmux-hosted primary's existing away-mode behavior is unchanged; the composer guard's semantics are untouched; behavioral tests cover both the refuse path and the existing pass path, colocated per repo convention; docs/ or the owning script headers are updated to state the non-tmux limitation or the new path. This is shared tracked firstmate material (bin/, docs/) so firstmate-coding-guidelines apply.
What Changed
bin/fm-supervise-daemon.shnow treats aFALLBACK(firstmate:0)target resolution as fatal: when neitherFM_SUPERVISOR_TARGET,$TMUX_PANE, nor$HERDR_ENV/$HERDR_PANE_IDidentifies the pane hosting the live primary, it prints a captain-facing error, logsstartup refused: ..., releases the lock and pidfile, and exits nonzero instead of pinning and arming into an unrelated pane. The previous warn-and-continue fallback (including theFALLBACK(pinned:<pane-id>)log variant) is gone; target resolution viaTMUX_PANE/herdr and the composer guard are untouched.bin/fm-supervisor-target-lib.shkeeps returning the pinned legacy fallback value with status 1, now documented as diagnostic-only since every caller treats the non-zero status as fatal.tests/fm-daemon.test.shcovering the refuse path (no tmux/herdr env → nonzero exit with the refusal message) and the unchanged tmux-hosted path (TMUX_PANEset → target resolved fromTMUX_PANE, no refusal); updateddocs/configuration.mdand.agents/skills/afk/SKILL.mdto state that away mode is unavailable for a non-tmux, non-herdr primary and how to override.Risk Assessment
✅ Low: A well-bounded arm-time refusal guarded by an existing early-exit pattern, with behavioral tests covering both the refuse and the tmux pass path, the composer guard untouched, and no reachable wrong-result path found; the two remaining notes are informational.
Testing
Ran the targeted
tests/fm-daemon.test.sh(the file owning away-mode arm behavior) fully green, then produced CLI transcripts of the actual end-user surface: arming /afk from a non-tmux, non-herdr primary now refuses loudly at arm time with the captain-facing error and exits 1 without leaving a lock or pidfile, while a primary hosted in a real tmux pane still arms normally against its own pane via $TMUX_PANE. I also re-ran the non-tmux invocation against the base commit's daemon scripts, which reproduced the original failure (silently arming into the unrelated pane %0 with only a warning), establishing red-before/green-after; the bin files were restored and the worktree is clean. No UI surface is involved — this is a CLI/daemon behavior change, so transcripts and startup logs are the appropriate reviewer-visible evidence. One non-blocking, pre-existing note:state/.afkremains set after the refusal, the same as for the older "target not found" startup failure.Evidence: /afk refuses to arm from a non-tmux primary (fixed behavior)
Source: /afk refuses to arm from a non-tmux primary (fixed behavior)
$ bin/fm-afk-start.sh # no TMUX_PANE, no HERDR_ENV afk: starting supervise daemon in foreground; keep this command as a tracked background session error: cannot verify this away-mode daemon's target pane hosts the live firstmate primary session (no FM_SUPERVISOR_TARGET override, and neither $TMUX_PANE nor $HERDR_ENV/$HERDR_PANE_ID is set) - the primary session does not appear to be running inside tmux or herdr, and away mode has no other verified delivery path, so it refuses to arm rather than escalate into an unrelated pane; run the primary inside tmux (or herdr), or set FM_SUPERVISOR_TARGET/FM_SUPERVISOR_BACKEND explicitly to the primary's own pane, to use away mode exit=1 --- state/.supervise-daemon.log --- [2026-08-27T00:07:53-0400] startup refused: primary session not confirmed hosted in tmux or herdr (target_source=FALLBACK, would-be target='%0') --- daemon pidfile / lock left behind? --- .supervise-daemon.logEvidence: Same command at base commit e6d03bd: silently armed into unrelated pane %0
Source: Same command at base commit e6d03bd: silently armed into unrelated pane %0
$ bin/fm-afk-start.sh # base commit, same non-tmux environment afk: starting supervise daemon in foreground; keep this command as a tracked background session warn: could not auto-discover supervisor pane (no FM_SUPERVISOR_TARGET, TMUX_PANE, or HERDR_ENV/HERDR_PANE_ID); falling back to '%0' — verify this is firstmate's pane --- state/.supervise-daemon.log --- [2026-08-27T00:12:16-0400] daemon starting (pid 3120753); target=%0; target_source=FALLBACK(pinned:%0); backend=tmux; backend_source=FALLBACK(tmux); afk=on; ...Evidence: tmux-hosted primary arms unchanged
Source: tmux-hosted primary arms unchanged
=== /afk arm from a tmux-hosted primary (TMUX_PANE=%201) === $ bin/fm-afk-start.sh afk: starting supervise daemon in foreground; keep this command as a tracked background session --- state/.supervise-daemon.log --- [2026-08-27T00:08:14-0400] daemon starting (pid 3041474); target=%201; target_source=TMUX_PANE; backend=tmux; backend_source=TMUX_PANE; afk=on; inject_skip='heartbeat'; stale_escalate=240s; batch=90sPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-afk-start.sh:165- fm_afk_start_main writes state/.afk before exec'ing the daemon, and the new FALLBACK refusal (bin/fm-supervise-daemon.sh:1454) exits 1 without clearing it. For the exact configuration this fix targets (primary not in tmux/herdr), /afk now leaves state/.afk present with no daemon running: bin/fm-claude-stop-autoarm.sh:120 exits early and bin/fm-guard.sh:186 sets afk=1, so firstmate suppresses normal per-wake handling while nothing supervises or escalates. Roll the flag (and the launcher's start-native record) back on refusal, or perform the tmux/herdr host check before writing the flag.tests/fm-daemon.test.sh:125- test_afk_start_tmux_hosted_primary_reaches_target_validation_unchanged asserts only assert_not_contains over $(cat "$log" 2>/dev/null). If the daemon exits before writing .supervise-daemon.log (or the file never appears within the 10s deadline), the haystack is empty and the assertion passes vacuously, so the 'existing pass path unchanged' criterion is not actually guarded. Add a positive assertion that the startup log records target_source=TMUX_PANE (or the tmux target-validation failure).bin/fm-supervise-daemon.sh:73- The script header still documents a 'then firstmate:0 fallback' target resolution that can no longer be used, and discover_supervisor_target's pinning branch (bin/fm-supervisor-target-lib.sh:63-69) is now unreachable from every caller: the daemon refuses whenever target_source is FALLBACK, and bin/fm-afk-launch.sh:468 aborts on its return 1. Update the header and drop or document the now-dead pinning branch.🔧 Fix: assert tmux pass path positively; document non-tmux refusal
2 infos still open:
bin/fm-supervise-daemon.sh:1460- The refusal is keyed on the stringtarget_source = "FALLBACK(firstmate:0)", which the daemon derives from its own inline copy of discover_supervisor_target's precedence (lines 1433-1441), while the discovery call's exit status (line 1442, the authoritative signal per the new comment in bin/fm-supervisor-target-lib.sh:51-57) is discarded with|| true. The two agree today for all three sources, so there is no live wrong result. But they are now two independent encodings of the same invariant: adding a source to discover_supervisor_target without editing the daemon's inline chain would make the daemon refuse a target discovery resolved successfully. Keying the refusal off the call's status (if ! discovered=$(discover_supervisor_target); then ...) while keeping target_source purely for the log line would collapse them.docs/configuration.md:137- The doc states the three sources fail to identify the primary's pane "only when the primary session is not hosted in tmux or herdr at all". The implemented check is presence of $TMUX_PANE/$HERDR_PANE_ID in the daemon's inherited environment, not proof that the pane hosts the live primary, so a stale-but-set $TMUX_PANE (pane since closed) skips the new plain refusal and falls through to the oldersupervisor target '...' does not resolve to a tmux paneerror instead. Away mode still refuses in that case (no dead-target arming), so this is an accuracy note on the doc's "only when", not a delivery hole; worth softening the wording since the intent frames the root cause as "never confirming the target actually hosts the live primary session".✅ **Test** - passed
✅ No issues found.
bash tests/fm-daemon.test.sh(full file, includes the two new colocated tests:test_afk_start_refuses_when_primary_not_hosted_in_tmux_or_herdr,test_afk_start_tmux_hosted_primary_reaches_target_validation_unchanged) — all ok, no failuresManual refuse path:env -u TMUX -u TMUX_PANE -u HERDR_ENV -u HERDR_PANE_ID FM_STATE_OVERRIDE=<tmp>/state bin/fm-afk-start.sh→ exit 1, refusal message,startup refusedlog line, no lock/pidfile leftManual pass path: realtmux new-session -d -s fmtest, thenenv TMUX_PANE=%201 TMUX=... bin/fm-afk-start.sh→daemon starting ... target=%201; target_source=TMUX_PANE; backend=tmuxRed check:git checkout e6d03bd -- bin/fm-supervise-daemon.sh bin/fm-supervisor-target-lib.shthen the same non-tmux invocation → base only warns and arms into%0(target_source=FALLBACK(pinned:%0)); bin files restored, worktree clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.