Repository navigation
fix(bin): refuse watchers from disposable checkouts and exit when the home is gone - #5552
Conversation
… home is gone Fixes kunchenguid#321 Fixes kunchenguid#4760 A watcher armed from a disposable no-mistakes validation checkout under .no-mistakes/worktrees/ outlived the validation step and kept writing the real home's state, and a running watcher never noticed when its home, state directory, or code root disappeared. The arm now refuses from such a checkout with the typed failure line, the watcher checks once per poll that its home, state directory (or its own lock holder record), and bin directory still exist and exits with a logged reason scoped to itself, and the shared test helpers reap every watcher a suite armed for a temporary home through the home-scoped stop.
|
Speaking as Kun's firstmate: Verdict: Diff reviewed (disposable VISION: One captain/interface — aligns. Authority — aligns (FM_GATE_REFUSE_BYPASS test hatch only). Scripts/agents — aligns. Restart — aligns (orphan exit). Delegation/spine — aligns. Vendor — aligns. Scope — aligns. Attestation: MATCH |
…ced by this branch's test-watcher reaper, which is what killed both CI checks (serial-2 cancelled at the 30-min cap; Lint 2 exit 143 = the suite's own TERM-trap code). Root cause: test_drain_asserts_watcher_liveness (tests/fm-wake-queue.test.sh) fabricates a .watch.lock whose pid is the test runner's own $$ with the runner's real identity, to make the drain believe a live watcher exists. The new make_case tracking registers that state dir for reaping, so at fm_test_cleanup the new fm_test_reap_watchers drives fm-watch-arm.sh --stop; its identity check matches (the fixture recorded the runner's identity) and it kill -TERMs the test runner. tests/lib.sh:231 is `trap 'fm_test_cleanup; exit 143' TERM`, so the TERM re-enters cleanup -> reap -> kills $$ again -> infinite loop until the runner cap. I reproduced this locally: the suite ran all tests then looped forever in cleanup spawning fm-watch-arm.sh --stop against a lock naming its own PID. Fix (tests/lib.sh, +5 lines): in fm_test_reap_watchers, skip any tracked lock whose pid equals our own $$ before driving --stop. This is the single shared reap boundary; seven $$-self-lock fixtures across four test files are all covered by the one guard, and real armed watchers (pid != $$) are still reaped. Invariant: the test reaper must only signal real armed watcher processes, never the test runner itself. Verified locally: tests/fm-wake-queue.test.sh -> EXIT 0 (63 ok, no hang); tests/fm-watch-arm.test.sh -> EXIT 0 (21 ok, including test_reaper_stops_a_tracked_watcher, confirming the guard does not over-skip). Lint 2's exit 143 was the same shard/cap signature; a fresh CI run on this new commit will re-evaluate it
… + stall eviction Header comment conflict only after kunchenguid#5594; retain both the stalled-holder eviction docs from main and this PR's per-poll home/state/code-root exit.
|
Speaking as Kun's firstmate: Verdict: Diff re-reviewed (disposable VISION: aligns — One captain one interface: yes (no silent orphan watchers writing live homes). Authority explicit: yes ( Conflict: DIRTY after #5594 (stall-eviction) landed on same header in |
…e-watcher docs docs/watcher-continuity.md conflict after main restructured the regression section; retain main's headings and add disposable-checkout / home-gone / reaper coverage bullets from this PR.
|
Speaking as Kun's firstmate: Second conflict resolve: After #5554 landed, |
|
Speaking as Kun's firstmate: Post-resolve: Second conflict (docs after #5554) resolved; Behavior portable serial 3 flake ( |
|
Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this. |
… home is gone (kunchenguid#5552) * fix(bin): refuse watchers from disposable checkouts and exit when the home is gone Fixes kunchenguid#321 Fixes kunchenguid#4760 A watcher armed from a disposable no-mistakes validation checkout under .no-mistakes/worktrees/ outlived the validation step and kept writing the real home's state, and a running watcher never noticed when its home, state directory, or code root disappeared. The arm now refuses from such a checkout with the typed failure line, the watcher checks once per poll that its home, state directory (or its own lock holder record), and bin directory still exist and exits with a logged reason scoped to itself, and the shared test helpers reap every watcher a suite armed for a temporary home through the home-scoped stop. * no-mistakes(lint): fix SC1007 by assigning empty string in watch-arm test * no-mistakes(ci): Found and fixed a genuine, reproducible hang introduced by this branch's test-watcher reaper, which is what killed both CI checks (serial-2 cancelled at the 30-min cap; Lint 2 exit 143 = the suite's own TERM-trap code). Root cause: test_drain_asserts_watcher_liveness (tests/fm-wake-queue.test.sh) fabricates a .watch.lock whose pid is the test runner's own $$ with the runner's real identity, to make the drain believe a live watcher exists. The new make_case tracking registers that state dir for reaping, so at fm_test_cleanup the new fm_test_reap_watchers drives fm-watch-arm.sh --stop; its identity check matches (the fixture recorded the runner's identity) and it kill -TERMs the test runner. tests/lib.sh:231 is `trap 'fm_test_cleanup; exit 143' TERM`, so the TERM re-enters cleanup -> reap -> kills $$ again -> infinite loop until the runner cap. I reproduced this locally: the suite ran all tests then looped forever in cleanup spawning fm-watch-arm.sh --stop against a lock naming its own PID. Fix (tests/lib.sh, +5 lines): in fm_test_reap_watchers, skip any tracked lock whose pid equals our own $$ before driving --stop. This is the single shared reap boundary; seven $$-self-lock fixtures across four test files are all covered by the one guard, and real armed watchers (pid != $$) are still reaped. Invariant: the test reaper must only signal real armed watcher processes, never the test runner itself. Verified locally: tests/fm-wake-queue.test.sh -> EXIT 0 (63 ok, no hang); tests/fm-watch-arm.test.sh -> EXIT 0 (21 ok, including test_reaper_stops_a_tracked_watcher, confirming the guard does not over-skip). Lint 2's exit 143 was the same shard/cap signature; a fresh CI run on this new commit will re-evaluate it --------- Co-authored-by: firstmate-oss <[email protected]>
… home is gone (kunchenguid#5552) * fix(bin): refuse watchers from disposable checkouts and exit when the home is gone Fixes kunchenguid#321 Fixes kunchenguid#4760 A watcher armed from a disposable no-mistakes validation checkout under .no-mistakes/worktrees/ outlived the validation step and kept writing the real home's state, and a running watcher never noticed when its home, state directory, or code root disappeared. The arm now refuses from such a checkout with the typed failure line, the watcher checks once per poll that its home, state directory (or its own lock holder record), and bin directory still exist and exits with a logged reason scoped to itself, and the shared test helpers reap every watcher a suite armed for a temporary home through the home-scoped stop. * no-mistakes(lint): fix SC1007 by assigning empty string in watch-arm test * no-mistakes(ci): Found and fixed a genuine, reproducible hang introduced by this branch's test-watcher reaper, which is what killed both CI checks (serial-2 cancelled at the 30-min cap; Lint 2 exit 143 = the suite's own TERM-trap code). Root cause: test_drain_asserts_watcher_liveness (tests/fm-wake-queue.test.sh) fabricates a .watch.lock whose pid is the test runner's own $$ with the runner's real identity, to make the drain believe a live watcher exists. The new make_case tracking registers that state dir for reaping, so at fm_test_cleanup the new fm_test_reap_watchers drives fm-watch-arm.sh --stop; its identity check matches (the fixture recorded the runner's identity) and it kill -TERMs the test runner. tests/lib.sh:231 is `trap 'fm_test_cleanup; exit 143' TERM`, so the TERM re-enters cleanup -> reap -> kills $$ again -> infinite loop until the runner cap. I reproduced this locally: the suite ran all tests then looped forever in cleanup spawning fm-watch-arm.sh --stop against a lock naming its own PID. Fix (tests/lib.sh, +5 lines): in fm_test_reap_watchers, skip any tracked lock whose pid equals our own $$ before driving --stop. This is the single shared reap boundary; seven $$-self-lock fixtures across four test files are all covered by the one guard, and real armed watchers (pid != $$) are still reaped. Invariant: the test reaper must only signal real armed watcher processes, never the test runner itself. Verified locally: tests/fm-wake-queue.test.sh -> EXIT 0 (63 ok, no hang); tests/fm-watch-arm.test.sh -> EXIT 0 (21 ok, including test_reaper_stops_a_tracked_watcher, confirming the guard does not over-skip). Lint 2's exit 143 was the same shard/cap signature; a fresh CI run on this new commit will re-evaluate it --------- Co-authored-by: firstmate-oss <[email protected]>
… home is gone (kunchenguid#5552) * fix(bin): refuse watchers from disposable checkouts and exit when the home is gone Fixes kunchenguid#321 Fixes kunchenguid#4760 A watcher armed from a disposable no-mistakes validation checkout under .no-mistakes/worktrees/ outlived the validation step and kept writing the real home's state, and a running watcher never noticed when its home, state directory, or code root disappeared. The arm now refuses from such a checkout with the typed failure line, the watcher checks once per poll that its home, state directory (or its own lock holder record), and bin directory still exist and exits with a logged reason scoped to itself, and the shared test helpers reap every watcher a suite armed for a temporary home through the home-scoped stop. * no-mistakes(lint): fix SC1007 by assigning empty string in watch-arm test * no-mistakes(ci): Found and fixed a genuine, reproducible hang introduced by this branch's test-watcher reaper, which is what killed both CI checks (serial-2 cancelled at the 30-min cap; Lint 2 exit 143 = the suite's own TERM-trap code). Root cause: test_drain_asserts_watcher_liveness (tests/fm-wake-queue.test.sh) fabricates a .watch.lock whose pid is the test runner's own $$ with the runner's real identity, to make the drain believe a live watcher exists. The new make_case tracking registers that state dir for reaping, so at fm_test_cleanup the new fm_test_reap_watchers drives fm-watch-arm.sh --stop; its identity check matches (the fixture recorded the runner's identity) and it kill -TERMs the test runner. tests/lib.sh:231 is `trap 'fm_test_cleanup; exit 143' TERM`, so the TERM re-enters cleanup -> reap -> kills $$ again -> infinite loop until the runner cap. I reproduced this locally: the suite ran all tests then looped forever in cleanup spawning fm-watch-arm.sh --stop against a lock naming its own PID. Fix (tests/lib.sh, +5 lines): in fm_test_reap_watchers, skip any tracked lock whose pid equals our own $$ before driving --stop. This is the single shared reap boundary; seven $$-self-lock fixtures across four test files are all covered by the one guard, and real armed watchers (pid != $$) are still reaped. Invariant: the test reaper must only signal real armed watcher processes, never the test runner itself. Verified locally: tests/fm-wake-queue.test.sh -> EXIT 0 (63 ok, no hang); tests/fm-watch-arm.test.sh -> EXIT 0 (21 ok, including test_reaper_stops_a_tracked_watcher, confirming the guard does not over-skip). Lint 2's exit 143 was the same shard/cap signature; a fresh CI run on this new commit will re-evaluate it --------- Co-authored-by: firstmate-oss <[email protected]>
Intent
Fixes #321
Fixes #4760
A watcher can be armed from a disposable no-mistakes validation checkout under
.no-mistakes/worktrees/, and a running watcher never exits when its home or state directory disappears, so validation runs leave orphan watchers that keep writing state into the live home.Refuse to arm a real watcher from a disposable validation checkout, make a running watcher exit when its home or state directory is gone (scoped to itself, never a global kill), and have the test helpers reap watchers they armed for a temporary home.
This closes upstream issues #321 and #4760.
What Changed
bin/fm-watch-arm.shnow refuses every mode with a typedwatcher: FAILED - refusing to arm from a disposable validation checkoutand exits 1 before touching state when its own script path lives under.no-mistakes/worktrees/, with the existingFM_GATE_REFUSE_BYPASS=1escape hatch lifting the refusal for sandboxed test homes.bin/fm-watch.shadds a once-per-poll home-gone check that exits 1 with a logged reason when its home (if it existed at arm time), state directory, singleton lock, or code root disappears, scoped to the current process so no other watcher is signalled.docs/watcher-continuity.mdand the test helpers/suites (tests/lib.sh,tests/wake-helpers.sh,tests/fm-watch-arm.test.sh) to document the behavior and add a test reaper plus coverage for the arm refusal and the home-gone/state-gone exits.Risk Assessment
✅ Low: The change is additive, self-scoped, and well-covered by behavior-asserting tests; the refusal, self-exit, and reaper each map directly to the stated intent with no reachable false-positive path found.
Testing
Ran the targeted real-process suite tests/fm-watch-arm.test.sh (all 21 tests pass, exit 0), which arms real watchers for temporary homes and observes end-to-end behavior. The four new tests drove: the disposable-checkout arm refusal, the state-directory-gone watcher exit within one poll, the home-gone watcher exit with lock release, and the tests/lib.sh reaper stopping a tracked watcher. I additionally reproduced the refusal manually - this validation worktree itself lives under .no-mistakes/worktrees/, so running the arm here with the bypass cleared is an authentic end-user reproduction and it printed the typed failure line and exited 1 before taking any lock. No screenshot applies; this is a CLI/daemon behavior change and the CLI transcript is the reviewer-visible surface. Worktree left clean; test temp dirs live outside it.
test_arm_refuses_a_disposable_validation_checkoutin tests/fm-watch-arm.test.sh plus manualFM_GATE_REFUSE_BYPASS= bash bin/fm-watch-arm.sh --stopfrom this real disposable worktree: 'watcher: FAI…test_watcher_exits_when_its_state_directory_is_removed- real watcher armed,rm -rf $state, pid gone within 30x0.1s polls, 'watcher: exiting - state directory' loggedtest_watcher_exits_when_its_home_is_removed- real watcher armed,rm -rf $home, pid gone, 'watcher: exiting - home no longer exists' logged, lock no longer names the exited pidtest_reaper_stops_a_tracked_watcher- seed watcher armed, fm_test_reap_watchers driven, watcher stopped and registry consumedEvidence: New-scenario results and manual refusal reproduction
Source: New-scenario results and manual refusal reproduction
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-watch.sh:2562- bin/fm-watch.sh:2562 adds a fourth per-poll self-exit trigger (SCRIPT_DIR/code-root gone) beyond the intent's stated remedy of exiting when 'home or state directory is gone'. It is defensible because the intent's problem statement names 'a discarded disposable checkout' (i.e. the code root) as an orphan source, and the check is cheap and self-scoped, so no action is required. The sibling lock-removed check (2559) is in-scope: it is needed so a detached helper'smkdir -p "$STATE"recreating the state dir cannot defeat state-gone detection.✅ **Test** - passed
✅ No issues found.
test_arm_refuses_a_disposable_validation_checkoutin tests/fm-watch-arm.test.sh plus manualFM_GATE_REFUSE_BYPASS= bash bin/fm-watch-arm.sh --stopfrom this real disposable worktree: 'watcher: FAI…test_watcher_exits_when_its_state_directory_is_removed- real watcher armed,rm -rf $state, pid gone within 30x0.1s polls, 'watcher: exiting - state directory' loggedtest_watcher_exits_when_its_home_is_removed- real watcher armed,rm -rf $home, pid gone, 'watcher: exiting - home no longer exists' logged, lock no longer names the exited pidtest_reaper_stops_a_tracked_watcher- seed watcher armed, fm_test_reap_watchers driven, watcher stopped and registry consumedbash tests/fm-watch-arm.test.sh(21 real-process tests, exit 0, including the four new behavior tests)FM_GATE_REFUSE_BYPASS= bash bin/fm-watch-arm.sh --stoprun from the real disposable worktree checkout - refused with exit 1✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.