Skip to content

fix(bin): bound stale alarms for backlog captain holds - #3842

Merged
kunchenguid merged 10 commits into
kunchenguid:mainfrom
mremond:fm/fm-stale-alarm-ignores-backlog-hold
Sep 7, 2026
Merged

kunchenguid merged 10 commits into
kunchenguid:mainfrom
mremond:fm/fm-stale-alarm-ignores-backlog-hold

Conversation

@mremond

@mremond mremond commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Propose an upstream PR that completes the fix the maintainer has already accepted on spurious watcher alarms, and present it so the maintainer can approve it easily without reconstructing the context.

The already-accepted fix this refers to is upstream issue #3443, opened 2026-09-01 and now closed. It established that a stale alarm on a quiet pane must consult the declared wait BEFORE queueing the wake. surface_nonterminal_stale in bin/fm-watch.sh now calls status_is_paused_or_captain_held and checks the .paused-resurfaced- cadence marker against PAUSE_RESURFACE_SECS before fm_wake_append, so a worker stopped on a declared wait alarms once and then has its pane churn absorbed for the window.

This PR completes that fix on the one wait source it does not read. A task that has been delivered and held for the captain records that wait in the backlog through bin/fm-captain-hold.sh, not in the status log, so its last status line stays "done: PR ..." for the whole time the decision is pending, and the alarm is queued against it anyway. Apply the same principle, in the same function, with the same cadence marker, to that remaining wait source.

What Changed

  • Consult open backlog captain calls before queueing terminal or inconclusive stale-pane wakes, reusing the existing resurfacing cadence while preserving unheld-task and secondmate behavior.
  • Expose captain-call lifecycle identity so released-and-reheld tasks start a fresh throttle window, and record throttle markers only after the wake is durably queued.
  • Document the dual wait records, add regression coverage for held, unheld, failed-append, and re-held cases, and isolate Herdr recovery fixtures from claimed worktree slots.

Risk Assessment

✅ Low: The change is bounded to stale-alarm handling, preserves first-sighting alarms, and continues alarming when the backlog hold cannot be proven open.

Testing

The initial ephemeral runner attempt stopped before scenarios because of a helper-path setup error; after correcting it, all focused target tests and manual controls passed, while the supplied base reproduced the defect. Reviewer-visible CLI transcripts were captured; no screenshot was applicable because this is a shell watcher/notification-queue change with no rendered UI. The broad repository suite was intentionally not run.

Evidence: Before-fix reproduction

Source: Before-fix reproduction

Base commit reproduced the duplicate-notification defect during held-delivery pane churn.

BASELINE REPRODUCTION: supplied base commit 6d396da7
not ok - [held-delivery] watcher exited during pane churn instead of supervising through it
baseline runner exit code: 1 (non-zero expected because the regression must reproduce)
Evidence: Target watcher behavior

Source: Target watcher behavior

Target transcripts show held work suppressing intermediate pane churn, cadence resurfacing, unheld controls continuing to notify, durable-queue retry, re-held lifecycle behavior, and secondmate scope.

FOCUSED TARGET WATCHER ACCEPTANCE RUN: 3a6b5783
ok - a parked live worker surfaces once, absorbs pane churn for the whole re-surface window, then re-surfaces when it elapses
ok - work under an open captain call surfaces once, absorbs pane churn, then re-surfaces when the window elapses
ok - a stale window with no open captain call keeps alarming on every new hash
ok - a wake that never reached the durable queue arms no re-surface throttle
ok - a released-then-re-held task is a distinct captain call whose first sight still alarms
ok - a non-paused secondmate retains normal stale suppression

OBSERVABLE OUTCOMES
held case: held-delivery
  surfaced notifications (first sight plus elapsed cadence): 2
  changed-pane events absorbed while captain call remained open: 2
  queued notification after cadence elapsed: 1
held case: held-worker-line
  surfaced notifications (first sight plus elapsed cadence): 2
  changed-pane events absorbed while captain call remained open: 4
  queued notification after cadence elapsed: 1
unheld control: unheld-delivery
  surfaced notifications across two changed-pane sightings: 2
