Skip to content

fix(daemon): refuse to arm away mode when the primary is not tmux/herdr-hosted - #31

Merged
sKeLe100 merged 12 commits into
mainfrom
fm/afk-delivery-unreachable
Aug 27, 2026
Merged

sKeLe100 merged 12 commits into
mainfrom
fm/afk-delivery-unreachable

Conversation

@sKeLe100

Copy link
Copy Markdown
Owner

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.sh now treats a FALLBACK(firstmate:0) target resolution as fatal: when neither FM_SUPERVISOR_TARGET, $TMUX_PANE, nor $HERDR_ENV/$HERDR_PANE_ID identifies the pane hosting the live primary, it prints a captain-facing error, logs startup 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 the FALLBACK(pinned:<pane-id>) log variant) is gone; target resolution via TMUX_PANE/herdr and the composer guard are untouched.
  • bin/fm-supervisor-target-lib.sh keeps returning the pinned legacy fallback value with status 1, now documented as diagnostic-only since every caller treats the non-zero status as fatal.
  • Added two behavioral tests in tests/fm-daemon.test.sh covering the refuse path (no tmux/herdr env → nonzero exit with the refusal message) and the unchanged tmux-hosted path (TMUX_PANE set → target resolved from TMUX_PANE, no refusal); updated docs/configuration.md and .agents/skills/afk/SKILL.md to 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/.afk remains 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.log

=== /afk arm from a NON-tmux, non-herdr primary (no TMUX_PANE, no HERDR_ENV) ===
$ bin/fm-afk-start.sh
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.log
Evidence: 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; ...

=== BASE COMMIT e6d03bd (before fix): same non-tmux primary ===
$ bin/fm-afk-start.sh
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
Terminated                 sleep 1
--- 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; inject_skip='heartbeat'; stale_escalate=240s; batch=90s
[2026-08-27T00:12:27-0400] daemon shutting down
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=90s

=== /afk arm from a tmux-hosted primary (TMUX_PANE=%201) ===
$ bin/fm-afk-start.sh   # run with the primary pane env, backgrounded
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=90s

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ 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 string target_source = &#34;FALLBACK(firstmate:0)&#34;, 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 older supervisor target &#39;...&#39; does not resolve to a tmux pane error 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 failures
  • Manual refuse path: env -u TMUX -u TMUX_PANE -u HERDR_ENV -u HERDR_PANE_ID FM_STATE_OVERRIDE=&lt;tmp&gt;/state bin/fm-afk-start.sh → exit 1, refusal message, startup refused log line, no lock/pidfile left
  • Manual pass path: real tmux new-session -d -s fmtest, then env TMUX_PANE=%201 TMUX=... bin/fm-afk-start.sh → daemon starting ... target=%201; target_source=TMUX_PANE; backend=tmux
  • Red check: git checkout e6d03bd -- bin/fm-supervise-daemon.sh bin/fm-supervisor-target-lib.sh then 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.

@sKeLe100
sKeLe100 force-pushed the fm/afk-delivery-unreachable branch 2 times, most recently from bb7850a to fb9113d Compare August 27, 2026 04:42
…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).
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
sKeLe100 force-pushed the fm/afk-delivery-unreachable branch from 50c6126 to 82e1e30 Compare August 27, 2026 08:50
@sKeLe100
sKeLe100 merged commit 62cb2d9 into main Aug 27, 2026
11 of 12 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant