Skip to content

fix(bin): reliably confirm herdr steer submission - #2647

Merged
kunchenguid merged 7 commits into
mainfrom
fm/herdr-local-send-flush-fix-r1
Aug 19, 2026
Merged

kunchenguid merged 7 commits into
mainfrom
fm/herdr-local-send-flush-fix-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

SHIP: fix the herdr backend adapter's LOCAL-SEND FLUSH FLAKINESS. Steers sent via bin/fm-send.sh to local claude crewmates on the herdr backend intermittently get swallowed or stuck-queued: the composer text lands but the Enter submit is not reliably confirmed, so the instruction sits unsent, or fm-send reports a swallow that then needs a re-send --key Enter or a full relaunch to unstick. This is real and recurring in live supervision. The opencode busy-queued-Enter exception was fixed for tmux but the herdr adapter observed the same behavior and was left unfixed; more broadly herdr's composer-submit confirmation is less reliable than tmux's.

Goal: make a herdr-backend steer land as reliably as a tmux steer. The Enter submit must be positively confirmed via the herdr adapter's own submit/agent-state primitive. fm-send must fail loudly (non-zero) ONLY on a genuine swallow - never false-positive a busy-queued Enter as swallowed, and never silently leave a steer unsent.

Preserve the distinction exactly: a busy-queued Enter that WILL submit = DELIVERED (not a failure); a genuinely idle composer that still holds unsent text = PENDING/needs-verify; a real swallow (text lost, no submit) = a genuine loud failure. Do not make the herdr path fail-open (hiding a real swallow) or fail-closed (screaming on a normal busy-queue).

