Skip to content

fix(bin): stop a self-hosted away daemon deferring every escalation - #3050

Closed
AgardnerAU wants to merge 10 commits into
kunchenguid:mainfrom
AgardnerAU:fm/fm-afk-inject-never-delivers
Closed

AgardnerAU wants to merge 10 commits into
kunchenguid:mainfrom
AgardnerAU:fm/fm-afk-inject-never-delivers

Conversation

@AgardnerAU

@AgardnerAU AgardnerAU commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Intent

On 2026-09-30, after a review of every comment on the fleet's open kunchenguid/firstmate pull requests, the captain approved one upstream refresh pass: bring each conflicting PR up to date with upstream main, post one short note on each PR, and post no reminder comments.

This task covers #3050 ("fix(bin): stop a self-hosted away daemon deferring every escalation"), on branch fm/fm-afk-inject-never-delivers from the fork AgardnerAU/firstmate into kunchenguid:main, current head a3936ce519b79d3bf59b97f6135f82c4541c44cd. Reuse that branch and that PR; never replace them.

Context: upstream closes a PR after 14 days of author silence, and only an author push or comment resets that clock; a stale close is irreversible. Every earlier maintainer request on this PR has been addressed, and the no-mistakes attestation in its body matches its current head. The maintainer triages on author activity, and test runs on fork PRs wait for maintainer approval.

What Changed

  • Added supervisor_pane_hosts_daemon to bin/fm-supervisor-target-lib.sh. It detects when the away-mode daemon runs inside the supervisor pane that it injects into, and it matches the tmux pane or the Herdr session and pane identity against the resolved target. pane_is_busy in bin/fm-supervise-daemon.sh no longer treats native busy as conclusive for a self-hosted daemon. Instead, it falls through to the rendered delivery signature, so escalations are no longer deferred for all of away mode.
  • fm_backend_herdr_agent_status_raw in bin/backends/herdr.sh now reports a self-hosted working status as empty. The classifiers map an empty status to unknown and never to idle, so the busy state, submit confirmation, wait-for-working and reconcile paths fall through to the rendered signature or the composer verdict. A swallowed Enter still resolves to pending. The idle, done and blocked statuses, and all statuses from other panes, pass through unchanged.
  • Documented this boundary in the AFK skill, docs/herdr-backend.md, docs/scripts.md and docs/verification/runtime-backends.md, which records the measured native-busy behaviour while a background job runs. Added Herdr backend and daemon tests for self-hosted delivery, and aligned these tests with the upstream submit identity probe and the Claude doorbell.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The refresh only merges upstream main and aligns three adapter fakes and two daemon digest assertions with upstream's new submit identity probe and Claude doorbell; the self-hosted boundary still holds, because the new direct agent get read (fm_backend_herdr_agent_identity_raw at bin/backends/herdr.sh:3434) uses only the agent name in submit and only idle/done as positive evidence in the pi classifier, so an unmasked self-hosted working cannot be read as idle or delivered.

Testing

