Skip to content

fix(bin): make every counted wake queue row presentable or retired - #3950

Merged
kunchenguid merged 5 commits into
kunchenguid:mainfrom
cisrd:fm/fm-wake-drain-counted-row-invariant
Sep 7, 2026
Merged

kunchenguid merged 5 commits into
kunchenguid:mainfrom
cisrd:fm/fm-wake-drain-counted-row-invariant

Conversation

@cisrd

@cisrd cisrd commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

A wake row that is counted as queued but not presented by bin/fm-wake-drain.sh can never be acknowledged, permanently wedging the queue and repeatedly waking supervision.

This was measured on 2026-09-07 in the fmverif second-mate home.
bin/fm-wake-drain.sh printed only WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else. with no presented row and no WAKE_ACK_REQUIRED command.
The queue itself still contained this row:
1788792074<TAB>574<TAB>stale<TAB>fleet:w2:p3<TAB>stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds).

Determine why this counted row is omitted from presentation and make the invariant true: every row counted in the pending-warning condition must either be presented with an executable acknowledgement path or be retired from the queue.
Do not assume the proposed cause; verify whether stale-row type, stopped endpoint, changed recovery generation, supervision-branch ownership, or another filter explains the divergence.
This is distinct from the existing monitoring defects that generate stale rows too often or escalate a declared external wait; this task owns the drain behavior after a row already exists.

What Changed

  • bin/fm-guard.sh now counts queued wakes per actor via a new fm_wake_actor_pending_count helper in bin/fm-wake-lib.sh, so the "queued wakes pending - drain them" warning only fires for rows the calling actor can actually present or retire; a non-empty queue whose rows are reserved by a live supervision-branch grant instead raises a distinct NOTICE naming the branch as holder and saying not to drain from there.
  • bin/fm-wake-drain.sh retires rows that can never be consumed: under the queue lock, a main drain drops rows missing the five appended fields or a numeric sequence, reports the count plus the removed rows verbatim (first 20, then a remainder count), and treats a failed repair as non-fatal so usable rows are still presented; a branch drain never retires. A main drain left with nothing of its own also prints a bounded WAKE ROWS HELD BY SUPERVISION BRANCH line with the held sequences instead of exiting silently.
  • Grant row-list validation and branch owner-record reads were deduplicated out of bin/fm-wake-drain.sh and bin/fm-wake-grant.sh into shared fm_wake_grant_rows_valid / fm_wake_branch_owner_matches / fm_wake_branch_grant_live helpers; tests/fm-wake-queue.test.sh adds two cases driving guard and drain together (branch-held row raises the advisory and becomes presentable and acknowledgeable once the grant clears; unusable rows are retired by main alone while remaining rows stay acknowledgeable), and docs/architecture.md and docs/watcher-continuity.md record the per-actor counting and retirement contract.

Risk Assessment

✅ Low: The change is well-bounded and lock-protected: the riskiest element (irreversible row retirement) is main-only, runs under the queue lock, reports what it removed, and never fails the drain, while the guard narrowing provably cannot silence a non-empty queue since main's and the branch's counted sets partition every queued row — and both behaviors are pinned by new tests that drive the real scripts.

Testing

Exercised the wake-queue, guard-stale-banner, branch-supervision and pi-branch-extension suites (all passing), proved both new tests fail on the base commit and pass on the target, and captured a before/after CLI transcript that replays the reported fmverif field row end-to-end: pre-fix the guard tells the operator to drain while the drain presents nothing and the queue stays wedged; post-fix the branch-held row raises a distinct "do not drain them from here" advisory with the drain naming the holder, and once the grant is released the same row is presented with an executable --ack-through command that empties the queue, while a structurally truncated row is retired with its content reported verbatim. This change has no UI surface — it is entirely stdout/stderr from shell CLIs — so the reviewer-visible evidence is the operator-facing terminal transcript rather than a screenshot.

Evidence: End-to-end CLI transcript: reported field state, before vs after the fix

Source: End-to-end CLI transcript: reported field state, before vs after the fix

Wake-queue counted-row invariant: end-to-end CLI transcript
===========================================================

Reproduction driven through the real CLIs (bin/fm-guard.sh, bin/fm-wake-drain.sh,
bin/fm-wake-grant.sh) against two trees: the base commit and the target commit.
Scenario A replays the reported fmverif field state verbatim: a single stale
fleet:w2:p3 row queued while a live supervision-branch grant holds it.
Scenario B queues a structurally truncated row alongside a usable one.

INVARIANT: any row counted in the pending-warning condition must be presented
with an executable acknowledgement path (or be retired from the queue).

######################################################################
# BEFORE the fix (base commit ffd2c899 - the reported field behavior)
# tree: /tmp/fm-e2e/base
######################################################################

===== A. the reported field state: one stale row queued, held by a LIVE supervision-branch grant =====

state/.wake-queue (verbatim):
    1788814215	1	stale	fleet:w2:p3	stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
    (live branch grant published for sequence 1)

$ bin/fm-guard.sh   # what the operator is told on every guarded command
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  After draining queued wakes, watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh   # what the operator gets when they follow that instruction
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

    queue holds 1 row(s)
    guard counts a row as drainable-by-main (ordinary warning): yes
    drain presents a row with an executable ack command:        no
    INVARIANT VIOLATED: counted but unpresentable -> queue is wedged

===== A2. same row, same kind, same endpoint - grant released (nothing else changed) =====

$ bin/fm-guard.sh
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh
    1788814215	1	stale	fleet:w2:p3	stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
    WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3035104.1788814215.FVhL35
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3035104.1788814215.FVhL35
    queue after acknowledgement: 0 row(s)

===== B. a structurally unusable row (lost its trailing fields) queued alongside a usable one =====

state/.wake-queue (verbatim):
    1788814217<TAB>1<TAB>signal<TAB>task-a.status<TAB>signal: task-a
    1788792074<TAB>574<TAB>stale<TAB>fleet:w2:p3

