Skip to content

Hold missed and unreported pending-reply escalations quiet before waking - #53

Merged
uayyagari merged 4 commits into
mainfrom
fm/qwr-bookkeeping-wakes
Oct 27, 2026
Merged

uayyagari merged 4 commits into
mainfrom
fm/qwr-bookkeeping-wakes

Conversation

@uayyagari

@uayyagari uayyagari commented Oct 26, 2026 •

Copy link
Copy Markdown

Problem

  • A missed or unreported pending-reply escalation wakes the supervisor at once, though the mate has usually acknowledged or answered where main already saw it. Each wake is a full supervisor turn re-reading about 193k tokens of context.
  • In the main home's status logs, 295 such escalations woke the supervisor in October. 120 were then closed by the supervisor itself within about 2 minutes ("Acknowledged; no reply needed", "Superseded", "Settled"), and 67 were answered by the mate later, median about 80 minutes.
  • Part of the quota-waste reduction (supervisor bookkeeping turns). Out of scope: the other quota-waste items.

Fix

  • pending-reply-missed and pending-reply-unreported escalations for a delivered request are now published with the home's own self-announced append: the keyed blocked decision is in the log and lists in the next drain's OPEN DECISIONS, but does not wake.
  • If the request is still unresolved after FM_PENDING_REPLY_WAKE_HOLD_SECS (default 3600, 0 restores the old behaviour), the tick appends one plain reminder under the same key. That wakes once. A reply inside the hold resolves the record and closes the decision with no wake.
  • delivery-unknown and recovery-delivery escalations are transport faults and still wake at once. Resolve, close, recovery repost and the missed-report logic are unchanged.
  • New record field escalation_wake_due_epoch; tunable documented in docs/configuration.md.

Worked example (web-perf, 2026-10-26): main steers web-perf, which answers working:; 1800 s later pending-reply-unreported escalates.

before: t+30m  blocked [key=pending-reply-X] appended -> wake -> supervisor turn -> "no reply needed" -> --resolve-key
after : t+30m  blocked [key=pending-reply-X] appended quietly (OPEN DECISIONS lists it, no wake)
        t+55m  web-perf sends done [corr=X] -> record resolves, decision closes, no wake
        (or, if still open at t+90m: one reminder line under the same key -> one wake)

Proof

  • tests/fm-pending-reply.test.sh passes (new: quiet escalation lists but does not wake and a reply inside the hold resolves silently; wakes once after the hold, not on repeated ticks, and still closes on a reply; delivery-unknown still wakes at once). Existing cases run with the hold set to 0, so their wake assertions are unchanged. Also run and passing: fm-secondmate-result-delivery, fm-send-resolve-key; bin/fm-lint.sh clean.
  • Before/after: replay of the real escalation history in the main home's status logs (2026-10-02 to 2026-10-26, escalations of kind missed/unreported), hold 3600 s, script below. Wakes counted per escalation.
                         before   after (conservative)   after (next-wake)
2026-10-26 (one day)       37            33                    19
2026-10 (whole month)     295           255                   136
  • Conservative: only escalations the mate answered inside the hold avoid the wake (13% fewer for the month). Next-wake: also counts a supervisor-closed escalation as avoided when any other status line arrived inside the hold, since OPEN DECISIONS lists it at that wake (53% fewer for the month, 48% on 10-26). The second figure assumes the supervisor closes the record at that wake, as the AGENTS drain contract requires.
  • Cost per wake from usage.py 2026-10-26: main supervisor 841 calls, 21.0M weighted tokens, about 25k weighted tokens and 192k cache-read per call. At least one call per wake: 37 to 19 wakes is at least 18 fewer calls on 10-26.
  • Not measured: live effect after deploy (the replay uses past logs, not a live run).
