one-copy: the single-copy lock, its Go package and Rust crate #1

Merged
merge-queue merged 1 commit from AHT-218-lock into main 2026-11-28 00:46:01 -08:00
Owner

The single-copy lock every interactive home app takes (AHT-218, for FP-17), as a Go package and a Rust crate with the same behavior, laid out as logline is. Its merge is the first release, v0.1.0.

What it adds (the repository held only its README before):

  • Claim(name) / claim(name): a per-user named lock. Windows: the named mutex Local\one-copy-<name>, its handle not inheritable, gone when the process ends. macOS and Linux: an flock on one-copy/<name>.lock in $XDG_RUNTIME_DIR or the user's cache folder, opened close-on-exec (Go keeps a bare descriptor, so garbage collection can't close it).
  • A held lock is retried for 5 seconds before "already open": looper's and tuner's own update runs tmux respawn-pane -k, which terminates the old copy and starts the new one in one step (at-tmux win32/win32-pty.c:416-418). The doc comments say so.
  • ONE_COPY_SCOPE, appended to the name when set, so a test copy on a throwaway tmux server runs beside his.
  • A terminal app's one line, ClaimOrExit / claim_or_exit: holds the lock for the process's life, or prints <name> is already open to stderr and exits 1. A lock the OS won't make is reported on stderr and the app starts anyway.
  • Rust only, for String Lab: claim_or_focus and focus_running. The holder records its process id in the named shared memory Local\one-copy-<name>-pid; a second copy finds that process's visible unowned top-level window, restores it if minimized, calls SetForegroundWindow and exits 0. On macOS and Linux there is no window to find, so it just exits 0.

What it doesn't do: take the library up in any app (that is FP-17's next work), forward anything to the running copy (at keeps all focusing of terminal apps), or give Go the window part (no Go desktop app needs it).

Tests, the same cases in both languages: a second claim refused and the name free after release, the scope giving a separate lock, a claim made while the holder ends taking it, and child processes showing the stderr line with exit 1 and a lock freed when its holder exits without letting it go. Go's also cover a lock nothing refers to staying held through garbage collection; Rust's on Windows read back the recorded process id. Nothing opens a window, so the bring-forward is checked by hand in String Lab when it takes the crate.

Checked before the push: ci-check (both languages' format, lints and Windows tests), Go vet for Linux, macOS and FreeBSD, Go's tests run on Linux under WSL, and clippy for Linux and macOS targets.

The single-copy lock every interactive home app takes ([AHT-218](https://openproject.home.romaine.life/wp/AHT-218), for [FP-17](https://openproject.home.romaine.life/wp/FP-17)), as a Go package and a Rust crate with the same behavior, laid out as logline is. Its merge is the first release, `v0.1.0`. **What it adds** (the repository held only its README before): - `Claim(name)` / `claim(name)`: a per-user named lock. Windows: the named mutex `Local\one-copy-<name>`, its handle not inheritable, gone when the process ends. macOS and Linux: an flock on `one-copy/<name>.lock` in `$XDG_RUNTIME_DIR` or the user's cache folder, opened close-on-exec (Go keeps a bare descriptor, so garbage collection can't close it). - A held lock is retried for 5 seconds before "already open": looper's and tuner's own update runs `tmux respawn-pane -k`, which terminates the old copy and starts the new one in one step (at-tmux `win32/win32-pty.c:416-418`). The doc comments say so. - `ONE_COPY_SCOPE`, appended to the name when set, so a test copy on a throwaway tmux server runs beside his. - A terminal app's one line, `ClaimOrExit` / `claim_or_exit`: holds the lock for the process's life, or prints `<name> is already open` to stderr and exits 1. A lock the OS won't make is reported on stderr and the app starts anyway. - Rust only, for String Lab: `claim_or_focus` and `focus_running`. The holder records its process id in the named shared memory `Local\one-copy-<name>-pid`; a second copy finds that process's visible unowned top-level window, restores it if minimized, calls `SetForegroundWindow` and exits 0. On macOS and Linux there is no window to find, so it just exits 0. **What it doesn't do:** take the library up in any app (that is FP-17's next work), forward anything to the running copy (at keeps all focusing of terminal apps), or give Go the window part (no Go desktop app needs it). **Tests**, the same cases in both languages: a second claim refused and the name free after release, the scope giving a separate lock, a claim made while the holder ends taking it, and child processes showing the stderr line with exit 1 and a lock freed when its holder exits without letting it go. Go's also cover a lock nothing refers to staying held through garbage collection; Rust's on Windows read back the recorded process id. Nothing opens a window, so the bring-forward is checked by hand in String Lab when it takes the crate. Checked before the push: `ci-check` (both languages' format, lints and Windows tests), Go vet for Linux, macOS and FreeBSD, Go's tests run on Linux under WSL, and clippy for Linux and macOS targets.
one-copy: the single-copy lock, its Go package and Rust crate (AHT-218)
All checks were successful
Suite rust / check-services (pull_request) Has been skipped
Suite go / check-format (pull_request) Successful in 26s
Suite release / module (pull_request) Has been skipped
Suite release / scope (pull_request) Successful in 23s
Suite rust / check-audit (pull_request) Has been skipped
Suite release / reused-checks (pull_request) Has been skipped
Suite release / publish (pull_request) Has been skipped
Suite release / deploy-image (pull_request) Has been skipped
Suite release / check-build (none, ubuntu-latest) (ubuntu-latest, none) (pull_request) Has been skipped
Suite release / home-sync (pull_request) Has been skipped
Suite rust / scope (pull_request) Successful in 22s
Suite rust / check-machete (pull_request) Has been skipped
Suite release / reserve (pull_request) Has been skipped
Suite go / check-services (pull_request) Has been skipped
Suite default / check-rules (pull_request) Successful in 19s
Suite go / check-test-windows (pull_request) Successful in 1m21s
Suite rust / check-typos (pull_request) Has been skipped
Suite release / finalize (pull_request) Has been skipped
Suite release / check-package (pull_request) Has been skipped
Suite release / dispatch (pull_request) Has been skipped
Suite default / check-fetches (pull_request) Successful in 20s
Suite release / build (none, ubuntu-latest) (ubuntu-latest, none) (pull_request) Has been skipped
Suite rust / check-format (pull_request) Successful in 30s
Suite go / check-test-linux (pull_request) Successful in 28s
Suite default / reused-checks (pull_request) Successful in 30s
Suite rust / check-test-linux (pull_request) Successful in 41s
Suite rust / check-test-windows (pull_request) Successful in 1m13s
Suite go / reused-checks (pull_request) Successful in 27s
Suite rust / reused-checks (pull_request) Successful in 39s
merge-queue landed on main
a454b50801
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
merge-queue deleted branch AHT-218-lock 2026-11-28 00:46:02 -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!1
No description provided.