$ bin/fm-guard.sh
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  After draining queued wakes, watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh
    1788814217	1	signal	task-a.status	signal: task-a
    WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3038985.1788814217.mbYZB2
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

    queue now holds 2 row(s):
      1788814217<TAB>1<TAB>signal<TAB>task-a.status<TAB>signal: task-a
      1788792074<TAB>574<TAB>stale<TAB>fleet:w2:p3

$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3038985.1788814217.mbYZB2
    queue after acknowledgement: 1 row(s)

$ bin/fm-guard.sh   # is the queue finally quiet?
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

    queue holds 1 row(s)
    guard counts a row as drainable-by-main (ordinary warning): yes
    drain presents a row with an executable ack command:        no
    INVARIANT VIOLATED: counted but unpresentable -> queue is wedged


######################################################################
# AFTER the fix (target commit 0227b23)
# tree: ~/.no-mistakes/worktrees/a03e7f5d4084/01M1YQBCAYD7E9ZWHV14G6B5ZK
######################################################################

===== A. the reported field state: one stale row queued, held by a LIVE supervision-branch grant =====

state/.wake-queue (verbatim):
    1788814219	1	stale	fleet:w2:p3	stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
    (live branch grant published for sequence 1)

$ bin/fm-guard.sh   # what the operator is told on every guarded command
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    NOTICE: wake rows held by the live supervision branch - it presents and acknowledges them; do not drain them from here.

$ bin/fm-wake-drain.sh   # what the operator gets when they follow that instruction
    WAKE ROWS HELD BY SUPERVISION BRANCH: 1 queued row(s) (1) are granted to the live supervision branch, which presents and acknowledges them.
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    NOTICE: wake rows held by the live supervision branch - it presents and acknowledges them; do not drain them from here.

    queue holds 1 row(s)
    guard counts a row as drainable-by-main (ordinary warning): no
    drain presents a row with an executable ack command:        no
    INVARIANT HOLDS

===== A2. same row, same kind, same endpoint - grant released (nothing else changed) =====

$ bin/fm-guard.sh
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh
    1788814219	1	stale	fleet:w2:p3	stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
    WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3041492.1788814219.nAZMDp
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3041492.1788814219.nAZMDp
    queue after acknowledgement: 0 row(s)

===== B. a structurally unusable row (lost its trailing fields) queued alongside a usable one =====

state/.wake-queue (verbatim):
    1788814221<TAB>1<TAB>signal<TAB>task-a.status<TAB>signal: task-a
    1788792074<TAB>574<TAB>stale<TAB>fleet:w2:p3

$ bin/fm-guard.sh
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ●  WATCHER DOWN - SUPERVISION IS OFF
    ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
    ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
    ●  This is a supervision warning only; the guarded operation WILL still run.
    ●  After draining queued wakes, watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
    ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

$ bin/fm-wake-drain.sh
    wake drain: retired 1 unusable queue row(s) that carried no sequence to present or acknowledge:
    wake drain:   1788792074	574	stale	fleet:w2:p3
    1788814221	1	signal	task-a.status	signal: task-a
    WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3044355.1788814221.7RuLMS
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
    WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.

    queue now holds 1 row(s):
      1788814221<TAB>1<TAB>signal<TAB>task-a.status<TAB>signal: task-a

$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3044355.1788814221.7RuLMS
    queue after acknowledgement: 0 row(s)

$ bin/fm-guard.sh   # is the queue finally quiet?
    WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.

    queue holds 0 row(s)
    guard counts a row as drainable-by-main (ordinary warning): no
    drain presents a row with an executable ack command:        no
    INVARIANT HOLDS
Evidence: Regression proof: new tests fail on base commit, pass on target commit

Source: Regression proof: new tests fail on base commit, pass on target commit

Regression proof: the two new tests fail on the base commit and pass on the target commit
=======================================================================================

The new tests were extracted verbatim from tests/fm-wake-queue.test.sh and run against
a clean export of the base commit (ffd2c899) so only the registration list differs.

--- BASE ffd2c899: test_main_is_never_told_to_drain_rows_only_the_branch_owns ---
ok - historical annotations replay nothing already announced and keep everything new
not ok - main drain went silent instead of naming who holds the queued rows
--- BASE ffd2c899: test_unconsumable_rows_are_retired_instead_of_wedging_the_queue ---
ok - historical annotations replay nothing already announced and keep everything new
not ok - main drain did not report the rows it retired

--- TARGET 0227b23: bash tests/fm-wake-queue.test.sh (full suite) ---
ok - a branch-held row raises no queued-wake warning for main, and the same row is presented and acknowledged once the grant clears
ok - structurally unusable rows are retired by main alone, leaving every remaining row presentable and acknowledgeable
suite exit code: 0
Evidence: Reproduction script used to generate the transcript (runnable against any tree)

Source: Reproduction script used to generate the transcript (runnable against any tree)

#!/usr/bin/env bash
# End-to-end reproduction of the reported field defect, driven through the real
# CLIs (bin/fm-guard.sh, bin/fm-wake-drain.sh, bin/fm-wake-grant.sh) of the tree
# passed as $1. Prints an operator-visible transcript.
set -u
TREE=$1
LABEL=$2
. "$TREE/tests/wake-helpers.sh"
TMP_ROOT=$(fm_test_tmproot fm-e2e-repro)
DRAIN="$ROOT/bin/fm-wake-drain.sh"
GRANT="$ROOT/bin/fm-wake-grant.sh"
GUARD="$ROOT/bin/fm-guard.sh"

PAYLOAD='stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)'

hr() { printf '\n===== %s =====\n' "$1"; }
run() { # <label> <cmd...>
  local label=$1; shift
  printf '\n$ %s\n' "$label"
  "$@" 2>&1 | sed 's/^/    /'
  return 0
}

printf '######################################################################\n'
printf '# %s\n' "$LABEL"
printf '# tree: %s\n' "$ROOT"
printf '######################################################################\n'

# ---------------------------------------------------------------- scenario A
dir=$(make_case field-repro); state="$dir/state"
printf 'window=test:fm-w2\nkind=ship\n' > "$state/x.meta"
FM_STATE_OVERRIDE="$state" bash -c '. "$1"; fm_wake_append stale "fleet:w2:p3" "$2"' _ "$ROOT/bin/fm-wake-lib.sh" "$PAYLOAD"

hr "A. the reported field state: one stale row queued, held by a LIVE supervision-branch grant"
printf '\nstate/.wake-queue (verbatim):\n'
sed 's/^/    /' "$state/.wake-queue"
FM_STATE_OVERRIDE="$state" "$GRANT" activate "$$" gen-live >/dev/null || { echo "GRANT ACTIVATE FAILED"; exit 1; }
seq0=$(awk -F '\t' 'END{print $2}' "$state/.wake-queue")
FM_STATE_OVERRIDE="$state" "$GRANT" publish gen-live "$seq0" >/dev/null || { echo "GRANT PUBLISH FAILED"; exit 1; }
printf '    (live branch grant published for sequence %s)\n' "$seq0"

run 'bin/fm-guard.sh   # what the operator is told on every guarded command' \
  env FM_STATE_OVERRIDE="$state" "$GUARD"
run 'bin/fm-wake-drain.sh   # what the operator gets when they follow that instruction' \
  env FM_STATE_OVERRIDE="$state" "$DRAIN"
invariant() { # <state> - INVARIANT: a row counted in the pending-warning condition
                # must be presented with an executable acknowledgement path.
  local st=$1 g d counted presented
  g=$(FM_STATE_OVERRIDE="$st" "$GUARD" 2>&1); d=$(FM_STATE_OVERRIDE="$st" "$DRAIN" 2>&1)
  case "$g" in *"queued wakes pending"*) counted=yes ;; *) counted=no ;; esac
  case "$d" in *WAKE_ACK_REQUIRED*) presented=yes ;; *) presented=no ;; esac
  printf '\n    queue holds %s row(s)\n' "$(awk 'END{print NR+0}' "$st/.wake-queue" 2>/dev/null || echo 0)"
  printf '    guard counts a row as drainable-by-main (ordinary warning): %s\n' "$counted"
  printf '    drain presents a row with an executable ack command:        %s\n' "$presented"
  if [ "$counted" = yes ] && [ "$presented" = no ]; then
    printf '    INVARIANT VIOLATED: counted but unpresentable -> queue is wedged\n'
  else
    printf '    INVARIANT HOLDS\n'
  fi
}
invariant "$state"

hr "A2. same row, same kind, same endpoint - grant released (nothing else changed)"
FM_STATE_OVERRIDE="$state" "$GRANT" release gen-live >/dev/null || echo "(release failed)"
run 'bin/fm-guard.sh' env FM_STATE_OVERRIDE="$state" "$GUARD"
run 'bin/fm-wake-drain.sh' env FM_STATE_OVERRIDE="$state" "$DRAIN"
err=$dir/a2.err
FM_STATE_OVERRIDE="$state" "$DRAIN" >/dev/null 2>"$err"
s=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through \([0-9][0-9]*\) --recovery-generation [A-Za-z0-9._-][A-Za-z0-9._-]*$/\1/p' "$err")
g=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through [0-9][0-9]* --recovery-generation \([A-Za-z0-9._-][A-Za-z0-9._-]*\)$/\1/p' "$err")
if [ -n "$s" ] && [ -n "$g" ]; then
  run "bin/fm-wake-drain.sh --ack-through $s --recovery-generation $g" \
    env FM_STATE_OVERRIDE="$state" "$DRAIN" --ack-through "$s" --recovery-generation "$g"
  printf '    queue after acknowledgement: %s row(s)\n' "$(awk 'END{print NR}' "$state/.wake-queue" 2>/dev/null || echo 0)"
else
  printf '    no acknowledgement command was presented\n'
fi

# ---------------------------------------------------------------- scenario B
dir=$(make_case truncated-repro); state="$dir/state"
printf 'window=test:fm-w2\nkind=ship\n' > "$state/x.meta"
FM_STATE_OVERRIDE="$state" bash -c '. "$1"; fm_wake_append signal "task-a.status" "signal: task-a"' _ "$ROOT/bin/fm-wake-lib.sh"
printf '1788792074\t574\tstale\tfleet:w2:p3\n' >> "$state/.wake-queue"

hr "B. a structurally unusable row (lost its trailing fields) queued alongside a usable one"
printf '\nstate/.wake-queue (verbatim):\n'
cat -A "$state/.wake-queue" | sed 's/\$$//; s/\^I/<TAB>/g; s/^/    /'
run 'bin/fm-guard.sh' env FM_STATE_OVERRIDE="$state" "$GUARD"
run 'bin/fm-wake-drain.sh' env FM_STATE_OVERRIDE="$state" "$DRAIN"
printf '\n    queue now holds %s row(s):\n' "$(awk 'END{print NR}' "$state/.wake-queue")"
cat -A "$state/.wake-queue" | sed 's/\$$//; s/\^I/<TAB>/g; s/^/      /'
err=$dir/b.err
FM_STATE_OVERRIDE="$state" "$DRAIN" >/dev/null 2>"$err"
s=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through \([0-9][0-9]*\) --recovery-generation [A-Za-z0-9._-][A-Za-z0-9._-]*$/\1/p' "$err")
g=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through [0-9][0-9]* --recovery-generation \([A-Za-z0-9._-][A-Za-z0-9._-]*\)$/\1/p' "$err")
if [ -n "$s" ] && [ -n "$g" ]; then
  run "bin/fm-wake-drain.sh --ack-through $s --recovery-generation $g" \
    env FM_STATE_OVERRIDE="$state" "$DRAIN" --ack-through "$s" --recovery-generation "$g"
else
  printf '    no acknowledgement command was presented\n'
fi
printf '    queue after acknowledgement: %s row(s)\n' "$(awk 'END{print NR}' "$state/.wake-queue" 2>/dev/null || echo 0)"
run 'bin/fm-guard.sh   # is the queue finally quiet?' env FM_STATE_OVERRIDE="$state" "$GUARD"
invariant "$state"
printf '\n'
Evidence: Key contrast — the reported field state, one stale row held by a live supervision-branch grant
BEFORE (base ffd2c899)
$ bin/fm-guard.sh
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
$ bin/fm-wake-drain.sh
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
queue holds 1 row(s)
guard counts a row as drainable-by-main (ordinary warning): yes
drain presents a row with an executable ack command: no
INVARIANT VIOLATED: counted but unpresentable -> queue is wedged

