Skip to content

fix(bin): stop stall alarms for leftover windows of retired tasks - #7959

Open
zestysoft wants to merge 3 commits into
kunchenguid:mainfrom
zestysoft:fm/firstmate-orphan-terminal-alarms
Open

zestysoft wants to merge 3 commits into
kunchenguid:mainfrom
zestysoft:fm/firstmate-orphan-terminal-alarms

Conversation

@zestysoft

@zestysoft zestysoft commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #8407

Intent

Stop supervision raising an alarm for terminal windows left behind by tasks that have already been retired, so a leftover window stops costing a wake, a pane check, and a report each time.

Context to read it: three windows left behind by landed, retired tasks each produced a stalled-worker alarm. The control path refuses to close them because no task record exists any more, and closing their workspace reports not-found, so today only the captain can shut them by hand. The alarm is not protecting anything - the work it points at is already landed and cleaned up.

What Changed

  • handle_push_transition in bin/fm-push-transition-lib.sh now checks whether a surviving task record actually owns the window that sent the edge. It does this by matching the record's target from fm_backend_target_of_meta against the window. If nothing owns the window, the edge is written to the triage log as absorbed push … (leftover endpoint, no task record) and its dedupe marker is committed. It returns early, so no stall row is queued and the supervisor is not woken.
  • tests/fm-supervision-events.test.sh gets three new cases: a blocked edge on a live task's window still raises one stall and one wake; an edge from a window no record owns queues nothing, wakes nothing, and is logged (also on a repeat edge); and the fallback task name only counts as an owner when that record's window matches.
  • docs/herdr-backend.md adds leftover endpoints to the list of push-path skips. docs/rex-backend.md now links to that list instead of repeating it.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: One small guard that only logs and commits when no task record owns the endpoint. Its ownership check uses fm_backend_target_of_meta, the same helper recorded_windows uses to build the subscribed set, and the target shapes match for herdr, rex and t3code, so live tasks still alarm. The poll stale loop stays the fallback.

Testing

I drove real Herdr lab sessions through the guarded fm-herdr-lab/herdr-test-safety helpers and never touched the default session. First, the existing real-Herdr smoke test showed a live task's blocked edge still enqueues a stale wake. Then a custom lab scenario retired a task while the wait was open and fed the real blocked record to the handler twice. The base commit raised 2 stale wakes. The target commit raised 0 and wrote two triage-log entries instead. The focused supervision-events test file also passes. All lab sessions and scratch state were torn down. The result is go.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Retired task's leftover Herdr window goes blocked (real herdr lab pane, task meta removed mid-wait): no stall wake and no queued stale row, only a triage-log line, on the first and later edges ✅ pass live leftover-endpoint-live.log AFTER section: wakes=0, stale_rows=0, wake-queue empty, 2 'leftover endpoint, no task record' triage entries
Regression repro: the same retired-window blocked edge on the base commit raises a stalled-worker alarm each time ✅ pass live leftover-endpoint-live.log BEFORE section: 2 WAKE lines 'stale: ...:w1:p2 (herdr: agent blocked ...)', 2 stale rows queued
Live task's Herdr window goes blocked (real herdr lab pane with matching task meta): a stale wake is still queued naming the task window ✅ pass live eventwait-smoke-live-task.log: 'ok - real herdr: the watcher fast-path enqueues a stale wake naming the task window from the live blocked transition'
Adversarial: a task record that names a different window must not make an unowned endpoint look owned ✅ pass live supervision-events.log: 'ok - handle_push_transition: only a task record whose endpoint matches counts as an owner'
Evidence: Real-Herdr leftover-window scenario, before vs after

Source: Real-Herdr leftover-window scenario, before vs after

=== AFTER (target commit) ===
[after] retiring task: removing retired1.meta while the wait is open
[after] wait rc=0 pane=w1:p2 to=blocked
[after] after edge 1: wakes=0 stale_rows=0
[after] after edge 2: wakes=0 stale_rows=0
[after] wake-queue:
  (none)
