Skip to content

test(tests): give re-arm recovery waits a budget that survives contended changed-suite runs - #5335

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-3793-watch-arm-changed-suite
Sep 23, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-3793-watch-arm-changed-suite

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #3793

The watcher recovery re-arm assertion fails in changed-suite runs while passing serially.

The issue reports that tests/fm-watch-arm.test.sh repeatedly fails its durable-recovery assertion in test_rearm_resurfaces_durable_queue_and_remote_open_decision ("not ok - re-arm stayed live instead of surfacing durable wakes and the still-open remote decision") during the runner's automatic changed-suite execution (bin/fm-test-run.sh --changed), while unchanged serial executions of the same suite (bin/fm-test-run.sh tests/fm-watch-arm.test.sh --jobs 1) pass. It blocks validation of otherwise unrelated contributions and needs attribution rather than being treated as a harmless retry. The report's evidence did not yet distinguish scheduler delay, interference from another selected suite, a fixture readiness race, or a production recovery defect, and it asked for a narrowly scoped reproduction and restoration of reliable recovery-test behavior.
Expected behavior: re-arming presents the retained durable wakes and the still-open remote decision within the test's bounded wait, while preserving the production recovery and acknowledgement contract. Any correction should retain the negative control that a genuinely absent recovery wake still fails.
The maintainer triage classed this as a restore: the suite already promises this assertion holds under the runner's normal changed-suite path, and the default validation path should not require an isolated serial rerun to pass. Help was wanted on attributing the changed-suite vs serial divergence without weakening the production recovery contract; a field incident becomes regression coverage.

What Changed

  • In tests/fm-watch-arm.test.sh, start_rearm_arm now gives the arm an explicit 30s confirmation budget (FM_ARM_CONFIRM_TIMEOUT) instead of the 10s default. It also waits up to 700 polls for the arm to confirm its watcher or exit, where it used to give up after a fixed 80 polls (about 4s). Every re-arm wait_for_exit, which used fixed 80- or 120-poll counts, now uses one named 400-poll ceiling that outlasts that budget. A passing case still returns as soon as the arm reports or exits, and a watcher that never surfaces its recovery still fails once the ceiling is spent. No bin/ code changes.
  • New case test_slow_rearm_recovery_is_still_surfaced reproduces the loaded-host failure from tests/fm-watch-arm.test.sh: recovery re-arm assertion fails in changed-suite runs but passes serially #3793 on any machine. Once the re-armed watcher publishes its beacon, the case adds a 0.6s delay to every mktemp and readlink call it makes. The case then checks three things: the recovery wake and the queued wake are still surfaced and drained, the delay actually held the re-arm for at least 12s, and the wakes are acknowledged. The commit notes that this case failed with the reported "stayed live" symptom on the old budgets.
  • docs/watcher-continuity.md lists the new slow-recovery case in the fm-watch-arm suite's coverage description.

Risk Assessment

✅ Low: The change only touches tests and one docs line, and does not modify any production recovery or acknowledgement code. It raises the arm's confirmation budget (FM_ARM_CONFIRM_TIMEOUT=30) and replaces the fixed 80/120-poll waits with iteration-counted ceilings sized above that budget: 700 x 0.05s in start_rearm_arm and 400 x 0.1s in wait_for_exit. It keeps the negative control: a watcher that stays live without surfacing its recovery still hits status 124 and fails. It also adds a regression case that slows mktemp and readlink after the successor's beacon is published, which reproduces the loaded-host divergence on any host.

Testing

