Skip to content

fix(watch): preserve queued wakes across watcher cycles - #807

Closed
raywest wants to merge 9 commits into
kunchenguid:mainfrom
raywest:fm/fm-watch-armfix-upstream-r1
Closed

raywest wants to merge 9 commits into
kunchenguid:mainfrom
raywest:fm/fm-watch-armfix-upstream-r1

Conversation

@raywest

@raywest raywest commented Jul 21, 2026

Copy link
Copy Markdown

What Changed

  • Snapshot durable wake-queue sequence boundaries before starting or attaching to watcher cycles, retain them across successors, and report post-boundary wakes as already queued rather than false FAILED alarms.
  • Preserve queued wake handling through abnormal watcher exits, partial signal appends, and Herdr transition-marker failures while retaining retry backoff for paused transitions.
  • Document the revised watcher-cycle outcomes and add regression coverage for queued-wake, successor, metadata-write, and transition-failure paths.

Risk Assessment

✅ Low: The latest successor-boundary fix is narrowly scoped and preserves the queue and retry invariants established by the surrounding changes.

Testing

Completed 1 recorded test check.

  • Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (55m36s)

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-watch-arm.sh:315 - This new “already queued” outcome is neither an actionable reason nor a literal FAILED line. Pi/OpenCode classify the nonzero exit as a failure, retry silently on success, and never prompt the model to drain the real queued wake. Make this outcome actionable to those adapters (or emit a canonical actionable line).
  • ⚠️ bin/fm-watch-arm.sh:138 - The sequence baseline is captured only after the watcher is forked. A child that appends a wake and is terminated before printing it in that interval is included in the baseline, so the new count is zero and the false FAILED result remains possible. Establish the queue boundary before starting/following the cycle.
  • ⚠️ bin/fm-watch.sh:681 - For a paused blocked pane, a failed marker commit now returns normally with no backoff. Because the marker remains absent, the next level reconciliation immediately returns the same transition, bypassing the normal poll wait and repeatedly hitting Herdr. Preserve a failure/backoff path when this no-wake commit fails.

🔧 Fix: Fix watcher cycle and retry backoff
1 warning still open:

  • ⚠️ bin/fm-watch-arm.sh:303 - A replacement watcher can append a wake before this loop samples its sequence, then exit before producing visible output. That wake is included in SUCCESSOR_QUEUE_SEQ, so the next unexplained close is still reported as empty. Carry the prior watched cycle’s boundary through successor adoption (or otherwise establish it before the successor can append).

🔧 Fix: Preserve queue boundary across successors
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"

🔧 Fix: Fail metadata writes; correct watcher assertion
✅ Re-checked - no issues remain.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Ray West added 9 commits July 21, 2026 04:10
PR kunchenguid#693 replaced the arm layer's silent empty-cycle exit with a loud
"watcher: FAILED" line, but never checked whether a wake had already
landed durably before claiming "no actionable reason" - so a wake
that queued successfully just before the process lost visibility into
its own reason text (an attached arm never sees the owning watcher's
stdout; an owned child can die between a successful append and its
own wake() call) got the same false alarm a genuinely stuck cycle
gets. bin/fm-watch-arm.sh now snapshots state/.wake-queue.seq at
cycle start and reports an accurate "N wake(s) already queued" line
instead of the typed FAILED text whenever the queue advanced during
the cycle, keeping the FAILED alarm only for the genuinely-empty case.

bin/fm-watch.sh's handle_push_transition and multi-file signal loop
also stop discarding an already-queued wake on an unrelated
post-append failure (a dedupe-marker commit, a partial append): those
failures are now best-effort/diagnostic instead of a silent exit 1.

bin/backends/herdr.sh's capability probe no longer SIGPIPEs on stderr
(cosmetic, pre-existing since PR kunchenguid#472; unrelated to the misreporting
but bundled per the same investigation).

Root-caused and reproduced deterministically in
data/scout-watcher-chain-w1/report.md; upstream issue kunchenguid#693.
raywest added a commit to raywest/firstmate that referenced this pull request Jul 21, 2026
* fix(watch): snapshot queue boundary before fork; dedupe partial-append count

Port two review-confirmed fixes for the watcher-cycle queued-wake reporting
landed by fork PR #7:

- Cycle-begin snapshot-before-fork race: the wake-queue sequence baseline is
  now captured before starting or attaching to a watcher cycle, not after.
  Capturing it after the fork let a child append and die in the gap, making
  the new-wake count zero and re-enabling the false FAILED outcome PR #7 was
  meant to eliminate. The same race in successor adoption is fixed by
  carrying the original boundary forward across replacement watchers instead
  of resampling mid-loop. Ported from raywest/firstmate
  fm/fm-watch-armfix-upstream-r1 (upstream kunchenguid/firstmate PR kunchenguid#807),
  narrowed to just this fix - the rest of that branch was rebuilt on
  upstream/main and carries unrelated packaging differences.

- Unique-file partial-append count: bin/fm-watch.sh's signal loop scans
  twice (before and after the grace sleep), so an unchanged pending file is
  listed twice. The append loop and the pending_total diagnostic both
  iterated raw pending lines instead of unique files, so a single file was
  durably appended to the wake queue twice. This fix originates here from
  the upstream PR kunchenguid#807 reviewer's finding, not as a port - no commit on that
  branch (or its predecessor) actually applies it, so it does not exist
  upstream to port.

Regression tests adapted/added for both paths.

* no-mistakes(document): Document watcher queue boundary timing

---------

Co-authored-by: Ray West <[email protected]>
@kunchenguid

kunchenguid commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#807 at 0c18f96d.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

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.

2 participants