Skip to content

feat(bin): add opt-in steer-acknowledgment contract to detect silent steer drops - #5

Merged
adonis-garcia-git merged 3 commits into
mainfrom
fm/fm-steer-ack
Aug 21, 2026
Merged

adonis-garcia-git merged 3 commits into
mainfrom
fm/fm-steer-ack

Conversation

@adonis-garcia-git

Copy link
Copy Markdown
Owner

Intent

Firstmate repo: add a steer acknowledgment contract so silent steer drops become detectable within minutes. Incident (2026-08-20, task helm-p6-attachments, claude on herdr): a rebase order sent via fm-send exited 0 and the pane read busy from the worker's own unrelated recap, but the worker never processed the order and sat parked 15 minutes while supervision reported the work as under way; the existing composer-verification layers verify SUBMISSION, not that the agent processed the message into a turn. Deliverable, designed inside the existing architecture with no new daemon: (1) opt-in ack protocol - fm-send gains an --ack flag that prefixes the order with a visible [ack=] mark (8 lowercase hex) and the generated ship and scout brief scaffolds teach workers to append 'resolved [key=ack-]: starting ' to the status file as their FIRST action on receiving a token-marked order, consistent with fm-classify-lib.sh keyed status semantics; (2) detection - one durable pending-ack record per sent token under state/pending-acks/ (a new one-owner library bin/fm-steer-ack-lib.sh, modeled on the pending-reply sidecar pattern), with a cheap watcher tick placed beside fm_pending_reply_tick that clears acked or orphaned records and queues exactly one durable actionable 'check: steer-ack:' wake naming the task and token when an order stays unacknowledged past a bounded window (default 180s, env-tunable via FM_STEER_ACK_WINDOW_SECS), enqueue-before-suppress so a watcher crash can duplicate but never lose the wake; (3) cleanup - any status-line sighting of the token clears the record (liberal matching is deliberate: a worker quoting the mark has demonstrably received the order), teardown clears the task's leftovers, and records are mutated only by the steer path, the watcher singleton, and teardown so lock-refused read-only sessions never touch them; (4) back-compat - plain fm-send without the flag is byte-identical, workers on old briefs simply never ack so only token-marked sends arm detection, and --ack is deliberately refused for secondmate targets (their marked requests already carry the pending-reply expectation), the --key path, explicit non-task endpoints, and harness command invocations (leading '/', or '$...' to codex) whose parsing the visible prefix would break - the record is also created before submit and discarded on every failed or unconfirmed submit so transport failure (already a loud fm-send error) never masquerades as a missed ack; (5) documentation per the repo's knowledge-placement decision tree - full contracts in script headers, plus exactly two AGENTS.md lines (the state-tree entry for pending-acks/ and one trigger line in section 7 pointing at fm-send's help). Behavioral tests in tests/fm-steer-ack.test.sh follow the neighboring watcher-test harness patterns (fake tmux stubs, real fm-watch.sh subprocess, real fm-teardown.sh with a minimal git fixture); a live spawned-worker demo was explicitly not required. A second, separate commit fixes four PRE-EXISTING environment-dependent test failures encountered while running the suite, per the repo rule to fix failures you see even when unrelated: subtests in fm-calm-pi-extension, fm-pi-watch-extension, and fm-turnend-guard import tracked .ts extensions with plain node and failed with ERR_UNKNOWN_FILE_EXTENSION on node < 22.18 (no default type stripping) - they now probe that capability once and skip with a clear reason; and fm-kimi-harness hard-requires python3 with tomllib (Python >= 3.11) because the Kimi hook fails closed without it, so on an older interpreter the whole accept/refuse matrix collapses into the same tomllib refusal - the file now skips with the concrete requirement named. CI with current runtimes still runs everything. bin/fm-lint.sh is clean and the full changed-selection test run is 57 suites / 0 failures on this machine.