This is a test-only fix for a flaky test, so the product surface is the repo's own test runner. I ran it on a host that was already heavily contended (load ~47-56 on 8 CPUs), which matches the issue's changed-suite conditions. Base vs fixed: the base re-arm assertion failed in 2 of 4 concurrent copies (the arm exited with status 1, before it could report the durable recovery) and the fixed version passed in all 4. The full changed-suite run (--changed) passed in about 7m52s. The negative control, which removes the recovery evidence, still fails with "slow re-arm stayed live instead of surfacing its recovery", so a recovery wake that is genuinely missing still fails the test. One caveat: with the old 80-poll waits restored, the new slow-recovery regression case still passed on this loaded host. The test's own poll loop slows down under load too, so that case fails before the fix only on a less loaded host; I report this below as an informational note, not a failure. I cleaned up all temporary test copies.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
The runner's changed-suite path (bin/fm-test-run.sh --changed) passes fm-watch-arm on a contended host without needing a serial rerun ✅ pass live changed-suite.log: FM_TEST_END tests/fm-watch-arm.test.sh exit=0, all cases ok, load average ~47
Base re-arm assertion fails under 4-way concurrency (reproduces the reported bug) ✅ pass live rearm-4-concurrent-copies-base.log: copies 1 and 3 'not ok - re-arm re-surface wake must close successfully: expected exit 0, got 1'
Fixed re-arm assertion surfaces the durable wakes and the still-open remote decision in every one of 4 concurrent copies ✅ pass live rearm-4-concurrent-copies-new.log: 4/4 ok
Adversarial: a re-arm with no recovery evidence to surface still fails the bounded wait ✅ pass live negative-control-absent-recovery.log: 'not ok - slow re-arm stayed live instead of surfacing its recovery', rc=1 after ~112s
New slow-recovery regression case fails when the old 80-poll waits are restored ⏸️ untested no The prior payload did not establish a live red result for this scenario. On this host (load ~50 on 8 CPUs, not controllable) the test's own poll loop slowed along with the recovery work, so the old wa…
Evidence: Changed-suite runner transcript (pass under load)

Source: Changed-suite runner transcript (pass under load)

 21:02:03 up 6 days,  1:07,  5 users,  load average: 46.16, 50.12, 52.53
FM_TEST_BEGIN 2026-09-22T21:02:04Z tests/fm-watch-arm.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - watch-arm: an attached arm reports the wake its cycle delivered instead of a false failure
ok - watch-arm: a delivered wake consumed by the handling turn still closes the attached arm cleanly
ok - watch-arm: an unusable launch confirm window refuses to arm by name
ok - watch-arm: a cycle that delivered no wake of its own still fails loudly
~/.no-mistakes/worktrees/42fe67ed39fa/01M35EQD2J30Y3ZDRPSV13NDJD/bin/fm-watch-arm.sh: line 566: 2920621 Killed                     "$WATCH" > "$child_out"
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 2924191.1790110975.f3VnIF
ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
~/.no-mistakes/worktrees/42fe67ed39fa/01M35EQD2J30Y3ZDRPSV13NDJD/bin/fm-watch-arm.sh: line 566: 2972185 Killed                     "$WATCH" > "$child_out"
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 2976294.1790111046.sTcbci
ok - watch-arm: a re-arm whose recovery cycle runs slowly still surfaces it
watcher: recovery state could not be persisted; retaining stale lock evidence
ok - watch-arm: marker publication failure retains stale-lock recovery evidence
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 3013784.1790111097.uPf1nQ
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 3 --recovery-generation 3028498.1790111117.vU600m
ok - watch-arm: a wake queued after handling drain is recovered once at successor arm
ok - watch-arm: interrupted handling leaves its wake durable for successor re-drain
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 0 --recovery-generation 3092679.1790111209.ULINmQ
ok - watch-arm: malformed recovery state is quarantined without a successor loop
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3116002.1790111240.sYnnJs
ok - watch-arm: publication after recovery handoff is surfaced
ok - watch-arm: restart publishes recovery before clearing a reused-pid watcher lock
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 7 --recovery-generation 3140320.1790111272.bkhA9d
ok - watch-arm: markerless legacy queues are adopted and recovered
ok - watch-arm: a watcher close during handling keeps the printed acknowledgement valid
ok - watch-arm: a moved recovery generation consumes handled rows and names its remedy
ok - watch-arm: downtime marker publication does not follow symlinks
FM_TEST_END 2026-09-22T21:09:55Z tests/fm-watch-arm.test.sh exit=0 duration_ms=471485 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=472060
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=1 duration_ms=471485 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-watch-arm.test.sh duration_ms=471485

