Skip to content

fix(afk): deliver away-mode escalations past a false busy signal and verify entry delivery - #2956

Closed
juangedaan wants to merge 6 commits into
kunchenguid:mainfrom
juangedaan:fm/afk-delivery-wedge
Closed

juangedaan wants to merge 6 commits into
kunchenguid:mainfrom
juangedaan:fm/afk-delivery-wedge

Conversation

@juangedaan

Copy link
Copy Markdown

Intent

Fix the away-mode escalation delivery wedge in firstmate: on a live home the away-mode sub-supervisor buffered 39 escalations over 7h16m and delivered zero of them into the captain pane, matching upstream issue #2917 (4721 consecutive busy-guard deferrals, 0 sent). Three layers were requested and all three are in this commit.

(1) Root cause. The pre-injection busy guard (pane_is_busy) was an unbounded single-source veto, and the max-defer escape re-ran the very same guard, so one false-positive busy reading blocked every delivery forever against a verifiably idle pane with an empty composer. The fix adds pane_busy_verdict, which corroborates the harness native agent-state against the rendered pane signature: busy requires corroboration, and a legible idle on either signal wins. pane_is_busy is deliberately kept as the single predicate every caller uses (rather than callers calling pane_busy_verdict directly) because six existing tests stub pane_is_busy as their seam; it now publishes PANE_BUSY_SOURCE so a deferral log can name the signal that vetoed it. tmux is intentionally unchanged because it exposes no native agent-state (always unknown), so its verdict still comes from the rendered signal alone. The max-defer flush now sets FM_INJECT_IGNORE_BUSY=1 so the escape bypasses the guard that deferred - a deliberate weakening of that guard, justified because the composer guard (which must read affirmatively empty) and the verified type-once submit protect the pane contents, while the busy guard only picks the moment; a digest queued behind the current turn beats 7h16m of silence. That safety boundary is pinned by test_busy_guard_escape_still_respects_a_pending_composer.

(2) Alarm channel. The max-defer wedge alarm defaulted to macOS Notification Center, so on Linux it silently went nowhere while firing 86 times. The requested constraint was to not invent new notification infrastructure if a supported channel already exists, so auto/default now resolves to the already-supported herdr channel off macOS when the herdr CLI is installed, rather than adding a new notifier.

(3) Entry verification. Away-mode entry now proves delivery instead of assuming it: the daemon injects one marked no-op operational message at startup and records ok/failed/skipped in state/.subsuper-delivery-selftest, and bin/fm-afk-launch.sh verify fails away-mode entry (naming the stop rollback command) when that proof is absent, so away mode is never reported active on an undeliverable path. The self-test deliberately retries within a bounded window (FM_DELIVERY_SELFTEST_SECS) because at entry the captain composer can legitimately hold an unsent line, which the composer guard correctly defers on; retrying distinguishes "not this instant" from "cannot deliver". The daemon does not exit on a failed self-test - it stays up as a passive recorder so verify can read the verdict - and verify deliberately skips the launcher lock because holding it for the whole timeout would block the very stop rollback a failed verdict tells the caller to run.

Deliberate scope decisions: upstream #2917 also suggested a floor on consecutive identical deferrals, which was skipped as redundant now that the time-based escape actually works. tests/fm-afk-launch.test.sh has one pre-existing herdr-lab e2e failure (could not prepare isolated lab session) that reproduces identically on baseline HEAD; it is out of scope and was deliberately not touched, because this task was explicitly dispatched without Herdr lifecycle authorization.

Evidence and repo conventions: root cause is proven failing-then-passing (with the daemon reverted to HEAD the suite fails at "max-defer did not deliver past a busy pane"), regression coverage lives in tests/fm-daemon.test.sh (110 assertions green), and end-to-end proof of both entry outcomes is tests/fm-afk-inject-e2e.test.sh Scenario D against a real tmux pane and a real daemon in an isolated state directory. Per this repo firstmate-coding-guidelines, harness-dependent behavior also gets a dated maintainer-verification record, which is the docs/verification/supervision.md addition; docs/wedge-alarm.md and the /afk skill were updated as the affected contract owners. bin/fm-lint.sh and bin/fm-doc-audience-check.sh are clean.

