Repository navigation
fix(bin): let fm-control exit and interrupt recover Claude workers on Herdr - #10
Merged
Merged
Conversation
Claude's optional vim editor mode makes Escape - which is also its interrupt key - leave the composer's text entry. Everything typed after that is read as editor commands instead of text: `/exit` is consumed as the search, end-of-word, delete-char and insert commands, and only the trailing `t` reaches the composer. On Herdr the Claude payload proof catches the fragment and refuses with `send-failed`, so `fm-control exit` reported that the exit command could not be sent and a wedged worker could not be stopped, interrupted out of the state, or relaunched. The interrupt now restores text entry when its own key took it away, proven from the harness's rendered indicator and only on a still-running agent. Exit types its command once more when a refusal is attributable to the mode: the composer was not taking text when the command was typed and is taking text now, which is what the refused `/exit` does to itself. Nothing is typed to establish that, so a composer with no modal editor - which renders no indicator either way - is never touched by a refusal it did not cause, and a refusal with any other cause is still reported. bin/fm-control-lib.sh gains the per-harness indicator and insert key, bin/fm-backend.sh gains the raw unsubmitted send the restore needs. Verified live in an isolated Herdr lab on herdr 0.9.1 with claude in vim mode: interrupt, exit after that interrupt, relaunch, and exit against a composer an earlier Escape had already left in command mode.
max-metaplanet
added a commit
that referenced
this pull request
Sep 25, 2026
) * fix(bin): submit the Herdr doorbell into a vim-mode Claude composer Claude's optional vim editor mode gives its composer a command mode whose keystrokes are editor commands, and Escape - Claude's own interrupt key - is what leaves text entry. A doorbell typed into a composer left there is eaten from the front: `: Firstma` becomes the space, find-backwards, replace, till and append commands, so only `te instruction waiting: ...` is inserted. The Herdr payload proof correctly refuses that fragment, and the steer was reported as a doorbell that did not reach the pane while no instruction was ever delivered. The adapter now recovers a refusal the mode caused, exactly once. After the refused fragment is cleared back to the proven-empty state the send started from, it checks the harness's text-entry indicator: an eaten payload usually ends on an insert command and has already restored text entry itself, so nothing is typed, and only an absent indicator makes the adapter type the text-entry key - which counts only when the indicator appears while the composer still reads empty. The payload is then typed and proven a second time before Enter, so the whole doorbell is submitted rather than its remainder. A payload still refused after that is reported send-failed with the composer empty. The steering ring no longer counts an unaccountable delivery as rung. A backend verdict of `unknown` means it could confirm neither the submission nor that its own half-typed text is gone, and a composer still holding that fragment answers every later ring with the pending skip, so both `unknown` and `send-failed` now report a failed ring and the watcher's re-ring is expected rather than a surprise. `pending` keeps its meaning: the composer provably holds the complete doorbell, which the next ring submits. The indicator, the text-entry key, and how the indicator is recognized move to bin/fm-composer-lib.sh, the composer owner, because delivery and lifecycle control now both read them; bin/fm-control.sh keeps its own restore and sources that owner directly. Two things this is NOT. It is not the composer-reader defect in kunchenguid#5558: the reader identified the idle pane and the fragment correctly, and refusing that fragment was the right call. And it is not a consequence of the restart-control change in #10 - the tail capture width that change replaced refuses the identical fragment, measured live against the same pane. Verified live in an isolated Herdr lab on herdr 0.9.1 with Claude Code 2.1.282, editorMode pinned per pane: the doorbell is submitted to a composer taking text, to one an Escape left in command mode, and to one with no modal editor. * no-mistakes(review): Count unknown rings as rung; read INSERT only in composer footer * no-mistakes(document): Document Herdr unaccounted verdict and footer-only indicator read
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
… Herdr Carried from fork commit 234a667 (#10). bin/backends/herdr.sh takes upstream's composer read instead of this commit's. Upstream independently diagnosed and fixed the same bounded-tail defect, and its fix is the stronger one: the capture is the full visible viewport rather than a 200-row tail, which also survives an overlay rendered between the composer and the pane bottom. Upstream's `fm_backend_herdr_composer_content` takes only a target, so this commit's extra row-count argument would have been silently ignored. bin/fm-control.sh unions the locals in do_exit, because both sides' variables are used in the merged body: upstream's `dialog` for the blocking-prompt refusal and this commit's `insert_signal` and `entry_before` for the modal-composer restore. tests/fm-control.test.sh keeps both the fake pane's after-Enter handling and this commit's vim screen branch, and keeps both independent test groups. The conflict boundary fell inside upstream's resume-flag test, so its closing brace is restored at the junction.
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
Restore firstmate's ability to recover a stuck worker on the Herdr backend.
Since this repository was synced onto current upstream (fork main b59c9fd),
bin/fm-control.sh <task> exitfails on Herdr for every persistent second mate - reproduced twice each on three separate homes throughbin/fm-secondmate-restart.sh- with "the exit command could not be sent to task on herdr". That message comes from the send step (fm_backend_send_text_submitaround bin/fm-control.sh:645) AFTER the composer-empty check has already passed. The Herdr server is healthy (0.9.1, protocol 22, running, compatible, restart_needed false) and every pane resolves throughherdr pane getwith agent_status done. Before the sync, the same night, the same exit on the same home worked.bin/fm-send.shstill works, both its durable inbox and its doorbell. So the fault is most likely in the synced send path against Herdr 0.9.1, not in Herdr or the panes. Interrupt and relaunch through fm-control may be affected too, and those three actions are how a wedged worker gets recovered.Known evidence trap: running fm-control under
bash -xproduces a DIFFERENT error, "endpoint reads unreadable", because the trace output leaks into the command substitutions that parse Herdr JSON. That is an artifact of tracing, not the cause; reproduce without tracing.What Changed
bin/backends/herdr.sh):fm_backend_herdr_send_text_submitused to read only a short tail sized from the payload length. It now reads 200 rows, both for the empty-composer check before typing and for the proof after typing. A/payload such as/exitopens Claude's slash-command list below the composer, and with many skills that list filled the whole tail. The proof then failed and the send returnedsend-failed, which surfaced as "the exit command could not be sent". Extraction still picks the lowest composer shape. The comment onfm_backend_herdr_proof_linesnow describes its remaining use: counting Ctrl+U presses for the composer clear.bin/fm-control.sh,bin/fm-control-lib.sh,bin/fm-backend.sh):fm_control_interrupt_insert_signal/fm_control_interrupt_insert_key(Claude's signal is-- INSERT --and its key isi), plus a backend-agnosticfm_backend_send_literal.send_interrupt_keyschecks whether the insert indicator was showing before the Escape presses. If it was, the indicator is gone afterwards, and the agent is still alive, it runsrestore_insert_mode. That sendsiraw, then requires the indicator back and the composer empty. Otherwise it clears the composer with Ctrl+U and refuses./exitwas typed and back in it after asend-failed,do_exitretypes the exit command once.docs/agent-control.mdand the Claude harness adapter reference cover the vim-mode interrupt and exit behaviour. New cases intests/fm-backend-herdr.test.shcover the slash-command payload proof, and new cases intests/fm-control.test.shcover the insert-mode restore and the exit retry.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change adds narrowly gated recovery steps: the insert key is typed only when an
-- INSERT --indicator was seen and then disappeared on a still-running agent, and exit is retried only once, after a Herdr refusal whose cause is shown by the mode change. A false read of the indicator only leads to a refusal, never to a wrong input being typed, and behavioral tests cover both the vim and non-vim paths.Testing
I drove 7 scenarios live, each in its own fm-lab-* Herdr session created and torn down through bin/fm-herdr-lab.sh, with real Claude 2.1.281 on Herdr 0.9.1 and the operator's full skill and plugin set, so the completion list was tall. The default session was never touched. Exit (vim and non-vim), interrupt then exit, busy interrupt then exit, relaunch, and a plain-text submit all passed. The first busy-interrupt run failed because of a bug in my test driver, not the product: it sent the key name
C-u, which Herdr rejects, so the test token stayed in the composer. fm-control correctly refused to type/exitonto that pending text. That log is kept as evidence of the guard working. I fixed the driver key toctrl+uand the re-run passed. Round-1 logs from the same labs show the base and be24904 failing with 'the exit command could not be sent', which confirms a73b713 is what fixes it. The targeted backend test file, including the new tall-completion-list regression test, passed. The only artifacts are CLI transcripts because there is no UI change. The worktree is clean./exit, the Claude payload proof reads/exitfrom the composer even with the tall slash-command completion list openfm-control exiton an idle vim-mode Claude on Herdr stops the agentfm-control exiton an idle Claude without vim mode also works (the fix does not depend on vim)fm-control interruptthenexiton a vim-mode Claude stops the agent/exitonto pending composer textfm-control relaunchreplaces a Claude worker on HerdrEvidence: Live proof: /exit read from the composer while the slash completion list is open
Source: Live proof: /exit read from the composer while the slash completion list is open
Evidence: fm-control exit on vim-mode Claude: stopped
Source: fm-control exit on vim-mode Claude: stopped
Evidence: fm-control exit on non-vim Claude: stopped
Source: fm-control exit on non-vim Claude: stopped
Evidence: fm-control interrupt then exit: stopped
Source: fm-control interrupt then exit: stopped
Evidence: Busy interrupt, composer still accepts text, then exit
Source: Busy interrupt, composer still accepts text, then exit
Evidence: Adversarial: pending composer text makes exit refuse rather than concatenate
Source: Adversarial: pending composer text makes exit refuse rather than concatenate
Evidence: fm-control relaunch replaces the Claude worker
Source: fm-control relaunch replaces the Claude worker
Evidence: Plain-text submit (the fm-send path) still works
Source: Plain-text submit (the fm-send path) still works
Evidence: Lab driver used for round 2
Source: Lab driver used for round 2
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-control.sh:740- The one-time exit retry only runs on asend-failedverdict, and only Herdr's Claude payload check produces that. On tmux, zellij or cmux, a Claude composer that is already in vim command mode whenexitstarts (idle agent, so no interrupt runs first) still turns/exitinto the charactert. Thattis then submitted as a prompt, and exit times out waiting for the agent to stop.entry_before=otheris already known before typing, but the change deliberately refuses to type into a composer whose mode is unproven. The intent is Herdr-only, so no action is needed here; this is a known gap on the other backends.🔧 **Test** - 2 issues found → auto-fixed ✅
bin/backends/herdr.sh:3348- fm-control exit still fails on Herdr 0.9.1 with Claude 2.1.281 at this commit, with or without vim mode and with or without a prior interrupt. After fm_backend_herdr_send_text_submit types/exit, Claude opens its slash-command completion list. With the operator's many skills and plugins the list pushes the composer row out of the fm_backend_herdr_proof_lines tail capture. fm_backend_herdr_composer_content returns rc=1, the payload proof fails, the composer is cleared, and the result is send-failed, which do_exit reports as 'the exit command could not be sent'. Plain text opens no list, which is why fm-send works. The vim-mode restore in this change is real but secondary. The exit/relaunch recovery the intent requires stays broken until the proof can see a/-prefixed payload while the completion list is open. Possible directions: capture past the list, or read the composer row instead of the tail. A deterministic regression should reproduce a tall completion list below the composer.live-lab-driver.sh <base-73ae45e> vim interrupt-exit: isolated fm-lab-* Herdr session, real Claude 2.1.281 in vim mode, fm-control interrupt then exit at the base commitlive-lab-driver.sh <head> vim interrupt-exit: same flow at be24904live-lab-driver.sh <head> vim plain-exit: fm-control exit on an idle vim-mode Claude with no prior interruptlive-lab-driver.sh <head> novim plain-exit: fm-control exit on an idle Claude with editorMode normallive-lab-driver.sh <head> novim probe-proof: typed/exitandhello worldunsubmitted, then called the adapter's own fm_backend_herdr_composer_content and fm_backend_herdr_composer_payload_shown to see what the send proof readslive-lab-driver.sh <head> vim busy-interrupt: interrupted a mid-turn Claude through fm-control, then typed a token raw to prove the composer takes textlive-lab-driver.sh <head> vim relaunch: fm-control interrupt, then fm-control relaunch --note🔧 Fix applied.
✅ Re-checked - no issues remain.
/exit, the Claude payload proof reads/exitfrom the composer even with the tall slash-command completion list openfm-control exiton an idle vim-mode Claude on Herdr stops the agentfm-control exiton an idle Claude without vim mode also works (the fix does not depend on vim)fm-control interruptthenexiton a vim-mode Claude stops the agent/exitonto pending composer textfm-control relaunchreplaces a Claude worker on Herdrlive-lab-driver-r2.sh <worktree> novim probe-proof: typed/exitwithout submitting into live Claude and read the composer the way the payload proof does, using a 200-row capturelive-lab-driver-r2.sh <worktree> vim plain-exit:bin/fm-control.sh mc1 exiton an idle vim-mode Claudelive-lab-driver-r2.sh <worktree> novim plain-exit:fm-control exiton an idle Claude without vim modelive-lab-driver-r2.sh <worktree> vim interrupt-exit:fm-control interrupt, thenfm-control exitlive-lab-driver-r2.sh <worktree> vim busy-interrupt: interrupt a Claude mid-turn, type a token into the composer, clear it, then exit (re-run after fixing the driver's key name)live-lab-driver-r2.sh <worktree> vim relaunch:fm-control interrupt, thenfm-control relaunch --notelive-lab-driver-r2.sh <worktree> novim send-plain:fm_backend_herdr_send_text_submitwith plain text on a live Claude, checking that the reply arrivesbash tests/fm-backend-herdr.test.sh(targeted, includes the new slash-completion-list regression test)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.