Repository navigation
fix(afk): deliver away-mode escalations past a false busy signal and verify entry delivery - #2956
Closed
juangedaan wants to merge 6 commits into
Closed
juangedaan wants to merge 6 commits into
juangedaan wants to merge 6 commits into
Conversation
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.
…lftest, fix vacuous tmux probe
Confidence Score: 5/5The 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 |
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]>
…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]>
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]>
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
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
bin/fm-supervise-daemon.shwithpane_busy_verdict, which corroborates the harness agent-state against the rendered pane signature (busy requires corroboration; a legible idle on either signal wins) and publishesPANE_BUSY_SOURCEfor deferral logs. The max-defer escape now flushes withFM_INJECT_IGNORE_BUSY=1so it bypasses the same guard that deferred, while the empty-composer guard and verified type-once submit still protect pane contents (pinned bytest_busy_guard_escape_still_respects_a_pending_composer).auto/defaultchannel 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.FM_DELIVERY_SELFTEST_SECSwindow, with the shutdown trap installed before the self-test runs) and records ok/failed/skipped instate/.subsuper-delivery-selftest;bin/fm-afk-launch.sh verifyfails away-mode entry and names the stop rollback when that proof is absent. Covered by newtests/fm-daemon.test.shassertions and e2e Scenario D intests/fm-afk-inject-e2e.test.sh, with docs updated indocs/wedge-alarm.md,docs/verification/supervision.md, and the/afkskill.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)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 passedEvidence: fm-daemon suite on target commit (110 assertions, exit 0)
Evidence: fm-afk-launch suite on target — sole failure is the herdr-lab prep
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)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 beforedelivery_selftestat line 1573 ever runs. Nofailedverdict is written, sowait_for_selftest_verdict failedtimes out, and the pidfile is removed on that exit sostart_daemonusually 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'sfailedverdict 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, buttrap cleanup TERM INTis 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 thefm-afk-launch.sh stoprollback 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 thedelivery_selftest "$STATE" || truecall belowtrap 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 recordingfailed- 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.shon 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 macOSFailing-then-passing proof:git checkout 038d0f7 -- bin/fm-supervise-daemon.sh && bash tests/fm-daemon.test.sh— exit 1 failing atnot ok - max-defer did not deliver past a busy pane, then restored daemon passesbash 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 0bash tests/fm-afk-launch.test.shon target (exit 1, sole failureherdr 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.