Skip to content

fix(backends): guard herdr first-launch harness dialogs at spawn - #805

Closed
Sa1mk0 wants to merge 8 commits into
kunchenguid:mainfrom
Sa1mk0:fm/herdr-dialog-harden-h3
Closed

Sa1mk0 wants to merge 8 commits into
kunchenguid:mainfrom
Sa1mk0:fm/herdr-dialog-harden-h3

Conversation

@Sa1mk0

@Sa1mk0 Sa1mk0 commented Jul 21, 2026 •

Copy link
Copy Markdown

Intent

Harden first-launch dialog handling for crews on the Herdr backend so Claude folder-trust and Bypass Permissions dialogs, plus Codex trust and hooks-review menus, no longer require manual intervention. Diagnose the recurring broken-pipe and silent send/readback paths, and make pre-agent TUI input reliable or fail loudly: classify only known dialog shapes, send one key at a time, re-read the pane to verify cursor or dialog movement, use bounded retries, never press Enter while a destructive No/exit choice is focused, and refuse unknown states. Corroborate visible dialogs with native agent state and allow only working to suppress a visible menu because live evidence records idle at a real displayed Claude trust dialog. Keep harness knowledge in the harness-adapters skill and mechanics in scripts, extend the existing fake-Herdr test runner, and record dated helper-isolated empirical evidence. The accepted live evidence is two real trust-dialog traversals with agent_status idle and clean teardown; document that the bypass variant is unreproducible because acceptance persists in Claude user state and do not reset that state. Preserve the smallest viable diff, require full lint and extended tests green, push the feature branch to remote fork, and update the PR against kunchenguid/firstmate main.

What Changed

  • bin/backends/herdr.sh gains fm_backend_herdr_handle_startup_dialog and its _dialog_classify / _dialog_drive_visible helpers: only four known menu shapes are recognized (Claude folder trust, Claude Bypass Permissions, Codex directory trust, Codex hooks review), focus is read from the dialog's own option rows so a composer glyph cannot be mistaken for the selection, each key is sent one at a time and verified by pane readback under bounded retries, Enter is never sent while a destructive No, exit row is focused, and unknown or unverifiable states fail closed. Visible menus are corroborated against agent get — only working suppresses a dialog, since live evidence records idle at a real displayed trust dialog. Down/Up are added to key normalization, and fm_backend_herdr_events_capable now pattern-matches the schema in-shell instead of printf | grep -q, removing the recurring printf: write error: Broken pipe under a caller's pipefail.
  • bin/fm-spawn.sh routes claude/codex spawns on the herdr backend through that handler after the launch Enter; an unverified pane exits non-zero without printing the spawned line, and the error names the id, window, and worktree because the task stays registered while the harness may be running.
  • Five FM_BACKEND_HERDR_DIALOG_* tunables (capture lines, polls, poll sleep, key retries, key sleep) are documented in docs/configuration.md; docs/herdr-backend.md adds the dated evidence block — two live Claude trust-dialog traversals, the live down key verification, the broken-pipe diagnosis, and a note that the bypass variant is unreproducible because acceptance persists in Claude user state — with the harness-level knowledge kept in the harness-adapters skill. The fake-Herdr runner grows 18 cases covering classification, cursor-move-before-Enter, destructive-default refusal, retry bounds, stale/repainted frames, agent-state corroboration, and the two spawn wiring paths.

Note: the pipeline's Test stage reported a non-zero exit for the full tests/*.test.sh sweep and Lint exited 127; both are unresolved on this branch as pushed.

Risk Assessment

