Skip to content

fix(bin): stop a self-hosted away daemon reading itself as the agent being busy - #1

Closed
AgardnerAU wants to merge 5 commits into
mainfrom
fm/fm-afk-inject-never-delivers
Closed

AgardnerAU wants to merge 5 commits into
mainfrom
fm/fm-afk-inject-never-delivers

Conversation

@AgardnerAU

Copy link
Copy Markdown
Owner

The fault

Away mode buffered every escalation and delivered none.

state/.supervise-daemon.log carried 6,910 consecutive inject deferred: supervisor pane busy (agent mid-turn) lines with no gap greater than 60 seconds anywhere in 8.7 hours, one buffer held undelivered for 31,396 seconds overnight, and zero deliveries. A genuinely busy agent would have shown at least one idle sample in 8.7 hours.

Away mode had worked: the 2026-08-19/20 daemon run delivered 14 escalations with zero deferrals. It broke by 2026-08-22.

Cause

On the native hosting (.agents/skills/afk/SKILL.md step 2) the away daemon runs as a background job of the very agent it injects into. A backend's native agent-state answers "is anything running in this pane", not "is the agent mid-turn". So the daemon's own existence pinned its own target busy for as long as away mode lasted.

Measured 2026-08-25 against Herdr 0.8.0 protocol 19 and Claude Code 2.1.245 on macOS aarch64, by read-only sampling of a Claude pane whose turn had ended while a harness-hosted background job kept running:

17:46:38 agent_status=working title=◐ ...
17:46:44 agent_status=working title=✳ ...
...
17:48:45 agent_status=working title=✳ ...

The harness's own title glyph turned from working ◐ to idle ✳ at 17:46:44 and the rendered footer stopped matching its delivery busy signature at the same sample, while agent_status stayed working for all 21 remaining samples across 121 seconds. A control pane with no background job reported done.

pane_is_busy treated native busy as conclusive, so the guard could never clear and the existing max-defer escape could never escape - it retried the same impossible condition.

The fix

Two changes, both narrow.

1. The busy guard. Native busy stays conclusive only when the daemon runs outside the pane it injects into. supervisor_pane_hosts_daemon (bin/fm-supervisor-target-lib.sh) recognizes the self-hosted case; the verdict then falls through to the rendered delivery signature that bin/fm-composer-lib.sh already owns as the authority on whether a pane can accept a keystroke. The composer guard is untouched, so a half-typed captain line still defers.

2. The same root cause at the submit boundary, found in review. The contaminated signal was still trusted when confirming a submit, and the busy-guard fix is what made that reachable. Chain: fm_backend_herdr_queued_enter_busy prints busy whenever raw status is working; fm_composer_queued_enter_verdict converts pending + busy to empty; escalate_flush then truncates the buffer and deletes the wedge marker. A swallowed Enter would have been recorded as delivered while the text sat unsent, with the alarm cleared instead of raised - silent loss, worse than the stall being fixed.

Inspection found a third affected read the review did not name, fm_backend_herdr_wait_for_working, which becomes load-bearing precisely because fixing the second one makes its branch reachable. Fixing the two named sites would have relocated the bug, not closed it.

All five raw reads in bin/backends/herdr.sh funnel through one function, so the boundary is owned once at fm_backend_herdr_agent_status_raw rather than repeated per call site. Repeating a predicate at three sites is three chances to miss the next one - which is what had already happened at two.

The masked value is empty, classifying as unknown - never idle. It must not assert the agent is free; that would trade one wrong answer for its opposite. Consumers fall through to a signal that really is about the agent, so a genuinely swallowed Enter still resolves to pending. Only working is masked; idle/done/blocked describe the agent and pass through unchanged.

Native-state call-site inventory