What Changed

  • bin/fm-send.sh gains an opt-in --ack flag that prefixes task-bound orders with a visible [ack=<token>] mark and arms a durable pending-ack record under state/pending-acks/ via the new one-owner library bin/fm-steer-ack-lib.sh; a watcher tick in bin/fm-watch.sh clears acked or orphaned records and queues exactly one durable check: steer-ack: wake when an order stays unacknowledged past a bounded window (default 180s, tunable via FM_STEER_ACK_WINDOW_SECS). Plain sends are byte-identical, --ack is refused for secondmate targets, --key sends, and harness-command invocations, records are discarded on failed or unconfirmed submits, and bin/fm-teardown.sh clears a task's leftovers. Ship and scout brief scaffolds (bin/fm-brief.sh) now teach workers to append a keyed resolved [key=ack-<token>] status line as their first action, with contracts documented in script headers plus two AGENTS.md lines and a docs/scripts.md inventory row. Covered by 14 behavioral subtests in tests/fm-steer-ack.test.sh using the neighboring watcher-test harness patterns (fake tmux, real fm-watch.sh and fm-teardown.sh).
  • Fixed four pre-existing environment-dependent test failures: Pi .ts-import subtests in tests/fm-calm-pi-extension.test.sh, tests/fm-pi-watch-extension.test.sh, and tests/fm-turnend-guard.test.sh now probe node's type-stripping capability once and skip with a clear reason on runtimes without it, and tests/fm-kimi-harness.test.sh skips naming the concrete Python >= 3.11 tomllib requirement instead of collapsing its accept/refuse matrix on older interpreters. CI on current runtimes still runs everything.

Risk Assessment

✅ Low: The feature is opt-in and additive with the plain-send path byte-identical, the durability and mutation-boundary invariants verified against the actual wake-queue and caller code, comprehensive behavioral tests following existing harness patterns, and a second commit that only capability-gates pre-existing environment-dependent test failures.

Testing

Ran the new 14-subtest fm-steer-ack behavioral suite (all pass, including real fm-watch.sh and fm-teardown.sh subprocess cases), captured a manual end-to-end CLI transcript driving the real fm-send/watcher-tick/brief surfaces through the full ack lifecycle (mark delivery, durable record, exactly-once escalation, ack clearing, refusals, docs), and confirmed the four environment-gated suites now skip with concrete named reasons instead of failing on this node 22.14 / Python 3.9 machine; no failures and the worktree is clean. No rendered UI is involved, so CLI transcripts are the evidence medium.

Evidence: Steer-ack end-to-end lifecycle transcript (real fm-send, watcher tick, brief, refusals, AGENTS.md lines)

============ 1. token format: fm_steer_ack_new_token generates 8 lowercase hex ============
82ab4773

3f72655b

a1801c04


============ 2. plain fm-send (no --ack): worker receives the exact bytes, no detection armed ============
(fm-send exit 0)
keystrokes the worker pane received: >>>rebase onto main now<<<
state/pending-acks/: no record armed (back-compat: plain send is byte-identical, arms nothing)

============ 3. fm-send --ack: order carries a visible [ack=<token>] mark and arms one durable record ============
(fm-send exit 0)
keystrokes the worker pane received: >>>[ack=1234abcd] rebase onto main now<<<
--- durable record state/pending-acks/helm.1234abcd ---
schema=fm-steer-ack.v1
task=helm
token=1234abcd
sent_epoch=1787285226
window_secs=180
summary=[ack=1234abcd] rebase onto main now
escalated_epoch=

============ 4. watcher tick inside the 180s window: silent, record preserved ============
tick output: >>><<< (empty = nothing to surface)
helm.1234abcd

============ 5. watcher tick 400s later, still no ack: exactly one actionable 'check: steer-ack:' wake ============
tick output: check: steer-ack: helm order [ack=1234abcd] unacknowledged for 400s (window 180s) - the worker may not have processed the steer; inspect its pane and re-issue if needed
--- durable wake queue state/.wake-queue ---
1787285226	1	check	steer-ack-helm-1234abcd	check: steer-ack: helm order [ack=1234abcd] unacknowledged for 400s (window 180s) - the worker may not have processed the steer; inspect its pane and re-issue if needed
second tick output: >>><<< (empty = no duplicate wake)
wake-queue lines for this order: 1