real	7m52.208s
user	1m24.063s
sys	4m17.925s
rc=0
Evidence: Base re-arm assertion, 4 concurrent copies (2/4 fail)

Source: Base re-arm assertion, 4 concurrent copies (2/4 fail)

 21:12:24 up 6 days,  1:17,  8 users,  load average: 56.75, 53.38, 52.90
copy 1 rc=1
copy 3 rc=1
copy 4 rc=0
copy 2 rc=0
copy 1: not ok - re-arm re-surface wake must close successfully: expected exit 0, got 1
copy 2: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
copy 3: not ok - re-arm re-surface wake must close successfully: expected exit 0, got 1
copy 4: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
Evidence: Fixed re-arm assertion, 4 concurrent copies (4/4 pass)

Source: Fixed re-arm assertion, 4 concurrent copies (4/4 pass)

 21:14:39 up 6 days,  1:19,  6 users,  load average: 52.64, 55.22, 53.80
copy 2 rc=0
copy 3 rc=0
copy 1 rc=0
copy 4 rc=0
copy 1: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
copy 2: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
copy 3: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
copy 4: ok - watch-arm: re-arm surfaces every queued wake and an open remote decision after downtime
Evidence: Negative control: absent recovery still fails

Source: Negative control: absent recovery still fails

 21:10:15 up 6 days,  1:15,  8 users,  load average: 46.30, 50.09, 51.87
~/.no-mistakes/worktrees/42fe67ed39fa/01M35EQD2J30Y3ZDRPSV13NDJD/bin/fm-watch-arm.sh: line 566: 3240815 Killed                     "$WATCH" > "$child_out"
wait_for_exit: owned pid 3246723 exceeded 400 polls; sending TERM
3246723 3239599 S    bash ~/.no-mistakes/worktrees/42fe67ed39fa/01M35EQD2J30Y3ZDRPSV13NDJD/bin/fm-watch-arm.sh --restart
wait_for_exit: owned pid 3246723 survived TERM; sending KILL
not ok - slow re-arm stayed live instead of surfacing its recovery

real	1m51.795s
user	0m7.057s
sys	0m27.889s
rc=1
mktemp: failed to create file via template '/tmp/fm-watch-arm-tests.yNT1X2/slow-rearm-recovery/state/.watcher-down.tmp.XXXXXX': No such file or directory
watcher: recovery state could not be persisted; retaining stale lock evidence
Evidence: Slow-recovery case with old waits restored (passed on this loaded host)

Source: Slow-recovery case with old waits restored (passed on this loaded host)

 21:10:15 up 6 days,  1:15,  8 users,  load average: 46.30, 50.09, 51.87
~/.no-mistakes/worktrees/42fe67ed39fa/01M35EQD2J30Y3ZDRPSV13NDJD/bin/fm-watch-arm.sh: line 566: 3240745 Killed                     "$WATCH" > "$child_out"
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 3247940.1790111426.X6MYVy
ok - watch-arm: a re-arm whose recovery cycle runs slowly still surfaces it