Five raw reads in bin/backends/herdr.sh (2772, 2789, 3000, 3056, 3337), all through the single reader now owning the boundary. Three sit in the away-mode submit path. Three further agent get sites bypass that reader and are not instances of this fault: the tab-prune guard errs conservative (a false working prevents a close), the liveness probe maps every status to live so contamination cannot change its verdict, and the identity probe backs the Pi composer shape, which is never self-hosted because Pi uses the terminal-backed launcher.

Separately, three callers consume the semantic wrapper fm_backend_busy_state: the daemon (fixed) plus bin/fm-pending-reply-lib.sh and bin/fm-busy-lib.sh, which classify worker panes. A worker pane never hosts the daemon, so the predicate is false there - proven by test, not argument.

Evidence

Every regression was mutation-checked rather than assumed:

Mutation Caught by
Remove the busy-guard fix self-hosted fall-through and delivery cases fail
Ignore native busy entirely pre-existing short-circuit assertion fails
Treat a self-hosted pane as never busy (inject mid-turn) "still defers on a genuinely mid-turn harness" fails
Remove the reader masking "a swallowed Enter must stay pending" reports empty
Report self-hosted as idle instead of no-status masking assertion fails on idle
Mask every status, not only working pass-through assertion fails
Mask worker panes too (blast radius) worker-pane classification fails

Reachability was determined, not assumed: the rendered-footer transition escape becomes reachable for the first time and is covered; the idle-native baseline branch does not become reachable, because the masked status classifies as unknown rather than idle.

One pre-existing test was made hermetic - it was the only pane_is_busy case not clearing ambient pane identity, so this change would otherwise have made its verdict depend on the environment. What it asserts is unchanged.

What ran, and what did not

Ran locally: the no-mistakes pipeline through intent, rebase, review, test, document and lint - all completed. bin/fm-lint.sh (ShellCheck 0.11.0, actionlint 1.7.12) and bin/fm-doc-audience-check.sh clean. Affected suites green, plus the seven mutation checks above.

Did NOT run: CI. This is a fork pull request, so workflow runs wait on an upstream maintainer to release them. There is no CI result here, and its absence is not evidence of green. The pipeline's push step returned HTTP 403 against the upstream, which is correct for an account without write access there; the branch was pushed to the fork instead.

Two pre-existing failures on this repository, unrelated to this change and reproduced on a clean tree, are reported separately rather than fixed here: tests/fm-afk-inject-e2e.test.sh and tests/fm-composer-lib.test.sh fail under an LC_ALL=C locale (multi-byte fixture comparisons; green under UTF-8), and tests/fm-pending-reply.test.sh fails its unmarked-crewmate-send case on the clean base.

kunchenguid and others added 5 commits August 24, 2026 22:05
* feat(bin,pi): per-actor wake consume, silent success gating, merge-poll dedup

Three related fixes to the shared wake-drain and Pi supervision-branch
dispatch machinery so a routine success is never main-blocking and a
mixed queue can safely split between actors.

1. Successful routine results no longer create main-blocking wake rows.
   fm-startup-network.sh only enqueues a check: startup-network wake when
   the deferred result is actionable (state is not "done", or the report
   carries a bootstrap-diagnostics actionable prefix); a clean success
   stays durable in the report file without ever waking the agent.