I ran the two targeted unit suites for the change (daemon and Herdr adapter); both pass. I then drove four live scenarios on real Herdr 0.9.1 in a disposable fm-lab session. The real away daemon ran in two ways: as a background job inside the supervisor pane (true self-hosting, with Herdr's own HERDR_ENV, HERDR_SESSION and HERDR_PANE_ID), or from a separate process. In every case the pane's native agent_status read working, and the adapter's busy_state read busy from outside the pane. Results: - S1: a self-hosted daemon delivered the digest, and the buffer emptied. - S2 (control): a daemon in its own terminal deferred with "supervisor pane busy" and kept the buffer. - S3 (adversarial): a self-hosted daemon with a real esc to interrupt render still deferred. - S4 (adversarial): a self-hosted daemon whose every Enter was swallowed kept the buffer, raised .subsuper-inject-wedged, and submitted nothing. The adapter single-owner boundary scenario (S5) is covered only by unit tests, so it is recorded as untested live. Two setup problems appeared and were fixed before the final run: - This machine's ~/.local/bin/herdr is a wrapper that execs the next herdr on PATH. Any Enter-swallowing test shim placed first on PATH therefore loops forever. This also hung the existing tests/fm-afk-inject-herdr-e2e.test.sh, which I killed; its lab session was torn down. My shim now execs /opt/homebrew/bin/herdr directly. - A bash-named fixture is classified as a bare shell pane, which drops native busy before the guard is reached. The fixture now runs with argv0 codex. Not done: - Showing that S1 fails on base commit eb77f02b needed an extracted copy of the base source in a temp directory, and the permission was denied. The colocated regression tests cover that reproduction. - No rendered-UI screenshot was captured. The change is daemon/CLI behaviour, and the evidence is the daemon log, the submitted-line log and pane captures in self-hosted-live.log. Cleanup: all lab sessions are torn down and the worktree is clean. Two small debug temp dirs (${TMPDIR}/fm-selfhost-live.Zg7Yvo and .nwx9yS) remain because the rm was denied.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Away daemon running as a background job inside the supervisor pane (native state pinned working, idle composer) delivers a needs-decision escalation into that pane ✅ pass live self-hosted-live.log case s1: pane-env shows Herdr's own HERDR_PANE_ID=w1:p2 matching the target; the submitted line starts with U+2063 FIRSTMATE_OP and names live-s1; buffer 0 bytes
Adversarial control: a daemon hosted in its own terminal against the same native-working pane still treats native busy as conclusive and defers ✅ pass live self-hosted-live.log case s2: repeated 'inject deferred: supervisor pane busy (agent mid-turn)', no submitted lines, buffer 75 bytes
Adversarial: a self-hosted daemon still defers while the pane renders a genuine mid-turn signature ('esc to interrupt') ✅ pass live self-hosted-live.log case s3: repeated busy deferrals, no submitted lines, buffer 78 bytes
Adversarial: a self-hosted submit whose Enter is always swallowed is not discarded as delivered; the buffer is kept and the wedge alarm is raised ✅ pass live self-hosted-live.log case s4: 'ERROR: away-mode escalation undelivered ... Buffer + wake-queue preserved; alarm marker written', buffer 79 bytes, wedge marker present, no submitted lines
Adapter single-owner boundary: agent_status_raw masks working only for a self-hosted pane; other panes and statuses are unchanged, and self-hosted submits confirm only on a rendered transition or a… ⏸️ untested no The prior payload did not establish a live result for this scenario. It was checked only by the unit suite tests/fm-backend-herdr.test.sh. The masking boundary for non-self-hosted panes and other stat…
Evidence: Live self-hosted Herdr lab transcript (4 scenarios, all PASS)

Source: Live self-hosted Herdr lab transcript (4 scenarios, all PASS)

herdr: herdr 0.9.1  session: fm-lab-selfhost-38861
shim forwards to: /opt/homebrew/bin/herdr
--- case s1-selfhosted-delivers (hosting=self render-busy=0 swallow-enter=0) target=fm-lab-selfhost-38861:w1:p2
pane-env HERDR_ENV=1 HERDR_SESSION=fm-lab-selfhost-38861 HERDR_PANE_ID=w1:p2
native agent_status (raw herdr agent get): working
pane process-state: agent; adapter busy_state from outside the pane: busy
submitted lines:
    e281a346495253544d4154455f4f503a20763120617761792d73757065727669736f723a2053757065727669736f7220657363616c617465202831206576656e74287329293a206c6976652d63312e7374617475733a206e656564732d6465636973696f6e3a206c6976652d73312d73656c66686f737465642d64656c6976657273207069636b2041206f72204220287072652d726561643b2072652d61726d206e6f74206e656564656420e280942077617463686572206461656d6f6e2d6d616e6167656429	⁣FIRSTMATE_OP: v1 away-supervisor: Supervisor escalate (1 event(s)): live-c1.status: needs-decision: live-s1-selfhosted-delivers pick A or B (pre-read; re-arm not needed — watcher daemon-managed)
buffered escalations:        0 bytes; wedge marker: absent
daemon log (inject-related):
    [2026-09-30T19:26:00+0800] daemon starting (pid 44706); target=fm-lab-selfhost-38861:w1:p2; target_source=FM_SUPERVISOR_TARGET; backend=herdr; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=0s
    [2026-09-30T19:26:07+0800] wake: signal: /var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s1-selfhosted-delivers/state/live-c1.status
    [2026-09-30T19:26:08+0800] escalate: needs-decision: /var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s1-selfhosted-delivers/state/live-c1.status -> live-c1.status: needs-decision: live-s1-selfhosted-delivers pick A or B
pane capture:
    |agardner@AG-MBP-96 tmp ❯ (exec -a codex bash '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/
    |agent.sh' '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s1-selfhosted-delivers/submitted.lo
    |g' 0 '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s1-selfhosted-delivers/launch.sh')
    |
    |❯RESULT PASS - self-hosted daemon delivered the escalation despite native working
--- case s2-terminal-hosted-defers (hosting=terminal render-busy=0 swallow-enter=0) target=fm-lab-selfhost-38861:w1:p3
pane-env HERDR_ENV=1 HERDR_SESSION=fm-lab-selfhost-38861 HERDR_PANE_ID=w1:p3
native agent_status (raw herdr agent get): working
pane process-state: agent; adapter busy_state from outside the pane: busy
submitted lines:
buffered escalations:       75 bytes; wedge marker: absent
daemon log (inject-related):
    [2026-09-30T19:26:24+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:25+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:27+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:28+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:29+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:30+0800] inject deferred: supervisor pane busy (agent mid-turn)
pane capture:
    |agardner@AG-MBP-96 tmp ❯ (exec -a codex bash '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/
    |agent.sh' '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s2-terminal-hosted-defers/submitted
    |.log' 0 -)
    |❯RESULT PASS - terminal-hosted daemon still defers on native working and keeps the buffer
--- case s3-selfhosted-midturn-defers (hosting=self render-busy=1 swallow-enter=0) target=fm-lab-selfhost-38861:w1:p4
pane-env HERDR_ENV=1 HERDR_SESSION=fm-lab-selfhost-38861 HERDR_PANE_ID=w1:p4
native agent_status (raw herdr agent get): working
pane process-state: agent; adapter busy_state from outside the pane: busy
submitted lines:
buffered escalations:       78 bytes; wedge marker: absent
daemon log (inject-related):
    [2026-09-30T19:26:40+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:41+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:43+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:44+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:45+0800] inject deferred: supervisor pane busy (agent mid-turn)
    [2026-09-30T19:26:46+0800] inject deferred: supervisor pane busy (agent mid-turn)
pane capture:
    |agardner@AG-MBP-96 tmp ❯ (exec -a codex bash '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/
    |agent.sh' '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s3-selfhosted-midturn-defers/submit
    |ted.log' 1 '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s3-selfhosted-midturn-defers/launc
    |h.sh')
    |• Working (5s • esc to interrupt)
    |❯RESULT PASS - self-hosted daemon still defers while the rendered busy signature shows a live turn
--- case s4-selfhosted-swallowed-enter (hosting=self render-busy=0 swallow-enter=1) target=fm-lab-selfhost-38861:w1:p5
pane-env HERDR_ENV=1 HERDR_SESSION=fm-lab-selfhost-38861 HERDR_PANE_ID=w1:p5
native agent_status (raw herdr agent get): working
pane process-state: agent; adapter busy_state from outside the pane: busy
submitted lines:
buffered escalations:       79 bytes; wedge marker: present
daemon log (inject-related):
    [2026-09-30T19:27:04+0800] ERROR: away-mode escalation undelivered 7s; last delivery failure: deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane). Buffer + wake-queue preserved; alarm marker written.
    [2026-09-30T19:27:05+0800] inject deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane)
    [2026-09-30T19:27:06+0800] inject deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane)
    [2026-09-30T19:27:08+0800] inject deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane)
    [2026-09-30T19:27:08+0800] inject deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane)
    [2026-09-30T19:27:08+0800] ERROR: away-mode escalation undelivered 12s; last delivery failure: deferred: supervisor composer not confirmed-empty (state=pending: pending input, dead-shell prompt, or unreadable pane). Buffer + wake-queue preserved; alarm marker written.