⚠️ Medium: Every safety-critical finding from the previous rounds is now closed with surgical, tested changes, but the branch still adds a mandatory pre-flight gate on every herdr claude/codex spawn that can hard-fail a spawn on environment-dependent conditions, so it warrants the usual post-merge attention rather than being treated as cosmetic.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 1 run (30m18s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • 🚨 bin/backends/herdr.sh:1367 - fm_backend_herdr_dialog_drive_visible's expected=dismissed retry loop authorizes another Enter from a readback that this change's own docs call unreliable ("the recent source retains dismissed frames inside the capture window"). If Enter chore: initialize no-mistakes gate #1 dismissed the Claude trust dialog and Claude then rendered the Bypass Permissions warning focused on the destructive No, exit, a stale capture still classifies claude-trust:accept, agent_status is still idle (the recorded live behaviour at a displayed dialog), and Enter docs: polish README banner and repo housekeeping #2 is delivered to No, exit. That contradicts the required criterion "never press Enter while a destructive No/exit choice is focused". Consider not retrying Enter at all, or requiring the post-key capture to differ from the pre-key capture before concluding anything.
  • ⚠️ bin/fm-spawn.sh:1264 - This is the first exit 1 that runs after $STATE/$ID.meta is written, the worktree is acquired, the pane exists, and the harness is already launched - and HERDR_PROJECTION_ABORT_CLEANUP was disarmed two lines earlier, so spawn_abort_cleanup does nothing. A cold harness start that exceeds the 20s (40 x 0.5s) poll budget while agent get still reports agent_not_found fails the spawn, suppresses the spawned <id> ... window=... line, and leaves a registered, running crewmate behind. fm-spawn.sh:101 claims it "fails the spawn rather than leaving a crewmate parked", but both happen.
  • ⚠️ bin/backends/herdr.sh:1330 - A dialog that classifies to a known kind but whose focus cannot be parsed hits drive_visible's catch-all and fails the spawn on the very first poll, with no retry and no further polling - unlike the unknown kind, which polls to the bounded timeout. The first capture is taken with zero delay after the launch Enter, so a mid-repaint frame (options rendered, cursor row not yet) or transcript text quoting a dialog header plus both options kills the spawn ~0s after launch.
  • ⚠️ bin/backends/herdr.sh:1234 - The focus scan keeps the last ❯ /› line anywhere in the 80-line capture, but that glyph pair is the repo's own verified agent composer prompt (FM_BACKEND_HERDR_BARE_PROMPT_RE='^[❯›]'). A composer row rendered below an overlay menu therefore overrides the menu's selected item. Codex's hooks-review menu is the concrete risk: it has no live traversal in docs/herdr-backend.md, and the fake-CLI fixtures place no composer row after the menu, so an empty focus would fail every such spawn. Scoping the scan to the lines of the matched dialog block would remove the ambiguity.
  • ℹ️ bin/backends/herdr.sh:1427 - FM_BACKEND_HERDR_DIALOG_POLL_SLEEP and FM_BACKEND_HERDR_DIALOG_KEY_SLEEP go straight to sleep while FM_BACKEND_HERDR_DIALOG_POLLS and _KEY_RETRIES get numeric fallbacks. A malformed exported value makes every sleep fail, turning the 40-poll loop into a tight spin of ~80 herdr CLI calls plus stderr noise before the spawn fails. Add the same case ... in ''|*[!0-9.]*) fallback ;; guard the other two tunables use.

🔧 Fix: guard herdr dialog focus, Enter retries, and spawn failure
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/backends/herdr.sh:1288 - The focus rewrite changed the codex-trust Press enter to continue fallback from "no selection glyph anywhere in the capture" (old codex-trust: empty-focus case) to "no row matched a recognized option", so it now also fires when a glyph row IS present but unrecognized. codex-trust's only reject pattern is *'No, quit'*, so a screen focused on e.g. ❯ 2. No, exit and choose another folder leaves choice=unknown, the fallback flips it to accept, and drive_visible sends Enter onto the destructive row. That contradicts the required criterion "never press Enter while a destructive No/exit choice is focused", and codex's trust screen has no live traversal in docs/herdr-backend.md - only a glyph-free fixture. Restoring the old width means gating the fallback on a glyph_seen=0 flag set inside the scan loop.
  • ℹ️ bin/backends/herdr.sh:1435 - The mid-repaint branch re-implements the loop tail (i=$((i + 1)); [ "$i" -lt "$polls" ] && sleep "$FM_BACKEND_HERDR_DIALOG_POLL_SLEEP"; continue) that already exists 27 lines below at line 1462. Two copies of the poll-advance logic will drift if the pacing ever changes; restructuring the branch to fall through to the shared tail (e.g. an unfocused=1 guard around the drive call) removes the duplicate.

🔧 Fix: gate codex trust Enter fallback on cursorless screen
1 info still open:

  • ℹ️ bin/backends/herdr.sh:1294 - glyph_seen is set by any ❯ /› row anywhere in the 80-line capture, including the pane's own shell prompt and the typed launch line. On a machine whose shell prompt uses those glyphs (starship/pure/agnoster - the same set the repo records as FM_BACKEND_HERDR_BARE_PROMPT_RE), codex's cursorless trust screen would classify codex-trust unknown, poll the full budget and fail the spawn rather than auto-accepting. This is fail-closed and is the same width the code had before round 2, so no action is required; noting it in case codex trust later needs to work in such a pane, where scoping the glyph scan to rows below the dialog header would recover the auto-accept.
⚠️ **Test** - 1 error
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
⚠️ **Document** - 1 info
  • ℹ️ docs/herdr-backend.md:979 - The broken-pipe diagnosis and fix for fm_backend_herdr_events_capable is recorded inside docs/herdr-backend.md's "Guarded first-launch dialog handling" → "Live Claude trust-dialog traversal" subsection, even though the owner of that function's contract is the "Native pane.agent_status_changed push escalation" section further down. I resolved discoverability with a one-line pointer from the owner section plus a code comment at the call site rather than relocating the evidence, since moving a dated evidence block inside a 1150-line document is a restructure beyond this change's scope. Follow-up worth considering: move the pipefail paragraph and its lab transcript under the events-escalation section's empirical-evidence block and leave a pointer behind.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@Sa1mk0 Sa1mk0 changed the title fix(herdr): guard first-launch trust and permission dialogs at spawn fix(backends): guard herdr first-launch harness dialogs at spawn Jul 21, 2026
@kunchenguid

kunchenguid commented Jul 22, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#805 at 4cb1b95c.

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