[after] triage log:
[2026-11-06T18:20:31-0800] absorbed push blocked (leftover endpoint, no task record): fm-lab-leftover-after-6154:w1:p2
[2026-11-06T18:20:31-0800] absorbed push blocked (leftover endpoint, no task record): fm-lab-leftover-after-6154:w1:p2
[after] RESULT wakes=0
exit=0
=== BEFORE (base commit bf05a4fc lib) ===
[before] retiring task: removing retired1.meta while the wait is open
[before] wait rc=0 pane=w1:p2 to=blocked
[before] WAKE: stale: fm-lab-leftover-before-11724:w1:p2 (herdr: agent blocked - waiting on human, escalated immediately, not via wedge timer)
[before] after edge 1: wakes=1 stale_rows=1
[before] WAKE: stale: fm-lab-leftover-before-11724:w1:p2 (herdr: agent blocked - waiting on human, escalated immediately, not via wedge timer)
[before] after edge 2: wakes=2 stale_rows=2
[before] wake-queue:
1794018038	1	stale	fm-lab-leftover-before-11724:w1:p2	stale: fm-lab-leftover-before-11724:w1:p2 (herdr: agent blocked - waiting on human, escalated immediately, not via wedge timer)
1794018039	2	stale	fm-lab-leftover-before-11724:w1:p2	stale: fm-lab-leftover-before-11724:w1:p2 (herdr: agent blocked - waiting on human, escalated immediately, not via wedge timer)
[before] triage log:
  (none)
[before] RESULT wakes=2
exit=0
Evidence: Leftover-window live scenario script

Source: Leftover-window live scenario script

