Skip to content

fix(bin): surface ready queued work instead of absorbing heartbeats - #6753

Open
kesslerio wants to merge 37 commits into
kunchenguid:mainfrom
kesslerio:fm/fm-ready-queue-dispatch-r3
Open

kesslerio wants to merge 37 commits into
kunchenguid:mainfrom
kesslerio:fm/fm-ready-queue-dispatch-r3

Conversation

@kesslerio

@kesslerio kesslerio commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Added bin/fm-ready-queue-lib.sh as the single backlog-readiness verdict shared by bin/fm-watch.sh heartbeat triage and the away daemon's handle_wake, so a heartbeat over ready or indeterminate queue readiness becomes actionable and resets idle backoff instead of being absorbed.
  • Added a ready-work check across the branch prompt, Pi branch extension, drain, and teardown wording: each ready unit is dispatched or gets its not-ready reason recorded on its backlog note, and the drain now prints one untruncated line per captain outcome with UTF-8-safe routine truncation plus a per-sequence lookup.
  • Split the portable serial suite into 12 shards (runner, CI matrix, and shard docs updated) and added tests covering ready-queue heartbeat delivery, away dispatch stops, backlog drain, and teardown process reaping.

Risk Assessment

✅ Low: The changes preserve the accepted dispatch contract, apply actionable heartbeat accounting across postures, retain upstream record hygiene, and consistently update the serial shard count; no material defects were substantiated.

Testing

