Skip to content

fix(wake): label drained wakes ROUTINE or ATTENTION to cut captain noise - #4459

Closed
pablontiv wants to merge 5 commits into
kunchenguid:mainfrom
pablontiv:fm/fix-3984-wake-noise
Closed

pablontiv wants to merge 5 commits into
kunchenguid:mainfrom
pablontiv:fm/fix-3984-wake-noise

Conversation

@pablontiv

@pablontiv pablontiv commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Routine watcher wakes surface as generic 'Stop hook feedback' blocks in the captain view: important messages get lost in the noise. Fix the presentation layer so a wake needing no captain action is distinguishable from one that does, without dropping or weakening the durable wake-queue/acknowledgement guarantees.

What Changed

  • bin/fm-wake-drain.sh: add wake_row_needs_attention and print_wake_presentation_class, which classify each non-empty drain's raw batch as ROUTINE or ATTENTION (heartbeats always routine, check/inactive-outcome rows always attention, signal/stale rows attention only when their status span has an unread captain-relevant record or an unsafe-to-read status file) and print a leading WAKE CLASS: line before the raw rows, without altering queue contents, wake eligibility, or acknowledgement.
  • bin/fm-wake-lib.sh: in fm_wake_print_annotations, change a failed fm_wake_status_cursor_offset read from aborting the whole annotation pass (return 1) to skipping just that status file (continue), so one unreadable status file no longer suppresses annotations for the rest of the batch.
  • docs/architecture.md: document the new WAKE CLASS presentation line and the rejected per-fingerprint "already surfaced" downgrade design.
  • tests/fm-wake-queue.test.sh and tests/fm-inactive-reconcile.test.sh: add coverage for the ROUTINE/ATTENTION classification, including inactive-outcome/inactive-reconcile rows always surfacing as ATTENTION.

Risk Assessment

✅ Low: Both confirmed prior findings were addressed exactly per user instructions: inactive-outcome/inactive-reconcile check wakes are now unconditionally ATTENTION on every presentation, and the captain-surfaced downgrade mechanism (which risked poisoning presentation state via automated drains) was fully removed with no dangling references; new tests exercise real drain/report behavior rather than source-grepping, and the header comments accurately document the rejected-downgrade rationale.

Testing