What Changed

  • Replaced the unbounded single-source busy veto in bin/fm-supervise-daemon.sh with pane_busy_verdict, which corroborates the harness agent-state against the rendered pane signature (busy requires corroboration; a legible idle on either signal wins) and publishes PANE_BUSY_SOURCE for deferral logs. The max-defer escape now flushes with FM_INJECT_IGNORE_BUSY=1 so it bypasses the same guard that deferred, while the empty-composer guard and verified type-once submit still protect pane contents (pinned by test_busy_guard_escape_still_respects_a_pending_composer).
  • The max-defer wedge alarm's auto/default channel now resolves to the existing herdr channel off macOS when the herdr CLI is installed, instead of silently firing into macOS Notification Center on Linux.
  • Away-mode entry now proves delivery: the daemon injects a marked no-op self-test message at startup (retried within a bounded FM_DELIVERY_SELFTEST_SECS window, with the shutdown trap installed before the self-test runs) and records ok/failed/skipped in state/.subsuper-delivery-selftest; bin/fm-afk-launch.sh verify fails away-mode entry and names the stop rollback when that proof is absent. Covered by new tests/fm-daemon.test.sh assertions and e2e Scenario D in tests/fm-afk-inject-e2e.test.sh, with docs updated in docs/wedge-alarm.md, docs/verification/supervision.md, and the /afk skill.

Risk Assessment

✅ Low: All three prior findings were fixed exactly as instructed (durable failed verdict on startup validation failure with a hardened non-vacuous tmux probe, trap installed before the self-test window, bounded unit-test retry), and a sweep of every fake-tmux consumer of the stricter fm_backend_target_exists probe plus the verify/clear/docs contract owners found no new issues.</risk_rationale>

Testing

Ran the targeted daemon unit suite (110 assertions green), reproduced the wedge by reverting only the daemon to baseline (suite fails exactly at "max-defer did not deliver past a busy pane") then confirmed the fix passes, ran the real-tmux end-to-end injection suite where Scenario D demonstrates both away-mode entry outcomes including the operator-visible delivery-verified message, and confirmed the one fm-afk-launch herdr-lab failure reproduces identically on baseline HEAD so it is pre-existing and out of scope as stated; no UI surface is involved, so evidence is CLI transcripts and durable state verdicts rather than screenshots.

Evidence: Failing-then-passing proof: fm-daemon suite against baseline daemon fails at the wedge

ok - max-defer flushes and clears the buffer on an empty bordered pane not ok - max-defer did not deliver past a busy pane: (exit=1; same suite on the fixed daemon: exit=0, 110 ok)

