Repository navigation
fix: keep watcher arms and reply listeners alive through slow cycles - #6103
Merged
Merged
Conversation
…aking supervision - fm_pending_reply_tick selects the records it has work for in one awk pass, so settled records cost no lock or fork and the walk no longer grows with the never-pruned store. - An attached arm keeps following a live, identity-matched holder whose beacon went stale until the lock changes or the shared stall bound (fm_watcher_stall_bound), then fails with a typed stalled-holder line so the retry replaces the holder. - The remote-reply adapter reports the job worker's preemption (exit 76) as a closed window, so the listener keeps its claim and polls again instead of being relaunched every watcher cycle.
|
This was referenced Sep 30, 2026
Closed
andrewesweet
pushed a commit
to andrewesweet/firstmate
that referenced
this pull request
Sep 30, 2026
…unchenguid#6103) * fix(bin): keep slow watcher cycles and preempted reply polls from breaking supervision - fm_pending_reply_tick selects the records it has work for in one awk pass, so settled records cost no lock or fork and the walk no longer grows with the never-pruned store. - An attached arm keeps following a live, identity-matched holder whose beacon went stale until the lock changes or the shared stall bound (fm_watcher_stall_bound), then fails with a typed stalled-holder line so the retry replaces the holder. - The remote-reply adapter reports the job worker's preemption (exit 76) as a closed window, so the listener keeps its claim and polls again instead of being relaunched every watcher cycle. * no-mistakes(document): Clarify watcher grace and attached-arm documentation
Intent
A
Context: that is the choice to ship parts 1+2+3 in one PR, as recommended by the two watcher-stall scout reports (data/fm-watcher-stall-s1/report.md and data/fm-watcher-cycle-cost-s1/report.md in the fmdev-f1 home). In the main home, watcher poll cycles take 130-270 s (one about 328 s) against a 300 s heartbeat grace, because every cycle walks all ~2,030 never-pruned pending-reply records with per-record locks, forks, and re-sourcing; under load a cycle passed the grace twice on 2026-09-28 and the Stop-hook auto-arm failed each time. The three parts:
Reproduce first in a real setup with a large pending-reply store, and prove each part with observable behavior (cycle time, attach behavior, listener stability). Not approved, follow-ups only: archiving long-resolved records, and decoupling the contributions poll from the check cadence.
What Changed
Risk Assessment
High (review): the review found no code defect. Its one finding, that the real-setup reproduction and cycle-time proof were absent from the diff, was resolved by the lab evidence in "Reproduction and measurements" below; that evidence stays outside the diff by decision.
Testing
No baseline commands were supplied for this phase. The three targeted end-to-end suites passed: settled records were skipped despite a held lock, an attached arm followed a slow watcher and handled a stalled holder, and a preempted remote-reply listener kept its claim without a false caught-up watermark or relaunch. A separate disposable 2,030-record tick took 0.132–0.141 seconds across three runs. The test fixtures were cleaned up; this measures the pending-reply tick, not a full watcher cycle or a before/after comparison.
bash tests/fm-pending-reply.test.sh;2030-record-cycle.logbash tests/fm-watch-arm.test.sh— slow-holder wake scenariobash tests/fm-watch-arm.test.sh— stalled-holder replacement scenariobash tests/fm-remote-reply.test.sh— preemption and listener-stability scenariosEvidence: 2,030-record pending-reply tick timings
Source: 2,030-record pending-reply tick timings
Reproduction and measurements
Every part was reproduced on the base code (
b5fdf74d, a pristine copy) before the fix and re-run on the fix, in disposable homes on the Mac mini (load 5-8); no live home was touched.Part 1 - one-pass record selection
Lab: 2,030 resolved records (every 7th with a closed escalation) plus 3 needing work.
fm_pending_reply_tick, 2,033 recordsfm-watch-arm.sh+fm-watch.sh,FM_POLL=15, 2,030 recordsOld and new ticks on identical 2,033-record labs with a fixed clock left identical record and status files; the only differences were the wall-clock
[at=]stamp on the appended escalation close and a file identity.Part 2 - attached arm follows a live holder
Real Stop hook -> supervision host -> arm -> watcher under a fake
claudesession (the scouts' Appendix A harness), grace scaled to 20 s: old attach give-up at 31 s, stall bound 60 s (main: 300 / 311 / 900 s). The second park's first arm attaches to the main-only pass-through's detached successor, as on main.attached-cycle-ended beacon_age=31, retrynonzero-exit beacon_age=32against the live holder, hook exit 2 withfirstmate watcher auto-arm FAILEDsignal:lineattached-holder-stalled beacon_age=60; retry evicted the holder (stalled-holder-replaced) and main got an ordinarycheck: rearm-resurfacewakewatcher_live=no hook_rerun=no queued_rows=2 arms_following=0)Part 3 - preempted reply long-poll
Real adapter, runner,
fm-on.sh, remote entrypoint, and job worker (only ssh faked); a same-home non-preemptible job, the liveness probe's shape, preempts the listener's poll.no-result: remote-reply-ios (exit 76), claim releasedfm-procevent.sh reconcilestarted=1started=0Regression tests
Each new test fails on the base code and passes on the fix:
test_tick_leaves_settled_records_alone("the tick blocked on a settled record's foreign-held lock"),test_attached_arm_follows_a_slow_live_holderandtest_attached_arm_hands_a_stalled_holder_to_its_replacement(watcher: FAILED - cycle ended without an actionable reason), and the remote-reply preemption cases ("a preempted reply poll did not report a closed window: 76").A 2,000-record timing assertion is deliberately kept out of the unit suite; the cycle-time proof is the lab measurement above.
Follow-ups and known limitations
queued_rows=2 arms_following=0.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-pending-reply.test.sh:1118- The intent requires: “Reproduce first in a real setup with a large pending-reply store, and prove each part with observable behavior (cycle time, attach behavior, listener stability).” This test builds 600 settled records and checks that the tick finishes within 60 seconds, but the change provides no before/after watcher-cycle timing for the reported ~2,030-record setup. The attach and listener tests provide behavioral evidence; the required real-setup reproduction and cycle-time proof remain absent from this change. Please provide that evidence or ask the author whether this criterion can be deferred.✅ **Test** - passed
✅ No issues found.
bash tests/fm-pending-reply.test.sh;2030-record-cycle.logbash tests/fm-watch-arm.test.sh— slow-holder wake scenariobash tests/fm-watch-arm.test.sh— stalled-holder replacement scenariobash tests/fm-remote-reply.test.sh— preemption and listener-stability scenariosbash tests/fm-pending-reply.test.shbash tests/fm-watch-arm.test.shbash tests/fm-remote-reply.test.shRan threefm_pending_reply_tickcycles against a disposable 2,030-record store and measured elapsed time.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.