Repository navigation
fix(bin): make every counted wake queue row presentable or retired - #6
Merged
Merged
Conversation
…gress (kunchenguid#3943) * fix(watch): detect stalled secondmate queue progress * no-mistakes(review): gate secondmate stall on active turns and progress episodes * no-mistakes(document): align secondmate wake-stall docs with progress-episode detector * no-mistakes(document): clarify active-turn gate in wake-stall config docs * no-mistakes(ci): Fixed the one real defect behind the failing checks. ROOT CAUSE (Greptile P1, real code defect in this PR): `secondmate_wake_stall_tick` in bin/fm-watch.sh reset the no-progress timer only when the oldest actionable queue sequence INCREASED (`[ "$seq" -gt "$observed_seq" ]`). When a secondmate is retired and reprovisioned under the same task ID, its fresh home's queue sequence restarts BELOW the recorded position, so the comparison is false, no reset happens, and the new queue inherits the retired generation's already-expired idle interval — emitting a false `secondmate wake-loop stalled` on its very first observation. That is precisely the false-alarm class the user intent requires this PR to remove. FIX (smallest, removal-first): bin/fm-watch.sh:749 now resets when the drain position MOVES AT ALL (`-ne` instead of `-gt`). Draining moves it up, reprovisioning moves it down; neither is a continued no-progress episode. The asymmetric `-gt` branch is removed rather than special-cased or hardened. Updated the function header comment plus the two doc sentences in docs/architecture.md and docs/configuration.md that stated the old advance-only semantics. REGRESSION TEST: added `test_secondmate_reprovisioned_queue_starts_a_fresh_interval` to tests/fm-wake-queue.test.sh (registered in the invocation list). It drives the real watcher through retired generation (seq 9) -> reprovision (seq 3, later clock) -> freeze, asserting observable wake-queue output, no source-text inspection. VERIFICATION: - Fails before / passes after: with the fix reverted the suite aborts on `not ok - a reprovisioned queue generation inherited the retired generation's idle interval and alerted`; with the fix it passes, and its third leg confirms the restarted generation still escalates on a genuine freeze (row=3 idle=2s), so the fix does not merely mute the alarm. - `bash tests/fm-wake-queue.test.sh`: exit 0, 38/38 pass, all five secondmate cases green. - `bin/fm-lint.sh`: clean (ShellCheck 0.11.0, actionlint 1.7.12). CHECKS NOT CAUSED BY THE CODE: the CI and "Require no-mistakes" runs (34152740610, 34152740604) both ended with conclusion `action_required` — workflow approval pending, not a test/build failure. Separately, `bin/fm-test-run.sh --check-coverage` exits 1 in this environment, but I confirmed by stashing my changes that it fails identically on the unmodified base tree (locale-related `comm: input is not in sorted order`); it is pre-existing and this change adds no new test file for the partition to account for. Changes are left uncommitted in the worktree * no-mistakes(ci): Fixed the one real code defect behind the failing checks. ROOT CAUSE (Greptile P1, second round, on the head commit e1304e6): `secondmate_wake_stall_tick` in bin/fm-watch.sh identified the queue's drain position by the sequence number ALONE. The previous round changed the comparison from `-gt` to `-ne`, which handles a reprovisioned queue that restarts BELOW the recorded position, but not one that restarts ON it. A mate retired and reprovisioned under the same task id gets a fresh home whose wake-queue sequence counter restarts at 1 — and the retained parent progress marker very plausibly holds a low sequence too (a queue frozen on its first row records seq 1). Equal sequence ⇒ no reset ⇒ the brand-new queue inherits the retired generation's long-expired idle interval and emits a false `secondmate wake-loop stalled` on its very first observation. That is exactly the false-alarm class this PR exists to remove. FIX (smallest, removal-first): the file already defines the identity of a queue row once, as `row_key="$epoch-$seq"` (used for stall receipts, the stall marker, and the notify key). The progress marker's separate, weaker seq-only identity is removed: `row_key` is now computed once right after the row is parsed, stored in the progress marker, and compared with `!=`. Across generations the epoch differs (the new generation's rows are appended later), so no sequence collision can carry a stale interval; within a generation the key is stable exactly while the position does not move. bin/fm-wake-lib.sh's `fm_wake_secondmate_progress_marker_write` now takes `<oldest-row-key>` and validates it the same way the two neighbouring row-key writers do. Updated the function header comment and the two doc sentences (docs/architecture.md, docs/configuration.md) that described the old sequence-only semantics. REGRESSION TEST: `test_secondmate_reprovisioned_queue_starts_a_fresh_interval` in tests/fm-wake-queue.test.sh now drives the reported case — the reprovisioned generation restarts on the SAME sequence 9 (epoch 200) that the retired generation recorded (epoch 100), at a later clock — and asserts observable watcher output only. Its third leg still confirms the restarted generation escalates on a genuine freeze (row=9 idle=2s), so the fix does not merely mute the alarm. Three seeded progress markers in the symlink, crash-window and prefix-receipt tests were updated to the epoch-sequence form. VERIFICATION: - Fails before / passes after: with bin/fm-watch.sh and bin/fm-wake-lib.sh reverted to HEAD and the new test in place, the suite aborts on `not ok - a reprovisioned queue generation inherited the retired generation's idle interval and alerted` (exit 1); with the fix, `bash tests/fm-wake-queue.test.sh` exits 0 with 38/38 pass, all six secondmate cases green. - `bin/fm-lint.sh`: clean (ShellCheck 0.11.0, actionlint 1.7.12). - I also started `bin/fm-test-run.sh tests/fm-watch-checkpoint.test.sh tests/fm-watch-triage.test.sh tests/fm-watch-recovery-loop.test.sh` as a blast-radius check; it was still running when this phase had to return, so its result is not included. No other suite references the stall detector or the progress marker (grep over tests/ for `wake-loop stall|SECONDMATE_WAKE_STALL|secondmate-wake-progress` matches only fm-wake-queue.test.sh), and the changed lib function has exactly one caller. CHECKS NOT CAUSED BY THE CODE: the CI and "Require no-mistakes" runs on the head commit (34154091191, 34154091236, 34154091945) all ended with conclusion `action_required` — pending workflow approval, not a test/build failure. `bin/fm-test-run.sh --check-coverage` still exits 1 in this environment for the pre-existing locale reason recorded in the previous phase (`comm: input is not in sorted order` on the unmodified base tree); this change adds no new test file. Changes are left uncommitted in the worktree: bin/fm-watch.sh, bin/fm-wake-lib.sh, docs/architecture.md, docs/configuration.md, tests/fm-wake-queue.test.sh --------- Co-authored-by: Alex William <[email protected]>
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
… ("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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
A wake row that is counted as queued but not presented by
bin/fm-wake-drain.shcan 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.shprinted onlyWARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.with no presented row and noWAKE_ACK_REQUIREDcommand.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.shnow counts queued wakes per actor via a newfm_wake_actor_pending_counthelper inbin/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 distinctNOTICEnaming the branch as holder and saying not to drain from there.bin/fm-wake-drain.shretires 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 boundedWAKE ROWS HELD BY SUPERVISION BRANCHline with the held sequences instead of exiting silently.bin/fm-wake-drain.shandbin/fm-wake-grant.shinto sharedfm_wake_grant_rows_valid/fm_wake_branch_owner_matches/fm_wake_branch_grant_livehelpers;tests/fm-wake-queue.test.shadds 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), anddocs/architecture.mdanddocs/watcher-continuity.mdrecord 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-throughcommand 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
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
Evidence: Reproduction script used to generate the transcript (runnable against any tree)
Source: Reproduction script used to generate the transcript (runnable against any tree)
Evidence: Key contrast — the reported field state, one stale row held by a live supervision-branch grant
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/mainbin/fm-watch.sh- merge conflict rebasing onto origin/maindocs/architecture.md- merge conflict rebasing onto origin/maindocs/configuration.md- merge conflict rebasing onto origin/maintests/fm-pi-branch-extension.test.sh- merge conflict rebasing onto origin/maintests/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), thenawait 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 casestest_main_is_never_told_to_drain_rows_only_the_branch_ownsandtest_unconsumable_rows_are_retired_instead_of_wedging_the_queuebash tests/fm-guard-stale-banner.test.sh(exit 0) — fm-guard.sh changedbash 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 cleangit archive ffd2c899export — 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) drivingbin/fm-wake-grant.sh,bin/fm-guard.shandbin/fm-wake-drain.shagainst base and target trees: scenario A replays the reportedstale 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 queueAGENTS.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.