Correction-only turn, no tools run. Per validation error, scenario 4 lacked a live=true drive to support its pass verdict (only a static grep was performed) and has been downgraded to untested with empty evidence and a stated reason. All other scenarios in the rejected payload already recorded live=true with non-empty evidence and are preserved unchanged.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Routine wake presented distinctly (heartbeat/no-op signal) ✅ pass live Manual live drain: appended a heartbeat wake via fm_wake_append, ran bin/fm-wake-drain.sh directly — output began with 'WAKE CLASS: ROUTINE - queued records declare no new captain-relevant event; supe…
Attention wake presented distinctly (actionable signal/check) ✅ pass live Manual live drain: appended a check inactive-outcome:child1 wake, drained it directly — output began with 'WAKE CLASS: ATTENTION - at least one queued record carries a new captain-relevant event or…
Inactive-outcome/inactive-reconcile check wakes are ATTENTION on every presentation, including a repeat (round-1 fix) ✅ pass live bash tests/fm-inactive-reconcile.test.sh — test_inactive_outcome_wake_is_always_attention and test_inactive_reconcile_notice_wake_is_attention both ok, driving the real fm-inactive-reconcile.sh queue…
captain-surfaced downgrade mechanism fully removed (round-2 fix) ⏸️ untested no Prior payload only ran a static grep for captain_surfaced/mark_captain_surfaced with live=false; that does not establish a live result for this scenario, so it cannot be recorded as pass without a liv…
Adversarial: symlink-swapped/escaped status file fails closed to ATTENTION, never leaks content ✅ pass live Manual live drain: created escape.status as a symlink to an out-of-state file containing 'must-not-be-read', appended a signal wake pointing at it, drained directly — output was ATTENTION and did not…
Regression: race-safety annotation on a mid-read symlink swap is preserved, not dropped (round-1 finding test-1 fix) ✅ pass live tests/fm-wake-queue.test.sh::test_structural_signal_enrichment_preserves_raw_rows — ok on 3/3 isolated runs and 3/3 full-suite runs; this is the exact regression test that failed on commit edb2a02 per…
Queue mechanics (durability, dedup, malformed-field counting) unaffected by the new WAKE CLASS presentation line ✅ pass live tests/fm-wake-queue.test.sh::test_concurrent_append_and_drain and test_drain_dedupes_obvious_duplicates (both updated to exclude the new WAKE CLASS line from field-count assertions) — ok across 3 full…
  • Outcome: 🔧 2 issues found → auto-fixed ✅ across 2 runs (36m24s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (2) ✅
  • 🚨 bin/fm-wake-drain.sh:626 - wake_row_needs_attention() treats check wakes keyed inactive-outcome:* (and inactive-reconcile:*) as ROUTINE (return 1), but these are exactly the wakes fm-inactive-reconcile.sh raises when a crew's own status log never got a done/failed line and the outcome was only detected via fm-crew-state.sh's authoritative read (reconcile_direct_child_locked in bin/fm-inactive-reconcile.sh, main-home path). Their payload is literally 'inactive terminal outcome awaiting captain presentation: child=$id state=$state' (bin/fm-inactive-reconcile.sh:523), and elsewhere in this same codebase done/failed verbs are always defined as captain-relevant (status_is_captain_relevant, bin/fm-classify-lib.sh:156-169). Because the reconcile scan only fires when the child has gone stale (age >= FM_INACTIVE_RECONCILE_SECS) and its status file wasn't otherwise updated, no other queued row (signal/stale) reliably carries this same event — this check wake is often the only presentation of a finished-or-failed child. Labeling the batch ROUTINE ('supervisor handling only') when it contains this row will cause a captain to skip exactly the kind of finding this change is meant to surface, defeating the stated intent ('important messages get lost in the noise'). The header comment's own qualifier 'Repeated inactive-outcome receipts ... are inherently supervision work' isn't honored by the code either — it treats every inactive-outcome key as routine, not just repeats.

🔧 Fix applied.
1 error still open:

  • 🚨 bin/fm-inactive-reconcile.sh:630 - The fix round's mark_captain_surfaced/captain-surfaced mechanism marks an inactive-outcome/inactive-reconcile fingerprint as 'surfaced' the first time ANY plain (non-ack) fm-wake-drain.sh invocation observes it in its raw rows -- not the first time a human captain actually sees the presented WAKE CLASS output. bin/fm-supervise-daemon.sh's handle_durable_wakes() (line 1484) runs a plain 'fm-wake-drain.sh' call purely for its own internal self-handle/escalate classification (classify_check always escalates via escalate_add/escalate_flush, a completely separate pane-injection channel, not fm-wake-drain.sh's own print_status_presentation output) and then immediately acks the batch via --ack-through (lines 1512-1513). This daemon is exactly the process that bin/fm-afk-start.sh execs to supervise a captain's own pane while the captain is AFK (FM_AFK_DAEMON=.../fm-supervise-daemon.sh). Concrete sequence: captain goes AFK -> a direct child finishes while AFK -> fm-inactive-reconcile.sh queues check:inactive-outcome:<fp> -> the AFK daemon's own housekeeping/watcher loop calls handle_durable_wakes, which plain-drains fm-wake-drain.sh, which calls wake_row_needs_attention -> mark_captain_surfaced, setting captain_surfaced=1 on the outcome record (even though this drain's output was never shown to the captain, only parsed internally and separately escalated) -> the daemon's --ack-through then dequeues the row, but because the .pending record was never moved to .presented (only an explicit 'acknowledge' call, never invoked from this daemon path, does that), the next reconcile scan re-queues the same fingerprint into the wake queue -> when the captain actually returns and fm-afk-return.sh runs the real captain-facing 'fm-wake-drain.sh' (bin/fm-afk-return.sh:585), that re-queued row is classified ROUTINE (captain_surfaced already 1), so the captain's own first sighting of the finished/failed child hides the exact ATTENTION label the round-1 fix was written to guarantee. tests/fm-inactive-reconcile.test.sh's new test only exercises two drains from the SAME (captain-facing) caller and does not distinguish caller identity, so it doesn't catch this. The smallest honest remedy is not a local patch to mark_captain_surfaced -- it requires distinguishing 'presented to the captain' from 'observed by any plain drain', which means new plumbing (e.g. a caller-identity/actor argument threaded through fm-wake-drain.sh and fm-inactive-reconcile.sh, or moving the mark to the captain's own explicit acknowledgement path) beyond this change's current mechanism.

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

🔧 **Test** - 2 issues found → auto-fixed ✅
  • 🚨 bin/fm-wake-drain.sh:630 - The new print_wake_presentation_class/wake_row_needs_attention classifier performs its own status-file read (status_presentation_cursor_offset) before print_status_presentation's enrichment pass reads the same file. This second, earlier read consumes the race window that the existing race-safety annotation (fm-classify-lib.sh's perl safe-read, 'wake annotation:' unreadable/race warning) depends on to detect a mid-read symlink swap. Reproduced live: tests/fm-wake-queue.test.sh's test_structural_signal_enrichment_preserves_raw_rows passes on base commit 036fec0 but fails on target commit edb2a02 with 'expected only the unreadable-race-safe status annotation, got 0' - the annotation is silently dropped instead of warning the captain that a status file was swapped to a symlink underneath the drain.
  • 🚨 live validation verdict: no-go (7 of 7 scenarios were driven live against the product); failed: Adversarial: a status file swapped to a symlink mid-drain (race/escape attempt) still produces the race-safety annotation and never leaks the escaped content
  • Live validation: ❌ no-go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Watcher-only wake batch (heartbeat/paused signal) is labeled ROUTINE without hiding raw rows ✅ pass live tests/fm-wake-queue.test.sh::test_drain_labels_routine_and_attention_wakes_distinctly, driven live
Captain-actionable wake batch (blocked signal) is labeled ATTENTION without hiding raw rows ✅ pass live tests/fm-wake-queue.test.sh::test_drain_labels_routine_and_attention_wakes_distinctly, driven live
First presentation of an inactive-outcome (finished/failed child) check wake is ATTENTION ✅ pass live tests/fm-inactive-reconcile.test.sh::test_inactive_outcome_wake_is_always_attention, driven live
A repeated, still-unacknowledged presentation of the same inactive-outcome wake stays ATTENTION (no captain-surfaced downgrade) ✅ pass live tests/fm-inactive-reconcile.test.sh::test_inactive_outcome_wake_is_always_attention, driven live
inactive-reconcile (undeliverable parent report) check wake is ATTENTION ✅ pass live tests/fm-inactive-reconcile.test.sh::test_inactive_reconcile_notice_wake_is_attention, driven live
Durable ack-through/acknowledgement flow still consumes a repeatedly-presented, unacknowledged row correctly (queue guarantees preserved) ✅ pass live tests/fm-inactive-reconcile.test.sh::test_inactive_outcome_wake_is_always_attention (ack-through assertions), driven live
Adversarial: a status file swapped to a symlink mid-drain (race/escape attempt) still produces the race-safety annotation and never leaks the escaped content ❌ fail live tests/fm-wake-queue.test.sh::test_structural_signal_enrichment_preserves_raw_rows fails on target (edb2a02) with 'expected only the unreadable-race-safe status annotation, got 0', passes on base (036f…
  • bash tests/fm-wake-queue.test.sh (full suite) - 1 failure: test_structural_signal_enrichment_preserves_raw_rows
  • bash tests/fm-wake-queue.test.sh with that test isolated/rerun 5x - fails every time (not flaky, deterministic regression)
  • Same test run against base commit 036fec0 in a scratch worktree (git worktree add --detach /tmp/fm-base-check 036fec0) - passes
  • bash tests/fm-inactive-reconcile.test.sh (full suite) - all pass, confirming round-1/round-2 review decisions (unconditional ATTENTION for check/inactive-outcome/inactive-reconcile wakes, no captain-surfaced downgrade) hold and the ack-through flow for a repeated unacknowledged presentation still works
  • Manual isolated re-drive of the enrichment scenario with debug output captured, confirming the WAKE CLASS: ATTENTION line prints but the expected 'wake annotation:' race-safety line is entirely absent

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

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Routine wake presented distinctly (heartbeat/no-op signal) ✅ pass live Manual live drain: appended a heartbeat wake via fm_wake_append, ran bin/fm-wake-drain.sh directly — output began with 'WAKE CLASS: ROUTINE - queued records declare no new captain-relevant event; supe…
Attention wake presented distinctly (actionable signal/check) ✅ pass live Manual live drain: appended a check inactive-outcome:child1 wake, drained it directly — output began with 'WAKE CLASS: ATTENTION - at least one queued record carries a new captain-relevant event or…
Inactive-outcome/inactive-reconcile check wakes are ATTENTION on every presentation, including a repeat (round-1 fix) ✅ pass live bash tests/fm-inactive-reconcile.test.sh — test_inactive_outcome_wake_is_always_attention and test_inactive_reconcile_notice_wake_is_attention both ok, driving the real fm-inactive-reconcile.sh queue…
captain-surfaced downgrade mechanism fully removed (round-2 fix) ⏸️ untested no Prior payload only ran a static grep for captain_surfaced/mark_captain_surfaced with live=false; that does not establish a live result for this scenario, so it cannot be recorded as pass without a liv…
Adversarial: symlink-swapped/escaped status file fails closed to ATTENTION, never leaks content ✅ pass live Manual live drain: created escape.status as a symlink to an out-of-state file containing 'must-not-be-read', appended a signal wake pointing at it, drained directly — output was ATTENTION and did not…
Regression: race-safety annotation on a mid-read symlink swap is preserved, not dropped (round-1 finding test-1 fix) ✅ pass live tests/fm-wake-queue.test.sh::test_structural_signal_enrichment_preserves_raw_rows — ok on 3/3 isolated runs and 3/3 full-suite runs; this is the exact regression test that failed on commit edb2a02 per…
Queue mechanics (durability, dedup, malformed-field counting) unaffected by the new WAKE CLASS presentation line ✅ pass live tests/fm-wake-queue.test.sh::test_concurrent_append_and_drain and test_drain_dedupes_obvious_duplicates (both updated to exclude the new WAKE CLASS line from field-count assertions) — ok across 3 full…
  • bash tests/fm-inactive-reconcile.test.sh (full suite, 1 run, all pass)
  • bash tests/fm-wake-queue.test.sh (full suite, 3 runs; 2 unrelated wall-clock-timing tests in fm-watch-checkpoint.sh flaked once each on different runs and passed on retry, then 3 consecutive clean runs)
  • Isolated re-run of test_structural_signal_enrichment_preserves_raw_rows and test_drain_labels_routine_and_attention_wakes_distinctly, 3x each, all pass
  • Manual live drive: fm_wake_append + bin/fm-wake-drain.sh direct CLI invocation for heartbeat (ROUTINE), check/inactive-outcome (ATTENTION, repeat-ATTENTION), and symlink-escape signal wake (fails closed to ATTENTION, no content leak)
  • grep -rn 'captain_surfaced|mark_captain_surfaced' bin/ (no matches; static-only, not a live behavioral drive)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Closes #3984

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on HEAD f637b730efe89d255bf9304d4d916424fcc78bfe (author claims Closes #3984) vs main (post-#4474/#4464/#4458). MERGEABLE/CLEAN. pablontiv is not a blocked author. No .github/** edits. Workflow approvals this pass: no (CI/NM already complete).

Attestation: MATCH (body binds tip). Require no-mistakes 34885017429 SUCCESS. CI 34882072157 SUCCESS (all portable/Herdr/timing green).

Diff reviewed: bin/fm-wake-drain.sh always prints a leading WAKE CLASS: ROUTINE|ATTENTION line for non-empty drains; heartbeats routine, check (incl. inactive-outcome/inactive-reconcile) always ATTENTION, signal/stale ATTENTION when status span has unread captain-relevant or unsafe read. Intentionally rejects per-fingerprint "already surfaced" downgrade (AFK daemon plain-drain poison risk). fm-wake-lib.sh annotation pass continues on one status-file read failure instead of aborting. Queue/ack mechanics unchanged. Tests + architecture.md.

Closes #3984 verified: no — issue ready-for-pr / VISION stamp called for unconfigured captain view to stop surfacing routine wakes as blocking Stop-hook turns (or batch them). This tip only adds a presentation class line; ROUTINE wakes still drain through the same captain-visible Stop-hook path. Labeling is useful incremental presentation, but it does not close the filed defect as accepted.

VISION.md (each rule)

  • One captain, one interface: aligns (partial) — distinct ROUTINE/ATTENTION shape helps honesty under load; does not yet deliver silence/batching for routine wakes that the issue named.
  • Authority is explicit: aligns — presentation only; no new autonomy grant.
  • Scripts own the mechanics: aligns — classifier is deterministic script work.
  • A restart is a non-event: aligns — does not weaken durable queue/ack; fails toward ATTENTION on unsafe reads.
  • Delegation with a spine: aligns — composes existing wake drain; not a new task shape.
  • The fleet outlives any vendor: aligns — harness-agnostic presentation label.
  • Scope: aligns — command-layer captain interface.

contract-class: new-default — unconfigured drain always emits the new WAKE CLASS line (matches issue ready-for-pr class). Always-on presentation change → no auto-merge.

This is a captain-decision hold (waiting-captain). Otherwise ready except default-behavior (and the incomplete Closes claim). Do not merge/rebase while on captain hold. Not waiting on the author for CI.

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.

Routine watcher wakes surface as "Stop hook feedback" blocks in the captain view: important messages get lost in the noise

2 participants