============ 6. worker acks in its status file (as the generated brief teaches): record cleared ============
--- worker status line appended to state/helm.status ---
resolved [key=ack-1234abcd]: starting rebase of helm onto main
tick output: >>><<< (empty = ack absorbed)
state/pending-acks/: record cleared by the ack sighting

============ 7. --ack refusals: secondmate, --key, harness command, non-task endpoint ============
exit=1
  stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  stderr: ●  WATCHER DOWN - SUPERVISION IS OFF
  stderr: ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  stderr: ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  stderr: ●  This is a supervision warning only; the requested message WILL still be sent.
  stderr: ●  repair missing watcher supervision with bin/fm-watch-arm.sh as its own Claude Code background task, never shell &.
  stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  stderr: error: --ack does not apply to a secondmate target; marked secondmate requests already carry the parent pending-reply expectation
exit=1
  stderr: WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
  stderr: WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
  stderr: error: --ack applies only to text sends, not the --key path
exit=1
  stderr: WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
  stderr: WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
  stderr: error: --ack cannot mark a harness command invocation (leading '/'); the [ack=...] prefix would break its parsing - phrase the order as plain text

============ 8. generated ship brief teaches the ack reply as the worker's first action ============
37-   cadence instead of treating it as a possible wedge. Use `blocked:` when you are stuck and need help.
38:   If a message from firstmate starts with `[ack={token}]`, it is a token-marked order:
39-   FIRST append `resolved [key=ack-{token}]: starting {one-line restatement of the order}`
40-   to the status file, then carry out the order. Never skip or defer that acknowledgment -
41-   it is how firstmate knows the order reached you.

============ 9. documentation: AGENTS.md lines added by this change ============
+  pending-acks/      durable acknowledgment records for token-marked orders sent via fm-send --ack; cleared on ack or teardown, escalated once by the watcher when unacknowledged; fm-steer-ack-lib.sh
+For an order whose silent loss would leave supervision blind, send it with `fm-send`'s opt-in `--ack` flag so an unacknowledged order surfaces on its own within minutes; the script's help owns the mechanics.
Evidence: Demo script that produced the transcript (isolated temp fleet, fake tmux backend)
#!/usr/bin/env bash
# Manual end-to-end demo of the steer acknowledgment contract, driven through
# the REAL bin/fm-send.sh, bin/fm-steer-ack-lib.sh watcher tick, and
# bin/fm-brief.sh - against an isolated temp fleet with a fake tmux backend
# (the same sanctioned sandbox seams the repo's own test harness uses).
set -u
REPO="/Users/mickeymouse/.no-mistakes/worktrees/f28831d0a816/01M0H71XSYKD8JVXD2175A37NG"
# shellcheck source=/dev/null
. "$REPO/tests/wake-helpers.sh"
fm_git_identity fmtest [email protected]

SEND="$ROOT/bin/fm-send.sh"
BRIEF="$ROOT/bin/fm-brief.sh"
ACK_LIB="$ROOT/bin/fm-steer-ack-lib.sh"
WAKE_LIB="$ROOT/bin/fm-wake-lib.sh"
TMP_ROOT=$(fm_test_tmproot fm-steer-ack-demo)

banner() { printf '\n============ %s ============\n' "$*"; }