Do it right: reproduce E2E against a live herdr-backed claude in an isolated named non-default herdr lab (never the live default session); root-cause via diagnostic-reasoning (compare against tmux's fm_tmux_submit_enter_core busy-queue fallback); fix herdr submit-confirm so queued-while-busy Enter is DELIVERED and idle-but-uncleared composer is PENDING, mirroring tmux semantics but using herdr's native primitives (do not bolt tmux mechanics onto herdr). bin/fm-composer-lib.sh is the ONE fleet-wide owner of composer shape / the empty/pending/pending-unproven/unknown decision - keep that policy there. Add a real behavioral test that exercises the submit-verify verdict path, not an implementation-snapshot/source-byte test; this is harness-dependent so include a portable regression that drives the classifier logic plus an env-gated live-harness guard. Update the herdr-backend doc note that currently records this as a known unfixed gap.

Firstmate shared tracked material (bin/, docs, the herdr adapter). Load firstmate-coding-guidelines first. yolo OFF - escalate any ask-user finding; do not answer it yourself. Note in the PR that homes pick this up after merge plus a firstmate self-update and that landing timing is coordinated with the main firstmate.

Decisions made while implementing: live Claude 2.1.236 on Herdr 0.8.0 keeps agent_status=idle for an entire landed turn (including a multi-second tool call), which is why wait_for_working false-positived pending. The fix keeps native working/blocked as the fast confirm, falls through to a cleared composer as positive delivery when native stays idle, and uses fm_composer_queued_enter_verdict for proven-pending plus generating busy (native working, or rendered busy footer only on an idle native baseline). Cursor's always-blocked native state must not receive the queued-Enter conversion. Tmux now calls the same shared verdict helper rather than inlining a second copy of the policy.

What Changed

  • Confirm Herdr submits through native state and composer fallback, distinguishing delivered busy-queued Enters from genuine idle pending swallows.
  • Centralize queued-Enter verdict policy in the composer library and reuse it across Herdr and tmux with backend-native busy signals.
  • Add portable regressions, an opt-in isolated live Herdr/Claude guard, and updated backend docs. Homes pick this up after merge and a Firstmate self-update; landing timing is coordinated with the main Firstmate.

Risk Assessment

✅ Low: The change is well-bounded, preserves the required submit-state distinctions, and the prior fixes now prevent confirmation after unreadable or wholly failed Enter attempts.

Testing

Inspected the branch, exercised shared queued-Enter classification, Herdr and tmux submit verdicts, fm-send pending/failure behavior, and a live isolated Herdr-backed Claude steer; all checks passed, the requested reply rendered, and lab cleanup preserved the default session.

Evidence: Live isolated Herdr submit-confirmation transcript

Source: Live isolated Herdr submit-confirmation transcript

ok - live Herdr submit confirm: Claude Code (2.1.236 (Claude Code)) on herdr 0.8.0 reports empty and renders the requested reply in isolated session fm-lab-herdr-submit-con-77346-20978

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (5) ✅
  • 🚨 bin/backends/herdr.sh:2812 - When native status remains idle but composer capture returns unknown, this branch continues the Enter retry loop. A landed Claude turn whose native status stays idle plus a transient pane-read failure can therefore receive another Enter, potentially activating a newly rendered prompt; this also contradicts the documented invariant that an unreadable target stops retrying. Return unknown immediately here, while continuing retries only for pending states.

🔧 Fix: Stop Herdr Enter retries on unreadable composers
1 error still open:

  • 🚨 bin/backends/herdr.sh:2831 - The queued-Enter conversion can report delivery even when every fm_backend_herdr_send_key ... Enter call failed because line 2799 discards those failures. Concrete path: native status is already working, literal text remains structurally pending, all Enter CLI calls fail, and the final native read remains working; this branch returns empty although no Enter was sent. Track whether any Enter call succeeded and permit the busy-queue conversion only after at least one successful key send; otherwise return a loud failure verdict.

🔧 Fix: Reject queued delivery when all Herdr Enter sends fail
1 error still open:

  • 🚨 bin/backends/herdr.sh:2799 - A failed Enter attempt still runs confirmation and can return empty before the exhaustion guard checks enter_sent. Concrete path: baseline is idle, fm_backend_herdr_send_key fails, then an unrelated native transition reports working or blocked; line 2806 falsely confirms this steer despite no successful Enter. When no Enter has yet succeeded, skip confirmation and consume the retry or return a transport failure at exhaustion.

🔧 Fix: Prevent confirmation after failed Herdr Enter
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/backends/herdr.sh:2807 - Before any Enter succeeds, a failed send_key immediately retries without the configured delay. A short Herdr transport hiccup can therefore consume the entire retry budget back-to-back and return send-failed, although the same retries spaced by sleep_s could recover. Sleep before continuing to preserve the retry loop's transient-failure tolerance.
  • ℹ️ .agents/skills/afk/SKILL.md:126 - The submit model still says the shared classifier is used only for non-idle or unreadable Herdr baselines, but the changed implementation now consults it whenever an idle native baseline remains idle. Update this operational guidance to describe the cleared-composer and pending fallback accurately.

🔧 Fix: Pace Herdr retries and clarify submit fallback
3 issues (1 error, 2 infos) still open:

  • 🚨 tests/fm-herdr-submit-confirm-live-e2e.test.sh:93 - The required live E2E guard can pass without reproducing the idle-native fallback or proving the steer landed: readiness accepts done/blocked, and after sending it asserts only the adapter's own empty verdict without observing the requested PONG. This contradicts the intent to “reproduce E2E against a live herdr-backed claude” and could preserve a false-positive confirmation bug. Require an idle baseline and observe the response before passing.
  • ℹ️ bin/backends/herdr.sh:3014 - The helper contract still calls native idle a genuine not-submitted signal and claims real Claude transitions to working within 90–490ms, while this change documents Claude 2.1.236 staying idle for an entire landed turn. Update the comments to describe idle as readable-but-inconclusive and the caller's composer fallback.
  • ℹ️ .agents/skills/afk/SKILL.md:206 - This second submit-model description still says Herdr's normal idle-baseline success means native state observed a turn start, omitting the newly supported cleared-composer and queued-busy confirmations. Align it with the updated description at line 126.

🔧 Fix: Align Herdr submit docs with idle fallback
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Inspected the target diff against f242264bc5f62934fe638673de0d2c16eeb02dd1 to identify the submit-confirmation behavior and focused regressions.
  • tests/fm-composer-lib.test.sh
  • tests/fm-backend-herdr.test.sh
  • tests/fm-tmux-submit-busy.test.sh
  • tests/fm-send-remote-delivery.test.sh
  • FM_HERDR_SUBMIT_CONFIRM_LIVE=1 tests/fm-herdr-submit-confirm-live-e2e.test.sh against Claude Code 2.1.236 and Herdr 0.8.0
  • herdr session list --json | jq -c '[.sessions[] | {name,running,default}]' to confirm the isolated lab was removed and the default session remained running
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.