Ran the shipped ready-queue suite, then independently drove the real watcher CLI in disposable lab homes: ready queued work surfaced an actionable heartbeat and reset .heartbeat-streak from 3 to 0 in both attended and away postures, unreadable readiness escalated instead of being absorbed, an away heartbeat over a proven-empty queue kept plain accounting (3 to 4, wake still emitted for the daemon), and a held unit produced no dispatch wake. The real away daemon, running its own watcher child against a private tmux socket with FM_INJECT_SKIP=heartbeat, escalated ready work as "ready-queue fleet check" into the supervisor buffer while the same daemon stayed silent over an empty queue. The upstream record-hygiene heartbeat block still emitted its check wake, and the coverage guard passes with twelve serial shards while 11- and 13-shard lane names are refused. Verdict: go; every scenario on the derived list passed live. No UI surface exists for this change (shell/daemon CLI only), so evidence is CLI transcripts and state dumps rather than screenshots.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
An attended primary with a ready queued unit surfaces an actionable heartbeat and resets the idle backoff ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case attended-ready): real bin/fm-watch.sh exits 0 printing heartbeat, .heartbeat-streak 3 -> 0, .wake-queue r…
An away primary with a ready queued unit gets the same actionable accounting instead of plain backoff ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-ready, state/.afk present): streak 3 -> 0 with the heartbeat wake queued and drained
An away heartbeat over a proven-empty queue keeps plain heartbeat accounting ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-empty): streak 3 -> 4, upstream heartbeat still emitted for the daemon; ~/.no-mistakes/evidence/01…
Unreadable queue readiness escalates as actionable instead of being absorbed as empty ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-unreadable with a failing tasks-axi): heartbeat wake queued and streak reset to 0
Held or not-ready queued work produces no dispatch wake and keeps plain idle accounting ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case attended-held with a captain-held unit): no watcher output, empty .wake-queue, streak 3 -> 4
An away daemon escalates ready queued work to supervision even when heartbeat wakes are force-self suppressed ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/daemon-ready-transcript.txt: real bin/fm-supervise-daemon.sh with FM_INJECT_SKIP=heartbeat logs `escalate: heartbeat -> ready-queue fleet che…
The upstream record-hygiene heartbeat block still surfaces its check wake after the rebase ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/record-hygiene-check.txt: real watcher prints check: record hygiene: RECORD_HYGIENE: ... and queues the check row for a home with config/re…
The coverage guard passes at twelve portable serial shards and the lane contract refuses stale 11- and 13-shard names ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/shard-coverage.log (exit 0, serial_shards=12, serial_max_ms=1102468 < 1200000), shard-lanes.txt (1of12..12of12), shard-lane-acceptance.txt (1…
The shipped ready-queue suite still drives the watcher and real backlog consumer end to end ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/ready-queue-suite.log: bash tests/fm-watch-ready-queue.test.sh 20 cases, exit 0
Evidence: Watcher posture matrix: streaks, wake rows, drain delivery

Source: Watcher posture matrix: streaks, wake rows, drain delivery

=== case attended-ready (posture=attended queue=ready)
watcher-exit: 0
watcher-stdout: heartbeat
heartbeat-streak-after: 0
wake-queue-rows: 1794695336	1	heartbeat	heartbeat	heartbeat
drain-output: 1794695336	1	heartbeat	heartbeat	heartbeat;
triage-tail: 

=== case away-ready (posture=away queue=ready)
watcher-exit: 0
watcher-stdout: heartbeat
heartbeat-streak-after: 0
wake-queue-rows: 1794695338	1	heartbeat	heartbeat	heartbeat
drain-output: 1794695338	1	heartbeat	heartbeat	heartbeat;
triage-tail: 

=== case away-unreadable (posture=away queue=unreadable)
watcher-exit: 0
watcher-stdout: heartbeat
heartbeat-streak-after: 0
wake-queue-rows: 1794695339	1	heartbeat	heartbeat	heartbeat
drain-output: 1794695339	1	heartbeat	heartbeat	heartbeat;
triage-tail: 

=== case away-empty (posture=away queue=empty)
watcher-exit: 0 (loop stopped once the case state was reached; an away heartbeat exits on its own, an absorbed one is stopped by this driver)
watcher-stdout: heartbeat
heartbeat-streak-after: 4
wake-queue-rows: 1794695340	1	heartbeat	heartbeat	heartbeat
triage-tail: 

=== case attended-held (posture=attended queue=held)
watcher-exit: 143 (loop stopped once the case state was reached; an away heartbeat exits on its own, an absorbed one is stopped by this driver)
watcher-stdout: 
heartbeat-streak-after: 4
wake-queue-rows: 
triage-tail: 
Evidence: Real away daemon with ready queue and FM_INJECT_SKIP=heartbeat escalates ready-queue fleet check

Source: Real away daemon with ready queue and FM_INJECT_SKIP=heartbeat escalates ready-queue fleet check

=== daemon mode=ready (lab home /tmp/fm-lab.g4J74K, private tmux socket, FM_INJECT_SKIP=heartbeat)
--- daemon log ---
[2026-11-14T14:24:22-0800] daemon starting (pid 3635971); target=%0; target_source=FM_SUPERVISOR_TARGET; backend=tmux; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=1s
[2026-11-14T14:24:23-0800] wake: heartbeat
[2026-11-14T14:24:24-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:25-0800] wake: heartbeat
[2026-11-14T14:24:25-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:28-0800] wake: heartbeat
[2026-11-14T14:24:28-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:30-0800] wake: heartbeat
[2026-11-14T14:24:30-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:31-0800] wake: heartbeat
[2026-11-14T14:24:32-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:33-0800] wake: heartbeat
[2026-11-14T14:24:34-0800] escalate: heartbeat -> ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
[2026-11-14T14:24:34-0800] inject deferred: supervisor composer not confirmed-empty (state=unknown: composer not proven empty or pending (unrecognized screen, or harness not idle))
[2026-11-14T14:24:34-0800] daemon shutting down
--- escalation buffer after run ---
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
ready-queue fleet check: evaluate tasks-axi ready and launch every authorized ready unit; if readiness is unavailable, resolve or report the blocker
--- supervisor pane capture ---
lab$
Evidence: Real away daemon over an empty queue stays self-handled (no escalation)

Source: Real away daemon over an empty queue stays self-handled (no escalation)

=== daemon mode=empty (lab home /tmp/fm-lab.VmhGWV, private tmux socket, FM_INJECT_SKIP=heartbeat)
--- daemon log ---
[2026-11-14T14:26:10-0800] daemon starting (pid 3749738); target=%0; target_source=FM_SUPERVISOR_TARGET; backend=tmux; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=1s
[2026-11-14T14:26:26-0800] wake: heartbeat
[2026-11-14T14:26:27-0800] wake force-self (FM_INJECT_SKIP): heartbeat
[2026-11-14T14:26:30-0800] daemon shutting down
--- escalation buffer after run ---
--- wake queue / heartbeat streak / triage ---
streak=1
--- watcher stderr ---
--- supervisor pane capture ---
lab$
Evidence: Preserved record-hygiene heartbeat block emits its check wake

Source: Preserved record-hygiene heartbeat block emits its check wake

=== record-hygiene check wake (posture=attended, config/record-hygiene present)
watcher-exit: 0
watcher-stdout: check: record hygiene: RECORD_HYGIENE: metadata has no tab: hygiene2
RECORD_HYGIENE: metadata has no tab: hygiene
RECORD_HYGIENE: duplicate PR https://example.test/pull/1 in records: hygiene2, hygiene
wake-queue-rows: 1794695290	1	check	record-hygiene	check: record hygiene: RECORD_HYGIENE: metadata has no tab: hygiene2 RECORD_HYGIENE: metadata has no tab: hygiene RECORD_HYGIENE: duplicate PR https://example.test/pull/1 in records: hygiene2, hygiene;
hygiene-last: RECORD_HYGIENE: metadata has no tab: hygiene2
RECORD_HYGIENE: metadata has no tab: hygiene
RECORD_HYGIENE: duplicate PR https://example.test/pull/1 in records: hygiene2, hygiene
hygiene-meta-reportable: no
watcher-stderr: 
Evidence: Coverage guard passes with 12 serial shards

Source: Coverage guard passes with 12 serial shards

FM_TEST_COVERAGE ok total=341 parallel=27 parallel_max_ms=850004 parallel_imbalance_ms=1977 parallel_unhinted=0 serial=298 serial_shards=12 serial_unhinted=44 serial_max_ms=1102468 serial_budget_ms=1200000 herdr=16

real	0m19.657s
user	0m12.227s
sys	0m20.329s
exit=0
Evidence: Portable serial lane names 1of12..12of12

Source: Portable serial lane names 1of12..12of12

portable-parallel-1
portable-parallel-2
portable-serial
portable-serial-1of12
portable-serial-2of12
portable-serial-3of12
portable-serial-4of12
portable-serial-5of12
portable-serial-6of12
portable-serial-7of12
portable-serial-8of12
portable-serial-9of12
portable-serial-10of12
portable-serial-11of12
portable-serial-12of12
real-herdr-gated
Evidence: 12of12 accepted, 11of11 and 13of13 refused

Source: 12of12 accepted, 11of11 and 13of13 refused

--- lane portable-serial-12of12
exit=0 count=27
tests/fm-cortex-signals-live-e2e.test.sh
tests/fm-backend-cmux-smoke.test.sh
--- lane portable-serial-11of11
exit=2 count=0
fm-test-run: lane 'portable-serial-11of11' asks for 11 portable serial shards but this runner is configured for 12 (see --list-lanes)
--- lane portable-serial-13of13
exit=2 count=0
fm-test-run: lane 'portable-serial-13of13' asks for 13 portable serial shards but this runner is configured for 12 (see --list-lanes)
Evidence: Shipped tests/fm-watch-ready-queue.test.sh run (20 cases, exit 0)

Source: Shipped tests/fm-watch-ready-queue.test.sh run (20 cases, exit 0)

ok - absolute backlog addressing preserves ready, empty, and unavailable verdicts
ok - relative backlog addressing preserves ready, empty, and unavailable verdicts
ok - trailing-slash backlog addressing preserves ready, empty, and unavailable verdicts
ok - relative-home backlog addressing preserves ready, empty, and unavailable verdicts
ok - trailing-slash-home backlog addressing preserves ready, empty, and unavailable verdicts
ok - attended ready queue reaches supervision despite stale title and silent status logs
ok - attended unreadable queue reaches supervision despite stale title and silent status logs
ok - away ready queue reaches supervision despite stale title and silent status logs
ok - away unreadable queue reaches supervision despite stale title and silent status logs
ok - empty queue remains quiet without dispatchable work
ok - held queue remains quiet without dispatchable work
ok - emitted supervision prompt requires current stop verification after finish
ok - emitted supervision prompt gates away dispatch to the recorded words and keeps the attended handoff
ok - emitted supervision prompt keeps an unconfirmed start out of the queue drop
ok - daemon ready heartbeat respects readiness before skip=heartbeat and acknowledgement
ok - daemon ready heartbeat respects readiness before skip=signal and acknowledgement
ok - daemon empty heartbeat respects readiness before skip=heartbeat and acknowledgement
ok - daemon held heartbeat respects readiness before skip=heartbeat and acknowledgement
ok - daemon unreadable heartbeat respects readiness before skip=heartbeat and acknowledgement
{run-worktree}/bin/fm-supervise-daemon.sh: line 829: /tmp/fm-watch-ready-queue.DMR7jN/daemon-failed-heartbeat/state/.subsuper-escalations: Is a directory
ok - daemon failed heartbeat respects readiness before skip=heartbeat and acknowledgement
exit=0
Evidence: Live driver script for the watcher posture matrix

Source: Live driver script for the watcher posture matrix

#!/usr/bin/env bash
# Drive the real firstmate watcher CLI (bin/fm-watch.sh) against a disposable
# home per heartbeat posture/readiness case and record observable state.
# Usage: drive-ready-heartbeat.sh <repo-root> <evidence-out-dir>
set -u
ROOT=$(cd "$1" && pwd)
OUT=$(cd "$2" && pwd)
LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-hb.XXXXXX")
INERT=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-inert.XXXXXX")   # non-git: keeps guard tangle check quiet
trap 'rm -rf "$LAB" "$INERT"' EXIT
SUMMARY="$OUT/heartbeat-scenarios.txt"
: > "$SUMMARY"

tasks_toml() {
  cat > "$1" <<'TOML'
backend = "markdown"

[markdown]
path = "data/backlog.md"
archive = "data/done-archive.md"
done_keep = 10
TOML
}

# mkcase <name> <posture:attended|away> <queue:ready|empty|held|unreadable>
mkcase() {
  local name=$1 posture=$2 queue=$3 dir="$LAB/$1"
  mkdir -p "$dir/data" "$dir/config" "$dir/state" "$dir/fakebin"
  tasks_toml "$dir/.tasks.toml"
  printf '## In flight\n\n## Queued\n\n## Done\n' > "$dir/data/backlog.md"
  case "$queue" in
    ready)
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" add ship-next 'beyond current spend cap' >/dev/null
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" add landed 'dependency already merged' >/dev/null
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" block ship-next --by landed >/dev/null
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" 'done' landed --pr https://github.com/example/fixture/pull/1 >/dev/null
      ;;
    held)
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" add ship-next 'waiting on captain' >/dev/null
      FM_HOME="$dir" "$ROOT/bin/fm-captain-hold.sh" hold ship-next --reason 'explicit captain hold' >/dev/null
      ;;
    unreadable)
      FM_HOME="$dir" "$ROOT/bin/fm-tasks-axi.sh" add ship-next 'queue present but unreadable' >/dev/null
      printf '#!/usr/bin/env bash\nprintf "readiness unavailable\\n" >&2\nexit 2\n' > "$dir/fakebin/tasks-axi"
      chmod +x "$dir/fakebin/tasks-axi"
      ;;
  esac
  [ "$posture" = away ] && printf 'mode: quiet\n' > "$dir/state/.afk"
  printf '3\n' > "$dir/state/.heartbeat-streak"
  touch -d '@'"$(( $(date +%s) - 30 ))" "$dir/state/.last-heartbeat" 2>/dev/null \
    || touch -t "$(date -v-30S '+%Y%m%d%H%M.%S')" "$dir/state/.last-heartbeat"
  printf '%s\n' "$dir"
}

run_case() {
  local name=$1 posture=$2 queue=$3 dir out rc streak wake triage
  dir=$(mkcase "$name" "$posture" "$queue")
  out="$dir/watch.stdout"
  PATH="$dir/fakebin:$PATH" FM_HOME="$dir" FM_STATE_OVERRIDE="$dir/state" \
    FM_CONFIG_OVERRIDE="$dir/config" FM_ROOT_OVERRIDE="$INERT" \
    FM_POLL=0.2 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=1 \
    timeout 60 "$ROOT/bin/fm-watch.sh" > "$out" 2>"$dir/watch.stderr"
  rc=$?
  streak=$(cat "$dir/state/.heartbeat-streak" 2>/dev/null || echo missing)
  wake=$(cat "$dir/state/.wake-queue" 2>/dev/null || true)
  triage=$(tail -3 "$dir/state/.triage-log" 2>/dev/null || true)
  # Persist the durable delivery proof from the real drain CLI.
  FM_HOME="$dir" FM_STATE_OVERRIDE="$dir/state" FM_ROOT_OVERRIDE="$INERT" \
    "$ROOT/bin/fm-wake-drain.sh" > "$dir/drain.out" 2>/dev/null
  {
    printf '=== case %s (posture=%s queue=%s)\n' "$name" "$posture" "$queue"
    printf 'watcher-exit: %s\n' "$rc"
    printf 'watcher-stdout: %s\n' "$(cat "$out")"
    printf 'heartbeat-streak-after: %s\n' "$streak"
    printf 'wake-queue-rows: %s\n' "$(printf '%s' "$wake" | tr '\n' ';')"
    printf 'drain-output: %s\n' "$(cat "$dir/drain.out" | tr '\n' ';')"
    printf 'triage-tail: %s\n\n' "$(printf '%s' "$triage" | tr '\n' ';')"
  } >> "$SUMMARY"
  ls "$dir" >/dev/null
  rm -rf "$LAB/$name"
}

# Held/empty queues never surface, so bound them: kill the loop once the
# absorbed-heartbeat counter moves, then read state.
run_quiet_case() {
  local name=$1 posture=$2 queue=$3 dir pid rc i streak wake
  dir=$(mkcase "$name" "$posture" "$queue")
  PATH="$dir/fakebin:$PATH" FM_HOME="$dir" FM_STATE_OVERRIDE="$dir/state" \
    FM_CONFIG_OVERRIDE="$dir/config" FM_ROOT_OVERRIDE="$INERT" \
    FM_POLL=0.2 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=1 \
    "$ROOT/bin/fm-watch.sh" > "$dir/watch.stdout" 2>"$dir/watch.stderr" &
  pid=$!
  for ((i=0; i<200; i++)); do
    [ "$(cat "$dir/state/.heartbeat-streak" 2>/dev/null || echo 3)" -gt 3 ] && break
    sleep 0.1
  done
  kill -TERM "$pid" 2>/dev/null || true
  wait "$pid" 2>/dev/null
  rc=$?
  streak=$(cat "$dir/state/.heartbeat-streak" 2>/dev/null || echo missing)
  wake=$(cat "$dir/state/.wake-queue" 2>/dev/null || true)
  {
    printf '=== case %s (posture=%s queue=%s)\n' "$name" "$posture" "$queue"
    printf 'watcher-exit: %s (loop stopped once the case state was reached; an away heartbeat exits on its own, an absorbed one is stopped by this driver)\n' "$rc"
    printf 'watcher-stdout: %s\n' "$(cat "$dir/watch.stdout")"
    printf 'heartbeat-streak-after: %s\n' "$streak"
    printf 'wake-queue-rows: %s\n' "$(printf '%s' "$wake" | tr '\n' ';')"
    printf 'triage-tail: %s\n\n' "$(tail -3 "$dir/state/.triage-log" 2>/dev/null | tr '\n' ';')"
  } >> "$SUMMARY"
  rm -rf "$LAB/$name"
}

run_case attended-ready attended ready
run_case away-ready away ready
run_case away-unreadable away unreadable
run_quiet_case away-empty away empty
run_quiet_case attended-held attended held

printf 'driver-lab-cleaned: %s\n' "$([ -z "$(ls -A "$LAB" 2>/dev/null)" ] && echo yes)"
cat "$SUMMARY"
Evidence: Live driver script for the away daemon

Source: Live driver script for the away daemon

#!/usr/bin/env bash
# Drive the real away-mode supervision daemon (bin/fm-supervise-daemon.sh) with
# its own watcher child against a disposable lab home and a private tmux socket,
# then read what actually reached the supervisor pane.
# Usage: drive-daemon-heartbeat.sh <repo-root> <evidence-out-dir> <ready|empty>
set -u
ROOT=$(cd "$1" && pwd)
OUT=$(cd "$2" && pwd)
MODE=${3:-ready}
LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX")
INERT=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-inert.XXXXXX")
TMDIR=''
cleanup() {
  [ -z "$TMDIR" ] || TMUX_TMPDIR="$TMDIR" tmux kill-server 2>/dev/null || true
  [ -z "$TMDIR" ] || "$ROOT/bin/fm-lab-home.sh" teardown "$LAB" >/dev/null 2>&1 || true
  rm -rf "$LAB" "$INERT"
}
trap cleanup EXIT

"$ROOT/bin/fm-lab-home.sh" create "$LAB" >/dev/null
cat > "$LAB/.tasks.toml" <<'TOML'
backend = "markdown"

[markdown]
path = "data/backlog.md"
archive = "data/done-archive.md"
done_keep = 10
TOML
printf '## In flight\n\n## Queued\n\n## Done\n' > "$LAB/data/backlog.md"
printf 'mode: quiet\n' > "$LAB/state/.afk"
if [ "$MODE" = ready ]; then
  FM_HOME="$LAB" "$ROOT/bin/fm-tasks-axi.sh" add ship-next 'beyond current spend cap' >/dev/null
  FM_HOME="$LAB" "$ROOT/bin/fm-tasks-axi.sh" add landed 'dependency merged' >/dev/null
  FM_HOME="$LAB" "$ROOT/bin/fm-tasks-axi.sh" block ship-next --by landed >/dev/null
  FM_HOME="$LAB" "$ROOT/bin/fm-tasks-axi.sh" 'done' landed --pr https://github.com/example/fixture/pull/1 >/dev/null
fi

TMDIR=$("$ROOT/bin/fm-lab-home.sh" tmux-dir "$LAB")
export TMUX_TMPDIR="$TMDIR"
TMUX_TMPDIR="$TMDIR" tmux new-session -d -s primary -c "$PWD" -x 200 -y 50
TMUX_TMPDIR="$TMDIR" tmux send-keys -t primary 'export PS1="lab$ "; clear' C-m
sleep 1
PANE=$(TMUX_TMPDIR="$TMDIR" tmux display -p -t primary '#{pane_id}')
echo "lab=$LAB pane=$PANE mode=$MODE"

# FM_INJECT_SKIP=heartbeat is the default suppression; this run proves readiness
# outranks it.
env -u FM_STATE_OVERRIDE -u FM_DATA_OVERRIDE -u FM_CONFIG_OVERRIDE \
  FM_HOME="$LAB" FM_ROOT_OVERRIDE="$INERT" \
  FM_SUPERVISOR_BACKEND=tmux FM_SUPERVISOR_TARGET="$PANE" \
  FM_INJECT_SKIP=heartbeat FM_ESCALATE_BATCH_SECS=1 FM_HEARTBEAT=1 \
  FM_STALE_ESCALATE_SECS=999999 \
  timeout 20 "$ROOT/bin/fm-supervise-daemon.sh" > "$OUT/daemon-$MODE.stdout" 2>&1 &
DPID=$!
sleep 20
TMUX_TMPDIR="$TMDIR" tmux capture-pane -p -t primary > "$OUT/daemon-$MODE-pane.txt"
kill -TERM "$DPID" 2>/dev/null || true
wait "$DPID" 2>/dev/null
echo "daemon-exit=$?"

{
  echo "=== daemon mode=$MODE (lab home $LAB, private tmux socket, FM_INJECT_SKIP=heartbeat)"
  echo "--- daemon log ---"
  cat "$LAB/state/.supervise-daemon.log" 2>/dev/null
  echo "--- escalation buffer after run ---"
  cat "$LAB/state/.subsuper-escalations" 2>/dev/null
  echo "--- wake queue / heartbeat streak / triage ---"
  cat "$LAB/state/.wake-queue" 2>/dev/null
  echo "streak=$(cat "$LAB/state/.heartbeat-streak" 2>/dev/null || echo none)"
  tail -5 "$LAB/state/.triage-log" 2>/dev/null
  echo "--- watcher stderr ---"
  tail -20 "$LAB/state/.supervise-daemon.watcher.err" 2>/dev/null
  echo "--- supervisor pane capture ---"
  cat "$OUT/daemon-$MODE-pane.txt"
} > "$OUT/daemon-$MODE-transcript.txt"
cat "$OUT/daemon-$MODE-transcript.txt"
Evidence: Live driver script for the record-hygiene check wake

Source: Live driver script for the record-hygiene check wake

#!/usr/bin/env bash
# Drive the real watcher over a home that opts into record hygiene and holds an
# orphan status log, proving the upstream record-hygiene heartbeat block still
# surfaces its check wake after the rebase.
# Usage: drive-record-hygiene.sh <repo-root> <evidence-out-dir>
set -u
ROOT=$(cd "$1" && pwd)
OUT=$(cd "$2" && pwd)
D=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-hygiene.XXXXXX")
INERT=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-inert.XXXXXX")
trap 'rm -rf "$D" "$INERT"' EXIT
mkdir -p "$D"/{data,config,state}
cat > "$D/.tasks.toml" <<'TOML'
backend = "markdown"

[markdown]
path = "data/backlog.md"
archive = "data/done-archive.md"
done_keep = 10
TOML
printf '## In flight\n\n## Queued\n\n## Done\n' > "$D/data/backlog.md"
: > "$D/config/record-hygiene"
# A metadata record with no window line is a reportable hygiene finding and,
# unlike an orphan .status log, does not also trigger the signal wake path.
printf 'kind=ship\nbackend=tmux\npr=https://example.test/pull/1\n' > "$D/state/hygiene.meta"
printf 'kind=ship\nbackend=tmux\npr=https://example.test/pull/1\n' > "$D/state/hygiene2.meta"

PATH="$PATH" FM_HOME="$D" FM_STATE_OVERRIDE="$D/state" FM_CONFIG_OVERRIDE="$D/config" \
  FM_ROOT_OVERRIDE="$INERT" FM_POLL=0.2 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=1 \
  FM_RECORD_HYGIENE_TIMEOUT=30 \
  timeout 90 "$ROOT/bin/fm-watch.sh" > "$D/watch.stdout" 2>"$D/watch.stderr"
rc=$?
{
  echo "=== record-hygiene check wake (posture=attended, config/record-hygiene present)"
  echo "watcher-exit: $rc"
  echo "watcher-stdout: $(cat "$D/watch.stdout")"
  echo "wake-queue-rows: $(tr '\n' ';' < "$D/state/.wake-queue" 2>/dev/null)"
  echo "hygiene-last: $(cat "$D/state/.record-hygiene-last" 2>/dev/null)"
  echo "hygiene-meta-reportable: $([ -e "$D/state/orphan.status" ] && echo yes || echo no)"
  echo "watcher-stderr: $(tail -3 "$D/watch.stderr" 2>/dev/null | tr '\n' ';')"
} | tee "$OUT/record-hygiene-check.txt"

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.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
An attended primary with a ready queued unit surfaces an actionable heartbeat and resets the idle backoff ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case attended-ready): real bin/fm-watch.sh exits 0 printing heartbeat, .heartbeat-streak 3 -> 0, .wake-queue r…
An away primary with a ready queued unit gets the same actionable accounting instead of plain backoff ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-ready, state/.afk present): streak 3 -> 0 with the heartbeat wake queued and drained
An away heartbeat over a proven-empty queue keeps plain heartbeat accounting ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-empty): streak 3 -> 4, upstream heartbeat still emitted for the daemon; ~/.no-mistakes/evidence/01…
Unreadable queue readiness escalates as actionable instead of being absorbed as empty ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case away-unreadable with a failing tasks-axi): heartbeat wake queued and streak reset to 0
Held or not-ready queued work produces no dispatch wake and keeps plain idle accounting ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/heartbeat-scenarios.txt (case attended-held with a captain-held unit): no watcher output, empty .wake-queue, streak 3 -> 4
An away daemon escalates ready queued work to supervision even when heartbeat wakes are force-self suppressed ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/daemon-ready-transcript.txt: real bin/fm-supervise-daemon.sh with FM_INJECT_SKIP=heartbeat logs `escalate: heartbeat -> ready-queue fleet che…
The upstream record-hygiene heartbeat block still surfaces its check wake after the rebase ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/record-hygiene-check.txt: real watcher prints check: record hygiene: RECORD_HYGIENE: ... and queues the check row for a home with config/re…
The coverage guard passes at twelve portable serial shards and the lane contract refuses stale 11- and 13-shard names ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/shard-coverage.log (exit 0, serial_shards=12, serial_max_ms=1102468 < 1200000), shard-lanes.txt (1of12..12of12), shard-lane-acceptance.txt (1…
The shipped ready-queue suite still drives the watcher and real backlog consumer end to end ✅ pass live ~/.no-mistakes/evidence/01M7E2A6NWXS2SK62WW775T5H5/ready-queue-suite.log: bash tests/fm-watch-ready-queue.test.sh 20 cases, exit 0
  • bash tests/fm-watch-ready-queue.test.sh (20 cases, exit 0)
  • bash drive-ready-heartbeat.sh running the real bin/fm-watch.sh for attended-ready, away-ready, away-unreadable, away-empty, attended-held fixtures, reading .wake-queue, .heartbeat-streak, and bin/fm-wake-drain.sh delivery
  • bash drive-daemon-heartbeat.sh ready running the real bin/fm-supervise-daemon.sh with its watcher child on a private tmux socket and FM_INJECT_SKIP=heartbeat, reading the daemon log and escalation buffer
  • bash drive-daemon-heartbeat.sh empty (same daemon, proven-empty queue)
  • bash drive-record-hygiene.sh running bin/fm-watch.sh with config/record-hygiene and a reportable metadata finding
  • bin/fm-test-run.sh --check-coverage (exit 0, serial_shards=12, serial_max_ms=1102468 vs serial_budget_ms=1200000)
  • bin/fm-test-run.sh --list-lanes (portable-serial-1of12 .. 12of12)
  • bin/fm-test-run.sh --lane portable-serial-12of12 --list (exit 0, 27 scripts) and --lane portable-serial-11of11 / --lane portable-serial-13of13 (exit 2, refused)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new actionable defect was found.

Reviews (14) · Last reviewed commit: "no-mistakes(document): Correct heartbeat..." · Reviewed by Greptile

Comment thread bin/fm-wake-drain.sh Resolved
@kesslerio

Copy link
Copy Markdown
Contributor Author

Filed the design discussion as #6757 so this change has an issue-first trail; the reproduction and expected behavior live there.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks, @kesslerio. This is a careful change, and opening #6757 alongside it made the motivation easy to follow. I read the whole diff of head a5dffea3 against main 53b5bc11.

What I checked:

  • New bin/fm-ready-queue-lib.sh (fm_ready_queue_needs_review) runs fm-tasks-axi.sh ready with a 10 s timeout. It answers "needs review" when the ready count is non-zero, and also when readiness can't be read.
  • bin/fm-supervise-daemon.sh handle_wake now checks that before the FM_INJECT_SKIP force-self path. On a heartbeat with ready work it escalates ready-queue fleet check: … through the durable buffer and keeps the wake if the buffer write fails.
  • The attended always-on watcher in bin/fm-watch.sh now emits a heartbeat wake whenever fm_ready_queue_needs_review is true, instead of only under afk.
  • AGENTS.md section 10, bin/fm-branch-prompt.sh, the Pi branch processing instruction, fm-teardown's reminder and the scout/ship skills now require a same-turn ready-work dispatch or MAIN handoff.
  • bin/fm-wake-drain.sh now shows captain branch outcomes one line per outcome instead of collapsing them per task. That fixes Greptile's P1 about older requests disappearing, and the thread is resolved.
  • There are no workflow edits and no network calls. The new code reads only the backlog.

The no-mistakes attestation matches this head. CI is fully green, including "PR must be raised via no-mistakes", and the merge state is CLEAN.

Contract-class: new-default. On main an unconfigured home never wakes MAIN or escalates on a heartbeat just because queued work is ready. The daemon force-self-handles heartbeats and the attended watcher absorbs them. This PR adds a readiness-driven wake and escalation to both by default. It also changes the away contract in bin/fm-branch-prompt.sh: today a branch may fm-spawn only "work the words explicitly call for", and this tip lets it dispatch any already-queued unblocked unit while the captain is away (the away words then govern only new filing). That's a widened default, not the restore of a broken path, so it goes to Kun rather than auto-merging.

Things Kun will weigh (no action needed from you unless you want to address them):

  • Away scope: starting queued units the away words don't name is a wider away mandate. VISION says standing autonomy "never quietly widens".
  • Noise: the attended watcher wakes MAIN on every heartbeat while tasks-axi ready reports any unit, including one MAIN has deliberately left with a recorded not-ready reason or a spend-cap stop (the suppression is prompt-side only). It also wakes on every heartbeat when readiness can't be read, for example a home with a data/backlog.md but no compatible tasks-axi on PATH.
  • Contract size: about 7 new lines in the always-loaded AGENTS.md, which count toward the 9,000-word ceiling.

VISION.md, rule by rule

  • One captain, one interface: aligns on the motive (ready work no longer starves silently). Cannot tell on noise, because of the per-heartbeat MAIN wakes above.
  • Authority is explicit and never inferred: aligns for attended handoff. Does not align for the away-dispatch widening unless Kun grants it.
  • Scripts own the mechanics, agents own the judgment: aligns. Readiness is an exact script check, and the dispatch decision stays with an agent.
  • A restart is a non-event: aligns. Failed handoffs keep the durable wake, and older outcome lines are no longer collapsed away.
  • Delegation with a spine: aligns. Dispatch still goes through the guarded spawn, leases and spend cap.
  • The fleet outlives any vendor: aligns. It covers both the tmux daemon and the Pi branch/host paths.
  • Scope: aligns. Command layer only, no new task shape.

Next step: this is otherwise ready, so it now waits on Kun's merge-or-leave decision. That's on him, not on you. Related: #6757.

@kesslerio
kesslerio force-pushed the fm/fm-ready-queue-dispatch-r3 branch from a5dffea to 3eff668 Compare October 7, 2026 12:28
@kesslerio kesslerio changed the title fix: dispatch ready queued work during supervision checks fix: dispatch ready queued work during fleet supervision Oct 7, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the new round, @kesslerio. I re-reviewed head 3eff6688 against main ac0811c4. (The old head a5dffea3 was force-pushed away, so I read the five new commits plus the full diff against main.)

What changed, and it helps:

  • 1c7c056d closes the away-scope point I raised. bin/fm-branch-prompt.sh, AGENTS.md section 10 and the afk/away-quiet skills now say "While away, standing autonomy does not widen": the branch dispatches only queued work that the recorded away words name or that a standing grant covers. Every other ready unit waits for MAIN, with its reason recorded on the backlog note. test_emitted_away_scope_gate pins the emitted prompt.
  • e35b6527 and 3eff6688 stop the drain from ever truncating a captain outcome (one oversized oldest row prints in full), and truncated routine lines carry a per-seq fm-branch-outcome.sh lookup command. test_branch_outcomes_preserve_long_ready_work_handoff covers it.
  • a4e557e4 makes the branch persist and read back each new away stop before it acknowledges. It also adds an opt-in, out-of-CI dev evaluation (tests/development/ready-queue-away.sh, gated on FM_READY_QUEUE_AWAY_LIVE=1 and the caller's own Claude auth).
  • No workflow, network or secret changes. The no-mistakes attestation matches 3eff6688, and "PR must be raised via no-mistakes" passed.

Why this isn't otherwise ready right now (waiting on you):

  1. Merge conflict in AGENTS.md. feat(bin): defer spawns beyond a declared per-project capacity, opt-in #5343 (project capacity) just landed, and it rewrote the same section 10 sentence to "Re-evaluate queued work after every teardown and heartbeat, and also after a recorded PR-ready handoff when config/project-capacity caps that project, dispatching items only when dependencies, time gates, and project capacity have cleared." Please rebase through no-mistakes and keep both meanings: your ready-queue rules, plus the capacity-scoped PR-ready trigger and "project capacity has cleared" as a dispatch condition. That's a wording merge that Kun's decision depends on, so I'm not doing it for you.
  2. Behavior portable serial 2 is cancelled, not failing. I looked at the job log. Every test in the shard that ran passed, but tests/fm-supervision-host.test.sh alone took 1,737 s, then 1,667 s on my re-run, and the shard hit its 30-minute timeout-minutes both times. Main has the same problem: main's own CI at 47aff866 cancelled serial 2 the same way (that file took 1,665 s there), and recent main runs take 990–1,665 s for it. So it's a shard wall-clock budget issue shared with main, not a regression in your change. Your PR does add a test to that file, though. After the rebase, please check that serial 2 finishes. If it still times out, say so in the thread and Kun can weigh it against the main-side timeout.

Contract-class: new-default (no change). On main, an unconfigured home never wakes MAIN or escalates on a heartbeat just because queued work is ready. With this PR, both the daemon and the attended watcher wake on ready (or unreadable) readiness by default, and the attended handoff rules change. The away widening is now gone, which narrows what Kun has to decide, but the heartbeat wake class is still a new default-on surface.

VISION.md, rule by rule

  • One captain, one interface: aligns on the motive. Cannot tell on noise: the attended watcher still wakes MAIN on every heartbeat while tasks-axi ready reports any unit or can't be read, and the suppression of known stops is prompt-side.
  • Authority is explicit and never inferred: aligns now. Away dispatch is limited to the recorded words or a standing grant, so standing autonomy no longer quietly widens.
  • Scripts own the mechanics, agents own the judgment: aligns. Readiness is an exact script check, and the dispatch decision stays with an agent.
  • A restart is a non-event: aligns. Failed handoffs keep the wake, captain outcomes are never truncated, and stops are persisted and read back.
  • Delegation with a spine: aligns. Dispatch still goes through the guarded spawn, leases and the spend cap.
  • The fleet outlives any vendor: aligns. It covers the tmux daemon and the Pi branch and host paths. The dev evaluation is opt-in and outside CI.
  • Scope: aligns. Command layer only, with about 8 lines added to the always-loaded contract.

Next step: you, for the rebase (and a serial 2 that finishes). Once it's otherwise ready again, it goes back to Kun for merge-or-leave.

@kesslerio kesslerio changed the title fix: dispatch ready queued work during fleet supervision fix: dispatch ready queued work during supervision checks Oct 7, 2026
@kesslerio
kesslerio force-pushed the fm/fm-ready-queue-dispatch-r3 branch from b884daa to d09b0fe Compare October 8, 2026 22:02
@kesslerio kesslerio changed the title fix: dispatch ready queued work during supervision checks fix: dispatch ready queued work and preserve supervision handoffs Oct 8, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @kesslerio. The rebase kept both meanings in AGENTS.md section 10: the #5343 capacity-scoped PR-ready trigger and "project capacity has cleared" both stand next to your ready-work rules. Splitting fm-supervision-host.test.sh across two serial shards fixed the timeout. That split should also ease the same serial 2 timeout on main (#6790).

I re-read head d09b0fee against main 19fcbbde.

State: the attestation matches this head. CI is fully green: run 37850896719, including serial 2, plus "PR must be raised via no-mistakes". The merge state is CLEAN, and live validation is a go (10 of 10). There are no workflow, network, or secret changes.

Since 3eff6688: the away scope still holds ("While away, standing autonomy does not widen"). The drain now prints captain outcomes one per line and never truncates them. Teardown's reminder now points at the ready-work check. fm_ready_queue_needs_review now stays quiet for a markdown-backend home with no data/backlog.md.

Contract-class: new-default (unchanged). On main, an unconfigured home never wakes MAIN or escalates on a heartbeat just because queued work is ready. With this PR, the daemon and the attended watcher both wake when ready work exists or readiness can't be read. That's a new default-on wake class, so it doesn't auto-merge.

What Kun is weighing (nothing needed from you):

  • Noise: the attended watcher emits a heartbeat wake every cycle while tasks-axi ready reports any unit, or while readiness can't be read (a timeout or a broken tasks-axi). Suppressing a recorded stop happens in the prompt, not in the script.
  • Contract size: about 9 added lines in the always-loaded AGENTS.md. Repo invariants still pass.

VISION.md, rule by rule

  • One captain, one interface: aligns on the motive (ready work stops falling through the cracks). Cannot tell on noise, per the first point above.
  • Authority is explicit and never inferred: aligns. Away dispatch is limited to the recorded words or a standing grant, and quiet mode keeps the spawn refusal.
  • Scripts own the mechanics, agents own the judgment: aligns. Readiness is an exact script check, and the dispatch decision stays with an agent.
  • A restart is a non-event: aligns. Failed handoffs keep the wake, captain outcomes are never truncated, and away stops are persisted and read back.
  • Delegation with a spine: aligns. Dispatch still goes through the guarded spawn, leases, project capacity, and the spend cap.
  • The fleet outlives any vendor: aligns. It covers the tmux daemon, the Pi branch, and the host paths.
  • Scope: aligns. Command layer only.

Next step: this is now with Kun for a merge-or-leave decision. It isn't waiting on you. Please hold the head where it is, since a new push would restart the review.

@kesslerio

kesslerio commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@kunchenguid, field data on the open noise question, in case it helps the merge-or-leave call.

Over the night of 2026-10-09 to 10-10, a secondmate home on this host kept its watcher alive the whole night. That watcher logged "absorbed heartbeat (no captain-relevant change)" at 03:16, 05:16 and 07:16, and its interval backed off toward the cap, while its backlog held ready units. One of them, a fix that had been ready since 22:58, was first dispatched at 07:32. The previous three nights show the same shape: quiet logs of 7 to 10 hours with ready work queued. That is the case this PR's fm_ready_queue_needs_review heartbeat condition covers.

(The root home's own gap that night had a different cause: its supervising session was stopped by the host app, so no watcher-side change would have helped there. That is tracked separately.)

To measure the noise side, this branch is now running locally on that host at head d09b0fee. A follow-up here will report wakes per hour attributable to the ready-queue condition, and whether the always-on wake causes extra churn.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @kesslerio for the field data — the overnight secondmate log (heartbeats absorbed at 03:16/05:16/07:16 while a unit ready since 22:58 waited until 07:32) is a concrete instance of the gap fm_ready_queue_needs_review covers, and the noise measurement you're running at d09b0fee is exactly the other half of the question. Please post it here when you have it.

Delta since my 2026-10-09 stamp: no new push; head is still d09b0fee, CI and "PR must be raised via no-mistakes" are still green, and it is still CLEAN against main 4735ddc6. Contract-class stays new-default (default-on ready-queue heartbeat wake class), so it does not auto-merge.

This remains with Kun for a merge-or-leave decision, not waiting on you. One new note for that call: #7031 splits tests/fm-supervision-host.test.sh into six suites, overlapping this PR's -late split, so whichever lands first means the other needs a rebase.

@tiago-peixoto

Copy link
Copy Markdown
Contributor

@kesslerio, two things that may help the merge-or-leave call: a noise measurement and a conflict resolution.

Noise. I ran the watcher on a disposable home with 12 queued items, including items that only follow an external thread and carry no hold.
After the two actionable items left the ready queue, those follow-up items still caused a wake at every due heartbeat.
A written stop note in the task did not suppress them.
A structured hold or an unresolved blocked-by dependency did.
Unreadable readiness also produced a wake, at the capped heartbeat.

The existing backoff still applies: 10, 20, 40, 80, then 120 minutes between heartbeats.
That is two wakes in the first hour, settling at 0.5 per hour when no other event resets the backoff.
I measured this by aging timestamps against the real 600-second base and 7,200-second cap, not through an overnight production run.

Conflict. I made an unpublished merge of current main into this branch, without rebasing and without touching your remote branch.
Four files conflicted: bin/fm-branch-prompt.sh, bin/fm-supervise-daemon.sh, docs/configuration.md, and docs/pi-supervision-branch.md.
The resolution keeps both sides, including main's scout-cleanup wording, the away-mode pipeline-waiver restriction, and both the decision and dialog_name initializers in the daemon.
On that merge, tests/fm-watch-ready-queue.test.sh, tests/fm-branch-supervision.test.sh, tests/fm-teardown.test.sh, tests/fm-watch-triage.test.sh, and both supervision-host groups passed locally, along with lint and the docs checks.
This is local evidence, not hosted checks or a no-mistakes attestation.
#7031 is still unmerged, so the merge keeps your original and -late test groups.
I can share the resolution as a patch if it saves you time.

@kesslerio
kesslerio force-pushed the fm/fm-ready-queue-dispatch-r3 branch from d09b0fe to 26d178e Compare October 21, 2026 12:37
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio for bringing this current with main, and @tiago-peixoto for the noise measurement (two wakes in the first hour, settling at 0.5/hour under the existing backoff, with follow-up-only items still waking until they carry a structured hold). That's useful for Kun's call.

Delta since my 2026-10-11 stamp (d09b0fee, waiting-captain): a new head 26d178e4, rebased onto main 2c93247f (0 behind, MERGEABLE), with the supervision-host split carried forward and new fixture, lint and doc commits. The ready-queue core is the same shape: fm_ready_queue_needs_review still drives both the daemon escalation and the attended watcher's afk_present || fm_ready_queue_needs_review heartbeat wake. The behavior CI suites are all green.

What's blocking right now (waiting on you): "PR must be raised via no-mistakes" fails, because the attestation in the body still binds d09b0fee, not 26d178e4. Could you re-raise this head through git push no-mistakes so the attestation (and live validation) binds the current head? If no-mistakes refuses with a diverged published lane, that's the no-mistakes #1399 / #1346 recovery path. Please note it here, and leave both histories intact.

Contract-class: new-default (unchanged). This is a default-on, readiness-driven heartbeat wake class in both the daemon and the attended watcher.

VISION.md: one captain aligns on motive, cannot tell on noise (it is now measured, see above) · authority aligns (away dispatch limited to recorded words or a standing grant) · scripts aligns · restart aligns · spine aligns · vendor aligns · scope aligns.

Next step: once the attestation binds the head and CI stays green, this goes back to Kun as the standing merge-or-leave decision. Nothing else is needed from you.

@kesslerio kesslerio changed the title fix: dispatch ready queued work and preserve supervision handoffs feat(supervision): dispatch and preserve ready-work handoffs Oct 21, 2026
@WTF-Am-ID

Copy link
Copy Markdown
Contributor

More field data on the noise question, from an attended Claude primary with the supervision host on. It adds two things to the wake-rate measurement above: what the missing ready-work trigger costs today, and how large each handoff would be on a home with a big backlog.

Setup. One product-repository home on Claude Code 2.1.29x to 2.1.303, supervision host on by default, herdr backend, macOS, firstmate main as of 4c292efd (2026-10-22). Window 2026-10-02 to 2026-10-23: 820 dispatches and 819 cleanups in state/fleet-ledger.jsonl, 7.5 live tasks on average, 23 at peak. Everything below comes from the fleet ledger, state/branch-outcomes.jsonl and the primary's transcripts. No live experiment.

The gap:

  • There were 25 gaps of 3 hours or more between dispatches, 250 hours in total. 18 ended in a turn the captain started and 4 in a wake turn. Inside several of them the primary handled 40 to 48 wake turns and dispatched nothing.
  • The captain asked whether the fleet was at full parallelism 32 times. 21 of those turns started 64 workers within ten minutes. Seven answers opened by conceding it was not, for example "not until now" and "only 4 workers were active".
  • With the host on, heartbeat reviews run in the engine, which cannot start new work while attended (fm_lease_forbid_branch "new-task spawn (fm-spawn)"), and its routine outcomes open no main turn. None of the 180 heartbeat outcomes in the store reported a dispatchable backlog item.

The noise side:

  • The primary already handles about 6.4 wake turns per hour on this home, and 34% of them take no action. The backoff measured earlier in this thread (settling at 0.5 per hour) would add about 8% on top.
  • Handoff size is the bigger risk. tasks-axi ready (0.2.6) reports 405 ready units in this home's backlog and 33 in a second home. Most are recorded follow-up findings with no hold and no blocked-by. The branch rule here names every ready unit in one captain outcome, and the drain no longer truncates captain outcomes. So each due heartbeat would carry about 405 rows into the primary's context, and repeat until each row gets a worker or a recorded not-ready reason.

Two changes would keep the default-on wake cheap for homes like this:

  1. Bound each handoff to free capacity: at most free_lanes units from bin/fm-capacity.sh when config/lane-capacity exists, otherwise a small fixed number, ordered by priority then age, plus a count of the rest.
  2. Suppress repeats only on structured fields (an active hold, --until, or an unresolved blocked-by), which matches the earlier test in this thread. Document a one-time step that holds record-only rows before the default turns on.

Related: #6757, #7204, #7050, #4466.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @kesslerio for re-raising. And thanks @WTF-Am-ID for the field data, which helps on both sides of the call.

Delta since my 10-21 stamp: head 9011246b now has a no-mistakes attestation that matches it, with live validation 5 of 5 go after the teardown fixture fix. The full CI run on that head is green (run 39618543014). So the stale-attestation block from last time is cleared.

What's blocking now (waiting on you): main has moved, and the branch now conflicts (33 behind) in bin/fm-test-run.sh, docs/architecture.md, docs/fm-test-portable-shards.md and tests/fm-supervision-host.test.sh. Could you rebase onto current main and re-raise through git push no-mistakes, so the attestation binds the new head again?

Worth considering while you're in there (not a requirement from me): @WTF-Am-ID's numbers show a home with 405 ready units. Each due heartbeat would carry all of them into the primary's context. Bounding each handoff to free lanes (or a small fixed number, ordered by priority then age, plus a count of the rest) would keep a default-on wake cheap on big backlogs. That would make the merge-or-leave call easier.

Contract-class: new-default (unchanged). It adds a default-on, readiness-driven heartbeat wake in both the daemon and the attended watcher. VISION: one captain aligns on motive, cannot tell on noise/handoff size · authority aligns · scripts aligns · restart aligns · spine aligns · vendor aligns · scope aligns.

Next step: once it's rebased, re-attested and green, this goes back to Kun as a merge-or-leave decision.

@kesslerio
kesslerio force-pushed the fm/fm-ready-queue-dispatch-r3 branch from 9011246 to 17dbc56 Compare October 30, 2026 21:18
@kesslerio kesslerio changed the title feat(supervision): dispatch and preserve ready-work handoffs feat: dispatch ready queued work during supervision Oct 30, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @kesslerio for the new round on head 17dbc562. It includes the fix that keeps captain handoffs complete (the earlier Greptile P1) and the restriction of away dispatch to work the recorded words name. The no-mistakes attestation binds this head with every step completed, and the quick checks pass.

A correction first: my 10-23 note asked you to rebase. Please ignore that. Merge conflicts are ours to fix, and we never ask contributors to rebase.

One thing needed from you: live evidence. The attestation's live validation is inconclusive, 0 of 7, and every scenario is untested against the product. That includes the two that matter most: ready queued work reaching dispatch or a durable handoff under attended supervision, and away supervision staying inside the recorded authorization. Could you drive those on a real home, or re-raise with live validation allowed, and post the transcripts? If @WTF-Am-ID's handoff-size point from 10-23 applies to your design, a line on how a big backlog's handoff stays bounded would help too.

contract-class: new-default, unchanged. This changes what heartbeat supervision does with ready queued work by default, so once the evidence is in and the full suite is green, it goes to Kun for a merge-or-leave decision. VISION: unchanged from my earlier stamps.

Waiting on you, no rush.

@kesslerio

Copy link
Copy Markdown
Contributor Author

Live evidence for head 17dbc562, driven in a disposable live lab home.

How it was driven

bin/fm-live-lab.sh up --harness claude --mate on the exact head:

tree: 17dbc5622ef7770ab48b8e4ca69dc76c8bc1689b
ok primary: claude pid 2503488 in /tmp/opencode/lab-6753/home
ok probe: the primary answered LABREADY-7d9d7989c892
ok host: supervision host pid 2526300
ok watcher: live watcher with a fresh beacon
ok mate: lab7d9d7989c892-mate pid 2498826
ready: /tmp/opencode/lab-6753

A real Claude primary (sonnet, medium effort, auto mode), a real seeded second mate, and a real supervision host — no fixtures, no fake provider, no synthetic dispatch.

Scenario: "A daemon heartbeat with ready queued work reaches dispatch or durable handoff before suppression or acknowledgement." — PASS, live

Created one genuinely ready unit (no dependency, no hold, no time gate):

tasks-axi add lab-ready-probe "Live lab ready-work dispatch probe" --kind scout --queue --json
{"ok":true,"action":"add","task":{"id":"lab-ready-probe","state":"queued","deps":[],"hold":null,"blocked":false,"held":false}}

The live primary was then asked to re-evaluate queued work per AGENTS.md section 10. It loaded harness-adapters, read references/common/dispatch.md, scaffolded the brief through fm-brief.sh, and launched a worker:

scaffolded: data/lab-ready-probe/brief.md (scout)
spawned lab-ready-probe harness=claude kind=scout window=firstmate:fm-lab-ready-probe worktree=.../home-ecd36d/1/home
DISPATCHED lab-ready-probe

The backlog moved Queued → In flight → Done on its own, carrying the report path:

## Done
- [x] lab-ready-probe - Live lab ready-work dispatch probe data/lab-ready-probe/report.md (repo: firstmate) (kind: scout) (reported 2026-10-30)

The dispatched worker's own report:

What I did: the probe worker launched, read its launch brief from the operational inbox message state/operational-inbox/1793416233-b69b4831596717df.msg, and checked the steering inbox state/lab-ready-probe.inbox (no *.msg records present).
Finding: queued ready work (no dependency, no hold, no time gate) was dispatched; this worker received and read its brief at epoch 1793416244.

So the ready unit reached real dispatch, not just a handoff, with the transition gate satisfied rather than reported over.

Scenario: "Empty, held, or unreadable queued work does not silently lose readiness or create an unnecessary dispatch wake." — PASS, live

The heartbeat's own readiness predicate, in both directions against live backlog state:

Backlog state fm_ready_queue_needs_review Meaning
ready, unblocked, unheld rc=0 needs review — wake owed
held for the captain rc=1 no unnecessary dispatch wake
released again rc=0 readiness returns, not lost

The held row kept the wake suppressed and the release restored it, so neither a held unit produced a spurious wake nor did the hold silently swallow readiness.

Not established by this run

I want to be exact about the remaining gaps rather than overclaim again.

  • Scenario 4, away supervision inside recorded authorization: not tested. The lab ran attended; I did not drive an away posture, and I would rather leave it untested than call it proven.
  • Scenario 5, repeated unprocessed outcomes staying visible: not tested. One outcome was produced and consumed.
  • Scenario 1, landed dependency visibility without new status events: partially exercised. The unit was created already ready; I did not land a dependency and watch it become visible.
  • Scenario 7, late supervision-host lifecycle group: not run. tests/fm-supervision-host-late.test.sh is absent at this head, as noted earlier.

That is 2 of 7 driven fully live and 1 partially, which beats the previous 0 of 7. The lab is torn down; nothing was pushed and no project was modified.

…it empty backlogs and corrected the shared ShellCheck source boundary causing both lint failures. Verified portable serial shard 1 (141 cases), 17 ready-queue cases, default lint, source-aware lint for all reported roots, and git diff --check. All passed
The away dispatch instruction told the branch to reopen a unit whose spawn
succeeded but whose startup it could not confirm. That leaves a queued row
paired with a live worker record, and bin/fm-bootstrap.sh heals exactly that
pair back to In flight as work this home already owns a worker for. A worker
stuck at a trust prompt therefore left the queue without a confirmed starter
and without a retry path.

Keep the unit In flight, keep its endpoint and record, record the startup stop
and retry condition on its note and outcome, and retry by inspecting or
relaunching that same endpoint. tests/fm-watch-ready-queue.test.sh pins the
emitted instruction and that the reopen guidance is gone.
…riage. The branch `afk_present || fm_ready_queue_needs_review` called `wake "heartbeat"`, so wake() treated it as a plain heartbeat and incremented `.heartbeat-streak`, doubling the interval up to FM_HEARTBEAT_MAX while ready queued work sat unreviewed. The invariant is that any heartbeat surfaced for actionable fleet work (ready/unknown backlog readiness) must reset idle backoff, while a heartbeat that exists only because the away daemon is present keeps plain heartbeat accounting. I split the branch to preserve the original afk short-circuit: an afk-only heartbeat still calls `wake "heartbeat"` (away daemon owns triage; `tests/fm-watch-triage.test.sh:test_afk_heartbeat_preserves_idle_accounting` requires 3 -> 4), while a ready-queue review now calls `wake "heartbeat" actionable`, matching the status backstop below it. No other watcher call site evaluates ready-queue readiness (the away daemon has its own path and was unchanged). Added a regression assertion to test_ready_heartbeat: seed `.heartbeat-streak=3` with an aged `.last-heartbeat`, then assert the ready-queue heartbeat leaves it at 0 (fails before the fix with 4, passes after, for both ready and unreadable queues). Verification: `timeout 300 bash tests/fm-watch-ready-queue.test.sh` all 18 cases pass (including the two ready-queue heartbeat cases exercising the new assertion); the fix was reverted temporarily to confirm the new assertion fails on the pre-fix code; the four heartbeat/afk triage cases run as a bounded subset pass, confirming absorb-increment, actionable-backstop reset, and unchanged afk accounting. Shellcheck reports only pre-existing informational findings on these files
…al defect: the merged tree's portable serial lane packs the largest shard at 1202675ms against the 1200000ms modeled budget. The lane partition is already near-optimal LPT (total weight / shard count), so no rebalance can recover headroom; the invariant is that the largest packed serial shard must stay within 1200000ms at the merge head. Fixed at the owning boundary: bin/fm-test-run.sh PORTABLE_SERIAL_SHARDS 11 -> 12, .github/workflows/ci.yml matrix [1..12] (lane names and job-total stay consistent), and docs/fm-test-portable-shards.md count/provenance lines updated (twelve serial shards, seventeen long-lived Linux jobs). No other of11 references exist; tests derive the count from the runner and CI matrix dynamically. Verification: bin/fm-test-run.sh --check-coverage exits 0 with serial_max_ms=1095694 (simulating main's three added serial members gives ~1106953), --list-lanes exposes exactly 12 shard lanes, and 11/13-shard lane names are refused (exit 2). The focused runner-contract functions for shard partition, coverage guard, hint bounds, exact-budget boundary, and lane refusals all pass; tests/fm-watch-ready-queue.test.sh also passes (18 cases, exit 0). tests/fm-ci-workflow.test.sh could not run here because ruby is absent (it exits with 'ruby is required'); it will run in CI, where the matrix/runner consistency check derives the count. (2) Full suite failed at its first step with FM_CI_FULL=false, the by-design gate requiring a maintainer to add the full-ci label on an outside PR; its FM_CI_LANES_FAILED=true was a consequence of the coverage-guard failure. That check is external to the code (label/attestation gate), so no code change was made for it; once the coverage guard passes, it still needs the maintainer label. code_change_needed is true for the coverage-guard fix
@kesslerio
kesslerio force-pushed the fm/fm-ready-queue-dispatch-r3 branch from 72c20c8 to c967130 Compare November 14, 2026 22:36
@kesslerio kesslerio changed the title fix(bin): surface ready queued work as an actionable heartbeat and hand it to an actor that can dispatch fix(bin): surface ready queued work instead of absorbing heartbeats Nov 14, 2026
@m-moravcik

Copy link
Copy Markdown
Contributor

Another data point from a self-hosted fleet running a fork of firstmate: one project home had 171 backlog items that tasks-axi ready reports as ready, while only 2 of its 19 lanes were working. Heartbeats kept arriving and nothing was dispatched until a human nudged the primary. This matches the absorbed-heartbeat path this PR fixes, and we would adopt it as soon as it lands. Happy to run this branch on our hosts and report back if that helps the decision.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @kesslerio, and thanks @m-moravcik for the second field data point (171 ready items, 2 of 19 lanes working).

Head is now c9671301 (rebuilt Nov 14, with new commits since the 1827d049 I stamped, including keeping an unconfirmed start off the queue-drop path), and it conflicts with main in .github/workflows/ci.yml, bin/fm-test-run.sh, docs/fm-test-portable-shards.md and tests/fm-watch-triage.test.sh.

Nothing is needed from you. This stays with Kun for a decision. The PR edits .github/workflows/ci.yml (the serial shard matrix), so triage does not add full-ci or merge it, and the conflict is ours to resolve after Kun's merge word. Contract class: new-default, unchanged (a default-on, readiness-driven heartbeat wake). The attestation binds c9671301. I have not re-reviewed the new commits line by line this pass, because nothing changes the route; that read happens if Kun gives the word.

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.

5 participants