# fake tmux: composer reads empty after Enter (clean confirmed submit);
# literal keystrokes the worker pane receives are recorded to FM_SEND_LOG.
fb="$TMP_ROOT/fakebin"; mkdir -p "$fb"
cat > "$fb/tmux" <<'SH'
#!/usr/bin/env bash
set -u
case "${1:-}" in
  send-keys)
    shift; literal=0
    while [ $# -gt 0 ]; do case "$1" in -t) shift 2 ;; -l) literal=1; shift ;; *) break ;; esac; done
    if [ "$literal" = 1 ]; then printf '%s' "${1:-}" >> "$FM_SEND_LOG"; fi
    exit 0 ;;
  display-message)
    for a in "$@"; do case "$a" in *cursor_y*) printf '1\n'; exit 0 ;; esac; done
    printf 'fakepane\n'; exit 0 ;;
  capture-pane) printf '╭────╮\n│    │\n╰────╯\n'; exit 0 ;;
  list-windows) exit 0 ;;
esac
exit 0
SH
chmod +x "$fb/tmux"
printf '#!/usr/bin/env bash\nexit 0\n' > "$fb/sleep"; chmod +x "$fb/sleep"

HOME_DIR="$TMP_ROOT/demo-home"; mkdir -p "$HOME_DIR/state"
STATE="$HOME_DIR/state"
fm_write_meta "$STATE/helm.meta" \
  "window=sess:fm-helm" "endpoint_task_id=helm" "worktree=$STATE/wt" \
  "project=$STATE/p" "harness=echo" "kind=ship" "mode=no-mistakes" "yolo=off"

send() {  # <log> <args...>
  local log=$1; shift
  : > "$log"
  env PATH="$fb:$PATH" \
    FM_ROOT_OVERRIDE="$HOME_DIR" FM_HOME="$HOME_DIR" FM_SEND_LOG="$log" \
    FM_SEND_SETTLE=0 FM_SEND_RETRIES=1 FM_SEND_SLEEP=0 \
    "$SEND" "$@" 2>"$log.err"
}

tick() {  # [fake-now-epoch]
  local now=${1:-}
  FM_STEER_ACK_NOW="$now" FM_STATE_OVERRIDE="$STATE" bash -c '
    set -u
    . "$1"; . "$2"
    fm_steer_ack_tick "$3"
  ' _ "$WAKE_LIB" "$ACK_LIB" "$STATE"
}

banner "1. token format: fm_steer_ack_new_token generates 8 lowercase hex"
bash -c ". '$WAKE_LIB'; . '$ACK_LIB'; fm_steer_ack_new_token; echo; fm_steer_ack_new_token; echo; fm_steer_ack_new_token; echo"

banner "2. plain fm-send (no --ack): worker receives the exact bytes, no detection armed"
send "$TMP_ROOT/plain.log" fm-helm "rebase onto main now" && echo "(fm-send exit 0)"
printf 'keystrokes the worker pane received: >>>%s<<<\n' "$(cat "$TMP_ROOT/plain.log")"
if [ ! -d "$STATE/pending-acks" ] || [ -z "$(find "$STATE/pending-acks" -type f 2>/dev/null)" ]; then
  echo "state/pending-acks/: no record armed (back-compat: plain send is byte-identical, arms nothing)"
fi

banner "3. fm-send --ack: order carries a visible [ack=<token>] mark and arms one durable record"
FM_STEER_ACK_TOKEN=1234abcd send "$TMP_ROOT/ack.log" fm-helm --ack "rebase onto main now" && echo "(fm-send exit 0)"
printf 'keystrokes the worker pane received: >>>%s<<<\n' "$(cat "$TMP_ROOT/ack.log")"
echo "--- durable record state/pending-acks/helm.1234abcd ---"
cat "$STATE/pending-acks/helm.1234abcd"

banner "4. watcher tick inside the 180s window: silent, record preserved"
out=$(tick) ; printf 'tick output: >>>%s<<< (empty = nothing to surface)\n' "$out"
ls "$STATE/pending-acks/"