real	0m53.281s
user	0m5.006s
sys	0m16.362s
rc=0
- Outcome: ⚠️ 1 info across 1 run (16m32s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-watch-arm.test.sh:391 - The new test_slow_rearm_recovery_is_still_surfaced case goes red before the fix only on a lightly loaded host. Each wait_for_exit poll starts its own ps and sleep processes, so a busy host slows the old 80-poll wait along with the delayed recovery. At load ~50 on this host, the case passed with the old waits restored. The base-vs-fixed concurrent comparison of the original assertion did reproduce the bug (2/4 base failures vs 0/4 fixed), so the fix itself is demonstrated.
  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
The runner's changed-suite path (bin/fm-test-run.sh --changed) passes fm-watch-arm on a contended host without needing a serial rerun ✅ pass live changed-suite.log: FM_TEST_END tests/fm-watch-arm.test.sh exit=0, all cases ok, load average ~47
Base re-arm assertion fails under 4-way concurrency (reproduces the reported bug) ✅ pass live rearm-4-concurrent-copies-base.log: copies 1 and 3 'not ok - re-arm re-surface wake must close successfully: expected exit 0, got 1'
Fixed re-arm assertion surfaces the durable wakes and the still-open remote decision in every one of 4 concurrent copies ✅ pass live rearm-4-concurrent-copies-new.log: 4/4 ok
Adversarial: a re-arm with no recovery evidence to surface still fails the bounded wait ✅ pass live negative-control-absent-recovery.log: 'not ok - slow re-arm stayed live instead of surfacing its recovery', rc=1 after ~112s
New slow-recovery regression case fails when the old 80-poll waits are restored ⏸️ untested no The prior payload did not establish a live red result for this scenario. On this host (load ~50 on 8 CPUs, not controllable) the test's own poll loop slowed along with the recovery work, so the old wa…
  • bin/fm-test-run.sh --changed --base ada21f5 (selects tests/fm-watch-arm.test.sh; full suite including the new slow-recovery case) on a host at load ~47-56 / 8 CPUs
  • Base (ada21f5) test_rearm_resurfaces_durable_queue_and_remote_open_decision run as 4 concurrent copies (temporary filtered copy of the test file, since removed)
  • New test_rearm_resurfaces_durable_queue_and_remote_open_decision run as 4 concurrent copies under the same load
  • Negative control: test_slow_rearm_recovery_is_still_surfaced with the dead watcher's lock, downtime marker and wake queue erased so no recovery wake exists
  • Counterfactual: test_slow_rearm_recovery_is_still_surfaced with the old waits restored (80 polls, 10s confirmation)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The re-arm recovery cases judged "the watcher stayed live instead of
surfacing recovery" with fixed budgets below what a real stale-lock
recovery costs on a contended host: the arm's default 10s confirmation
deadline, a start helper that returned after about 4s whether or not the
arm had confirmed its watcher, and an 80-poll exit wait.
A changed-suite run beside other suites starves the recovery's many
short-lived processes while this suite's sleeping poll loops keep their
pace, so a watcher still surfacing its recovery read as one that stayed
live (issue kunchenguid#3793).
The original 0.25s window after confirmation was widened to 80 polls in
kunchenguid#3837, which left the same race at a larger size.

Following the CONTRIBUTING.md fixture-budget rule, the re-arm helper now
gives the arm an explicit 30s confirmation budget and waits for its
confirmation or exit within a ceiling that outlasts it, and every wait on
a re-armed watcher uses one named iteration-counted ceiling that outlasts
the same budget.
A passing case returns as soon as the arm reports or exits, and a watcher
that never surfaces its recovery still fails.

A new case delays every mktemp and readlink the re-armed watcher runs
after it publishes its beacon, so its first poll and exit take about 13s
on any host.
It fails with the reported symptom on the previous budgets and passes now.
No bin/ change.
@kunchenguid
kunchenguid merged commit a5d78f8 into kunchenguid:main Sep 23, 2026
20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

Contract-class: restore. Tip vs main: tests/fm-watch-arm.test.sh re-arm waits used the 10s confirm default and fixed ~80/120-poll ceilings that fail under contended changed-suite load while serial passes. Tip gives re-arm an explicit 30s FM_ARM_CONFIRM_TIMEOUT, 700-poll confirm wait, and 400-poll exit ceiling, plus a loaded-host reproduction case — no bin/ production change. Closes #3793 verified. Suite already promised this assertion under the runner's normal changed-suite path.

VISION.md (per-rule)

  • One captain, one interface: aligns — context-sensitive validation failure burns attention.
  • Authority is explicit: aligns — no new autonomy.
  • Scripts own the mechanics: aligns — test/arm recovery budgets belong in deterministic coverage.
  • A restart is a non-event: aligns — durable-queue resurfacing on re-arm is restart-safety.
  • Delegation with a spine: aligns — independent validation must be trustworthy.
  • The fleet outlives any vendor: aligns — portable suite reliability.
  • Scope: aligns — field incident → regression coverage; command-layer test discipline.

Gates: CLEAN, CI green, NM green, attestation MATCH, safe. No Firstmate flag. No workflow approval. No security FYI.