Repository navigation
fix(supervision): prevent Copilot watcher arms from blocking chat - #25
Merged
Merged
Conversation
A Copilot primary rendered as harness `unknown` and received the generic fallback protocol, which does not constrain how the arm is launched. Arming `bin/fm-watch-arm.sh` through an attached shell call with a long `initial_wait` then pinned the model turn open for the whole watcher cycle, and Copilot queues everything the captain types while a turn is active, so chat silently stopped being delivered until the call was stopped. - Add `docs/supervision-protocols/copilot.md`: an attached arm with a short `initial_wait` that returns promptly, `detach: true` forbidden because a detached arm cannot be stopped and outlives the session, and the completion-notification wake path. - Make the renderer's snippet selection allowlist-driven via `fm_harness_is_verified` instead of a hardcoded five-name case, so a verified adapter can no longer silently fall through to the generic protocol, and force the heading to `unknown` when a verified adapter's snippet is missing. - Derive the rendered `initial_wait` from `FM_ARM_CONFIRM_TIMEOUT` so it clears the arm's confirmation budget without covering the watcher cycle, and wire copilot into the repair and ordinary-wake lines. - Generalize `bin/fm-watch-arm.sh`'s header into a harness-agnostic invariant: the script blocks for the whole cycle, so the arming tool call must return promptly. - Correct `docs/turnend-guard.md`, `docs/configuration.md`, and `docs/architecture.md`, which claimed every verified primary harness has a tracked turn-end integration; record Copilot's gap and why wiring it is a global-file trust decision. - Add an `FM_CHECKPOINT_TIMEOUT_IMPL` seam to `bin/fm-watch-checkpoint.sh` so the perl fallback, which is the real path on macOS where neither `timeout` nor `gtimeout` exists, is testable and unknown values fail closed. - Add regression coverage: a structural test that every verified adapter renders its own protocol, a Copilot renderer test, cross-harness matrix arms, a turn-end integration-list test, and three checkpoint fallback tests. Copy `bin/fm-harness-policy.sh` into the two test fixtures that hand-pick `bin/`.
Review of the previous commit surfaced four confirmed defects in it. - The derived `initial_wait` was unbounded above. FM_ARM_CONFIRM_TIMEOUT is a documented operator knob for slow hosts, and the renderer propagated it uncapped, so FM_ARM_CONFIRM_TIMEOUT=300 rendered a 305 second attached call into the protocol, the repair line, and the wake line, reopening the exact blocked-chat incident in text that simultaneously said the call must return promptly. The rendered value is now capped at 30 seconds. - The renderer normalized a malformed FM_ARM_CONFIRM_TIMEOUT to 10 while `bin/fm-watch-arm.sh` fed the same value straight into integer arithmetic under `set -u`. A non-integer aborted the arm with "unbound variable" and a decimal, idiomatic here because FM_ARM_ATTACH_POLL defaults to 0.5, aborted with an arithmetic error. The post-fork deadline runs after the watcher child exists, so the arm died with no status line and orphaned a live watcher while the protocol told the model to trust only that status line. The arm now applies the same normalization. - `FM_CHECKPOINT_TIMEOUT_IMPL=perl` skipped the installed-check that the header and usage promised, and `auto` fell through to perl unprobed, so a host without perl got an opaque 127 passthrough instead of the intended exit 2. Both paths are now gated. - `.agents/skills/harness-adapters/SKILL.md` still told agents not to run a primary session on copilot and stated that the renderer deliberately falls back to the unknown-harness protocol for it, which the previous commit made false. Because that file is loaded as operating instructions before every spawn and recovery, the stale text was live guidance contradicting the new protocol. Also drops a contested rationale from the copilot protocol, keeping the uncontested reason a detached arm is forbidden, and tells the model to read the arm's output rather than assume a result when the call returns before a status line appears. Regression coverage: renderer cap assertions across the snippet, repair line, and wake line; a real-process arm test proving a malformed confirm timeout still yields a status line, verified to fail without the guard; PATH-scoped checkpoint tests that assert the uninstalled and no-implementation paths deterministically on any host; and an allowlist-driven session-start integration test mirroring the turn-end one, with the copilot gap recorded in docs/sessionstart-nudge.md. A reviewer claim that Copilot enforces a 30 second minimum initial_wait was tested and does not hold on Copilot CLI 1.0.77: initial_wait 15 and 5 each returned after exactly that many seconds. The protocol now notes that some builds may raise a smaller value, which is harmless because the hold stays bounded either way.
A second review round found two more recurrence paths in the numeric normalization added by the previous commit, both confirmed by direct probe. - A leading zero passes an all-digits guard but bash reads it as octal, so FM_ARM_CONFIRM_TIMEOUT=08, a natural way to write 8, made `$((08 + 5))` an arithmetic error. Under `set -eu` that aborted the renderer outright with "unbound variable", and because the derivation runs unconditionally it took down the supervision block for EVERY harness, not just copilot. Verified: `--harness claude` exited 1 as well. bin/fm-turnend-guard.sh calls the renderer with `2>/dev/null || <generic fallback>`, so this would have degraded silently rather than surfacing. - A value large enough to overflow the addition wrapped negative, and a negative value passes the cap's `-le` test, so FM_ARM_CONFIRM_TIMEOUT=9223372036854775807 rendered `initial_wait -9223372036854775804` into the protocol and repair line. Both shapes are now rejected to the default in the renderer and in bin/fm-watch-arm.sh, which had inherited the same weak guard. Also bounds the post-cap recovery guidance. Telling the model to read the arm's output "until" a status line appears invited an unbounded read_bash loop, and read_bash holds the turn open exactly like the arming call does, so that reintroduced the queued-chat symptom through a different path. It is now one short read, then treat supervision as unconfirmed and re-arm. Regression coverage asserts the octal blast radius on an unrelated harness as well as copilot, and that no negative wait can be rendered.
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
Fix an operator-facing Firstmate bug: captain chat input was silently queued while fleet supervision was running. The accepted diagnosis found two coupled causes. First, Copilot CLI queues typed input while a model turn is active, and an attached bash tool call holds that turn open for its whole initial_wait, while bin/fm-watch-arm.sh blocks on wait for the entire unbounded watcher cycle. Second, bin/fm-supervision-instructions.sh selected protocol snippets from a hardcoded claude|codex|opencode|pi|grok case with no copilot arm, so a verified copilot primary rendered as harness unknown and received the permissive generic fallback that told it to arm the watcher without a bounded wait.
Scope is Wave 1 of the accepted report only. Deliberate decisions a reviewer cannot see in the diff:
Explicitly out of scope by captain instruction: Wave 2, and any global Copilot hook install or change. The Copilot primary has no tracked turn-end or session-start hook backstop; that gap is recorded in docs and tracked by decision hold copilot-primary-global-hook-fallback.
Two findings from prior review rounds should not be re-raised without new evidence. A claim that Copilot CLI enforces a 30 second initial_wait floor was disproven by direct probe on this host: initial_wait 15 returned after exactly 15 ticks and initial_wait 5 after exactly 5, on Copilot CLI 1.0.77. The protocol notes it as harmless if some other build differs. Separately, tests/fm-session-start.test.sh fails on any host where COPILOT_CLI is set because the test does not pin the harness; this was proven pre-existing by stashing all changes and re-running on the base commit, and is deliberately not fixed here.
Repo style constraints in force: one full sentence per line in tracked Markdown, plain dash never em dash, no agent name as commit co-author, bin scripts must pass bin/fm-lint.sh, tests colocated in tests as subject.test.sh running under set -u with errexit deliberately off.
What Changed
initial_wait, so the model turn returns promptly while completion notifications still wake supervision.FM_ARM_CONFIRM_TIMEOUTvalues in both rendering and watcher arming.timeout,gtimeout, andperl, and update live operating docs and regression coverage for the Copilot supervision path.Risk Assessment
✅ Low: The change is well-bounded and closes the reachable Copilot queued-chat path with an allowlist-selected protocol, a capped attached-call wait, consistent timeout normalization, and explicit documentation of the intentionally deferred hook backstop.
Testing
No pre-supplied baseline test command was present; a base-commit render reproduced the unknown-harness fallback, the focused automated tests completed successfully, a hermetic session start rendered Copilot's attached 15-second arm contract, malformed and oversized timeout inputs stayed normalized or capped, and a live arm emitted a healthy status before HUP tore down its watcher child. The CLI-facing change is demonstrated with reviewer-visible transcripts.
Evidence: Base versus target Copilot supervision render
Evidence: End-to-end Copilot session-start supervision block
Evidence: Copilot initial_wait derivation, cap, and normalization matrix
Evidence: Live malformed-timeout arm and teardown transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
env -u COPILOT_CLI bash tests/fm-supervision-instructions.test.shenv -u COPILOT_CLI bash tests/fm-watch-checkpoint.test.shenv -u COPILOT_CLI bash tests/fm-watcher-lock.test.shenv -u COPILOT_CLI bash tests/fm-turnend-guard.test.shenv -u COPILOT_CLI bash tests/fm-sessionstart-nudge.test.shHermetic end-to-end session start viaCOPILOT_CLI=1 FM_FAKE_HARNESS=copilot run_session_start ..., capturing the actual Copilot supervision blockFM_ARM_CONFIRM_TIMEOUT={default,20,300,not-a-number,08,9223372036854775807} bin/fm-supervision-instructions.sh --harness copilotHome-scoped liveFM_ARM_CONFIRM_TIMEOUT=08 bin/fm-watch-arm.sh, thenkill -HUP 43515and verification that watcher PID 43529 stopped and temporary output was removedBase-versus-target renderer comparison usinggit show 4363d945...and the checked-out target renderer✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.