ok - fm-afk-start.sh fails before daemon startup when the afk flag cannot be written
ok - fm-afk-start.sh ignores stale pidfile-only live pids
ok - fm-afk-start.sh reclaims stale daemon locks whose live pid identity no longer matches
ok - supervise daemon state root is scoped by FM_HOME
ok - routine signal self-handles
ok - captain-relevant status verbs escalate
ok - check + unknown escalate; heartbeat self-handles
ok - transient stale self-handles and records a persistence marker
ok - enriched stale wedges bypass status absorption without disturbing busy workers
ok - stale + terminal status escalates immediately
ok - paused reasons with captain phrases remain pause-classified
ok - a captain-held transfer classifies as pause, not as a wedge candidate
ok - handle_wake on a paused stale records a pause marker, drops the wedge marker, and does not escalate
ok - handle_wake records a declared pause from a routine signal for long-cadence rechecks
ok - a terminal signal clears pause and stale tracking across both supervisors
ok - housekeeping migrates a normal-watcher's declared pause into daemon tracking
ok - housekeeping clears an already-resumed watcher pause across both supervisors
ok - housekeeping seeds pause tracking from status without a watcher marker
ok - persistent stale escalates after threshold and clears its marker
ok - resumed (busy) stale clears its marker without escalating
ok - housekeeping re-surfaces a stale declared pause on the long cadence and resets its window
ok - housekeeping re-surfaces a forgotten captain hold on the long cadence and resets its window
ok - housekeeping clears a paused marker whose pane became busy again, without escalating
ok - housekeeping clears a paused marker once the crew is no longer declaring the pause
ok - housekeeping clears the pause marker once a captain hold is answered
ok - housekeeping moves an existing stale marker to pause before wedge escalation
ok - housekeeping moves a captain hold's existing stale marker to pause before wedge escalation
ok - housekeeping clears tracking when a crew leaves pause
ok - persistent herdr stale resolves the target from metadata and escalates
ok - herdr idle busy-footer stale clears through capture corroboration
ok - resumed herdr stale clears through backend-aware busy state
ok - persistent Orca stale resolves the terminal from metadata
ok - multiple escalations flush as a single batched digest
ok - batch flush measures max-delay from the first append, not the last
ok - catch-all scan escalates a missed terminal once, not twice
ok - handle_wake routes routine->self and captain->escalate
ok - INJECT_SKIP forces self-handle, bypassing captain-relevant classification
ok - is_wake_reason distinguishes watcher wake reasons from singleton-status stdout
ok - terminal-stale escalate removes its marker so housekeeping does not re-escalate
ok - captain signal escalate marks seen so the catch-all scan does not re-fire
ok - _collapse_newlines replaces newlines with literal separator
ok - afk flag absent: daemon does not inject, buffer preserved
ok - busy-guard defers injection when supervisor pane is busy
ok - marker detection: marker -> stay afk, no marker -> exit afk
ok - /afk invocation is exempt from afk exit (no self-cancel)
ok - should_exit_afk returns false when afk is not active
ok - strip_injection_marker removes the sentinel marker cleanly
ok - pane_input_pending detects partial input on the cursor line
ok - pane_input_pending: a blank unidentified cursor row defers (strict container-proof rule)
ok - pane_input_pending: only proven empty agent prompts pass
ok - fm_tmux_composer_state: a bare shell prompt ($/%/#/>) reads unknown, never empty (dead-shell injection safety)
ok - fm_tmux_composer_state: a bordered composer box and bare agent glyphs (❯/›) still read empty
ok - fm_tmux_composer_state: only matching edge borders form a composer box
ok - pane_input_pending preserves bright placeholder-like drafts in styled captures
ok - classify_signal dedupes against the catch-all scan seen marker
ok - classify_stale dedupes against the signal path seen marker
ok - AFK nonterminal working:+merged keeps wedge aging and re-escalates at bound
ok - genuine done: and merge-check events still escalate
ok - pane_input_pending: an idle bordered composer is NOT pending (afk-invx-i5)
ok - pane_input_pending: text inside a bordered composer is still pending
ok - submit-ACK confirms a submit when the composer returns to a bordered-empty box
ok - submit-ACK reports pending on a persistently swallowed Enter (type-once)
ok - max-defer on an empty stuck pane types once, alarms, and preserves the buffer
ok - max-defer flushes and clears the buffer on an empty bordered pane
not ok - max-defer did not deliver past a busy pane: 
Evidence: E2E: real tmux pane, real daemon — Scenario D proves both away-mode entry outcomes

ok - Scenario A: partial input defers injection; digest arrives clean after idle ok - Scenario B: swallowed Enter produces exactly one clean digest ok - Scenario C: a normal captain status injects exactly one clean single-line sentinel digest fm-afk-launch: away-mode delivery verified: one escalation confirmed into the captain pane ok - Scenario D: away-mode entry proves one delivery and refuses when it cannot all e2e injection tests passed

ok - Scenario A: partial input defers injection; digest arrives clean after idle
ok - Scenario B: swallowed Enter produces exactly one clean digest
ok - Scenario C: a normal captain status injects exactly one clean single-line sentinel digest
fm-afk-launch: away-mode delivery verified: one escalation confirmed into the captain pane
ok - Scenario D: away-mode entry proves one delivery and refuses when it cannot
all e2e injection tests passed
Evidence: fm-daemon suite on target commit (110 assertions, exit 0)
ok - fm-afk-start.sh fails before daemon startup when the afk flag cannot be written
ok - fm-afk-start.sh ignores stale pidfile-only live pids
ok - fm-afk-start.sh reclaims stale daemon locks whose live pid identity no longer matches
ok - supervise daemon state root is scoped by FM_HOME
ok - routine signal self-handles
ok - captain-relevant status verbs escalate
ok - check + unknown escalate; heartbeat self-handles
ok - transient stale self-handles and records a persistence marker
ok - enriched stale wedges bypass status absorption without disturbing busy workers
ok - stale + terminal status escalates immediately
ok - paused reasons with captain phrases remain pause-classified
ok - a captain-held transfer classifies as pause, not as a wedge candidate
ok - handle_wake on a paused stale records a pause marker, drops the wedge marker, and does not escalate
ok - handle_wake records a declared pause from a routine signal for long-cadence rechecks
ok - a terminal signal clears pause and stale tracking across both supervisors
ok - housekeeping migrates a normal-watcher's declared pause into daemon tracking
ok - housekeeping clears an already-resumed watcher pause across both supervisors
ok - housekeeping seeds pause tracking from status without a watcher marker
ok - persistent stale escalates after threshold and clears its marker
ok - resumed (busy) stale clears its marker without escalating
ok - housekeeping re-surfaces a stale declared pause on the long cadence and resets its window
ok - housekeeping re-surfaces a forgotten captain hold on the long cadence and resets its window
ok - housekeeping clears a paused marker whose pane became busy again, without escalating
ok - housekeeping clears a paused marker once the crew is no longer declaring the pause
ok - housekeeping clears the pause marker once a captain hold is answered
ok - housekeeping moves an existing stale marker to pause before wedge escalation
ok - housekeeping moves a captain hold's existing stale marker to pause before wedge escalation
ok - housekeeping clears tracking when a crew leaves pause
ok - persistent herdr stale resolves the target from metadata and escalates
ok - herdr idle busy-footer stale clears through capture corroboration
ok - resumed herdr stale clears through backend-aware busy state
ok - persistent Orca stale resolves the terminal from metadata
ok - multiple escalations flush as a single batched digest
ok - batch flush measures max-delay from the first append, not the last
ok - catch-all scan escalates a missed terminal once, not twice
ok - handle_wake routes routine->self and captain->escalate
ok - INJECT_SKIP forces self-handle, bypassing captain-relevant classification
ok - is_wake_reason distinguishes watcher wake reasons from singleton-status stdout
ok - terminal-stale escalate removes its marker so housekeeping does not re-escalate
ok - captain signal escalate marks seen so the catch-all scan does not re-fire
ok - _collapse_newlines replaces newlines with literal separator
ok - afk flag absent: daemon does not inject, buffer preserved
ok - busy-guard defers injection when supervisor pane is busy
ok - marker detection: marker -> stay afk, no marker -> exit afk
ok - /afk invocation is exempt from afk exit (no self-cancel)
ok - should_exit_afk returns false when afk is not active
ok - strip_injection_marker removes the sentinel marker cleanly
ok - pane_input_pending detects partial input on the cursor line
ok - pane_input_pending: a blank unidentified cursor row defers (strict container-proof rule)
ok - pane_input_pending: only proven empty agent prompts pass
ok - fm_tmux_composer_state: a bare shell prompt ($/%/#/>) reads unknown, never empty (dead-shell injection safety)
ok - fm_tmux_composer_state: a bordered composer box and bare agent glyphs (❯/›) still read empty
ok - fm_tmux_composer_state: only matching edge borders form a composer box
ok - pane_input_pending preserves bright placeholder-like drafts in styled captures
ok - classify_signal dedupes against the catch-all scan seen marker
ok - classify_stale dedupes against the signal path seen marker
ok - AFK nonterminal working:+merged keeps wedge aging and re-escalates at bound
ok - genuine done: and merge-check events still escalate
ok - pane_input_pending: an idle bordered composer is NOT pending (afk-invx-i5)
ok - pane_input_pending: text inside a bordered composer is still pending
ok - submit-ACK confirms a submit when the composer returns to a bordered-empty box
ok - submit-ACK reports pending on a persistently swallowed Enter (type-once)
ok - max-defer on an empty stuck pane types once, alarms, and preserves the buffer
ok - max-defer flushes and clears the buffer on an empty bordered pane
ok - max-defer escape delivers past a busy verdict instead of re-running the guard that deferred
ok - busy guard vetoes an ordinary injection but yields to the bounded escape on the same pane
ok - bounded busy-guard escape still defers on a pending composer
ok - delivery_selftest proves one injection and records a durable ok
ok - delivery_selftest records a durable failure and alarms when delivery cannot be proven
ok - fm-afk-launch verify passes on a proven delivery and fails loudly otherwise
ok - max-defer on a pending composer alarms without typing
ok - normal flush clears a stale wedge marker
ok - below MAX_DEFER: no inject, no alarm, buffer preserved
ok - max-defer does not flush or alarm while afk is inactive
ok - library mode: sourcing the daemon defaults FM_WEDGE_ALARM_EXEC to discard (no test can fire a real notification)
ok - wake helpers replace inherited notifier overrides with the safe recorder
ok - the discard seam suppresses every notifier, including command: (fires nothing)
ok - direct notifier helpers honor the discard seam, including command:
ok - osascript channel routes through the notifier seam with the summary (never a real notification)
ok - herdr channel routes through the notifier seam with the summary (never a real notification)
ok - command channel runs the captain command with the summary on $1 and on stdin
ok - command channel failures redact configured commands while logging their exit status
ok - unknown channel directives are redacted while the alarm keeps running
ok - off disables every active alert regardless of directive position (marker and tmux flash are unaffected)
ok - auto resolves to the macOS osascript notifier on Darwin (default-on)
ok - auto off macOS uses an installed herdr notifier and selects nothing when none exists
ok - config/wedge-alarm selects every configured channel and skips comment and blank lines
ok - a failing channel logs and falls back to the next channel, never crashing the alarm
ok - a hung notifier is bounded, logged, and falls through to the next channel
ok - a backgrounded command notifier remains bounded until its process group is reaped
ok - a hung notifier override is bounded, logged, and proceeds to the next channel
[1]+  Terminated              sh -c 'sleep 30 & printf "%s" "$!" > "$1"; wait' sh "$child_file"
ok - daemon shutdown stops and reaps the active notifier process group
ok - inject_wedge_alarm writes the marker AND emits the active alert even with no tmux status-line (herdr backend)
ok - in-process wedge throttle prevents alert spam when the marker cannot persist
ok - fm-send returns 3 with a non-error no-resend warning when confirmation stays pending
ok - fm-send exits non-zero when initial text send fails
ok - fm-send exits non-zero unless delivery is proven empty
ok - discover_supervisor_backend: override > TMUX_PANE > HERDR_ENV+HERDR_PANE_ID > tmux fallback
ok - discover_supervisor_target: override > TMUX_PANE > herdr '<session>:<pane-id>' composition > firstmate:0 fallback
ok - pane_busy_verdict: busy needs corroboration, a legible idle on either signal wins, and each verdict names its signal
ok - pane_is_busy: agrees with pane_busy_verdict and publishes its signal for the deferral log
ok - primary busy guard isolates rendered signatures by detected harness
ok - pane_is_busy: omitted backend defaults to tmux for Grok's isolated fallback
ok - pane_input_pending: dispatches through fm_backend_composer_state for backend=herdr
ok - inject_msg: herdr busy-guard defers before ever attempting a submit
ok - inject_msg: herdr composer-guard defers before ever attempting a submit
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
ok - inject_msg: defers on a dead-shell/unreadable composer (unknown), never typing the escalation into a shell
ok - inject_msg: unrecognized composer states defer by default
Evidence: fm-afk-launch suite on target — sole failure is the herdr-lab prep
ok - clear-stale: removes escalations buffer, sidecar, and wedge marker
ok - clear-stale: leaves the durable wake-queue intact (no pending work dropped)
ok - launcher paths: relative home and state ignore CDPATH before daemon command construction
ok - launcher paths: absolute symlink spellings are preserved
ok - launcher paths: unresolved relative FM_HOME fails loudly
ok - launcher paths: unresolved relative FM_STATE_OVERRIDE fails loudly
ok - refresh: daemon already alive - stale artifacts preserved (current session's buffer kept)
ok - stop-ordering: daemon SIGTERM'd while .afk still present (flush is not a no-op)
ok - stop-ordering: .afk cleared last
ok - stop-ordering: daemon-terminal record removed
ok - stop identity: stale lock cannot signal an unrelated live process
ok - failed start: away flag and delivery artifacts roll back
ok - concurrent start: one serialized daemon terminal remains tracked
ok - launcher lock: incomplete publication receives initialization grace
ok - launcher signal: TERM exits and releases the lifecycle lock
fm-afk-launch: daemon launched in non-visible herdr workspace ws-partial (pane lab:pane-exact), supervising lab:captain
ok - herdr create: malformed response recovers durable exact ownership
fm-afk-launch: herdr create failed after returning exact ids; closing lab:pane-exact
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr create error: unconfirmed exact id is persisted for reconciliation
fm-afk-launch: failed to run daemon in herdr pane lab:pane-exact; closing it
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr run failure: unconfirmed exact id remains reconcilable
fm-afk-launch: failed to persist daemon terminal record; closing tmux:exact-session
ok - record failure: newly created terminal is closed by exact id
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
ok - readiness failure: exact terminal and durable record roll back
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - readiness failure: unconfirmed terminal retains its reconciliation id
ok - tmux absence: clean missing differs from transport probe failure
ok - native lifecycle: launcher owns state with no terminal
ok - native lifecycle: uniform stop clears state without closing a terminal
ok - native entry: launcher-prepared lifecycle state is not rewritten
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - teardown failure: exact terminal record is preserved
ok - record publication: failed atomic rename preserves the complete prior record
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - record read: malformed record fails closed without acting on a partial id
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: malformed daemon terminal record; refusing to stop away mode
ok - stop: malformed terminal record preserves away state and fails closed
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-1797726036-940723-11365-1787573978'
ok - tmux launch: planned exact target is recorded before creation and removed on failure
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-235536195-940754-24711-1787573978'
ok - tmux launch: unique names eliminate collision teardown
ok - stop validation: malformed record causes no daemon or state side effects
ok - launcher lock: incomplete metadata fails acquisition and releases lock
fm-afk-launch: failed to clear away-mode flag
fm-afk-launch: away mode stopped; terminal teardown remains recorded for retry
ok - stop state: away-flag removal failure is surfaced
fm-afk-launch: away-mode daemon did not exit after SIGTERM; preserving lifecycle state
ok - stop liveness: captured live daemon preserves lifecycle state after lock release
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - refresh record: malformed terminal identity fails closed
fm-afk-launch: failed to clear stale away-mode artifacts
ok - clear failure: native entry aborts and restores prior state
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: terminal close command failed, but exact absence was confirmed
ok - confirmed absence: cleanup succeeds and removes the stale record
fm-afk-launch: rollback restoration incomplete; backup retained at /tmp/fm-afk-restore-fail.9Ey4Si/state/.afk-launch-backup.VP5iL5
ok - rollback restore: incomplete restoration retains its recovery backup
ok - flag failure: lifecycle aborts without active state
fm-herdr-lab: fleet-state tripwire requires exactly one running default session
not ok - herdr e2e: could not prepare isolated lab session
ok - tmux e2e: captain window pane count unchanged after start (no split-window)
ok - tmux e2e: daemon launched in a separate detached session
ok - tmux e2e: captain window pane count unchanged after stop
ok - tmux e2e: daemon session killed by exact id on stop
ok - tmux e2e: record + .afk cleared on stop
Evidence: fm-afk-launch suite on baseline 038d0f7 — identical sole failure (pre-existing)

not ok - herdr e2e: could not prepare isolated lab session (exit=1, 45 ok — identical to target commit run)

ok - clear-stale: removes escalations buffer, sidecar, and wedge marker
ok - clear-stale: leaves the durable wake-queue intact (no pending work dropped)
ok - launcher paths: relative home and state ignore CDPATH before daemon command construction
ok - launcher paths: absolute symlink spellings are preserved
ok - launcher paths: unresolved relative FM_HOME fails loudly
ok - launcher paths: unresolved relative FM_STATE_OVERRIDE fails loudly
ok - refresh: daemon already alive - stale artifacts preserved (current session's buffer kept)
ok - stop-ordering: daemon SIGTERM'd while .afk still present (flush is not a no-op)
ok - stop-ordering: .afk cleared last
ok - stop-ordering: daemon-terminal record removed
ok - stop identity: stale lock cannot signal an unrelated live process
ok - failed start: away flag and delivery artifacts roll back
ok - concurrent start: one serialized daemon terminal remains tracked
ok - launcher lock: incomplete publication receives initialization grace
ok - launcher signal: TERM exits and releases the lifecycle lock
fm-afk-launch: daemon launched in non-visible herdr workspace ws-partial (pane lab:pane-exact), supervising lab:captain
ok - herdr create: malformed response recovers durable exact ownership
fm-afk-launch: herdr create failed after returning exact ids; closing lab:pane-exact
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr create error: unconfirmed exact id is persisted for reconciliation
fm-afk-launch: failed to run daemon in herdr pane lab:pane-exact; closing it
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr run failure: unconfirmed exact id remains reconcilable
fm-afk-launch: failed to persist daemon terminal record; closing tmux:exact-session
ok - record failure: newly created terminal is closed by exact id
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
ok - readiness failure: exact terminal and durable record roll back
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - readiness failure: unconfirmed terminal retains its reconciliation id
ok - tmux absence: clean missing differs from transport probe failure
ok - native lifecycle: launcher owns state with no terminal
ok - native lifecycle: uniform stop clears state without closing a terminal
ok - native entry: launcher-prepared lifecycle state is not rewritten
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - teardown failure: exact terminal record is preserved
ok - record publication: failed atomic rename preserves the complete prior record
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - record read: malformed record fails closed without acting on a partial id
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: malformed daemon terminal record; refusing to stop away mode
ok - stop: malformed terminal record preserves away state and fails closed
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-2142599072-961178-10719-1787574040'
ok - tmux launch: planned exact target is recorded before creation and removed on failure
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-3874677644-961209-30792-1787574040'
ok - tmux launch: unique names eliminate collision teardown
ok - stop validation: malformed record causes no daemon or state side effects
ok - launcher lock: incomplete metadata fails acquisition and releases lock
fm-afk-launch: failed to clear away-mode flag
fm-afk-launch: away mode stopped; terminal teardown remains recorded for retry
ok - stop state: away-flag removal failure is surfaced
fm-afk-launch: away-mode daemon did not exit after SIGTERM; preserving lifecycle state
ok - stop liveness: captured live daemon preserves lifecycle state after lock release
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - refresh record: malformed terminal identity fails closed
fm-afk-launch: failed to clear stale away-mode artifacts
ok - clear failure: native entry aborts and restores prior state
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: terminal close command failed, but exact absence was confirmed
ok - confirmed absence: cleanup succeeds and removes the stale record
fm-afk-launch: rollback restoration incomplete; backup retained at /tmp/fm-afk-restore-fail.GxX2Db/state/.afk-launch-backup.Y3LT9d
ok - rollback restore: incomplete restoration retains its recovery backup
ok - flag failure: lifecycle aborts without active state
fm-herdr-lab: fleet-state tripwire requires exactly one running default session
not ok - herdr e2e: could not prepare isolated lab session
ok - tmux e2e: captain window pane count unchanged after start (no split-window)
ok - tmux e2e: daemon launched in a separate detached session
ok - tmux e2e: captain window pane count unchanged after stop
ok - tmux e2e: daemon session killed by exact id on stop
ok - tmux e2e: record + .afk cleared on stop

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • 🚨 tests/fm-afk-inject-e2e.test.sh:475 - Scenario D's undeliverable-pane half cannot pass as written: it starts the daemon with SUPERVISOR_TARGET_OVERRIDE='%99999', but the daemon validates the target at startup (bin/fm-supervise-daemon.sh:1559, fm_backend_target_exists -> tmux display-message -p -t %99999, which fails through the e2e shim against the real private-socket tmux) and exits before delivery_selftest at line 1573 ever runs. No failed verdict is written, so wait_for_selftest_verdict failed times out, and the pidfile is removed on that exit so start_daemon usually fails first at 'daemon did not start'. This contradicts the intent's evidence claim that Scenario D 'proves both directions end to end'. It also means the daemon's failed verdict path is unreachable for a nonexistent-pane entry in production (verify still fails safe, but only via its 90s timeout with the generic 'did not report' message). The failure half needs a shape the daemon can survive startup with, e.g. a pane killed after startup validation or a permanently pending composer.
  • ⚠️ bin/fm-supervise-daemon.sh:1573 - delivery_selftest runs before the shutdown trap is installed: it is called at bin/fm-supervise-daemon.sh:1573 while the singleton lock and pidfile are held, but trap cleanup TERM INT is not installed until line 1593. The self-test retries for up to FM_DELIVERY_SELFTEST_SECS (default 45s), so a SIGTERM in that window - including the fm-afk-launch.sh stop rollback prescribed on entry failure, arriving during a slow entry - kills the daemon by default action, leaking the lock directory and pidfile and skipping the shutdown flush. Before this change the unprotected lock-to-trap window was microseconds. Fix: move the delivery_selftest &#34;$STATE&#34; || true call below trap cleanup TERM INT (cleanup already tolerates empty WATCHER_PID/CUR_TMP).
  • ℹ️ tests/fm-daemon.test.sh:1359 - test_delivery_selftest_records_failure_and_alarms never overrides FM_DELIVERY_SELFTEST_SECS/FM_DELIVERY_SELFTEST_SLEEP, so delivery_selftest retries the unreachable-pane injection for the full 45s default window (15 attempts at 3s intervals) before recording failed - adding ~45s of wall-clock to every fm-daemon.test.sh run. Passing FM_DELIVERY_SELFTEST_SECS=1 FM_DELIVERY_SELFTEST_SLEEP=1 in the test keeps the assertions identical and fast (the e2e Scenario D already does exactly this).

🔧 Fix: record startup delivery failures, trap before selftest, fix vacuous tmux probe
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-daemon.test.sh on target commit — exit 0, 110 assertions, covering pane_busy_verdict corroboration, PANE_BUSY_SOURCE deferral logging, bounded max-defer escape, escape-respects-pending-composer safety boundary, delivery_selftest ok/failed verdicts, fm-afk-launch verify gate, and herdr auto-channel resolution off macOS
  • Failing-then-passing proof: git checkout 038d0f7 -- bin/fm-supervise-daemon.sh &amp;&amp; bash tests/fm-daemon.test.sh — exit 1 failing at not ok - max-defer did not deliver past a busy pane, then restored daemon passes
  • bash tests/fm-afk-inject-e2e.test.sh — real tmux pane + real daemon on a private socket; Scenarios A–C plus Scenario D (entry self-test ok path with operator-visible verify success message, gone-pane failed verdict, pending-composer failed verdict, verify rejecting both failure paths); exit 0
  • bash tests/fm-afk-launch.test.sh on target (exit 1, sole failure herdr e2e: could not prepare isolated lab session, 45 ok) and on a pristine baseline-038d0f7 extraction (identical sole failure, 45 ok) — confirms the failure is pre-existing and not a regression
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Away mode could buffer escalations indefinitely: the pre-injection busy
guard was a single-source veto, and the max-defer escape re-ran the same
guard, so one false positive blocked every delivery while the wedge alarm
fired into a channel that resolved to nothing on Linux (upstream kunchenguid#2917;
a live home buffered 39 escalations over 7h16m and delivered none).

- pane_busy_verdict corroborates the native agent state against the
  rendered pane before declaring busy, and a legible idle on either
  signal wins. pane_is_busy stays the single predicate and publishes
  PANE_BUSY_SOURCE so a deferral names the signal that vetoed it. tmux
  is unchanged because it exposes no native agent state.
- The max-defer flush now sets FM_INJECT_IGNORE_BUSY so the escape
  bypasses the guard that deferred. The composer guard and the verified
  submit still apply, so the pane's contents stay protected.
- auto/default resolves to herdr off macOS when the CLI is installed,
  instead of leaving a non-macOS host with no active alert.
- The daemon proves one injection reaches the captain pane at startup
  and records the verdict; bin/fm-afk-launch.sh verify fails away-mode
  entry when that proof is absent, so away mode is never reported
  active on an undeliverable path.

Regression coverage in tests/fm-daemon.test.sh and end-to-end proof of
both entry outcomes in tests/fm-afk-inject-e2e.test.sh Scenario D.
@greptile-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (4): Last reviewed commit: "fix(afk): parse leading-zero self-test t..." | Re-trigger Greptile

Comment thread bin/fm-supervise-daemon.sh Resolved
Malformed or non-positive FM_DELIVERY_SELFTEST_SECS collapsed the retry
window to one attempt, and an invalid FM_DELIVERY_SELFTEST_SLEEP made a
tight retry loop. Fall back to the defaults (45s window, 3s gap) using
the same guard pattern as FM_WEDGE_ALARM_TIMEOUT_SECS.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread bin/fm-afk-launch.sh Resolved
…eout

FM_AFK_VERIFY_TIMEOUT_SECS=0 made the poll condition false before the
durable record was ever read, so verify rejected an already-present ok
verdict and directed a rollback of a working away-mode entry. The loop
now reads the record once before checking the deadline.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread bin/fm-supervise-daemon.sh Resolved
FM_DELIVERY_SELFTEST_SECS=09 passed the all-digits validation but blew up
the deadline arithmetic as invalid octal, silently losing the bounded
retry window. Coerce both timing values with 10# and cover it with a
regression test that traps the arithmetic error in a subshell.

Co-Authored-By: Claude Fable 5 <[email protected]>
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