pane capture:
    |agardner@AG-MBP-96 tmp ❯ (exec -a codex bash '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/
    |agent.sh' '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s4-selfhosted-swallowed-enter/submi
    |tted.log' 0 '/var/folders/41/64hrmnwx11q5lw3l9d7zmfgr0000gn/T//fm-selfhost-live.6Lo5dK/s4-selfhosted-swallowed-enter/lau
    |nch.sh')
    |❯ ... not needed — watcher daemon-managed)RESULT PASS - swallowed self-hosted submit keeps the buffer and raises the wedge marker
teardown: fm-lab-selfhost-38861 removed
exit=0
Evidence: Live scenario driver script

Source: Live scenario driver script

#!/usr/bin/env bash
# Live validation for PR #3050: a self-hosted away daemon (running as a
# background job INSIDE the supervisor pane it injects into) must not read the
# pane's pinned native `working` as the agent being mid-turn.
#
# Real herdr, isolated fm-lab-* session via bin/fm-herdr-lab.sh. The fixture
# "agent" pins its native agent_status to `working` for its whole life (the
# measured vendor behaviour while a background job runs) while rendering an
# idle `❯ ` composer. Usage: self-hosted-live.sh <worktree-root>
set -u
ROOT=$1
DAEMON="$ROOT/bin/fm-supervise-daemon.sh"
. "$ROOT/tests/herdr-test-safety.sh"
herdr_forget_inherited_pane
SESSION="fm-lab-selfhost-$$"
export HERDR_SESSION="$SESSION"
W=$(mktemp -d "${TMPDIR:-/tmp}/fm-selfhost-live.XXXXXX")
RC=0
say() { printf '%s\n' "$*"; }
result() { say "RESULT $1 - $2"; [ "$1" = PASS ] || RC=1; }
cleanup() {
  for p in "$W"/*/state/.supervise-daemon.pid; do
    [ -f "$p" ] && kill "$(cat "$p")" 2>/dev/null
  done
  pkill -f "$W/" 2>/dev/null
  fm_herdr_lab_teardown "$SESSION" >/dev/null 2>&1 && say "teardown: $SESSION removed"
  if [ -n "${KEEP:-}" ]; then say "kept $W"; else rm -rf "$W"; fi
}
trap cleanup EXIT
fm_herdr_lab_prepare "$SESSION" || { say "prepare failed"; exit 1; }
. "$DAEMON"
fm_backend_source herdr || exit 1
say "herdr: $(herdr --version)  session: $SESSION"

CONTAINER_RAW=$(fm_backend_herdr_container_ensure /tmp) || exit 1
CONTAINER=${CONTAINER_RAW%%$'\t'*}
SEEDED=${CONTAINER_RAW#*$'\t'}

# Swallow-every-Enter shim (active only while <case>/swallow exists).
# Resolve the real binary: a PATH wrapper that execs "the next herdr on PATH"
# would otherwise find this shim again and loop forever.
REAL_HERDR=
for c in $(type -ap herdr); do
  head -c 4 "$c" | grep -q '^#!' || { REAL_HERDR=$c; break; }
done
[ -n "$REAL_HERDR" ] || { say "no real herdr binary"; exit 1; }
say "shim forwards to: $REAL_HERDR"
mkdir -p "$W/shim"
cat > "$W/shim/herdr" <<SHIM
#!/usr/bin/env bash
if [ "\${1:-}" = pane ] && [ "\${2:-}" = send-keys ] && [ -n "\${FM_LIVE_SWALLOW:-}" ] && [ -f "\$FM_LIVE_SWALLOW" ]; then
  for a in "\$@"; do [ "\$a" = enter ] && exit 0; done
fi
exec "$REAL_HERDR" "\$@"
SHIM
chmod +x "$W/shim/herdr"

cat > "$W/agent.sh" <<'AGENT'
#!/usr/bin/env bash
# args: <log> <render-busy 0|1> <daemon-launcher or ->
LOG=$1 BUSY=$2 LAUNCH=$3
herdr pane report-agent "$HERDR_PANE_ID" --source fm-live --agent fm-live --state working --session "$HERDR_SESSION" >/dev/null 2>&1
printf 'pane-env HERDR_ENV=%s HERDR_SESSION=%s HERDR_PANE_ID=%s\n' "${HERDR_ENV:-}" "${HERDR_SESSION:-}" "${HERDR_PANE_ID:-}" > "$LOG.env"
[ "$LAUNCH" = - ] || { bash "$LAUNCH" & }
stty -echo -icanon min 1 time 0 2>/dev/null
_buf=
redraw() { local s=$_buf; [ ${#s} -gt 40 ] && s="...${s: -37}"; printf '\r\033[K❯ %s' "$s"; }
[ "$BUSY" = 1 ] && printf '• Working (5s • esc to interrupt)\n'
redraw
while IFS= read -r -n 1 c; do
  if [ -z "$c" ] || [ "$c" = $'\r' ]; then
    printf '%s\t%s\n' "$(printf '%s' "$_buf" | od -An -tx1 | tr -d ' \n')" "$_buf" >> "$LOG"
    _buf=; printf '\r\033[K\n'; [ "$BUSY" = 1 ] && printf '• Working (5s • esc to interrupt)\n'; redraw
  else
    case "$c" in $'\177') _buf=${_buf%?} ;; *) _buf+=$c ;; esac; redraw
  fi
done
AGENT

new_pane() {  # <name> -> PANE
  local ids tab pane i n=0
  ids=$(fm_backend_herdr_create_task "$CONTAINER" "$1" /tmp "$SEEDED") || return 1
  SEEDED=
  read -r tab pane <<<"$ids"
  for i in $(seq 1 100); do
    fm_backend_herdr_cli "$SESSION" pane process-info --pane "$pane" 2>/dev/null | jq -e '.result.process_info as $p | ($p.foreground_processes|length==1) and ($p.foreground_processes[0].pid==$p.shell_pid)' >/dev/null 2>&1 && n=$((n+1)) || n=0
    [ $n -ge 10 ] && break; sleep 0.1
  done
  PANE=$pane
}

# daemon_env <case-dir> <target> <swallow 0|1> -> writes launcher script
daemon_launcher() {
  local d=$1 target=$2 sw=$3 extra=${4:-}
  cat > "$d/launch.sh" <<L
export PATH="$W/shim:\$PATH" FM_LIVE_SWALLOW="$d/$( [ "$sw" = 1 ] && echo swallow || echo noswallow )"
export FM_DAEMON_PRIMARY_HARNESS=codex FM_STATE_OVERRIDE="$d/state" FM_SUPERVISOR_BACKEND=herdr FM_SUPERVISOR_TARGET="$target"
export FM_ESCALATE_BATCH_SECS=0 FM_HOUSEKEEPING_TICK=1 FM_POLL=1 FM_SIGNAL_GRACE=1 FM_HEARTBEAT=999999 FM_CHECK_INTERVAL=999999
export FM_INJECT_CONFIRM_SLEEP=0.4 FM_INJECT_CONFIRM_RETRIES=4 FM_STALE_ESCALATE_SECS=999999 $extra
exec nohup "$DAEMON" >"$d/daemon.out" 2>"$d/daemon.err"
L
}

run_case() {  # <name> <render-busy> <hosting: self|terminal> <swallow> <extra-env>
  local name=$1 busy=$2 hosting=$3 sw=$4 extra=${5:-} d="$W/$1" target
  mkdir -p "$d/state"; : > "$d/submitted.log"
  [ "$sw" = 1 ] && touch "$d/swallow"
  new_pane "fm-live-$name" || { say "pane create failed"; return 1; }
  target="$SESSION:$PANE"
  afk_enter "$d/state"
  daemon_launcher "$d" "$target" "$sw" "$extra"
  if [ "$hosting" = self ]; then
    fm_backend_herdr_send_text_line "$target" "(exec -a codex bash '$W/agent.sh' '$d/submitted.log' $busy '$d/launch.sh')"
  else
    fm_backend_herdr_send_text_line "$target" "(exec -a codex bash '$W/agent.sh' '$d/submitted.log' $busy -)"
    sleep 1; ( env -u HERDR_ENV -u HERDR_PANE_ID bash "$d/launch.sh" & )
  fi
  sleep 3
  say "--- case $name (hosting=$hosting render-busy=$busy swallow-enter=$sw) target=$target"
  say "$(cat "$d/submitted.log.env" 2>/dev/null)"
  say "native agent_status (raw herdr agent get): $(fm_backend_herdr_cli "$SESSION" agent get "$PANE" | jq -r .result.agent.agent_status)"
  say "pane process-state: $(fm_backend_herdr_pane_process_state "$SESSION" "$PANE"); adapter busy_state from outside the pane: $(env -u HERDR_ENV -u HERDR_PANE_ID bash -c ". '$DAEMON'; fm_backend_source herdr; fm_backend_busy_state herdr '$target'")"
  echo "needs-decision: live-$name pick A or B" > "$d/state/live-c1.status"
  sleep "${WAIT:-10}"
  say "submitted lines:"; sed 's/^/    /' "$d/submitted.log"
  say "buffered escalations: $(wc -c < "$d/state/.subsuper-escalations" 2>/dev/null || echo 0) bytes; wedge marker: $([ -e "$d/state/.subsuper-inject-wedged" ] && echo present || echo absent)"
  say "daemon log (inject-related):"; grep -iE 'busy|inject|deliver|defer|wedge|escalat' "$d/state/.supervise-daemon.log" 2>/dev/null | tail -6 | sed 's/^/    /'
  say "pane capture:"; fm_backend_herdr_capture "$target" 6 | sed 's/^/    |/'
  CASE_DIR=$d
  afk_exit "$d/state" 2>/dev/null
  [ -f "$d/state/.supervise-daemon.pid" ] && kill "$(cat "$d/state/.supervise-daemon.pid")" 2>/dev/null
}

# S1: self-hosted, idle render, pinned native working -> digest delivered
run_case s1-selfhosted-delivers 0 self 0
if grep -q 'live-s1-selfhosted-delivers' "$CASE_DIR/submitted.log" && [ ! -s "$CASE_DIR/state/.subsuper-escalations" ]; then
  result PASS "self-hosted daemon delivered the escalation despite native working"; else result FAIL "self-hosted daemon did not deliver"; fi

[ -n "${ONLY_S1:-}" ] && exit $RC
# S2: same pane shape, daemon in its own terminal -> native busy stays conclusive
run_case s2-terminal-hosted-defers 0 terminal 0
if ! grep -q 'live-s2' "$CASE_DIR/submitted.log" && [ -s "$CASE_DIR/state/.subsuper-escalations" ]; then
  result PASS "terminal-hosted daemon still defers on native working and keeps the buffer"; else result FAIL "terminal-hosted daemon injected into a native-busy pane"; fi

# S3: self-hosted, real mid-turn render -> still defers
run_case s3-selfhosted-midturn-defers 1 self 0
if ! grep -q 'live-s3' "$CASE_DIR/submitted.log" && [ -s "$CASE_DIR/state/.subsuper-escalations" ]; then
  result PASS "self-hosted daemon still defers while the rendered busy signature shows a live turn"; else result FAIL "self-hosted daemon injected mid-turn"; fi

# S4: self-hosted, every Enter swallowed -> not discarded as delivered; wedge raised
WAIT=16 run_case s4-selfhosted-swallowed-enter 0 self 1 "FM_MAX_DEFER_SECS=3"
if ! grep -q 'live-s4' "$CASE_DIR/submitted.log" && [ -s "$CASE_DIR/state/.subsuper-escalations" ] && [ -s "$CASE_DIR/state/.subsuper-inject-wedged" ]; then
  result PASS "swallowed self-hosted submit keeps the buffer and raises the wedge marker"; else result FAIL "swallowed self-hosted submit was lost or wedge not raised"; fi

exit $RC
Evidence: fm-daemon unit suite output

Source: fm-daemon unit suite output

ok - fm-afk-start.sh fails before daemon startup when the afk flag cannot be written
ok - fm-afk-start.sh ignores stale pidfile-only live pids
ok - fm-afk-start.sh reclaims stale daemon locks whose live pid identity no longer matches
ok - supervise daemon state root is scoped by FM_HOME
ok - routine signal self-handles
ok - captain-relevant status verbs escalate
ok - check + unknown escalate; heartbeat self-handles
ok - a delivered unknown wake is acknowledged once per away session; a new one and ordinary escalations still fire
ok - a failed unknown-wake acknowledgement write does not re-inject a delivered digest
ok - transient stale self-handles and records a persistence marker
ok - enriched stale wedges bypass status absorption except under a declared wait, without disturbing busy workers
ok - an enriched wedge under a declared wait uses the pause cadence and restores wedge detection on resume
ok - stale + terminal status escalates immediately
ok - stale escalation and current wait cadence remain independent
ok - paused reasons with captain phrases remain pause-classified
ok - a foreign resolved line keeps a pause, while the worker's own resolved line retracts it
ok - a captain-held transfer classifies as pause, not as a wedge candidate
ok - handle_wake on a paused stale records a pause marker, drops the wedge marker, and does not escalate
ok - handle_wake records a declared pause from a routine signal for long-cadence rechecks
ok - a terminal signal clears pause and stale tracking across both supervisors
ok - housekeeping migrates a normal-watcher's declared pause into daemon tracking
ok - housekeeping clears an already-resumed watcher pause across both supervisors
ok - housekeeping seeds pause tracking from status without a watcher marker
ok - persistent stale escalates after threshold and clears its marker
ok - resumed (busy) stale clears its marker without escalating
ok - housekeeping re-surfaces a stale declared pause on the long cadence and resets its window
ok - housekeeping re-surfaces a forgotten captain hold on the long cadence and resets its window
ok - housekeeping silences a captain hold only under an away record, never under quiet mode's
ok - a busy pane cannot gate the pause clear once its crew's status no longer declares the wait
ok - housekeeping matures a busy pane's declared-wait window into exactly one recheck per window
ok - housekeeping bounds a distant declared time, defers to a near one, and rechecks a passed one at once
ok - housekeeping clears a paused marker once the crew is no longer declaring the pause
ok - housekeeping clears the pause marker once a captain hold is answered
ok - housekeeping moves an existing stale marker to pause before wedge escalation
ok - housekeeping moves a captain hold's existing stale marker to pause before wedge escalation
ok - housekeeping clears tracking when a crew leaves pause
ok - persistent herdr stale resolves the target from metadata and escalates
ok - herdr idle busy-footer stale clears through capture corroboration
ok - resumed herdr stale clears through backend-aware busy state
ok - persistent Orca stale resolves the terminal from metadata
ok - multiple escalations flush as a single batched digest
ok - batch flush measures max-delay from the first append, not the last
ok - catch-all scan escalates a missed terminal once, not twice
ok - handle_wake routes routine->self and captain->escalate
ok - a decision-owned queued row escalates once as the decision, then suppresses until the status changes
ok - a captain-held decision-owned row is self-handled without escalation, now and on repeat
ok - INJECT_SKIP forces self-handle, bypassing captain-relevant classification
ok - is_wake_reason distinguishes watcher wake reasons from singleton-status stdout
ok - terminal-stale escalate removes its marker so housekeeping does not re-escalate
ok - captain signal escalate marks seen so the catch-all scan does not re-fire
ok - _collapse_newlines replaces newlines with literal separator
ok - afk flag absent: daemon does not inject, buffer preserved
ok - busy-guard defers injection when supervisor pane is busy
ok - marker detection: marker -> stay afk, no marker -> exit afk
ok - /afk invocation is exempt from afk exit (no self-cancel)
ok - should_exit_afk returns false when afk is not active
ok - strip_injection_marker removes the sentinel marker cleanly
ok - a marker-preserving primary still receives the typed U+2063 away-supervisor envelope and no record
ok - record-backed doorbell: only a doorbell naming this home's own record stays afk; a bare ASCII label, a missing record, and another home's record exit
ok - pane_input_pending detects partial input on the cursor line
ok - pane_input_pending: a blank unidentified cursor row defers (strict container-proof rule)
ok - pane_input_pending: only proven empty agent prompts pass
ok - fm_tmux_composer_state: a bare shell prompt ($/%/#/>) reads unknown, never empty (dead-shell injection safety)
ok - fm_tmux_composer_state: a bordered composer box and bare agent glyphs (❯/›) still read empty
ok - fm_tmux_composer_state: only matching edge borders form a composer box
ok - pane_input_pending preserves bright placeholder-like drafts in styled captures
ok - classify_signal dedupes against the catch-all scan seen marker
ok - turn-end markers stay routine while mixed actionable status batches escalate
ok - an actionable event is escalated to an away captain despite later routine appends
ok - the daemon commits exactly the endpoint captured by classification
ok - a stale wake escalates a blocker hidden by later progress
ok - a stale span read failure surfaces without advancing its marker
ok - a recreated status rejects the old captured identity
ok - an unverifiable status identity surfaces without advancing markers
ok - a status read failure surfaces without advancing the daemon suppressor
ok - catch-all routine scans advance before later actionable appends
ok - failed escalation writes retain durable wakes and classification positions
ok - catch-all markers advance only after escalation buffering succeeds
ok - classification failure retains the complete durable wake batch
ok - missing-status stale wakes remain ordinary and acknowledgeable
ok - transient unreadable signals recover without advancing their position
ok - daemon catch-all reclassifies permission-recovered status content
ok - a permanent classification failure is reported, acknowledged, and never advances its position
ok - the away-mode catch-all scan surfaces a masked event once
ok - classify_stale dedupes against the signal path seen marker
ok - AFK nonterminal working:+merged keeps wedge aging and re-escalates at bound
ok - genuine done: and merge-check events still escalate
ok - pane_input_pending: an idle bordered composer is NOT pending (afk-invx-i5)
ok - pane_input_pending: text inside a bordered composer is still pending
ok - submit-ACK confirms a submit when the composer returns to a bordered-empty box
ok - submit-ACK reports pending on a persistently swallowed Enter (type-once)
ok - max-defer on an empty stuck pane types once, alarms, and preserves the buffer
ok - max-defer flushes and clears the buffer on an empty bordered pane
ok - max-defer on a pending composer alarms without typing
ok - normal flush clears a stale wedge marker
ok - an oversized buffered digest is delivered bounded, with the full text kept durable
ok - a digest past its byte budget counts the omitted events and keeps them in the full text
ok - an initial-send failure logs its stage, bytes, and stderr, and the wedge alarm names it
ok - an Enter-confirmation failure logs its own stage and byte count
ok - a bounded digest's full-text file survives a failure after typing, and a deferral writes none
ok - below MAX_DEFER: no inject, no alarm, buffer preserved
ok - max-defer does not flush or alarm while afk is inactive
ok - library mode: sourcing the daemon defaults FM_WEDGE_ALARM_EXEC to discard (no test can fire a real notification)
ok - wake helpers replace inherited notifier overrides with the safe recorder
ok - the discard seam suppresses every notifier, including command: (fires nothing)
ok - direct notifier helpers honor the discard seam, including command:
ok - osascript channel routes through the notifier seam with the summary (never a real notification)
ok - herdr channel routes through the notifier seam with the summary (never a real notification)
ok - command channel runs the captain command with the summary on $1 and on stdin
ok - command channel failures redact configured commands while logging their exit status
ok - unknown channel directives are redacted while the alarm keeps running
ok - off disables every active alert regardless of directive position (marker and tmux flash are unaffected)
ok - auto resolves to the macOS osascript notifier on Darwin (default-on)
ok - auto on a non-macOS platform selects no built-in OS channel (the marker or a configured command carries it)
ok - config/wedge-alarm selects every configured channel and skips comment and blank lines
ok - a failing channel logs and falls back to the next channel, never crashing the alarm
ok - a hung notifier is bounded, logged, and falls through to the next channel
ok - a backgrounded command notifier remains bounded until its process group is reaped
ok - a hung notifier override is bounded, logged, and proceeds to the next channel
ok - daemon shutdown stops and reaps the active notifier process group
ok - inject_wedge_alarm writes the marker AND emits the active alert even with no tmux status-line (herdr backend)
ok - in-process wedge throttle prevents alert spam when the marker cannot persist
ok - fm-send returns 3 with a non-error no-resend warning when confirmation stays pending
ok - fm-send exits non-zero when initial text send fails
ok - fm-send exits non-zero unless delivery is proven empty
ok - discover_supervisor_backend: override > TMUX_PANE > HERDR_ENV+HERDR_PANE_ID > tmux fallback
ok - discover_supervisor_target: override > TMUX_PANE > herdr '<session>:<pane-id>' composition > firstmate:0 fallback
ok - pane_is_busy: herdr native busy_state='busy' short-circuits without a capture fallback
ok - supervisor_pane_hosts_daemon: recognizes only a daemon running inside the target pane itself
ok - pane_is_busy: self-hosted daemon falls through native busy to the rendered delivery signature
ok - pane_is_busy: self-hosted fall-through still defers on a genuinely mid-turn harness
ok - pane_is_busy: native busy stays conclusive when the daemon runs outside the target pane
ok - inject_msg: delivers an away-mode escalation whose target reads native busy only because the daemon hosts it
ok - self-hosted delivery composes with actionable status spans and declared-wait cadence
ok - escalate_flush: a swallowed self-hosted submit keeps the buffer and leaves the wedge marker raised
ok - primary busy guard isolates rendered signatures by detected harness
ok - pane_is_busy: omitted backend defaults to tmux for Grok's isolated fallback
ok - pane_input_pending: dispatches through fm_backend_composer_state for backend=herdr
ok - inject_msg: herdr busy-guard defers before ever attempting a submit
ok - inject_msg: herdr composer-guard defers before ever attempting a submit
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
ok - inject_msg: defers on a dead-shell/unreadable composer (unknown), never typing the escalation into a shell
ok - inject_msg: unrecognized composer states defer by default
exit=0
Evidence: Live result summary
native agent_status (raw herdr agent get): working | adapter busy_state from outside the pane: busy (all cases)
RESULT PASS - self-hosted daemon delivered the escalation despite native working
RESULT PASS - terminal-hosted daemon still defers on native working and keeps the buffer
RESULT PASS - self-hosted daemon still defers while the rendered busy signature shows a live turn
RESULT PASS - swallowed self-hosted submit keeps the buffer and raises the wedge marker
- Outcome: ⚠️ 1 info across 1 run (10m51s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-afk-inject-herdr-e2e.test.sh - On this machine ~/.local/bin/herdr is a /bin/sh wrapper that execs the next herdr on PATH. tests/fm-afk-inject-herdr-e2e.test.sh puts its Enter-swallowing shim first on PATH and execs command -v herdr, which is that wrapper, so the two exec each other forever and the suite hangs. This is a local environment problem and not caused by this change. The test was killed and its lab session torn down.
  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Away daemon running as a background job inside the supervisor pane (native state pinned working, idle composer) delivers a needs-decision escalation into that pane ✅ pass live self-hosted-live.log case s1: pane-env shows Herdr's own HERDR_PANE_ID=w1:p2 matching the target; the submitted line starts with U+2063 FIRSTMATE_OP and names live-s1; buffer 0 bytes
Adversarial control: a daemon hosted in its own terminal against the same native-working pane still treats native busy as conclusive and defers ✅ pass live self-hosted-live.log case s2: repeated 'inject deferred: supervisor pane busy (agent mid-turn)', no submitted lines, buffer 75 bytes
Adversarial: a self-hosted daemon still defers while the pane renders a genuine mid-turn signature ('esc to interrupt') ✅ pass live self-hosted-live.log case s3: repeated busy deferrals, no submitted lines, buffer 78 bytes
Adversarial: a self-hosted submit whose Enter is always swallowed is not discarded as delivered; the buffer is kept and the wedge alarm is raised ✅ pass live self-hosted-live.log case s4: 'ERROR: away-mode escalation undelivered ... Buffer + wake-queue preserved; alarm marker written', buffer 79 bytes, wedge marker present, no submitted lines
Adapter single-owner boundary: agent_status_raw masks working only for a self-hosted pane; other panes and statuses are unchanged, and self-hosted submits confirm only on a rendered transition or a… ⏸️ untested no The prior payload did not establish a live result for this scenario. It was checked only by the unit suite tests/fm-backend-herdr.test.sh. The masking boundary for non-self-hosted panes and other stat…
  • bash tests/fm-daemon.test.sh (0 failures; includes the supervisor_pane_hosts_daemon, pane_is_busy self-hosted, inject_msg, actionable-wait and swallowed-escalation cases)
  • bash tests/fm-backend-herdr.test.sh (0 failures; includes agent_status_raw masking in both directions and the three self-hosted send_text_submit cases)
  • bash ~/.no-mistakes/evidence/01M3S0FJRB8F1421H1FPJB21X7/self-hosted-live.sh &lt;worktree&gt;: live script on real herdr 0.9.1 in a throwaway fm-lab-selfhost-* session through bin/fm-herdr-lab.sh prepare/teardown. It runs the real bin/fm-supervise-daemon.sh inside a Herdr pane whose registered agent (argv0 codex) is pinned to agent_status=working. 4 scenarios, all PASS.
  • Attempted tests/fm-afk-inject-herdr-e2e.test.sh. It hung in a local environment loop (see testing_summary) and was killed; its lab session was torn down.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…being busy

Away mode buffered every escalation and delivered none. The daemon log carried
6,910 consecutive "supervisor pane busy (agent mid-turn)" deferrals with no gap
over 8.7 hours, one buffer held 31,396 seconds overnight, and zero deliveries.

Cause. On the native hosting the daemon runs as a background job of the very
agent it injects into. A backend's native agent-state answers "is anything
running in this pane", not "is the agent mid-turn", so the daemon's own
existence pinned its target busy for as long as away mode lasted. Measured
2026-08-25 on Herdr 0.8.0 with Claude Code 2.1.245: agent_status stayed
"working" for 121 seconds after the turn ended, across 21 samples, while the
harness's own title glyph and rendered footer both showed idle; a control pane
with no background job reported "done".

pane_is_busy treated native busy as conclusive, so the guard could never clear
and the max-defer escape could never escape.

Native busy now stays conclusive only when the daemon runs outside the pane it
injects into. supervisor_pane_hosts_daemon recognizes the self-hosted case, and
the verdict then falls through to the rendered delivery signature that
fm-composer-lib.sh already owns as the authority on whether a pane can accept a
keystroke. The composer guard is untouched, so a half-typed captain line still
defers.

Coverage pins the condition from both sides: a self-hosted daemon delivers
through native busy, still defers while the harness renders a live turn, and a
terminal-hosted daemon keeps native busy conclusive. Each new test was checked
to fail without the fix, and the pre-existing short-circuit assertion catches
the over-broad repair.
@greptile-apps

greptile-apps Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Fixes away-mode daemon escalation deferral in self-hosted setup.

The PR appears safe to merge.

Reviews (3) · Last reviewed commit: "test: align self-hosted delivery tests w..."

@AgardnerAU AgardnerAU changed the title fix(bin): stop a self-hosted away daemon reading itself as the agent being busy fix(bin): deliver self-hosted away daemon escalations Aug 31, 2026
@AgardnerAU AgardnerAU changed the title fix(bin): deliver self-hosted away daemon escalations fix(bin): stop a self-hosted away daemon deferring every escalation Sep 18, 2026
@AgardnerAU

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch; it is no longer conflicting. Head is now a3936ce519b79d3bf59b97f6135f82c4541c44cd.

Validated on that head: tests/fm-daemon.test.sh 133 assertions and tests/fm-backend-herdr.test.sh 213 assertions, both zero failures, plus bin/fm-lint.sh and bin/fm-doc-audience-check.sh clean.

The two red checks are both action_required with zero jobs started, which is the fork-PR state awaiting a maintainer to release the workflow runs; they do not reflect a failure in this branch. Ready for CI.

@AgardnerAU

Copy link
Copy Markdown
Contributor Author

The workflow runs on this pull request are held at action_required with no job started, so the required checks cannot report a result. The change itself is validated at the current head and the branch is not conflicting.

Could a maintainer release the held runs when convenient? Happy to rebase first if the base has moved far enough to matter.

1 similar comment
@AgardnerAU

Copy link
Copy Markdown
Contributor Author

The workflow runs on this pull request are held at action_required with no job started, so the required checks cannot report a result. The change itself is validated at the current head and the branch is not conflicting.

Could a maintainer release the held runs when convenient? Happy to rebase first if the base has moved far enough to matter.

…r-delivers

# Conflicts:
#	docs/verification/runtime-backends.md
…probe and Claude doorbell

Upstream now probes pane identity before each Herdr submit and delivers Claude-bound digests as a record-backed doorbell, so the self-hosted submit fakes take the identity prefix and the self-hosted digest checks read the delivered record.
@AgardnerAU

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch; it is now up to date and ready for CI. The only conflict was two independent additions to docs/verification/runtime-backends.md, both kept. The self-hosted delivery tests now match upstream's Herdr submit identity probe and Claude doorbell delivery.

@AgardnerAU

Copy link
Copy Markdown
Contributor Author

Closing: no longer needed on our side; superseded by #5805.

@AgardnerAU AgardnerAU closed this Nov 29, 2026
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