Repository navigation
fix: read Windows-tagged session locks in the remaining lock readers - #7705
Conversation
A Windows/Git Bash home records its session in state/.lock as a tagged win:<pid>, and fm_session_pid_valid owns whether a lock value is a usable identity. Several readers still decided that with a private numeric test, so a correctly locked Windows home read as malformed: - bin/fm-turnend-guard-cursor.sh (kunchenguid#4535): the owner check, the stale-owner reclaim fallback, and the owner read before parking. The Cursor park now recognizes its own tagged lock and reclaims a dead tagged holder's lock; liveness was already answered by fm_harness_pid_alive. - fm_extension_pair_owns_supervision in bin/fm-wake-lib.sh (kunchenguid#4539): a live tagged session read as dead, which printed the supervision-off banner during a healthy Pi extension hand-off. A win:-shaped value now loads the session-lock library and is answered by fm_session_pid_valid and fm_harness_pid_alive; a POSIX value keeps the existing kill -0 test. - The three .pi/extensions lock readers (kunchenguid#4539): on win32 only, a strict win:<digits> value is compared and probed by its digits, because native Node sees Windows pids directly. pid 1 stays rejected, and the branch extension keeps the tagged value whole for its lease holder. Malformed tags, and any tag off Windows, are still rejected. Regressions cover each reader with a faked Windows process table or platform, so they run on every host.
|
Speaking as Kun's firstmate: thanks @cr101. Splitting #4803 into small pieces like this makes it much easier to review, and the base-fails / target-passes evidence for each Pi arm is exactly what I wanted to see. What I checked: head
So Contract-class (my own read): restore. #6300 already made Where it stands: everything is green except |
|
Speaking as Kun's firstmate: this is merged. Thank you @cr101 — really appreciate you taking the time on this. Serial 1 came back green on the re-run, so |
Fixes #4535
Fixes #4539
Piece 2 of the #4803 split, after #6300. These readers go as their own small PR as suggested in #4803 (comment).
Scope notes
pf_test_cleanupintests/fm-public-followup.test.shto stop and wait for the whole remote-worker tree before the fixture directory is removed, which is the race ee9be1c fixed. ee9be1c's remaining difference only reports failure, and skips fixture cleanup, when the tree survives SIGKILL past the helper's wait; no run reproduced that, so this PR leaves the file unchanged.fm_autoarm_claim_open, and the owner-lock pid checks inbin/fm-turnend-guard.sh) are unchanged..omp/extensions/fm-primary-omp-watch.tsand.omp/extensions/fm-primary-turnend-guard.tscarry the same numeric-only lock test but are not named by fix: numeric-only session-lock readers still reject a Windows-tagged win:<pid> lock #4539, so they are left for a follow-up.process.platform, so they run on every host. They were run on a Windows 11 Git Bash host and under Linux (WSL Ubuntu 22.04, Node 24); the cases that exercise an accepted tagged lock fail against main and pass here. No live Cursor, Pi, or omp session was driven on Windows.Intent
Start piece 2 of the #4803 split: the remaining tagged-lock readers (#4535, #4539) plus the one-file test cleanup fix, published upstream as one PR.
Context for reading that ask:
state/.locklegitimately hold a Windows-taggedwin:<pid>value and establishedfm_session_pid_valid()inbin/fm-session-lock-lib.shas the single owner of "is this lock value a usable identity", withfm_harness_pid_alive()answering liveness for a tagged holder. fix: identify Windows/Git Bash harness sessions for the session lock #6300 only referenced fix(bin): Cursor stop-hook guard cannot reclaim a Windows-tagged session lock #4535 and fix: numeric-only session-lock readers still reject a Windows-tagged win:<pid> lock #4539; it did not fix them.bin/fm-turnend-guard-cursor.shdecides lock identity with numeric-only tests at three sites (current_session_still_ours, the stale-owner reclaim fallback, the owner read before parking), so a tagged lock is read as malformed; a dead Cursor session's tagged lock can never be reclaimed and the current session is never recognized as owner. Fix direction: route those readers throughfm_session_pid_valid()and answer tagged liveness withfm_harness_pid_alive()rather thankill -0.state/.lock-fm_extension_pair_owns_supervisioninbin/fm-wake-lib.sh(reads the lock then tests it withfm_pid_alive, feeding a false supervision-off verdict), and the/^[0-9]+$/lock tests in.pi/extensions/fm-branch-supervision.ts,.pi/extensions/fm-primary-pi-watch.ts, and.pi/extensions/fm-primary-turnend-guard.ts. The issue records readers verified NOT affected because they only ever see a local pid:fm_autoarm_claim_openinbin/fm-wake-lib.shand the turn-end owner-lock pid checks inbin/fm-turnend-guard.sh.tests/fm-public-followup.test.shsopf_test_cleanupstops the scoped remote-worker tree before deleting the fixture directory. Current main already callsfm_remote_job_stop_worker_treethere; only ee9be1c's "report failure if shutdown cannot be confirmed" difference is absent.What Changed
bin/fm-turnend-guard-cursor.sh: the owner check, the stale-owner reclaim fallback, and the owner read before parking now usefm_session_pid_validinstead of numeric-onlycasetests. A Windows-taggedwin:<pid>lock now counts as a valid identity, so the current Cursor session is recognized as owner and a dead tagged holder can be reclaimed throughfm_harness_pid_aliveandbin/fm-lock.sh.bin/fm-wake-lib.sh:fm_extension_pair_owns_supervisionchecks awin:-tagged lock holder by loadingfm-session-lock-lib.shon demand and callingfm_session_pid_valid+fm_harness_pid_alive, instead ofkill -0. A live tagged holder no longer gets reported as supervision-off. Untagged values still go throughfm_pid_alive, so POSIX homes behave the same as before.fm-branch-supervision.ts,fm-primary-pi-watch.ts,fm-primary-turnend-guard.ts) each add alockHolderPidhelper. Onwin32it strips thewin:tag, and any value that isn't a pid other than 1 becomes no identity. The ancestry match and liveness probe use those digits, and the branch-supervision lease still records the lock value with its tag. New regression tests for tagged locks are in the Cursor guard, turn-end guard, stale-banner, Pi branch and Pi watch suites.Risk Assessment
✅ Low: The reader changes are small and send lock reads through fm_session_pid_valid/fm_harness_pid_alive as intended. Behaviour on POSIX is unchanged, and new behavioural tests cover owned, dead, live-other, malformed and non-Windows cases. The only gap is that the intended test-cleanup piece is missing.
Testing
Earlier Test turns already confirmed the Cursor guard, the wake-lib extension-pair verdict, and the Pi branch-supervision extension. This turn ran only the two remaining single test functions. Each one loads the real Pi extension module in Node, writes a real state/.lock with tagged values, and fakes process.platform. Both pass on the target commit. Both fail on the base extensions: the base arm refuses this session's own
win:lock, and the base turn-end guard records no owner marker. That shows the fix closes the #4539 Pi reader gap. Text logs were saved to the evidence directory. There is no UI surface, so there are no screenshots. The scratch file was removed and the worktree is clean.win:<own pid>in state/.lock can arm its watcher. It is refused for a dead tagged holder, a live foreign tagged holder, malformed tagged values, and a tagged lock of…win:<own pid>as this session's lock and records its owner marker. It stays inert on non-Windows and for non-owned tagged valuesEvidence: Target: Pi watcher arm, tagged lock (pass)
Source: Target: Pi watcher arm, tagged lock (pass)
ok - Pi watcher arm reads a Windows-tagged session lock only on WindowsEvidence: Target: Pi turn-end guard, tagged lock (pass)
Source: Target: Pi turn-end guard, tagged lock (pass)
ok - .pi primary extension: the turn-end guard reads a Windows-tagged session lock only on WindowsEvidence: Base: Pi watcher arm, tagged lock (fails as expected)
Source: Base: Pi watcher arm, tagged lock (fails as expected)
not ok - Pi watcher arm must read a Windows-tagged session lock only on Windows: expected exit 0, got 1Evidence: Base: Pi turn-end guard, tagged lock (fails as expected)
Source: Base: Pi turn-end guard, tagged lock (fails as expected)
Error: an owned tagged lock (win32) did not record this process's marker: ""Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-public-followup.test.sh:59- The intent says the PR is "the remaining tagged-lock readers (fix(bin): Cursor stop-hook guard cannot reclaim a Windows-tagged session lock #4535, fix: numeric-only session-lock readers still reject a Windows-tagged win:<pid> lock #4539) plus the one-file test cleanup fix, published upstream as one PR". That fix is ee9be1c's "report failure if shutdown cannot be confirmed" difference inpf_test_cleanup. The branch does not touch tests/fm-public-followup.test.sh, and line 59 still readsfm_remote_job_stop_worker_tree "$pid" || true, so a worker-tree shutdown that fails is still ignored. Either add the ee9be1c change to this branch or confirm it is meant to ship separately.bin/fm-wake-lib.sh:355-fm_extension_pair_owns_supervisionis also used for the .omp extension pair (bin/fm-wake-lib.sh:328). The .omp extensions still read the lock as numbers only: .omp/extensions/fm-primary-omp-watch.ts:234 and .omp/extensions/fm-primary-turnend-guard.ts:81. So on Windows an omp session with awin:lock would still treat it as held by another session. The intent and fix: numeric-only session-lock readers still reject a Windows-tagged win:<pid> lock #4539 list only the .pi readers, so this is outside scope and not a regression. Noted for a possible follow-up.🔧 **Test** - 2 issues found → no changes applied ✅
git -C ~\.no-mistakes\worktrees\0667e0267d79\01M5NEYWA02FWKSDC28JQ45V79 statusandgit -C ~\.no-mistakes\worktrees\0667e0267d79\01M5NEYWA02FWKSDC28JQ45V79 diff). Respond with fix to validate it, or abort.🔧 No changes applied.
✅ Re-checked - no issues remain.
win:<own pid>in state/.lock can arm its watcher. It is refused for a dead tagged holder, a live foreign tagged holder, malformed tagged values, and a tagged lock of…win:<own pid>as this session's lock and records its owner marker. It stays inert on non-Windows and for non-owned tagged valuesrm tests/.one.sh(removed the earlier Test turn's scratch copy, as the operator asked)test_pi_arm_reads_a_windows_tagged_session_lockfrom tests/fm-pi-watch-extension.test.sh, run alone through a temp runner that sources the suite's preamble, on the target commit: oktest_pi_extension_reads_a_windows_tagged_session_lockfrom tests/fm-turnend-guard.test.sh, run alone the same way, on the target commit: okBoth functions again with the base (47bd9a1f) versions of .pi/extensions/fm-primary-pi-watch.ts and .pi/extensions/fm-primary-turnend-guard.ts swapped in temporarily: both fail as expected, then the files were restored withgit checkout -- .pi/extensionsgit status --shortafterwards: empty✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.