one-copy: answer at once when the lock's holder is running #2

Merged
merge-queue merged 4 commits from holder-alive-answers-at-once into main 2026-11-28 02:10:13 -08:00
Owner

A second copy of a running app is now told at once instead of after 5 seconds: a terminal app's second copy printed <name> is already open after about 5.1 s, and a second String Lab waited 5 s before bringing the running window forward. Work package AHT-218, under FP-17.

What changes (Go and Rust, same behavior)

  • On Windows, a claim that finds the lock held reads the holder's process id from Local\one-copy-<name>-pid and answers AlreadyOpen at once when that process is running and is the same program. Running means it opens (SYNCHRONIZE | PROCESS_QUERY_LIMITED_INFORMATION), WaitForSingleObject(h, 0) times out, and GetExitCodeProcess is still STILL_ACTIVE. Same program means the image's file name from QueryFullProcessImageNameW, compared without its folder or case, matches this process's own. claim_or_focus brings the window forward at once.
  • The 5-second retry stays only for a holder that isn't seen running: no id recorded yet, a process that has ended or is ending, or an id Windows has since given to some other program.
  • The Go package now records the holder's id too, with the Rust crate's section name and layout (4 bytes, native-endian u32), so a Go app and a Rust one read each other's.
  • macOS and Linux keep the 5-second retry: the flock records no holder.

Why the exit code check is there. A holder killed by TerminateProcess stays unsignaled for a while with its mutex still held. Over 200 runs measured here, every terminated holder showed that window, and its exit code was already set in every sample. A wait check alone would have refused the new copy during tmux's respawn-pane -k update of looper and tuner. With only the wait check, the new terminated-holder test fails 3 of 3 runs.

Tests. Both languages: a holder terminated at the moment of the claim, with its lock taken (the respawn case). Windows: a running child holder answered in under 1.5 s (it takes about 10 ms); the holder's recorded id read back; and a held mutex waited for, then taken once released, in three cases: no id, the id of a process that has ended, and the id of a running cmd.exe. The old in-process "holder ends" test is gone: on Windows an in-process holder now counts as running. Each new test fails with its check removed. Go runs on Linux too (in WSL); Rust's Linux and macOS builds pass clippy.

Merging releases v0.1.1. The README's pins move to it; the crate's Cargo.toml version stays 0.1.0, as in the other modules.

A second copy of a running app is now told at once instead of after 5 seconds: a terminal app's second copy printed `<name> is already open` after about 5.1 s, and a second String Lab waited 5 s before bringing the running window forward. Work package [AHT-218](https://openproject.home.romaine.life/wp/AHT-218), under [FP-17](https://openproject.home.romaine.life/wp/FP-17). **What changes (Go and Rust, same behavior)** - On Windows, a claim that finds the lock held reads the holder's process id from `Local\one-copy-<name>-pid` and answers `AlreadyOpen` at once when that process is running and is the same program. Running means it opens (`SYNCHRONIZE | PROCESS_QUERY_LIMITED_INFORMATION`), `WaitForSingleObject(h, 0)` times out, and `GetExitCodeProcess` is still `STILL_ACTIVE`. Same program means the image's file name from `QueryFullProcessImageNameW`, compared without its folder or case, matches this process's own. `claim_or_focus` brings the window forward at once. - The 5-second retry stays only for a holder that isn't seen running: no id recorded yet, a process that has ended or is ending, or an id Windows has since given to some other program. - The Go package now records the holder's id too, with the Rust crate's section name and layout (4 bytes, native-endian `u32`), so a Go app and a Rust one read each other's. - macOS and Linux keep the 5-second retry: the `flock` records no holder. **Why the exit code check is there.** A holder killed by `TerminateProcess` stays unsignaled for a while with its mutex still held. Over 200 runs measured here, every terminated holder showed that window, and its exit code was already set in every sample. A wait check alone would have refused the new copy during tmux's `respawn-pane -k` update of looper and tuner. With only the wait check, the new terminated-holder test fails 3 of 3 runs. **Tests.** Both languages: a holder terminated at the moment of the claim, with its lock taken (the respawn case). Windows: a running child holder answered in under 1.5 s (it takes about 10 ms); the holder's recorded id read back; and a held mutex waited for, then taken once released, in three cases: no id, the id of a process that has ended, and the id of a running `cmd.exe`. The old in-process "holder ends" test is gone: on Windows an in-process holder now counts as running. Each new test fails with its check removed. Go runs on Linux too (in WSL); Rust's Linux and macOS builds pass clippy. Merging releases v0.1.1. The README's pins move to it; the crate's `Cargo.toml` version stays 0.1.0, as in the other modules.
one-copy: tidy two Go comments
All checks were successful
Suite rust / check-services (pull_request) Has been skipped
Suite rust / check-typos (pull_request) Has been skipped
Suite rust / check-format (pull_request) Successful in 46s
Suite rust / check-test-linux (pull_request) Successful in 1m3s
Suite go / scope (pull_request) Successful in 52s
Suite release / scope (pull_request) Successful in 1m1s
Suite rust / scope (pull_request) Successful in 58s
Suite release / check-package (pull_request) Has been skipped
Suite release / reused-checks (pull_request) Has been skipped
Suite rust / check-machete (pull_request) Has been skipped
Suite rust / check-audit (pull_request) Has been skipped
Suite release / reserve (pull_request) Has been skipped
Suite release / publish (pull_request) Has been skipped
Suite go / check-test-linux (pull_request) Successful in 58s
Suite release / home-sync (pull_request) Has been skipped
Suite release / dispatch (pull_request) Has been skipped
Suite release / deploy-image (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite release / module (pull_request) Has been skipped
Suite release / finalize (pull_request) Has been skipped
Suite release / check-build (none, ubuntu-latest) (ubuntu-latest, none) (pull_request) Has been skipped
Suite release / build (none, ubuntu-latest) (ubuntu-latest, none) (pull_request) Has been skipped
Suite default / check-rules (pull_request) Successful in 40s
Suite go / check-format (pull_request) Successful in 49s
Suite default / reused-checks (pull_request) Successful in 41s
Suite go / check-test-windows (pull_request) Successful in 2m34s
Suite rust / check-test-windows (pull_request) Successful in 1m23s
merge-queue landed on main
Suite go / reused-checks (pull_request) Successful in 31s
Suite rust / reused-checks (pull_request) Successful in 33s
4c2f177fec
merge-queue deleted branch holder-alive-answers-at-once 2026-11-28 02:10:14 -08:00
Sign in to join this conversation.
No reviewers
No labels
queue
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/one-copy!2
No description provided.