unheld control: unheld-blocker
  surfaced notifications across two changed-pane sightings: 2
unheld control: unheld-worker-line
  surfaced notifications across two changed-pane sightings: 2
released and re-held lifecycle control:
  surfaced notifications (first call, then distinct re-held call): 2
  second call notification currently queued: 1
durability control after failed queue append:
  successful retry notification currently queued: 1
RESULT: accepted watcher behavior demonstrated end to end through fm-watch.sh, fm-captain-hold.sh, tasks-axi, and the durable notification queue.
Evidence: Safety controls

Source: Safety controls

Unreadable backlog produced two notifications; three stable polls made zero tasks-axi calls; the due changed-pane check consulted tasks-axi and suppressed the duplicate notification.

FOCUSED SAFETY CONTROLS: target 3a6b5783
ok - unreadable captain-call backlog left both changed-pane notifications unsuppressed
  surfaced notifications across two sightings: 2
ok - backlog consultation stayed off the ordinary poll path and occurred only when a changed-pane notification was due
  tasks-axi invocations during three stable ordinary polls: 0
  tasks-axi invocations after changed-pane notification became due: 5
  notifications queued for the held changed-pane sighting inside cadence: 0
RESULT: only a proven readable open captain call bounds a due notification; ordinary polls remain backlog-free.

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.

  • Targeted test_live_declared_wait_churn_honors_the_resurface_throttle, test_open_captain_call_bounds_stale_churn, test_stale_churn_without_a_captain_call_still_alarms, test_failed_wake_append_does_not_arm_the_captain_hold_throttle, test_reheld_captain_call_starts_its_own_resurface_window, and test_secondmate_nonpaused_stale_remains_suppressed from tests/fm-watch-triage.test.sh
  • Ran test_open_captain_call_bounds_stale_churn against a temporary git archive 6d396da7c43f03315873332b2591119a8c780a97; it reproduced the pre-fix repeated-notification failure
  • Manually drove fm-watch.sh, fm-captain-hold.sh, tasks-axi, and the durable notification queue with an unreadable-backlog control
  • Manually counted tasks-axi calls across three stable polls and a due changed-pane classification to verify backlog consultation remains off the ordinary polling path
  • Rechecked git status --short and target commit/tree after testing
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported re-held-call suppression failure is fixed because the throttle scope now includes a lifecycle identity that changes when an answer is recorded and the task is held again; no blocking failure remains.

Reviews (6): Last reviewed commit: "fix(ci): isolate the Herdr restart fixtu..." | Re-trigger Greptile

Comment thread bin/fm-watch.sh Resolved
@mremond mremond changed the title fix(bin): bound stale alarms for backlog captain holds fix(bin): bound stale alarms during captain holds Sep 6, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on HEAD c8581105c5cd84a13277c60db0d516f72da54d62. Extends #3443's wait-before-stale-alarm principle to backlog captain holds (terminal-stale + open --identity), so a hold the line predicate cannot see still bounds pane-churn alarms.

Contract-class: restore. Same principle as #3443 for the hold record; no new unconfigured always-on behavior. Unheld paths keep alarming.

Attestation MATCH tip. Greptile SUCCESS 5/5. Tip NM SUCCESS (34038223601). CI run 34038084492 still in_progress (serial portable jobs pending; parallel/Herdr/Lint green so far). MERGEABLE/UNSTABLE — not merging until CI fully green.

No competing PR on this surface. Security: clean tip expected (bin/docs/tests only; no workflow writes) — FYI only, not a captain card.

VISION (per rule):

  • One captain, one interface — aligns (bounds noise during an open captain decision without hiding the first sight).
  • Authority is explicit — aligns (no new autonomy; hold already recorded).
  • Scripts own the mechanics — aligns (watcher + captain-hold identity).
  • A restart is a non-event — aligns (durable hold/throttle markers).
  • Delegation with a spine — aligns (narrow restore of promised wait semantics).
  • The fleet outlives any vendor — aligns (scripted, harness-agnostic).
  • Scope — aligns (supervision continuity under captain holds).