#!/usr/bin/env bash
# Live scenario: a real Herdr lab pane whose task is retired (meta removed)
# while the watcher's bounded wait is open emits a real blocked edge. Feed the
# real record to handle_push_transition from LIB_DIR and print what happened.
# Usage: leftover-endpoint-live.sh <repo-root> <lib-dir> <label>
set -u
ROOT=$1; LIB_DIR=$2; LABEL=$3
. "$ROOT/tests/herdr-test-safety.sh"
herdr_forget_inherited_pane
SESSION="fm-lab-leftover-$LABEL-$$"
export HERDR_SESSION="$SESSION"
SCRATCH=
cleanup_all() { [ -n "$SCRATCH" ] && rm -rf "$SCRATCH"; herdr_safe_stop_and_delete "$SESSION"; }
trap cleanup_all EXIT
fm_herdr_lab_prepare "$SESSION" || { echo "prepare failed"; exit 1; }
. "$ROOT/bin/fm-backend.sh"; fm_backend_source herdr
CR=$(fm_backend_herdr_container_ensure /tmp); CONTAINER=${CR%%$'\t'*}; SEED=${CR#*$'\t'}
IDS=$(fm_backend_herdr_create_task "$CONTAINER" "fm-retired1" /tmp "$SEED")
read -r _T PANE_ID <<EOF
$IDS
EOF
TARGET="$SESSION:$PANE_ID"
SCRATCH=$(mktemp -d "${TMPDIR:-/tmp}/fm-leftover.XXXXXX"); STATE="$SCRATCH/state"; mkdir -p "$STATE"
printf 'window=%s\nbackend=herdr\nkind=ship\n' "$TARGET" > "$STATE/retired1.meta"
# an unrelated live task so the state dir is not empty
printf 'window=%s:w99:p99\nbackend=herdr\nkind=ship\n' "$SESSION" > "$STATE/other.meta"
fm_herdr_lab_cli "$SESSION" pane report-agent "$PANE_ID" --source fm-leftover --agent claude --state idle >/dev/null 2>&1
OUT="$SCRATCH/out"; RCF="$SCRATCH/rc"
( fm_backend_herdr_wait_transition "$SESSION" 8 "$STATE" "$TARGET" > "$OUT"; echo $? > "$RCF" ) &
WPID=$!
sleep 0.5
echo "[$LABEL] retiring task: removing retired1.meta while the wait is open"
rm -f "$STATE/retired1.meta"
fm_herdr_lab_cli "$SESSION" pane report-agent "$PANE_ID" --source fm-leftover --agent claude --state blocked >/dev/null 2>&1
wait "$WPID"
REC=$(cat "$OUT"); echo "[$LABEL] wait rc=$(cat "$RCF") pane=$(fm_transition_pane_id "$REC") to=$(fm_transition_to_status "$REC")"
export FM_STATE_OVERRIDE="$STATE" FM_ROOT_OVERRIDE="$ROOT"
. "$LIB_DIR/fm-push-transition-lib.sh"
WAKES=0; wake() { WAKES=$((WAKES+1)); echo "[$LABEL] WAKE: $1"; return 0; }
for edge in 1 2; do
  handle_push_transition herdr "$SESSION" "$REC"
  echo "[$LABEL] after edge $edge: wakes=$WAKES stale_rows=$(awk -F '\t' '$3=="stale"' "$STATE/.wake-queue" 2>/dev/null | wc -l | tr -d ' ')"
  rm -f "$STATE"/.herdr-escalated-* # let the second edge pass dedupe, like a re-block
done
echo "[$LABEL] wake-queue:"; cat "$STATE/.wake-queue" 2>/dev/null || echo "  (none)"
echo "[$LABEL] triage log:"; cat "$STATE/.watch-triage.log" 2>/dev/null || echo "  (none)"
echo "[$LABEL] RESULT wakes=$WAKES"
Evidence: Real-Herdr smoke test: live task still alarms

Source: Real-Herdr smoke test: live task still alarms

ok - real herdr (herdr 0.9.5): events.subscribe capability gate passes (protocol >= 16, events surface present in api schema)
ok - real herdr (herdr 0.9.5): a driven idle->blocked transition returns the blocked record in 0.718s (pane w1:p2)
ok - real herdr: the watcher fast-path enqueues a stale wake naming the task window from the live blocked transition
(all 3 ok lines; script exits 0 after cleanup_all)
Evidence: Focused supervision-events test run

Source: Focused supervision-events test run

ok - handle_push_transition: a blocked crew enqueues a stale wake naming its window and wakes the supervisor
ok - handle_push_transition: a rex blocked edge's wake names the backend and carries Rex's blocked kind and message
ok - handle_push_transition: enqueue failure cannot commit the Herdr dedupe marker
ok - handle_push_transition: a blocked edge on a live task's window still raises a stall
ok - handle_push_transition: an endpoint with no task record is only logged, never a stall or a wake
ok - handle_push_transition: only a task record whose endpoint matches counts as an owner
ok - handle_push_transition: a declared-pause crew is absorbed (no fast wake), left to the poll loop's long cadence
ok - handle_push_transition: a captain-held crew is absorbed (no fast wake), left to the poll loop's long cadence
ok - event_wait_or_sleep: herdr windows go on the event pane list, but kind=secondmate endpoints are excluded
ok - event_wait_or_sleep: herdr keeps the push wait in a mixed home; T3's wait runs only without another push backend
ok - event_wait_or_sleep: one cached capability probe owns validation across bounded waits
ok - event_wait_or_sleep: a home with no push-capable window is inert (sleeps POLL, never touches the event path)
ok - event_wait_or_sleep: consecutive event-path failures disable the fast-path and revert to pure polling (fail-closed)
# fm-supervision-events.test.sh: all assertions passed
exit=0
Evidence: Before/after summary
BEFORE (bf05a4fc): after edge 2: wakes=2 stale_rows=2
AFTER (4ece7bec): after edge 2: wakes=0 stale_rows=0
triage: absorbed push blocked (leftover endpoint, no task record): fm-lab-leftover-after-6154:w1:p2

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 - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Retired task's leftover Herdr window goes blocked (real herdr lab pane, task meta removed mid-wait): no stall wake and no queued stale row, only a triage-log line, on the first and later edges ✅ pass live leftover-endpoint-live.log AFTER section: wakes=0, stale_rows=0, wake-queue empty, 2 'leftover endpoint, no task record' triage entries
Regression repro: the same retired-window blocked edge on the base commit raises a stalled-worker alarm each time ✅ pass live leftover-endpoint-live.log BEFORE section: 2 WAKE lines 'stale: ...:w1:p2 (herdr: agent blocked ...)', 2 stale rows queued
Live task's Herdr window goes blocked (real herdr lab pane with matching task meta): a stale wake is still queued naming the task window ✅ pass live eventwait-smoke-live-task.log: 'ok - real herdr: the watcher fast-path enqueues a stale wake naming the task window from the live blocked transition'
Adversarial: a task record that names a different window must not make an unowned endpoint look owned ✅ pass live supervision-events.log: 'ok - handle_push_transition: only a task record whose endpoint matches counts as an owner'
  • bash tests/fm-backend-herdr-eventwait-smoke.test.sh (real herdr 0.9.5, isolated fm-lab session): live task blocked edge -> stale wake
  • bash $EV/leftover-endpoint-live.sh &lt;root&gt; &lt;bin&gt; after: real herdr lab pane, task meta removed mid-wait, real blocked record fed twice to handle_push_transition at target commit
  • Same script against the base-commit (bf05a4fc) fm-push-transition-lib.sh with unchanged deps, to reproduce the old alarm
  • bash tests/fm-supervision-events.test.sh (focused file covering live-task, retired-endpoint, and mismatched-owner paths)
  • herdr session list --json: checked that no fm-lab-leftover/eventwait session was left behind
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Reviews (3) · Last reviewed commit: "no-mistakes(document): Document push-pat..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zestysoft, the base-vs-target lab run (leftover window logged three times with no stall, while the live window still wakes at once) shows the fix clearly.

I read the diff at 9cb38fd8 against main c9da5523. handle_push_transition now checks that a live .meta actually owns the edge's target, using the same fm_backend_target_of_meta that recorded_windows subscribes with, so herdr, orca and t3code targets resolve the same way on both sides. Unowned edges are logged to the triage log and committed, with no stall and no wake. No workflow, network or credential changes.

  • contract-class: new-default. Today every blocked/question push edge raises a stall. This adds a new skip class to that default alarm path (docs/herdr-backend.md's skip list grows). It's well guarded and low risk, but quieting an alarm by default is Kun's call, so after the full suite passes this goes to him as a merge-or-leave decision rather than an auto-merge.
  • no-mistakes: attestation binds this head, all steps completed. Live 4 of 5. Greptile 5/5 with no open threads. Coverage guard and repo invariants pass.
  • Full suite: the red Full suite check just means outside PRs need our full-ci label first. This is waiting on us to run the full suite, not on you.

Separate note: your #7958 is in a nearby area but changes a different file (bin/fm-wake-lib.sh's reaper tombstone), so I don't see any overlap between the two.

@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Oct 29, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zestysoft. I re-checked every gate on head 9cb38fd8 against main b936f040. Nothing has changed since my last note, so I've added the full-ci label and the full suite is now running (run 40965621978).

This is waiting on our full-suite run, not on you. If it passes, it goes to the captain for a merge-or-leave call (new-default).

@kunchenguid kunchenguid added full-ci Maintainer go-ahead: run the full CI suite on this outside pull request and removed full-ci Maintainer go-ahead: run the full CI suite on this outside pull request labels Oct 30, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zestysoft. The full suite on head 9cb38fd8 (40965621978) failed in one lane, and it isn't from this change. Behavior portable serial 3 failed in tests/fm-wake-queue.test.sh with wake drain: queue lock could not be acquired safely / not ok - concurrent append/drain subprocess failed. That's lock contention on a busy runner. This PR only touches bin/fm-push-transition-lib.sh, two docs and tests/fm-supervision-events.test.sh, and it doesn't touch the wake queue or the lock helpers. Every other lane passed.

I've removed and re-added the full-ci label, so a fresh full suite is now running (40991169187). Nothing is needed from you. If it passes, this goes to the captain for the merge decision, because it changes what the unconfigured watcher does with leftover endpoints.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zestysoft. The fresh full suite on head 9cb38fd8 passed (40991169187, every lane green). The no-mistakes attestation binds this head, Greptile is 5/5, there are no open threads, and live evidence is posted.

Every gate is green, so this is now with the captain for the merge decision. It is not waiting on you. The reason it needs the captain: it adds a new skip class to the default push-stall alarm path (endpoints with no task record stop raising stall wakes), and that changes behaviour for every unconfigured home.

A native push edge on a pane whose task was already retired raised a
stalled-worker alarm that nothing could act on. The push handler now
checks that a surviving task record owns the endpoint; an unowned
leftover is reported once as a housekeeping check and later edges are
only logged. Live task endpoints still alarm unchanged.
@zestysoft
zestysoft force-pushed the fm/firstmate-orphan-terminal-alarms branch from 9cb38fd to 4ece7be Compare November 7, 2026 02:22
@zestysoft zestysoft changed the title fix(bin): stop push stall alarms for endpoints with no task record fix(bin): stop stall alarms for leftover windows of retired tasks Nov 7, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @zestysoft. Tip refreshed to 4ece7bec against main bf05a4fc, with full-ci already labelled and the Full suite green on this exact head (every lane, including Herdr / herdr-core / portable / lint).

Re-checked on tip: handle_push_transition only raises a stall when a surviving .meta owns the edge's window via fm_backend_target_of_meta (same helper recorded_windows uses). Unowned leftover endpoints are triage-logged and committed, with no stall and no wake; live tasks still alarm. Live A/B against real herdr: base raised 2 stale wakes, tip raised 0 with two leftover-endpoint triage lines. No workflow, credential, or checksum changes. Greptile tip green; 0 open threads. no-mistakes binds 4ece7bec with no skipped steps. MERGEABLE CLEAN. Rockets: none.

Contract-class stays new-default. Today every blocked/question push edge on a mapped window raises a stall. This adds a new skip class to that default alarm path (docs/herdr-backend.md's skip list grows). Quietening an alarm by default for every unconfigured home is Kun's merge-or-leave call, not an auto-merge.

VISION: One captain aligns (less false noise) · Authority → captain call (new default skip) · Scripts own the mechanics aligns · Restart aligns · Delegation aligns (field leftover windows → regression) · Vendor aligns (herdr/rex/t3code via shared target helper) · Scope aligns.

Still waiting on Kun, not on you. Every gate is green on this tip, so this stays with the captain for the merge decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leftover windows of retired tasks keep raising stalled-worker alarms that cannot be cleared

2 participants