Repository navigation
fix(bin): stop a self-hosted away daemon reading itself as the agent being busy - #1
Closed
AgardnerAU wants to merge 5 commits into
Closed
AgardnerAU wants to merge 5 commits into
AgardnerAU wants to merge 5 commits into
Conversation
* 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.
…gent-status reader
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. |
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.
The fault
Away mode buffered every escalation and delivered none.
state/.supervise-daemon.logcarried 6,910 consecutiveinject 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.mdstep 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:
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, whileagent_statusstayedworkingfor all 21 remaining samples across 121 seconds. A control pane with no background job reporteddone.pane_is_busytreated 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 thatbin/fm-composer-lib.shalready 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_busyprints busy whenever raw status isworking;fm_composer_queued_enter_verdictconvertspending + busytoempty;escalate_flushthen 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.shfunnel through one function, so the boundary is owned once atfm_backend_herdr_agent_status_rawrather 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- neveridle. 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 topending. Onlyworkingis masked;idle/done/blockeddescribe 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 furtheragent getsites bypass that reader and are not instances of this fault: the tab-prune guard errs conservative (a falseworkingprevents a close), the liveness probe maps every status toliveso 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) plusbin/fm-pending-reply-lib.shandbin/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:
emptyidleinstead of no-statusidleworkingReachability 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
unknownrather thanidle.One pre-existing test was made hermetic - it was the only
pane_is_busycase 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) andbin/fm-doc-audience-check.shclean. 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.shandtests/fm-composer-lib.test.shfail under anLC_ALL=Clocale (multi-byte fixture comparisons; green under UTF-8), andtests/fm-pending-reply.test.shfails its unmarked-crewmate-send case on the clean base.