Stamp waiting-ci restore. Revisit when CI 34038084492 completes green.

@mremond
mremond force-pushed the fm/fm-stale-alarm-ignores-backlog-hold branch from c858110 to d09f953 Compare September 7, 2026 01:51
@mremond mremond changed the title fix(bin): bound stale alarms during captain holds fix(bin): throttle stale alarms for backlog captain holds Sep 7, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Newer activity on HEAD d09f953c358c5047ffa7fb823c14ee5d3e8a486e (moved past prior stamp c8581105). Still extends #3443's wait-before-stale-alarm principle to backlog captain holds, now binding the throttle to captain-call lifecycle identity (--identity hold-set stamp + answer count) so re-holds start a fresh bound.

Contract-class: restore. Same promised wait semantics for an open captain hold; unheld paths keep alarming.

Attestation MATCH. Greptile 5/5. Tip NM SUCCESS. CI run 34074352902: Behavior tests (Herdr) FAILURE — tests/fm-backend-herdr-presentation-e2e.test.sh (not ok - concurrent primary recovery teardown failed / watcher-still-down banner). Other portable/Lint/invariants green. MERGEABLE/UNSTABLE — not merging.

VISION: One captain — aligns (bounds noise during an open decision). Authority — aligns. Scripts — aligns. Restart — aligns (lifecycle identity). Delegation — aligns. Fleet — aligns. Scope — aligns.

Security: bin/docs/tests only — FYI only.

Stamp waiting-author restore. Please clear the Herdr presentation e2e failure on this tip (or show it flake-only with a green re-run). Not waiting on the captain.

@mremond
mremond force-pushed the fm/fm-stale-alarm-ignores-backlog-hold branch from f1c9ea5 to 21920de Compare September 7, 2026 07:47
…tus line

A legitimate wait has two records and the stale alarm reads only one.
`status_is_paused_or_captain_held` takes a status line, so it sees a wait the
worker declared. It cannot see the wait firstmate records when it hands work to
the captain: `bin/fm-captain-hold.sh hold` writes that into the backlog and
leaves the status log alone, so a delivered task keeps `done: PR ...` as its
last line for the whole time the captain is deciding.

Both stale branches were blind to it, and each churned a new pane hash back into
its own alarm: a `done:` line is captain-relevant and reaches the terminal-stale
branch, while a held task whose last line is `working:` reaches
`surface_nonterminal_stale` and fails its declared-wait test.

Consult that second record where the watcher is about to alarm, through
`bin/fm-captain-hold.sh open`, which already owns the predicate's semantics, and
bound the alarm on the shared `.paused-resurfaced-<key>` marker and
`PAUSE_RESURFACE_SECS` window the declared-wait absorb already uses. The first
sight still alarms, the window's end alarms once more, and a held crew that goes
genuinely silent still escalates through the wedge timer.

Only an established open captain call bounds anything: an unreadable backlog, an
absent or incompatible tasks-axi, a row this home does not carry, and every task
with no hold keep alarming exactly as before. The backlog hold is deliberately
not recorded as a declared pause, because the loop-top reconciliation and
`pause_state_class` both read the status line and would clear a flag that line
does not support.

Extends the fix in kunchenguid#3443, which closed the forms of this loop that the status
line itself can express.
Three gaps in the bound added by the previous commit, all in how the throttle is
scoped and where the backlog is consulted.

The scope carried only the status-log signature. A task can be held, answered
with `--release`, and re-held as a genuinely different captain call without any
status append, so the second call inherited the first one's marker and its first
sight was absorbed - the one thing this bound must never do. The task id is not
the call: `bin/fm-captain-hold.sh open` gains `--identity`, which reports the
call's own lifecycle - its hold-set stamp and the number of recorded answers -
on an exit 0 and only then, leaving the silent predicate every existing caller
reads unchanged. The throttle scope now carries that identity.

The terminal path recorded the throttle before publishing the durable wake. A
failed append exits the watcher with nothing queued, and the next sighting then
read that fresh marker and absorbed the retry, turning a delayed alarm into a
lost one. Recording moves behind the append, as the non-terminal path already
had it, and the comment claiming the marker could not outlive its wake is gone
because it was false.