2. Per-actor wake-drain consume contract. bin/fm-wake-drain.sh now scopes
   presentation and --ack-through to the current actor
   (bin/fm-lease-lib.sh's fm_lease_actor): main keeps the original
   whole-queue cutoff behavior, unaffected. A branch actor
   (FM_SUPERVISION_ACTOR=branch, set only inside the Pi supervision
   branch's own bash tool calls) is scoped to an explicit eligible-row
   snapshot instead of a cutoff comparison, so it can never remove a row
   it was not granted - the fix for the swallow risk that used to force
   an all-or-nothing whole-queue fallback to main.
   .pi/extensions/lib/fm-branch-dispatch.ts's scopeForUnreadWake is the
   single owner of eligibility: a check-kind row (merge-confirmation
   polls, Relay mentions, credential/auth failures) is now excluded
   rather than vetoing the whole scan for a non-heartbeat wake, while a
   heartbeat review keeps its original all-or-nothing rule unchanged.
   writeEligibleRowsSnapshot publishes the exact eligible sequence
   numbers before every branch prompt; fm-primary-pi-watch.ts's offer
   still refuses a check-kind trigger outright so a main-only close is
   never itself routed to the branch.

3. A repeat identical merged-PR-poll result for an already-notified task
   is absorbed instead of enqueued again. A poll's own retirement state
   is scoped to one registration and cannot see a prior registration's
   outcome, so a task re-registered after its merge was already surfaced
   would otherwise wake main a second time for the same event.
   bin/fm-pr-lib.sh's new per-task pr-poll-merge-notified marker survives
   across re-registrations to catch that case; the first notification for
   a task still reaches main unchanged.

Regression tests colocated in tests/fm-startup-network.test.sh,
tests/fm-wake-queue.test.sh (including the mixed-queue no-swallow
property), tests/fm-pi-branch-extension.test.sh, and
tests/fm-pr-check-security.test.sh. docs/watcher-continuity.md and
docs/pi-supervision-branch.md updated for the new contracts.

* no-mistakes(review): Bind merge deduplication to canonical PR identity

* no-mistakes(review): Serialize wake row ownership across main and branch

* no-mistakes(review): Bind branch grants and deduplicate within actor claims

* no-mistakes(review): Fallback main-owned wake claims to main delivery

* no-mistakes(review): Clarify silent startup success guidance

* no-mistakes(review): Release residual branch grants after settled prompts

* no-mistakes(review): Reject truncated wake rows as corrupted

* no-mistakes(document): Document per-actor routing and silent startup success

* no-mistakes(lint): Fix ShellCheck findings in wake grant and startup test

* no-mistakes: apply CI fixes
* Hide branch outcome tool in Pi Calm

* no-mistakes(review): Preserve stock outcomes rendering and document tool audit

* no-mistakes(review): Document branch read tool audit disposition

* no-mistakes(review): Match stock outcomes output sanitization

* no-mistakes(document): Document Calm custom-tool visibility
…being busy

Away mode buffered every escalation and delivered none. The daemon log carried
6,910 consecutive "supervisor pane busy (agent mid-turn)" deferrals with no gap
over 8.7 hours, one buffer held 31,396 seconds overnight, and zero deliveries.

Cause. On the native hosting the daemon runs as a background job of the very
agent it injects into. A backend's native agent-state answers "is anything
running in this pane", not "is the agent mid-turn", so the daemon's own
existence pinned its target busy for as long as away mode lasted. Measured
2026-08-25 on Herdr 0.8.0 with Claude Code 2.1.245: agent_status stayed
"working" for 121 seconds after the turn ended, across 21 samples, while the
harness's own title glyph and rendered footer both showed idle; a control pane
with no background job reported "done".

pane_is_busy treated native busy as conclusive, so the guard could never clear
and the max-defer escape could never escape.

Native busy now stays conclusive only when the daemon runs outside the pane it
injects into. supervisor_pane_hosts_daemon recognizes the self-hosted case, and
the verdict then falls through to the rendered delivery signature that
fm-composer-lib.sh already owns as the authority on whether a pane can accept a
keystroke. The composer guard is untouched, so a half-typed captain line still
defers.

Coverage pins the condition from both sides: a self-hosted daemon delivers
through native busy, still defers while the harness renders a live turn, and a
terminal-hosted daemon keeps native busy conclusive. Each new test was checked
to fail without the fix, and the pre-existing short-circuit assertion catches
the over-broad repair.
@AgardnerAU

Copy link
Copy Markdown
Owner Author

Opened against the wrong base (fork-internal AgardnerAU:main), so this never reached upstream. Replaced by kunchenguid#3050, same branch and same commit 6039514. Closing this one; the branch stays.

@AgardnerAU AgardnerAU closed this Aug 25, 2026
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.

2 participants