banner "5. watcher tick 400s later, still no ack: exactly one actionable 'check: steer-ack:' wake"
future=$(( $(date +%s) + 400 ))
out=$(tick "$future"); printf 'tick output: %s\n' "$out"
echo "--- durable wake queue state/.wake-queue ---"
cat "$STATE/.wake-queue"
out=$(tick "$future"); printf 'second tick output: >>>%s<<< (empty = no duplicate wake)\n' "$out"
echo "wake-queue lines for this order: $(grep -c 'steer-ack-helm-1234abcd' "$STATE/.wake-queue")"

banner "6. worker acks in its status file (as the generated brief teaches): record cleared"
printf 'resolved [key=ack-1234abcd]: starting rebase of helm onto main\n' >> "$STATE/helm.status"
echo "--- worker status line appended to state/helm.status ---"
tail -1 "$STATE/helm.status"
out=$(tick "$future"); printf 'tick output: >>>%s<<< (empty = ack absorbed)\n' "$out"
if [ -z "$(find "$STATE/pending-acks" -type f 2>/dev/null)" ]; then
  echo "state/pending-acks/: record cleared by the ack sighting"
fi

banner "7. --ack refusals: secondmate, --key, harness command, non-task endpoint"
SM_HOME="$TMP_ROOT/sm-home"; mkdir -p "$SM_HOME/state"
fm_write_secondmate_meta "$SM_HOME/state/domain.meta" "$SM_HOME" "sess:fm-domain"
HOME_SAVE=$HOME_DIR; STATE_SAVE=$STATE
HOME_DIR=$SM_HOME; STATE=$SM_HOME/state
send "$TMP_ROOT/sm.log" fm-domain --ack "audit the build" || echo "exit=$?"
sed 's/^/  stderr: /' "$TMP_ROOT/sm.log.err"
HOME_DIR=$HOME_SAVE; STATE=$STATE_SAVE
send "$TMP_ROOT/key.log" fm-helm --ack --key Enter || echo "exit=$?"
sed 's/^/  stderr: /' "$TMP_ROOT/key.log.err"
send "$TMP_ROOT/cmd.log" fm-helm --ack "/compact now" || echo "exit=$?"
sed 's/^/  stderr: /' "$TMP_ROOT/cmd.log.err"

banner "8. generated ship brief teaches the ack reply as the worker's first action"
BR_HOME="$TMP_ROOT/brief-home"; mkdir -p "$BR_HOME/data"
FM_HOME="$BR_HOME" "$BRIEF" ship-task demo-proj >/dev/null 2>&1
grep -n -B1 -A3 'ack={token}' "$BR_HOME/data/ship-task/brief.md"

banner "9. documentation: AGENTS.md lines added by this change"
cd "$REPO" && git diff e5a9b332..208e292c -- AGENTS.md | grep '^+' | grep -v '^+++'
Evidence: Key lifecycle moments from the transcript
--ack delivery: keystrokes the worker pane received: >>>[ack=1234abcd] rebase onto main now<<<
durable record: state/pending-acks/helm.1234abcd (schema=fm-steer-ack.v1, task=helm, token=1234abcd, window_secs=180)
tick in-window: silent, record preserved
tick +400s: check: steer-ack: helm order [ack=1234abcd] unacknowledged for 400s (window 180s) - the worker may not have processed the steer; inspect its pane and re-issue if needed
second tick: silent, exactly 1 durable wake-queue line
worker ack 'resolved [key=ack-1234abcd]: starting...' -> record cleared, no wake
plain send back-compat: >>>rebase onto main now<<< delivered byte-identical, no record armed
refusals: secondmate (pending-reply expectation), --key path, leading-'/' harness command

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.

  • bash tests/fm-steer-ack.test.sh - all 14 subtests pass (arming, back-compat, refusals, unconfirmed-submit discard, tick window/escalation/clearing/orphans/re-arm, clear_task scoping, real fm-watch.sh escalate-once and absorb, brief teaching, real fm-teardown.sh cleanup with git fixture)
  • Manual end-to-end demo driving real bin/fm-send.sh, bin/fm-steer-ack-lib.sh tick, and bin/fm-brief.sh against an isolated temp fleet with fake tmux: plain vs --ack keystroke comparison, durable record content, in-window silence, exactly-once wake past window with durable .wake-queue line, ack-line clearing, three refusal stderr messages, generated ship-brief ack instruction, AGENTS.md added lines
  • bash tests/fm-calm-pi-extension.test.sh - exit 0; .ts-import subtest skips with 'no type stripping' reason on node 22.14, other subtests run
  • bash tests/fm-pi-watch-extension.test.sh - exit 0; skips with clear type-stripping reason
  • bash tests/fm-turnend-guard.test.sh - exit 0; 20 subtests pass, only the two Pi .ts-import subtests skip with clear reason
  • bash tests/fm-kimi-harness.test.sh - exit 0; skips naming the concrete Python >= 3.11 tomllib requirement on Python 3.9
  • Verified node 22.14 / Python 3.9 locally, i.e. exactly the environment the gating commit targets; verified git status --porcelain clean after testing