The backlog was consulted only on a new terminal pane hash. A captain call can
open after a hash was absorbed as provably working, changing neither the pane nor
the status log, so nothing re-read the backlog and the wedge timer kept firing
possible-wedge alarms through a legitimate wait. That timer now consults the call
at its own alarm boundary and takes the same bounded cadence - and only at that
boundary, so an ordinary repeat poll under the bound stays the local-only read it
was.

Regression coverage for each, all driving churn through one watcher process
rather than relaunching per pane change: relaunch cost dominated the earlier
shape, and an absorbing watcher stays in its poll loop across churn in production
anyway. An unheld task still alarms on every new hash, and an elapsed wedge timer
with no open captain call still escalates as a possible wedge.
Lifts the lifecycle-identity and cadence-ownership work back out, leaving the
change at the shape that matches the defect actually observed: the stale alarm
did not consult the backlog captain hold, on either stale branch.

Reviewing the wider version surfaced a series of adjacent gaps in the watcher's
alarm state machine - a call opening after the first alarm, marker invalidation
at the hold lifecycle boundary, and which deadline a terminal timer represents.
They are real, but fixing them turns a small extension into a state-machine
change to the alarm path, which is a different review on a subsystem that is
being actively reworked. They are named as known limitations rather than carried
here, and none of them is load-bearing for what remains: the bound does strictly
less than the reverted version, leaves the wedge path escalating on
STALE_ESCALATE_SECS exactly as before, and introduces no silence that the
existing terminal-alarm path did not already have.

Kept from the reverted work is the record-after-append ordering, because that is
a defect in the code being shipped rather than an adjacent one: recording the
cadence marker before publishing the durable wake let a failed append lose an
alarm outright instead of delaying it.

History is preserved: the earlier commits stay on the branch and this removal
sits on top of them.
… log

The throttle this change introduces was scoped to the task's status-log
signature. Answering a call with `--release` and holding the task again creates a
genuinely different captain call without necessarily appending to that log, so
the second call inherited the first one's marker and its first sight was
absorbed.

That is the one alarm this bound must never swallow. A delivery announced twice
is noise; a decision waiting on the captain that is never surfaced is invisible,
because nobody asks for what they do not know to ask for.

Measured rather than assumed, on the same fixture - a delivered task held for the
captain, released, and re-held with no status append, driven through bin/fm-watch.sh:

  base c499f84    call-1 first=ALARM  call-1 churn=ALARM     new call first sight=ALARM
  before this fix call-1 first=ALARM  call-1 churn=absorbed  new call first sight=absorbed
  after           call-1 first=ALARM  call-1 churn=absorbed  new call first sight=ALARM

Base never suppresses the new call, so the suppression came from this change and
closing it completes the fix rather than widening it.

`bin/fm-captain-hold.sh open` gains `--identity`, printing the call's lifecycle -
its hold-set stamp and count of recorded answers - on an exit 0 and only then, so
the silent predicate bin/fm-teardown.sh reads is untouched. The throttle scope
carries that identity beside the status signature.

The sibling case was measured too and is NOT included: on the status-declared
path, where the last line is `captain-held:`, base already absorbs a re-held
call's first sight. That behaviour predates this change and stays documented as a
known limitation rather than repaired here.
The Herdr behaviour test intermittently reused a local worktree still claimed
by an earlier fixture after a restart.
The restart scenarios now use an isolated Treehouse project.

The full Herdr test passes on Herdr 0.8.2; bash -n and git diff --check pass as
well.
@mremond
mremond force-pushed the fm/fm-stale-alarm-ignores-backlog-hold branch from 21920de to 3a6b578 Compare September 7, 2026 08:41
@mremond mremond changed the title fix(bin): throttle stale alarms for backlog captain holds fix(bin): bound stale alarms for backlog captain holds Sep 7, 2026
@kunchenguid
kunchenguid merged commit d4eb228 into kunchenguid:main Sep 7, 2026
16 of 17 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

eduardstan added a commit to eduardstan/firstmate that referenced this pull request Sep 7, 2026