Replay script (python3 replay.py 3600 [day-prefix])
import glob,re,sys,collections,datetime
# usage: replay.py <state-dir> <hold-secs> [day-prefix]
state,hold=sys.argv[1],int(sys.argv[2]); day=sys.argv[3] if len(sys.argv)>3 else ''
esc={};res={};ev=[]
for f in glob.glob(state+'/*.status'):
    for l in open(f,errors='ignore'):
        if 'pending-reply' not in l:
            a=re.search(r'\[at=(\d+)\]',l)
            if a: ev.append(int(a[1]))
        m=re.match(r'(blocked|resolved) \[key=pending-reply-(\w+)\] \[at=(\d+)\]: pending-reply-([\w-]+)',l)
        if not m: continue
        if m[1]=='blocked':
            if m[4] in('missed','unreported'): esc[m[2]]=(int(m[3]),m[4])
        else:
            v=re.search(r'via=([\w-]+)',l); res[m[2]]=(int(m[3]),v[1] if v else '?')
ev.sort()
import bisect
by=collections.defaultdict(lambda:[0,0,0])
for c,(t,k) in esc.items():
    d=datetime.datetime.utcfromtimestamp(t).strftime('%Y-%m-%d')
    if day and not d.startswith(day): continue
    r=res.get(c)
    worker_quick = r and r[1] in('status','document','helper','?') and r[0]-t<hold
    by[d][0]+=1                      # before: every escalation wakes
    by[d][1]+=0 if worker_quick else 1   # conservative: only worker replies inside the hold avoid a wake
    # with-next-wake: a supervisor-closed record is also seen, and closed, at the next
    # unrelated wake inside the hold (OPEN DECISIONS lists it there)
    i=bisect.bisect_right(ev,t); seen_in_hold = i<len(ev) and ev[i]<t+hold
    closed_by_op = r and r[1]=='operator-resolve-key'
    by[d][2]+=0 if (worker_quick or (closed_by_op and seen_in_hold)) else 1
tb=ta=tn=0
for d in sorted(by):
    b,a,n=by[d]; tb+=b; ta+=a; tn+=n; print(d,'before',b,'after(conservative)',a,'after(next-wake)',n)