AFTER (target 0227b23)
$ bin/fm-guard.sh
NOTICE: wake rows held by the live supervision branch - it presents and acknowledges them; do not drain them from here.
$ bin/fm-wake-drain.sh
WAKE ROWS HELD BY SUPERVISION BRANCH: 1 queued row(s) (1) are granted to the live supervision branch, which presents and acknowledges them.
queue holds 1 row(s)
guard counts a row as drainable-by-main (ordinary warning): no
drain presents a row with an executable ack command: no
INVARIANT HOLDS

AFTER, grant released (same row, same kind, same stopped endpoint)
$ bin/fm-wake-drain.sh
1788814191 1 stale fleet:w2:p3 stale: fleet:w2:p3 (paused 7227s, awaiting external - declared pause, ...)
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3009737.1788814191.NkvT26
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3009737.1788814191.NkvT26
queue after acknowledgement: 0 row(s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 6 issues found → auto-fixed ✅
  • ⚠️ bin/fm-wake-lib.sh - merge conflict rebasing onto origin/main
  • ⚠️ bin/fm-watch.sh - merge conflict rebasing onto origin/main
  • ⚠️ docs/architecture.md - merge conflict rebasing onto origin/main
  • ⚠️ docs/configuration.md - merge conflict rebasing onto origin/main
  • ⚠️ tests/fm-pi-branch-extension.test.sh - merge conflict rebasing onto origin/main
  • ⚠️ tests/fm-wake-queue.test.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-guard.sh:189 - Suppressing branch-held rows from the guard count removes the only always-on alarm for a grant that is never released, so such a row can stay unacknowledged indefinitely with no automatic signal. Concrete sequence: the watcher wakes, the Pi extension calls activateEligibleRowsOwner(process.pid, gen) and writeEligibleRowsSnapshot for seq N (.pi/extensions/fm-branch-supervision.ts:879,1402), then await session.prompt(...) (line 1416) never settles - there is no timeout or abort anywhere in that file, and releaseEligibleRowsSnapshot runs only after a settled prompt (line 1437) or in the rejection handler (line 1442), neither of which fires. The owner pid is the live Pi process, so fm_wake_branch_grant_live stays true forever. From then on every guarded command in the captain's main session takes this line, fm_wake_actor_pending_count main returns 0 because seq N is reserved, and the queued-wakes warning that previously fired on every guarded command goes silent. The branch actor's own warning is suppressed by design (line 267), and bin/fm-watch.sh's secondmate_wake_stall_tick only inspects foreign secondmate homes ($home/state/.wake-queue), not the captain's own queue - so no channel alarms. print_branch_held_notice (bin/fm-wake-drain.sh:119) surfaces it only if someone manually runs a drain. This is a deliberate consequence of the stated invariant (uncounted rows satisfy it vacuously) and is documented in the header here and in docs/watcher-continuity.md, but it trades an always-on alarm for a pull-only notice. Flagging as ask-user rather than auto-fix because the remedy is not a correction of what the change does: bounding a grant's lifetime, or alarming on a grant older than some threshold, needs new durable state and a new timer, which extends the change beyond its stated intent. Confirm whether losing the automatic alarm for an unreleasable grant is acceptable.

🔧 Fix: add guard advisory for branch-held wake rows
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-wake-queue.test.sh (full suite, exit 0) — includes the two new cases test_main_is_never_told_to_drain_rows_only_the_branch_owns and test_unconsumable_rows_are_retired_instead_of_wedging_the_queue
  • bash tests/fm-guard-stale-banner.test.sh (exit 0) — fm-guard.sh changed
  • bash tests/fm-branch-supervision.test.sh (exit 0)
  • bash tests/fm-pi-branch-extension.test.sh (exit 0)
  • Regression proof: extracted both new test functions verbatim and ran them against a clean git archive ffd2c899 export — both fail pre-fix (not ok - main drain went silent instead of naming who holds the queued rows, not ok - main drain did not report the rows it retired)
  • Manual end-to-end CLI reproduction (wake-drain-invariant-repro.sh) driving bin/fm-wake-grant.sh, bin/fm-guard.sh and bin/fm-wake-drain.sh against base and target trees: scenario A replays the reported stale fleet:w2:p3 (paused 7227s, awaiting external ...) row under a live branch grant; scenario A2 releases the grant leaving the row otherwise identical; scenario B queues a structurally truncated row beside a usable one, then acknowledges through to an empty queue
⚠️ **Document** - 1 info
  • ℹ️ AGENTS.md:135 - Judgment call, no action taken: AGENTS.md:135 still describes state/.wake-queue as "durable queued wakes retained until post-handling acknowledgement", while a main drain now also retires structurally unusable rows without an acknowledgement. I left it unchanged deliberately - AGENTS.md is always-loaded and its size discipline forbids conditional detail, the line's own five-field format already implies the shape a retired row lost, and the exception's authoritative owner (docs/watcher-continuity.md "Per-actor acknowledgement") now states it in full. Flagging only so the omission is a visible decision rather than an oversight.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Alex William and others added 4 commits September 7, 2026 22:03
A wake row could be counted as queued while no drain would ever present
it, leaving the operator told to "drain them before anything else" by a
command that printed nothing and offered no acknowledgement.

Two independent paths produced that state.
A row reserved by a live supervision-branch grant is excluded from a main
drain by design, but fm-guard.sh counted the whole queue, so main was
warned about rows only the branch could present, on every guarded command
for as long as the grant was held.
A row that lost its five appended fields or its numeric sequence can never
be claimed, presented, or named by an --ack-through cutoff, yet it still
counted as queued, wedging the queue permanently.

The guard now counts only the rows the calling actor can itself present or
retire, and a main drain retires unusable rows under the queue lock,
reporting them in bounded escaped form before removal so the evidence
survives for the separate row-generating defects. A retirement failure is
reported loudly and never suppresses unrelated consumable work. A main
drain whose remaining rows are all branch-held says so in one bounded line
instead of exiting silently. Grant row-list and owner-record reads move
into fm-wake-lib.sh so the drain, the grant publisher, and the guard share
one implementation.

Ownership is unchanged: a branch drain still touches nothing outside its
grant and never retires a row, and main still cannot present or acknowledge
an active grant.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GghGvsa4JDB1E5FuznX2i1
@greptile-apps

greptile-apps Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(ci): Addressed the Greptile ..." | Re-trigger Greptile

Comment thread bin/fm-wake-lib.sh Resolved
… ("Unreadable queue suppresses alarms"). Root cause: fm_wake_actor_pending_count inferred "the queue could not be counted" only from awk's printed output (`case "$count" in ''|*[!0-9]*) count=1`). That relies on awk aborting before its END rule when the input cannot be opened. An awk that reaches END after a failed open prints `0`, which the fallback accepts as a genuine count; both actor counts then read zero and bin/fm-guard.sh emits neither the queued-wake warning nor the branch-held advisory for a queue nobody proved empty. Fix (bin/fm-wake-lib.sh:1828,1835): both counting awk invocations now set `count=''` on a non-zero awk exit status, so the existing "cannot be counted => report a pending row" fallback is driven by awk's exit status instead of an implementation-defined detail of what it printed. No new code path or behavior; the pre-existing fallback just becomes unconditional. Comment updated to state why. Regression test (tests/fm-wake-queue.test.sh: test_uncountable_queue_still_raises_the_pending_alarm, registered in the run list): runs the real bin/fm-guard.sh against a non-empty, unreadable queue with a PATH-injected awk emulating an END-running implementation (prints 0, exits 2; execs the real awk otherwise) and asserts "queued wakes pending" is still emitted; disconfirming half asserts the same fake awk over a readable, provably empty queue stays silent. Fails on the pre-fix library ("not ok - a queue that could not be counted silenced the queued-wake alarm"), passes after. Verified locally: bin/fm-test-run.sh tests/fm-wake-queue.test.sh -> 0 failed; tests/fm-guard-stale-banner.test.sh + tests/fm-watcher-lock.test.sh -> 0 failed; bin/fm-lint.sh (ShellCheck 0.11.0 + actionlint 1.7.12) clean. Caveat reported honestly: on the awks available/known here (mawk locally, plus gawk and BWK/macOS awk, all of which treat an unopenable input as fatal and skip END) the alarm was not actually suppressed - I reproduced the unreadable-queue case and the warning fired. The change removes the code's dependence on that awk detail rather than repairing an outage observed on this platform. Both intent constraints still hold: every counted row remains presentable or retirable, and no alarm-suppressing path was added
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on HEAD 58c5901496bf9f1037187deac99a56069b1779fb vs main (post-#3952 tip). MERGEABLE/CLEAN. Author cisrd is not a blocked author. No .github/** edits. Workflow approvals this pass: no (CI/NM already green). Attestation MATCH for tip. CI 34163148631 SUCCESS. Require no-mistakes 34163148614 SUCCESS (earlier synchronize fail superseded). Greptile Review pass / 5/5.

Diff reviewed: fm_wake_actor_pending_count so guard only warns for rows the actor can present/retire; distinct NOTICE when main sees only branch-held rows; main drain retires structurally unusable rows under the queue lock (reports verbatim, non-fatal on write failure) and names branch-held sequences instead of exiting silent; grant helpers deduped into fm-wake-lib.sh; docs + two new end-to-end tests. Field wedge (counted but unpresentable) is corrective. Safe review — auto-merging as restore.

Contract-class: restore. Restores the already-promised drain contract: every row counted in the pending-warning condition is presentable with an ack path or is retired. Unconfigured empty-queue behavior unchanged; the broken "warn then present nothing" path is what is corrected. Not new-default (no new autonomy grant; retirement is only for rows that can never be claimed/acked).

VISION.md (each rule)

  • One captain, one interface: aligns — honest pending vs held vs retire signals; no silent wedge.
  • Authority is explicit and never inferred: aligns — no new autonomy; branch ownership stays explicit.
  • Scripts own the mechanics, agents own the judgment: aligns — queue/guard/drain classification is exact script work.
  • A restart is a non-event: aligns — durable queue repaired; unusable rows reported on retirement; usable rows stay ackable.
  • Delegation with a spine: aligns (N/A to worker contracts; supervision continuity).
  • The fleet outlives any vendor: aligns.
  • Scope: aligns — command-layer wake continuity; field incident → regression coverage.

Merging now.

@kunchenguid
kunchenguid merged commit 3af74fe into kunchenguid:main Sep 7, 2026
15 of 16 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @cisrd — really appreciate you taking the time on this.

lytv pushed a commit to lytv/mymate that referenced this pull request Sep 8, 2026
…unchenguid#3950)

* fix(bin): make every counted wake queue row presentable or retired

A wake row could be counted as queued while no drain would ever present
it, leaving the operator told to "drain them before anything else" by a
command that printed nothing and offered no acknowledgement.

Two independent paths produced that state.
A row reserved by a live supervision-branch grant is excluded from a main
drain by design, but fm-guard.sh counted the whole queue, so main was
warned about rows only the branch could present, on every guarded command
for as long as the grant was held.
A row that lost its five appended fields or its numeric sequence can never
be claimed, presented, or named by an --ack-through cutoff, yet it still
counted as queued, wedging the queue permanently.

The guard now counts only the rows the calling actor can itself present or
retire, and a main drain retires unusable rows under the queue lock,
reporting them in bounded escaped form before removal so the evidence
survives for the separate row-generating defects. A retirement failure is
reported loudly and never suppresses unrelated consumable work. A main
drain whose remaining rows are all branch-held says so in one bounded line
instead of exiting silently. Grant row-list and owner-record reads move
into fm-wake-lib.sh so the drain, the grant publisher, and the guard share
one implementation.

Ownership is unchanged: a branch drain still touches nothing outside its
grant and never retires a row, and main still cannot present or acknowledge
an active grant.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GghGvsa4JDB1E5FuznX2i1

* no-mistakes(test): keep SIGTERM-safe arithmetic in wake queue retirement pass

* no-mistakes(review): add guard advisory for branch-held wake rows

* no-mistakes(document): document per-actor wake counting and unusable-row retirement

* no-mistakes(ci): Addressed the Greptile P1 on bin/fm-wake-lib.sh:1840 ("Unreadable queue suppresses alarms"). Root cause: fm_wake_actor_pending_count inferred "the queue could not be counted" only from awk's printed output (`case "$count" in ''|*[!0-9]*) count=1`). That relies on awk aborting before its END rule when the input cannot be opened. An awk that reaches END after a failed open prints `0`, which the fallback accepts as a genuine count; both actor counts then read zero and bin/fm-guard.sh emits neither the queued-wake warning nor the branch-held advisory for a queue nobody proved empty. Fix (bin/fm-wake-lib.sh:1828,1835): both counting awk invocations now set `count=''` on a non-zero awk exit status, so the existing "cannot be counted => report a pending row" fallback is driven by awk's exit status instead of an implementation-defined detail of what it printed. No new code path or behavior; the pre-existing fallback just becomes unconditional. Comment updated to state why. Regression test (tests/fm-wake-queue.test.sh: test_uncountable_queue_still_raises_the_pending_alarm, registered in the run list): runs the real bin/fm-guard.sh against a non-empty, unreadable queue with a PATH-injected awk emulating an END-running implementation (prints 0, exits 2; execs the real awk otherwise) and asserts "queued wakes pending" is still emitted; disconfirming half asserts the same fake awk over a readable, provably empty queue stays silent. Fails on the pre-fix library ("not ok - a queue that could not be counted silenced the queued-wake alarm"), passes after. Verified locally: bin/fm-test-run.sh tests/fm-wake-queue.test.sh -> 0 failed; tests/fm-guard-stale-banner.test.sh + tests/fm-watcher-lock.test.sh -> 0 failed; bin/fm-lint.sh (ShellCheck 0.11.0 + actionlint 1.7.12) clean. Caveat reported honestly: on the awks available/known here (mawk locally, plus gawk and BWK/macOS awk, all of which treat an unopenable input as fatal and skip END) the alarm was not actually suppressed - I reproduced the unreadable-queue case and the warning fired. The change removes the code's dependence on that awk detail rather than repairing an outage observed on this platform. Both intent constraints still hold: every counted row remains presentable or retirable, and no alarm-suppressing path was added

---------

Co-authored-by: Alex William <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
dnth added a commit to dnth/firstmate that referenced this pull request Sep 9, 2026
* fix(bin): derive watcher beacon staleness grace from poll cadence

Port of upstream kunchenguid/firstmate kunchenguid#3946, adapted: the fork has no
away-mode daemon predicate, so only the shared derivation and its two
in-scope readers change.

fm-claude-stop-autoarm.sh required the watcher beacon fresh within the
flat FM_GUARD_GRACE default (300s), but a healthy watcher touches the
beacon once per cycle and can legitimately age up to FM_POLL seconds
between touches, so a long-poll home reads stale mid-wait and the hook
misjudges a live cycle as down.

fm-wake-lib.sh gains fm_poll_derived_grace, the single owner of the
max(300, FM_POLL + 60) formula. fm-watch.sh's own pre-acquisition
beacon-staleness check and the auto-arm hook both derive their default
grace from it, and the hook now exports its resolved FM_GUARD_GRACE to
the fm-watch-arm.sh invocations so arm and check agree on one value.

* fix(bin): count only actor-presentable wake rows and retire unusable rows

Port of upstream kunchenguid/firstmate kunchenguid#3950, adapted to the fork's
SCOPED drain and OMP branch-grant machinery.

A branch grant already excluded its rows from a main drain, but
fm-guard.sh still counted every queued row as pending for the calling
actor, so main was told to run a drain that could only print nothing for
as long as the branch held the grant. And a queue row that lost the five
appended fields or its numeric sequence was counted as queued while it
could never be claimed, presented, or named by an --ack-through cutoff,
wedging the queue permanently.

fm-wake-lib.sh gains the shared per-actor helpers:
fm_wake_grant_rows_valid, fm_wake_branch_owner_matches,
fm_wake_branch_grant_live, and fm_wake_actor_pending_count - the last
reports a pending row when a queue exists but cannot be counted, so an
unreadable queue still raises the alarm. fm-wake-drain.sh and
fm-wake-grant.sh now delegate their grant row-list and owner-record
reads to the library. A main drain retires structurally unusable rows
under the queue lock and reports them verbatim (a branch drain never
does), and a main drain left with only branch-held rows names the
holder instead of exiting silently. fm-guard.sh warns only for rows the
calling actor can itself present or retire, and gives main a distinct
held-by-branch advisory when that is the whole non-empty queue.

tests/fm-wake-queue.test.sh covers the branch-held warning boundary end
to end, the uncountable-queue alarm, and main-only retirement.

* fix(bin): gate secondmate wake-loop stall alerts on real queue no-progress

Port of upstream kunchenguid/firstmate kunchenguid#3943, which lands the detector's
final form on this fork (the fork had no foreign-queue stall check at
all, so the whole feature arrives already fixed).

The watcher now reads the oldest structurally valid actionable row in
every endpoint-recorded local secondmate home's durable wake queue, and
times the interval since that position last changed instead of the row's
age. A queue that is draining is not stalled, so a moved oldest row -
drain progress, or a queue reprovisioned under the same task id that
restarts its sequence anywhere - ends the no-progress episode and starts
a fresh observation interval, recorded by
state/.secondmate-wake-progress-<task> as the same epoch-sequence row
identity the stall receipts use. Declared external-wait pause rows are
not actionable evidence, and a mate provably inside an active turn (an
exact busy verdict bounded by FM_BUSY_TURN_MAX_SECS) never escalates.
One keyed check notification covers each no-progress episode across
watcher and handling crashes; the foreign queue is only ever read.

FM_SECONDMATE_WAKE_STALL_SECS defaults to 180 and is the backstop behind
the active-turn gate, not a substitute for it.

Fork adaptation: the parent watcher keeps its secondmate home-beacon
rule, so the ported tests give the fixture mate a fresh
.last-watcher-beat under its (stubbed or real) clock to isolate the
stall detector; assertions are unchanged from upstream.

tests/fm-wake-queue.test.sh covers progress tracking, once-per-episode
alerting, declared-pause exclusion, reprovisioned-generation reset,
active-turn deferral, and marker symlink rejection.

* fix(bin): never type doorbells into dead panes; recover them instead

Port of upstream kunchenguid#3823, adapted: the fork's task-inbox ring reserves
return code 6 for a positively dead or missing endpoint (codes 3-5 are
OMP-native and Hermes-lock outcomes here). The doorbell line itself is
now a shell no-op (": ...") with quoted, printable-only paths, so even a
liveness race that loses to an exiting agent runs nothing in a bare
shell. The watcher escalates a dead/missing endpoint's unhandled record
once through the ordinary stale wake - over stale busy-state evidence -
instead of walking the re-ring ladder, and fm-send reports the skipped
doorbell as recovery, not a re-ring. Remote secondmate send inherits the
rc-6 recovery notice through fm-send without a new branch. Secondmate
restart also resolves all arrived persist answers before any timeout
decision and rechecks at the decision boundary, so a reply landing at
the deadline wins over the fallback nudge.

Regression coverage: doorbell shell-noop across real shells, control-byte
path rejection, dead/missing ring skip, watcher escalate-once-without-
ringing, dead-pane override of stale busy state, and the
resolution/timeout boundary race. Fake tmux inventories across the suite
now list recorded windows and answer pane_current_command so the
recovery-grade endpoint check exercises real paths.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(omp): prove the doorbell turn instead of trusting triggerTurn

The task-inbox doorbell claimed `.delivered` the moment sendMessage
returned, but OMP can downgrade `triggerTurn` to append-only delivery on
an idle, non-streaming session: the steer was accepted and reported
received while no turn ever ran, leaving an idle worker stranded with an
unhandled durable record.

The extension now renames an accepted request to `.awaiting-turn` when no
turn is open and settles it to `.delivered` only on a `turn_start` or
`agent_start` proving the turn actually began. A steer that lands while a
turn is open is still delivered immediately, since it joins that turn.
When the bound passes with no turn, the extension re-drives the same
instruction through `sendUserMessage` - a user prompt an idle session
cannot defer - and a failed re-drive reports `.failed` rather than
stranding silently. Requests left `.awaiting-turn` by a dead generation
re-queue as `.pending` on the next activation. Installs on runtimes
without the event or user-prompt surface keep the prior accept-only
semantics.

On the shell side, `fm_omp_task_doorbell_request_existing` reports an
awaiting-turn request as in-flight, so fm-send honestly reports a
downgraded doorbell as queued (exit 4 semantics) rather than received
while the extension's own recovery still wakes the worker.

Regression coverage drives the downgrade end to end: an accepted
sendMessage with no turn event stays unproven, the bounded grace re-drives
the identical instruction through sendUserMessage exactly once, a firing
turn_start settles without any re-drive, an open turn delivers the steer
immediately, a failing re-drive reports failed, and a dead generation's
unsettled proof re-enters delivery on activate. The suite's tmux fake also
now lists the recorded task window so the recovery-grade endpoint check
exercises the live path instead of classifying the fixture missing.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(bin): bound detached procevent runners to their owning home's lease

A runner is detached into its own process group so it survives the turn
that started it, and on its own that lets a runner outlive its whole
home: once reparented to init, nothing bounds its lifetime, so a blocking
source child - and everything it spawns - can poll forever after the home
that owns the work is gone. This is the upstream kunchenguid#3904 port, adapted to
the fork's simpler procevent (no extension subsystem or capture
reservations).

Every claim now records the canonical physical state root with its
device, inode, owner, and mode, and every claimed runner spawns a
detached owner guard in a separate process group. The guard re-reads the
recorded root's .owner-lease marker - refreshed by register, handled,
reconcile, sweep, and an attached start's keepalive - and after two
consecutive checks cannot prove both the root identity and a fresh lease,
it signals the runner's whole process group. Runner descendants inherit
FM_PROCEVENT_IN_RUNNER so they cannot keep their own lease alive; a
confused agent that deliberately strips the marker is out of scope.

Reconcile no longer signals a leaderless surviving group: once the leader
is gone, PID/PGID reuse makes the group's provenance unprovable, so the
claim stays owned and uncertain instead of risking a foreign group or a
second poller on one canonical source. Retirement and reconcile take
their signal through an identity-and-leadership-gated group path, and a
launch floor paces relaunches per registration generation so a
crash-looping source cannot spin.

Fork deviations from upstream: the state-root check requires ownership
and canonicality but not a private mode (operational homes use
group-readable state roots), the serialized launch-floor section releases
the source lock at the stamp write because this caller holds no further
locked work, central storage keeps its distinct commit point, and the
usage window is widened to keep the durability-boundary line visible.

Regression coverage: an orphaned runner's group is stopped by its guard
after the home's lease expires, a crashed leader's ambiguous group is
preserved rather than signalled or replaced, and the registration
replacement test now waits for the old generation's source to actually
start so the launch-floor supersede check cannot eat the race.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(omp): latch a provider-broken branch with a bounded cooldown probe

A settled branch prompt whose last assistant message carries stopReason
"error" is a provider failure OMP reports on the message instead of
rejecting prompt(), so the old code never latched: every later wake kept
paying for a predictably broken branch turn before its settlement could
reject to main. Port of upstream kunchenguid#3497, adapted to the fork's extension
shape (generation-only guards, offer.accept(promise) settlement).

Two consecutive settled provider errors now latch the branch off and
merge a captain-facing health note. While latched, main keeps every wake
except one recovery probe after each cooldown, which starts at five
minutes and doubles to a one-hour ceiling; a probe that ends in a durable
fm_branch_report clears the latch with a second note, and a failed probe
reschedules by the current cooldown. A settled prompt that produced no
durable outcome now rejects its settlement instead of silently claiming
its granted wake rows.

The branch record keeps its SessionManager so the settled-prompt scan can
read only the entries the prompt appended. The strict typecheck also
caught two stale errors from the earlier doorbell work: the doorbell
options builder returned a Required<> literal missing turnGraceMs, and
its `on` property signature could not accept the runtime's overloaded
event subscription - the latter is now a method declaration so the
parameter stays bivariant.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(omp): start a fresh supervision branch conversation per main session

Port of upstream kunchenguid#3600. A branch conversation that outlives its main
session keeps reasoning from an older thread's accumulated memory, which
competes with today's generated prompt and current fleet rules. The OMP
extension kept one persistent conversation keyed on a durable pointer,
so /new, /resume, /fork, and reload all reopened the stale thread.

The branch record is now scoped to the extension generation: createBranch
reopens only a conversation it built under the current generation, and
both session_start and session_switch advance the generation, drop the
live handle (beginDispose + dispose), and re-anchor the mirror so the
fresh branch receives the new main session's dialog from its start. The
durable outcome store, not the conversation, carries unacknowledged
outcomes across the boundary. The on-disk pointer remains a record for
operators and the effort picker's model lookup, not a reopen source.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(omp): give the supervision branch main's live model registry

Port of upstream kunchenguid#3871 by equivalent mechanism. A provider an extension
registered into main's runtime at run time is invisible to a freshly
discovered registry, so pinning or following such a model built a branch
that could not resolve its own model. OMP's createAgentSession already
takes a modelRegistry option, so instead of upstream's provider-by-provider
config copy into an isolated ModelRuntime, the branch session now receives
main's live registry directly - read-only sharing: the branch never
installs, converts, or overwrites credentials or registrations. The
resolve and picker paths already read that same registry, so the build,
the pin resolution, and the picker now agree on one model catalog.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(bin/omp): route decision-owned signal and stale wake batches to main

Port of upstream kunchenguid#3776. A needs-decision status append, a captain-held
status transfer surfaced through the no-verb signal path, or a blocked
pending-reply escalation is owned by the captain and must stay on main.
The previous logic only forced the check-kind class to main, so a
coalesced signal batch that also contained routine rows could end up split:
the decision row to the branch, the rest to main, which loses the
single-actor ordering the per-actor acknowledgement contract depends on.

The bash side now:

- `status_span_first_actionable_record` returns a side-band flag when its
  span carries a needs-decision, a captain-held declaration, or a pending-
  reply escalation, without changing the event text it already returns.
- `signal_files_actionable` surfaces those files (even when the captain-held
  line is otherwise non-actionable) and populates
  `FM_SIGNAL_NEEDS_DECISION_FILES`.
- The watcher appends the row payload as `needs-decision:$files` for exactly
  the flagged files; other files in the same batch keep the ordinary reason.

The OMP dispatch side now:

- `scopeForUnreadWake` parses each mapped task's `.status` log to detect an
  open needs-decision or a current captain-held declaration, and excludes
  those rows from `eligibleSeqs` while populating `needsDecisionKeys`.
- `offerWakeToBranch` in `fm-primary-omp.ts` cross-references the current
  signal or stale trigger keys against every unread decision-owned row by
  task identity: any overlap forces the entire coalesced batch to main.
- Heartbeat handling remains independent, and a decision-owned row in one
  task does not affect eligibility for other tasks.

Also fixed a pre-existing full-lint `SC2031` info note in
`tests/fm-afk-launch.test.sh` by disabling it file-wide, so the canonical
lint run is green again.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(core/omp/pi): settle watcher delivery on runtime acceptance, consume on turn start

Port of upstream kunchenguid#3513. A follow-up queued while main is streaming joins
that run as a user message without raising before_agent_start, so waiting
for the model to consume the wake stalled the successor chain: no successor
started, later wakes were not delivered, and the turn-end guard re-armed by
hand.

The shared core now:

- Treats sendFollowUp resolution as delivery; consumption is tracked only
  to let a session replacement replay a wake the runtime accepted but had
  not yet read.
- Keeps accepted-but-unconsumed wakes in a per-generation unconsumedWakes
  map keyed by the pending token.
- Consumes a wake when the runtime starts a turn carrying the exact wake
  text: before_agent_start for an idle main, message_start for a streaming
  main.
- Does not mark a pending row delivered or finish cleanup until the wake is
  consumed or the branch owns it.
- Skips over unconsumed rows when picking the next pending record, so the
  successor chain keeps moving while waiting for a streaming main to read
  the prior wake.
- Defers a verified successor's failure close when the pipeline is still
  delivering the wake it was started for; the retry runs once that delivery
  settles.
- Adds armRetired so a child the core itself killed does not earn a
  deferred retry.

The Pi and OMP adapters both gain a message_start handler that extracts the
user message text and passes it to watch.acknowledgeWake.

Documentation in docs/omp-supervision-branch.md now states the delivery
versus consumption boundary for main fall-back follow-ups.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* no-mistakes(review): Make supervision provider latch recoverable after transient failures

* no-mistakes(review): Correlate doorbells and latch rejected supervision prompts

* no-mistakes(review): Correlate doorbell turn proofs and recover prompt failures

* no-mistakes(review): Correlate synchronous turn proofs to each doorbell dispatch

* no-mistakes(review): Correlate turn proof and redrive uncorrelated doorbells

* no-mistakes(test): Fix procevent sweep claims and OMP turn handler coexistence

* no-mistakes(test): Preserve claim-only sources for reliable home sweeps

* no-mistakes(test): Disabled unreliable turn observation for generated OMP workers

* no-mistakes(document): Updated stale branch-session documentation

* no-mistakes(review): Enforce state-root identity before ownership and stale-claim decisions

* no-mistakes(review): Requeue unreadable awaiting-turn requests for redelivery

* no-mistakes(document): Correct stale supervision and process-event verification docs

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>