⚠️ **Document** - 1 info
  • ℹ️ docs/scripts.md:8 - Pre-existing drift: docs/scripts.md toolbelt inventory is missing 10 bin/ scripts unrelated to this change (fm-lint.sh, fm-doc-audience-check.sh, fm-push-transition-lib.sh, fm-transition-lib.sh, fm-startup-memory-budget.sh, fm-startup-memory-budget-lib.sh, fm-cd-pretool-check.sh, fm-cd-command-policy.mjs, fm-install-shellcheck.sh, fm-herdr-session-cleanup.sh), and no check enforces the table's completeness; a follow-up could backfill the rows and add a completeness assertion.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…r drops surface within minutes

A steer can submit cleanly (composer verification proves submission) and still
never be processed into a turn by the worker - the 2026-08-20 incident left a
rebase order unprocessed for 15 minutes while supervision reported the work as
under way. Close that gap with an acknowledgment layer over the existing
architecture, no new daemon:

- bin/fm-steer-ack-lib.sh owns durable per-order records under
  state/pending-acks/, the [ack=<token>] mark, ack detection against the
  task's status file, the watcher tick, and task cleanup.
- fm-send.sh --ack (opt-in) prefixes the visible mark and arms the record
  before delivery; failed or unconfirmed submits discard it; secondmate,
  --key, and harness-command targets are refused; plain sends are unchanged.
- The generated ship and scout briefs teach workers to append
  'resolved [key=ack-<token>]: starting <restatement>' as the first action on
  a token-marked order, consistent with the keyed status grammar.
- The watcher clears acked or orphaned records each cycle and queues exactly
  one durable actionable check wake per order unacknowledged past the window
  (default 180s, FM_STEER_ACK_WINDOW_SECS), enqueue-before-suppress.
- Teardown clears the task's leftover records.

Records are mutated only by the steer path, the watcher singleton, and
teardown, so lock-refused read-only sessions never touch them.
… runtime's actual capabilities

Four suites failed on machines whose runtimes cannot exercise them, in the
same silent-capability class the per-user npm-tool fix (#4) addressed:

- Node below 22.18 has no default type stripping, so subtests that
  dynamically import tracked .ts extensions with plain node failed with
  ERR_UNKNOWN_FILE_EXTENSION instead of skipping. Probe the capability once
  and skip with a clear reason in fm-calm-pi-extension (the
  missing-adapter-export subtest, which fabricates its own fake Pi package
  and so cannot ride the sibling package-presence gates),
  fm-pi-watch-extension (whole file - every subtest imports the .ts
  extension), and the two Pi subtests in fm-turnend-guard.
- The Kimi hook fails closed without python3+tomllib (Python >= 3.11), so on
  an older interpreter every config-validation path collapses into the same
  tomllib refusal and fm-kimi-harness's accept/refuse matrix cannot run at
  all; skip the file with the concrete requirement named.

CI with current runtimes still runs everything; only genuinely incapable
environments skip, each with the exact missing capability in the reason.
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.

1 participant