print('TOTAL before',tb,'conservative after',ta,'(%d%% fewer)'%(100*(tb-ta)//max(tb,1)),'next-wake after',tn,'(%d%% fewer)'%(100*(tb-tn)//max(tb,1)))

Fork footprint vs upstream main

Fork footprint vs upstream main

  • Upstream files touched by this change: 3 (+521/-18 lines vs upstream)
    • bin/fm-pending-reply-lib.sh (+198/-10): on the fork ledger
    • docs/configuration.md (+127/-1): on the fork ledger
    • tests/fm-pending-reply.test.sh (+196/-7): on the fork ledger
  • Upstream files the fork already modifies on origin/main: 67 of 194 changed files (+15356/-273 lines, includes fork-only files)
  • Result: ok

Intent

We are using way too much quota for the work given; anything to bring the wastage down. Measured 2026-10-26 (Claude transcripts, about 101.6M weighted tokens): workers 41%, no-mistakes final runs 20%, second mate supervisors 20%, main supervisor 19%. Main supervisor session: 759 calls at about 193k tokens of cache re-read per call; interview-recordings second mate: 517 calls at about 218k per call. Many supervisor turns were bookkeeping-only (pending-reply-missed or unreported wakes, 'Captain, shipshape.' no-ops). Each fix ships as its own PR with before/after numbers.

Risk Assessment

✅ Low: The quiet-escalation hold is small and self-contained, and the fix round closed both earlier findings without new defects. Before the reminder fires it now checks that the keyed decision is still open (round 1 finding 1). The reminder text now uses due minus escalated_epoch for the hold length (round 1 finding 2). Both new tests would fail without the fixes.

Testing

I drove the real bin/fm-watch.sh and bin/fm-wake-drain.sh in disposable lab homes made with bin/fm-lab-home.sh, with plain FM_HOME and the override variables unset. One flow was used throughout: second mate hibit acknowledges a request with working [corr=...] and goes quiet. Baseline with hold=0 (the old behavior): the watcher woke within 2s. With the default 1h hold it stayed blocked for the whole 40s while the decision still showed as open. A 15s hold woke it once, with a "still unresolved" reminder under the same key. After a real drain and ack, no repeat came in the next 40s. A decision main had already closed got no reminder and no wake. A reply during the hold closed the decision, the only wake was for the reply itself, and no reminder followed. Delivery-unknown still woke at once. The focused pending-reply test file passes. The before/after number shown here is wakes per quiet escalation: one at once before, versus none, or one after the hold if still unresolved. Fleet token savings would need live measurement over time. Every lab home was removed afterward and the worktree is clean. There is no UI surface; the evidence is CLI transcripts.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Unreported escalation with the default 1h hold lists as an open decision but does not wake the watcher (vs. hold=0 baseline waking in 2s) ✅ pass live 01-hold0-baseline-wakes-at-once.txt, 02-hold3600-quiet-no-wake.txt
Escalation still unresolved after the hold wakes the supervisor exactly once with a reminder under the same key ✅ pass live 03-hold-expires-wakes-once.txt
Adversarial: main closes the quiet decision (fm-send --resolve-key close note) before the hold ends; the reminder must not reopen it or wake ✅ pass live 04-closed-by-main-not-reminded.txt
Mate replies inside the hold: decision closes and no reminder wake follows ✅ pass live 05-reply-inside-hold-closes-quietly.txt
Guard: delivery-unknown (transport fault) escalations still wake at once despite the hold ✅ pass live 06-delivery-unknown-wakes-at-once.txt; tests/fm-pending-reply.test.sh
Evidence: Baseline: hold=0 wakes watcher at once (old behavior)

Source: Baseline: hold=0 wakes watcher at once (old behavior)

== baseline announced
== record before watcher: phase=acknowledged
== watcher EXITED (WAKE) after 2s; stdout:
signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.Y3CceY/state/hibit.status
== hibit.status:
   working [corr=60aa869d02b8dead]: on it
   blocked [key=pending-reply-60aa869d02b8dead] [at=1793048819]: pending-reply-unreported: task=hibit pending-reply-id=60aa869d02b8dead request=check the PR 367 canvas - acknowledged only, no result reached main
== open decisions:
   pending-reply-60aa869d02b8dead	blocked	pending-reply-unreported: task=hibit pending-reply-id=60aa869d02b8dead request=check the PR 367 canvas - acknowledged only, no result reached main== record: escalation_wake_due_epoch= escalated_epoch=1793048819 phase=escalated 
Evidence: Default 1h hold: escalation listed as open decision, watcher stays blocked 40s

Source: Default 1h hold: escalation listed as open decision, watcher stays blocked 40s

== baseline announced
== record before watcher: phase=acknowledged
== watcher still blocking after 40s (NO WAKE)
== hibit.status:
   working [corr=7dc1b02c045bfa46]: on it
   blocked [key=pending-reply-7dc1b02c045bfa46] [at=1793048822]: pending-reply-unreported: task=hibit pending-reply-id=7dc1b02c045bfa46 request=check the PR 367 canvas - acknowledged only, no result reached main
== open decisions:
   pending-reply-7dc1b02c045bfa46	blocked	pending-reply-unreported: task=hibit pending-reply-id=7dc1b02c045bfa46 request=check the PR 367 canvas - acknowledged only, no result reached main== record: escalation_wake_due_epoch=1793052422 escalated_epoch=1793048822 phase=escalated 
Evidence: Hold expires: one reminder wake, drain shows OPEN DECISIONS, no repeat after ack

Source: Hold expires: one reminder wake, drain shows OPEN DECISIONS, no repeat after ack

== baseline announced
== record before watcher: phase=acknowledged
== watcher EXITED (WAKE) after 21s; stdout:
signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.6Z3uR2/state/hibit.status
== supervisor runs fm-wake-drain.sh:
   | 1793048931	2	signal	hibit.status	signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.6Z3uR2/state/hibit.status
   | wake annotation: unread wake-EVENT since last drain, not current state: hibit.status: working [corr=1dae1379e1c0b4eb]: on it
   | wake annotation: unread wake-EVENT since last drain, not current state: hibit.status: blocked [key=pending-reply-1dae1379e1c0b4eb] [at=1793048913]: pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main
   | wake annotation: latest wake-EVENT observed at drain, not current state: hibit.status: blocked [key=pending-reply-1dae1379e1c0b4eb] [at=1793048929]: pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main - still unresolved after 0m
   | OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
   | hibit [key=pending-reply-1dae1379e1c0b4eb] blocked: pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main - still  [truncated]
   | OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
== drain acked through 2
== restarting watcher for 40s
== second watcher still blocking after 40s (NO REPEAT WAKE)
== hibit.status:
   working [corr=1dae1379e1c0b4eb]: on it
   blocked [key=pending-reply-1dae1379e1c0b4eb] [at=1793048913]: pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main
   blocked [key=pending-reply-1dae1379e1c0b4eb] [at=1793048929]: pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main - still unresolved after 0m
== open decisions:
   pending-reply-1dae1379e1c0b4eb	blocked	pending-reply-unreported: task=hibit pending-reply-id=1dae1379e1c0b4eb request=check the PR 367 canvas - acknowledged only, no result reached main - still unresolved after 0m== record: escalated_epoch=1793048913 phase=escalated escalation_wake_due_epoch= 
Evidence: Main closed the key before the hold: no reminder, no wake

Source: Main closed the key before the hold: no reminder, no wake

== baseline announced
== record before watcher: phase=acknowledged
== baseline announced
== main closed pending-reply-905d051a9e842188; open decisions now: []
== watcher still blocking after 45s (NO WAKE)
== hibit.status:
   working [corr=905d051a9e842188]: on it
   blocked [key=pending-reply-905d051a9e842188] [at=1793048985]: pending-reply-unreported: task=hibit pending-reply-id=905d051a9e842188 request=check the PR 367 canvas - acknowledged only, no result reached main
   resolved [key=pending-reply-905d051a9e842188]: pending-reply-resolved: task=hibit pending-reply-id=905d051a9e842188 via=operator-resolve-key handled
== open decisions:
== record: escalated_epoch=1793048985 phase=escalated escalation_wake_due_epoch= 
Evidence: Mate reply inside the hold: decision closes, no reminder afterward

Source: Mate reply inside the hold: decision closes, no reminder afterward

== baseline announced
== record before watcher: phase=acknowledged
== quiet escalation open: [pending-reply-569778d7b062cc35]
== mate hibit replies inside the hold: done [corr=569778d7b062cc35]
== watcher EXITED (WAKE) after 6s; stdout:
signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.J4Zi2r/state/hibit.status
== supervisor runs fm-wake-drain.sh:
   | 1793049040	2	signal	hibit.status	signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.J4Zi2r/state/hibit.status
   | wake annotation: unread wake-EVENT since last drain, not current state: hibit.status: working [corr=569778d7b062cc35]: on it
   | wake annotation: unread wake-EVENT since last drain, not current state: hibit.status: blocked [key=pending-reply-569778d7b062cc35] [at=1793049034]: pending-reply-unreported: task=hibit pending-reply-id=569778d7b062cc35 request=check the PR 367 canvas - acknowledged only, no result reached main
   | wake annotation: unread wake-EVENT since last drain, not current state: hibit.status: done [corr=569778d7b062cc35]: canvas fixed in PR 367
   | wake annotation: latest wake-EVENT observed at drain, not current state: hibit.status: resolved [key=pending-reply-569778d7b062cc35] [at=1793049035]: pending-reply-resolved: task=hibit pending-reply-id=569778d7b062cc35 via=status
   | UNREAD STATUS (new since last drain, not re-printed after this presentation):
   | hibit resolved [key=pending-reply-569778d7b062cc35] [at=1793049035]: pending-reply-resolved: task=hibit pending-reply-id=569778d7b062cc35 via=status
== drain acked through 2
== restarting watcher for 35s
== second watcher still blocking after 35s (NO REPEAT WAKE)
== hibit.status:
   working [corr=569778d7b062cc35]: on it
   blocked [key=pending-reply-569778d7b062cc35] [at=1793049034]: pending-reply-unreported: task=hibit pending-reply-id=569778d7b062cc35 request=check the PR 367 canvas - acknowledged only, no result reached main
   done [corr=569778d7b062cc35]: canvas fixed in PR 367
   resolved [key=pending-reply-569778d7b062cc35] [at=1793049035]: pending-reply-resolved: task=hibit pending-reply-id=569778d7b062cc35 via=status
== open decisions:
== record: escalation_wake_due_epoch=1793049049 escalated_epoch=1793049034 phase=resolved 
Evidence: Delivery-unknown still wakes at once despite the 1h hold

Source: Delivery-unknown still wakes at once despite the 1h hold

== baseline announced
== record before watcher: phase=delivery_unknown
== watcher EXITED (WAKE) after 3s; stdout:
signal: /var/folders/vr/_90lw3_s0bs_nw2f7b6t9yrm0000gn/T//fm-lab.qSQqFC/state/hibit.status
== hibit.status:
   blocked [key=pending-reply-349ea0d755874c42] [at=1793049162]: pending-reply-delivery-unknown: task=hibit pending-reply-id=349ea0d755874c42 request=check the PR 367 canvas
== open decisions:
   pending-reply-349ea0d755874c42	blocked	pending-reply-delivery-unknown: task=hibit pending-reply-id=349ea0d755874c42 request=check the PR 367 canvas== record: escalation_wake_due_epoch= escalated_epoch=1793049162 phase=escalated 
Evidence: Lab driver script used for all scenarios

Source: Lab driver script used for all scenarios

#!/usr/bin/env bash
# Drive the real bin/fm-watch.sh in a disposable lab FM_HOME for one scenario.
# usage: drive-watch.sh <scenario> <hold-secs> <watch-seconds>
#   scenario: quiet | closed-by-main
set -u
ROOT=${ROOT:?}
scen=$1 hold=$2 budget=$3
LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX"); rmdir "$LAB"
"$ROOT/bin/fm-lab-home.sh" create "$LAB" >/dev/null
state="$LAB/state"; status="$state/hibit.status"
clean() { [ -n "${WPID:-}" ] && kill "$WPID" 2>/dev/null; wait 2>/dev/null; rm -rf "$LAB"; }
trap clean EXIT
run_env() { env -u NO_MISTAKES_GATE -u FM_GATE_REFUSE_BYPASS -u FM_ROOT_OVERRIDE -u FM_STATE_OVERRIDE \
  -u FM_DATA_OVERRIDE -u FM_CONFIG_OVERRIDE -u FM_PROJECTS_OVERRIDE FM_HOME="$LAB" \
  FM_PENDING_REPLY_ACK_SECS=0 FM_PENDING_REPLY_WAKE_HOLD_SECS="$hold" "$@"; }
# A delivered request to second mate hibit that acknowledged with working: and went quiet.
corr=$(UNKNOWN=${UNKNOWN:-} run_env bash -c '. "$1/bin/fm-pending-reply-lib.sh"
  c=$(fm_pending_reply_create "$FM_HOME" "$FM_HOME/state" hibit "check the PR 367 canvas")
  if [ "${UNKNOWN:-}" = 1 ]; then fm_pending_reply_prepare_delivery "$FM_HOME/state" "$c" >/dev/null; fm_pending_reply_mark_delivery_unknown "$FM_HOME/state" "$c" >/dev/null
  else fm_pending_reply_mark_delivered "$FM_HOME/state" "$c" >/dev/null; fi
  printf "%s" "$c"' _ "$ROOT")
if [ "${UNKNOWN:-}" = 1 ]; then : > "$status"; else printf 'working [corr=%s]: on it\n' "$corr" > "$status"; fi
run_env bash -c '. "$1/bin/fm-pending-reply-lib.sh"; fm_pending_reply_try_resolve "$FM_HOME/state" "$2" || true' _ "$ROOT" "$corr"
run_env bash -c '. "$1/bin/fm-wake-lib.sh"; fm_wake_status_mark_current "$2" "$3" && echo "== baseline announced"' _ "$ROOT" "$state" "$status"
echo "== record before watcher: phase=$(grep '^phase=' "$state"/pending-replies/* | cut -d= -f2)"
if [ "$scen" = closed-by-main ]; then
  # First tick escalates quietly; then main closes the key exactly as fm-send --resolve-key writes it.
  run_env bash -c '. "$1/bin/fm-pending-reply-lib.sh"; fm_pending_reply_tick "$FM_HOME/state"' _ "$ROOT"
  key="pending-reply-$corr"
  note=$(run_env bash -c '. "$1/bin/fm-pending-reply-lib.sh"; fm_pending_reply_close_note_for_key "$2" hibit operator-resolve-key handled' _ "$ROOT" "$key")
  printf 'resolved [key=%s]: %s\n' "$key" "$note" >> "$status"
  run_env bash -c '. "$1/bin/fm-wake-lib.sh"; fm_wake_status_mark_current "$2" "$3" && echo "== baseline announced"' _ "$ROOT" "$state" "$status"
  echo "== main closed $key; open decisions now: [$(run_env bash -c '. "$1/bin/fm-classify-lib.sh"; status_open_decisions "$2"' _ "$ROOT" "$status")]"
fi
if [ "$scen" = reply-in-hold ]; then
  run_env bash -c '. "$1/bin/fm-pending-reply-lib.sh"; fm_pending_reply_tick "$FM_HOME/state"' _ "$ROOT"
  echo "== quiet escalation open: [$(run_env bash -c '. "$1/bin/fm-classify-lib.sh"; status_open_decisions "$2"' _ "$ROOT" "$status" | cut -f1)]"
  printf 'done [corr=%s]: canvas fixed in PR 367\n' "$corr" >> "$status"
  echo "== mate hibit replies inside the hold: done [corr=$corr]"
fi
out="$LAB/watch.out"; start=$(date +%s)
run_env FM_POLL=1 FM_SIGNAL_GRACE=1 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 \
  FM_SECONDMATE_LIVENESS_SECS=99999999 "$ROOT/bin/fm-watch.sh" > "$out" 2>"$LAB/watch.err" &
WPID=$!
while kill -0 "$WPID" 2>/dev/null && [ $(( $(date +%s) - start )) -lt "$budget" ]; do sleep 0.5; done
if kill -0 "$WPID" 2>/dev/null; then echo "== watcher still blocking after ${budget}s (NO WAKE)"; kill "$WPID"; else
  echo "== watcher EXITED (WAKE) after $(( $(date +%s) - start ))s; stdout:"; cat "$out"; fi
WPID=
drain() {  # run fm-wake-drain as the supervisor does, then ack it
  local err="$LAB/drain.err" seq gen
  echo "== supervisor runs fm-wake-drain.sh:"
  run_env "$ROOT/bin/fm-wake-drain.sh" 2>"$err" | sed 's/^/   | /'
  seq=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--ack-through \([0-9][0-9]*\) --recovery-generation .*$/\1/p' "$err")
  gen=$(sed -n 's/^WAKE_ACK_REQUIRED:.*--recovery-generation \([A-Za-z0-9._-][A-Za-z0-9._-]*\)$/\1/p' "$err")
  if [ -n "$seq" ]; then run_env "$ROOT/bin/fm-wake-drain.sh" --ack-through "$seq" --recovery-generation "$gen" >/dev/null 2>&1 && echo "== drain acked through $seq"; fi
}
if [ -n "${RESTART:-}" ]; then
  drain
  echo "== restarting watcher for ${RESTART}s"
  start=$(date +%s)
  run_env FM_POLL=1 FM_SIGNAL_GRACE=1 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 \
    FM_SECONDMATE_LIVENESS_SECS=99999999 "$ROOT/bin/fm-watch.sh" > "$out" 2>>"$LAB/watch.err" &
  WPID=$!
  while kill -0 "$WPID" 2>/dev/null && [ $(( $(date +%s) - start )) -lt "$RESTART" ]; do sleep 0.5; done
  if kill -0 "$WPID" 2>/dev/null; then echo "== second watcher still blocking after ${RESTART}s (NO REPEAT WAKE)"; kill "$WPID"; else
    echo "== second watcher EXITED (WAKE) after $(( $(date +%s) - start ))s; stdout:"; cat "$out"; fi
  WPID=
fi
echo "== hibit.status:"; sed 's/^/   /' "$status"
echo "== open decisions:"; run_env bash -c '. "$1/bin/fm-classify-lib.sh"; status_open_decisions "$2"' _ "$ROOT" "$status" | sed 's/^/   /'
echo "== record: $(grep -E '^(phase|escalated_epoch|escalation_wake_due_epoch)=' "$state"/pending-replies/* | tr '\n' ' ')"

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-pending-reply-lib.sh:1499 - The held-escalation reminder never checks whether the keyed decision is still open before it reopens it and wakes the supervisor. Example: hibit's request escalates quietly as blocked [key=pending-reply-&lt;corr&gt;] and shows up in the next drain's OPEN DECISIONS. Main handles it with fm-send hibit --resolve-key pending-reply-&lt;corr&gt; .... fm-send closes the decision with an operator-resolve-key note (fm-send.sh:607, fm_pending_reply_close_note_for_key), but the record stays phase=escalated with escalation_wake_due_epoch still set. Once the hold runs out, fm_pending_reply_tick calls fm_pending_reply_wake_held_escalation. try_resolve fails because there is no correlated report. fm_pending_reply_escalation_line (line 1248) still finds the original blocked line, because it matches text and ignores whether the decision is open. The plain append at line 1502 then reopens a decision main already closed and wakes the supervisor for a bookkeeping-only turn, which is the waste the intent sets out to remove. Fix: before appending, apply the same open-decision check _fm_pending_reply_close_escalation_locked uses (lines 1308-1316): scan status_open_decisions for the escalation's key and note, and when the key is no longer open, clear escalation_wake_due_epoch without appending. Related: when escalation_line returns empty (status file missing or replaced), the function clears the due epoch without waking. That contradicts the comment at line 1444 that 'a miss is never dropped', so that case should be handled on purpose too.
  • ℹ️ bin/fm-pending-reply-lib.sh:1500 - The reminder text 'still unresolved after $((hold / 60))m' reads FM_PENDING_REPLY_WAKE_HOLD_SECS when the reminder fires, not the hold that set the due time. If the env value changes between escalation and reminder (for example a restart with a new value, or 0), the label is wrong, e.g. 'after 0m'. A more accurate value is now minus escalated_epoch, both already in the record.

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

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Unreported escalation with the default 1h hold lists as an open decision but does not wake the watcher (vs. hold=0 baseline waking in 2s) ✅ pass live 01-hold0-baseline-wakes-at-once.txt, 02-hold3600-quiet-no-wake.txt
Escalation still unresolved after the hold wakes the supervisor exactly once with a reminder under the same key ✅ pass live 03-hold-expires-wakes-once.txt
Adversarial: main closes the quiet decision (fm-send --resolve-key close note) before the hold ends; the reminder must not reopen it or wake ✅ pass live 04-closed-by-main-not-reminded.txt
Mate replies inside the hold: decision closes and no reminder wake follows ✅ pass live 05-reply-inside-hold-closes-quietly.txt
Guard: delivery-unknown (transport fault) escalations still wake at once despite the hold ✅ pass live 06-delivery-unknown-wakes-at-once.txt; tests/fm-pending-reply.test.sh
  • drive-watch.sh quiet 0 25: real fm-watch.sh in a lab FM_HOME with FM_PENDING_REPLY_WAKE_HOLD_SECS=0 (old behavior baseline)
  • drive-watch.sh quiet 3600 40: same request with the default 1h hold; watcher observed for 40s
  • RESTART=40 drive-watch.sh quiet 15 60: 15s real-time hold expires, supervisor drains and acks via bin/fm-wake-drain.sh, then a re-armed watcher is observed for 40s
  • drive-watch.sh closed-by-main 15 45: main closes key pending-reply-<corr> with the fm-send --resolve-key close note before the hold ends; watcher observed past the hold
  • RESTART=35 drive-watch.sh reply-in-hold 15 30: mate hibit writes done [corr=...] inside the hold; drain, ack, and re-armed watcher observed past the hold
  • UNKNOWN=1 drive-watch.sh quiet 3600 30: delivery-unknown record with the 1h hold
  • bash tests/fm-pending-reply.test.sh (focused file, includes the 5 new quiet-escalation tests)
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

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

✅ **Push** - passed

✅ No issues found.

A missed or unreported pending-reply escalation woke the supervisor at once,
though the mate had usually acknowledged or answered where main already saw it.
Publish it as a self-announced decision (listed in OPEN DECISIONS, no wake) and
wake once, with a reminder under the same key, only if it is still unresolved
after FM_PENDING_REPLY_WAKE_HOLD_SECS (default 3600). Delivery-unknown and
recovery-delivery escalations still wake at once.
@uayyagari
uayyagari marked this pull request as draft October 26, 2026 18:01
@uayyagari
uayyagari marked this pull request as ready for review October 26, 2026 20:55
@uayyagari
uayyagari merged commit 4f1622b into main Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant