fix(builder): the profile edit lock is an OS advisory lock, freed on exit #3020

Merged
HumanBean merged 1 commit from PedroRossi/Longshot:fix/profile-edit-lock-holders into main 2026-12-05 18:43:13 +00:00
Contributor

Summary

The profile edit lock protects profile.json and trust.json while the builder (serving a playing game's channel),
the launcher and mod commands change them. It worked by writing a lock file holding the holder's pid and the time,
and taking it again when it looked stale (a dead holder, or one that had held it too long). Judging a file stale and
moving it aside is racy β€” the four points from the review:

  • two takers can both decide a dead holder's lock is stale and both take it (two holders);
  • a taker can read the lock after it is created but before its text is written, see nothing, and move a live one away;
  • putting a moved-aside lock back can lose the holder's own write;
  • an unknown or future modification time was treated as the oldest possible lock.

Rather than patch each race in the by-hand scheme, this replaces the mechanism with an operating-system advisory
lock
on the lock file (std::fs::File::try_lock), exactly as build-core's WorkLock, GameLock and ProfileLock
already do: one holder at a time, released when the guard is dropped or the process ends however it ends. There is no
stale detection left to race, a crashed edit leaves no file that keeps the next one out, and nothing reads or writes
the lock's contents. edit_lock waits up to WAIT for a held lock, then Busy. About 100 lines of pid/time,
staleness and move-aside code are gone; the public API (edit_lock, EditGuard::take, LockError, EDIT_LOCK,
WAIT) is unchanged.

Read first: EditGuard::take in builder/crates/launcher-profile/src/edit.rs.

Testing

Tested: on this PC (Debian 13), game-free. The four races were timing-dependent in the old scheme and aren't
unit-testable as deterministic races; removing the scheme removes them. Three tests lock in the new behavior:
one_edit_at_a_time_and_the_lock_frees_when_dropped (mutual exclusion and release β€” fails on main, which
deleted the lock file on release, part of what enabled the create-again race), a_waiting_taker_gets_it_the_moment_the_holder_lets_go
(the wait, across threads, on the real OS lock), and a_lock_file_left_by_a_dead_holder_does_not_keep_the_next_one_out.
cargo test -p launcher-profile passes; cargo clippy -p launcher-profile --all-targets -D warnings and rustfmt are
clean; cargo check -p build-driver compiles against the unchanged API. mise run test on both lock branches merged on current main: 832 passed, 56 failed, 13 skipped, the same as main β€” the 56 are pre-existing (45 need a tool this PC lacks on PATH under --strict: clang, spirv-val, glslang; the rest are GPU/compile fixtures), none in launcher-profile or longshot-builder. This change is tooling (the builder
and launcher's lock) and does not run in the game, so it was not run in-game.

Still to test:

  • Windows, by hand: two editors of one profile at once (a build serving a game's channel while a mod command or the
    launcher edits it), expecting one to wait and neither to lose a write. std::fs::File::try_lock uses LockFileEx
    there; the Linux flock path is covered above.

Measurements

Nothing to measure: a lock held for the moment of an edit; the new path makes fewer system calls than the old pid/time/stale scheme, and nothing a build or the game runs changes.

Risks

The lock file is now left in place when released (as build-core's locks leave theirs), where the old scheme deleted it
on drop; this is what lets the OS own the lock and is the point of the change. The public API is unchanged, so
build-driver's callers are untouched. A revert restores the old scheme.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

Found in an AI-assisted audit of the repository. The change, the tests and this description were made with Claude Code;
I reviewed them.

Co-Authored-By: Claude Opus 5.5 [email protected]

πŸ€– Generated with Claude Code

## Summary The profile edit lock protects `profile.json` and `trust.json` while the builder (serving a playing game's channel), the launcher and `mod` commands change them. It worked by writing a lock file holding the holder's pid and the time, and taking it again when it looked *stale* (a dead holder, or one that had held it too long). Judging a file stale and moving it aside is racy β€” the four points from the review: - two takers can both decide a dead holder's lock is stale and both take it (two holders); - a taker can read the lock after it is created but before its text is written, see nothing, and move a live one away; - putting a moved-aside lock back can lose the holder's own write; - an unknown or future modification time was treated as the oldest possible lock. Rather than patch each race in the by-hand scheme, this replaces the mechanism with an **operating-system advisory lock** on the lock file (`std::fs::File::try_lock`), exactly as build-core's `WorkLock`, `GameLock` and `ProfileLock` already do: one holder at a time, released when the guard is dropped or the process ends however it ends. There is no stale detection left to race, a crashed edit leaves no file that keeps the next one out, and nothing reads or writes the lock's contents. `edit_lock` waits up to `WAIT` for a held lock, then `Busy`. About 100 lines of pid/time, staleness and move-aside code are gone; the public API (`edit_lock`, `EditGuard::take`, `LockError`, `EDIT_LOCK`, `WAIT`) is unchanged. Read first: `EditGuard::take` in `builder/crates/launcher-profile/src/edit.rs`. ## Testing **Tested:** on this PC (Debian 13), game-free. The four races were timing-dependent in the old scheme and aren't unit-testable as deterministic races; removing the scheme removes them. Three tests lock in the new behavior: `one_edit_at_a_time_and_the_lock_frees_when_dropped` (mutual exclusion and release β€” **fails on `main`**, which deleted the lock file on release, part of what enabled the create-again race), `a_waiting_taker_gets_it_the_moment_the_holder_lets_go` (the wait, across threads, on the real OS lock), and `a_lock_file_left_by_a_dead_holder_does_not_keep_the_next_one_out`. `cargo test -p launcher-profile` passes; `cargo clippy -p launcher-profile --all-targets -D warnings` and rustfmt are clean; `cargo check -p build-driver` compiles against the unchanged API. `mise run test` on both lock branches merged on current main: 832 passed, 56 failed, 13 skipped, the same as main β€” the 56 are pre-existing (45 need a tool this PC lacks on PATH under `--strict`: clang, spirv-val, glslang; the rest are GPU/compile fixtures), none in launcher-profile or longshot-builder. This change is tooling (the builder and launcher's lock) and does not run in the game, so it was not run in-game. **Still to test:** - Windows, by hand: two editors of one profile at once (a build serving a game's channel while a `mod` command or the launcher edits it), expecting one to wait and neither to lose a write. `std::fs::File::try_lock` uses `LockFileEx` there; the Linux `flock` path is covered above. ## Measurements Nothing to measure: a lock held for the moment of an edit; the new path makes fewer system calls than the old pid/time/stale scheme, and nothing a build or the game runs changes. ## Risks The lock file is now left in place when released (as build-core's locks leave theirs), where the old scheme deleted it on drop; this is what lets the OS own the lock and is the point of the change. The public API is unchanged, so build-driver's callers are untouched. A revert restores the old scheme. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. --- Found in an AI-assisted audit of the repository. The change, the tests and this description were made with Claude Code; I reviewed them. Co-Authored-By: Claude Opus 5.5 <[email protected]> πŸ€– Generated with [Claude Code](https://claude.com/claude-code)
The edit lock (launcher-profile's edit.rs) is made empty and its holder's text written a moment later: a taker that
reads it in between finds nothing readable, takes it as stale and moves it away, and both hold the lock. And when a
stale lock can't be moved (on Windows, a program holding it), the loop tries again at once, never sleeping nor looking
at its deadline. Three cases: a young unreadable lock is held (and taken once older than the wait), an unwritten one
is held, an unmovable stale one waits out the wait. They fail on main (the last by its timeout).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(builder): the profile edit lock takes a stale lock only when it is one, and puts back one moved in error
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
9b9def088a
An unreadable lock is stale only once older than the wait (stale reads the file's age): younger, a taker between
making it and writing it holds it. A stale lock moved aside is looked at first (move_stale): a fresh one another taker
made since the read goes back in its place, never removed. A move that fails, or that took a fresh lock, waits as for
a held one, so the deadline and the sleep apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01: the game built by a builder from main @ 1938a302 with this change merged (and my two other builder pull requests from the same audit), through the PC's job queue, played from the Market entrance repository save, then the control bridge's quit; exit 0. The profile code this changes runs in the launcher's play and build, not in the game.

Tested in game: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01: the game built by a builder from main @ 1938a302 with this change merged (and my two other builder pull requests from the same audit), through the PC's job queue, played from the Market entrance repository save, then the control bridge's quit; exit 0. The profile code this changes runs in the launcher's play and build, not in the game.
PedroRossi changed title from WIP: fix(builder): the profile edit lock takes a stale lock only when it is one, and puts back one moved in error to fix(builder): the profile edit lock takes a stale lock only when it is one, and puts back one moved in error 2026-12-02 17:54:22 +00:00
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The recovery path can still give two editors the lock and lose profile changes. A partially written holder record can also be mistaken for an old lock.

The change adds a wait for young unreadable locks and failed stale-lock moves, but its move-and-restore protocol does not preserve mutual exclusion during recovery.

Blocking (4): must change before merging.

  1. L1 builder/crates/launcher-profile/src/edit.rs:78: Moving a fresh lock away before checking it leaves the lock path available to another editor, so putting it back cannot ensure mutual exclusion. (more on the line) Do: Use a cross-process locking or stale-recovery protocol that never makes a live holder's lock path available to another taker, and add a controlled concurrent test covering this interleaving.
  2. L2 builder/crates/launcher-profile/src/edit.rs:81: Restoring a moved lock by copying its current contents loses a holder's subsequent write to the original file. (more on the line) Do: Keep the original lock object and its ownership intact throughout recovery, including while its creator is writing, and test this interleaving.
  3. L3 builder/crates/launcher-profile/src/edit.rs:56: A partially written holder record can already parse as a PID and timestamp, bypassing the new age protection. (more on the line) Do: Publish a complete holder record atomically or use a representation that cannot be accepted until the write is complete; add a test for a parseable partial record.
  4. L4 builder/crates/launcher-profile/src/edit.rs:71: An unknown or future modification time is treated as the oldest possible lock, including when the lock was just created. (more on the line) Do: Treat an unavailable or future timestamp conservatively as young, or use a recovery mechanism that does not rely on wall-clock file age.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 builder/crates/launcher-profile/src/edit.rs:140: The Windows held-open-file recovery path still needs the run listed in the pull request. (more on the line) Do: Run the stated Windows case and record the result after the recovery protocol is corrected.

@fix can do L1, L2, L3 and L4.

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven overall. The author reports that the new game-free cases fail on main and pass here, but they do not exercise the concurrent move-and-restore interleavings or a partially written valid record.

Other systems: The lock protects builder channel edits and is exposed to launcher and mod-tool editors. Both Windows and Linux can encounter the recovery races; the reported Linux game run does not exercise them. The Windows held-open-file case remains untested.

Switches: None.

Reviewed: 9b9def088a against 1938a302fe: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, both commits, the complete diff and edit.rs, and the builder channel caller. Skimmed the other lock references and the reported runs. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance in trailers.
  • The change adds no switches, generated files, game-derived files, or renderer API changes.
  • The failed-move branch now reaches the deadline check and sleep.
  • The pull request names the checks reported to fail on the base as well.

Testing: No code or tests were run during review. The author reports game-free tests and a Linux game run; CI is still running, and the Windows held-open-file case is outstanding.

Overlaps and merge order: No overlapping pull requests identified from the supplied information.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The recovery path can still give two editors the lock and lose profile changes. A partially written holder record can also be mistaken for an old lock. The change adds a wait for young unreadable locks and failed stale-lock moves, but its move-and-restore protocol does not preserve mutual exclusion during recovery. **Blocking (4)**: must change before merging. 1. **L1** `builder/crates/launcher-profile/src/edit.rs:78`: Moving a fresh lock away before checking it leaves the lock path available to another editor, so putting it back cannot ensure mutual exclusion. (more on the line) **Do:** Use a cross-process locking or stale-recovery protocol that never makes a live holder's lock path available to another taker, and add a controlled concurrent test covering this interleaving. 2. **L2** `builder/crates/launcher-profile/src/edit.rs:81`: Restoring a moved lock by copying its current contents loses a holder's subsequent write to the original file. (more on the line) **Do:** Keep the original lock object and its ownership intact throughout recovery, including while its creator is writing, and test this interleaving. 3. **L3** `builder/crates/launcher-profile/src/edit.rs:56`: A partially written holder record can already parse as a PID and timestamp, bypassing the new age protection. (more on the line) **Do:** Publish a complete holder record atomically or use a representation that cannot be accepted until the write is complete; add a test for a parseable partial record. 4. **L4** `builder/crates/launcher-profile/src/edit.rs:71`: An unknown or future modification time is treated as the oldest possible lock, including when the lock was just created. (more on the line) **Do:** Treat an unavailable or future timestamp conservatively as young, or use a recovery mechanism that does not rely on wall-clock file age. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `builder/crates/launcher-profile/src/edit.rs:140`: The Windows held-open-file recovery path still needs the run listed in the pull request. (more on the line) **Do:** Run the stated Windows case and record the result after the recovery protocol is corrected. `@fix` can do L1, L2, L3 and L4. **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven overall. The author reports that the new game-free cases fail on main and pass here, but they do not exercise the concurrent move-and-restore interleavings or a partially written valid record. **Other systems:** The lock protects builder channel edits and is exposed to launcher and mod-tool editors. Both Windows and Linux can encounter the recovery races; the reported Linux game run does not exercise them. The Windows held-open-file case remains untested. **Switches:** None. **Reviewed:** 9b9def088a7f against 1938a302feb0: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, both commits, the complete diff and edit.rs, and the builder channel caller. Skimmed the other lock references and the reported runs. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance in trailers. - The change adds no switches, generated files, game-derived files, or renderer API changes. - The failed-move branch now reaches the deadline check and sleep. - The pull request names the checks reported to fail on the base as well. **Testing:** No code or tests were run during review. The author reports game-free tests and a Linux game run; CI is still running, and the Windows held-open-file case is outstanding. **Overlaps and merge order:** No overlapping pull requests identified from the supplied information. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -53,2 +53,4 @@
/// it holds it.
fn stale(text: &str, age: Duration, now: SystemTime, alive: &dyn Fn(u32) -> bool) -> bool {
let mut it = text.split_whitespace();
let (Some(pid), Some(at)) =
Member

L3 (blocking): A partially written holder record can already parse as a PID and timestamp, bypassing the new age protection.

When: If a reader sees a prefix such as 1234 1 while the creator is writing its current timestamp, both fields parse and the timestamp appears decades old. The reader removes the young live lock as stale and both editors can write the profile.

Do: Publish a complete holder record atomically or use a representation that cannot be accepted until the write is complete; add a test for a parseable partial record.

**L3** (blocking): A partially written holder record can already parse as a PID and timestamp, bypassing the new age protection. *When:* If a reader sees a prefix such as `1234 1` while the creator is writing its current timestamp, both fields parse and the timestamp appears decades old. The reader removes the young live lock as stale and both editors can write the profile. **Do:** Publish a complete holder record atomically or use a representation that cannot be accepted until the write is complete; add a test for a parseable partial record.
@ -63,0 +68,4 @@
.and_then(|m| m.modified())
.ok()
.and_then(|at| SystemTime::now().duration_since(at).ok())
.unwrap_or(Duration::MAX)
Member

L4 (blocking): An unknown or future modification time is treated as the oldest possible lock, including when the lock was just created.

When: If the system clock moves backward after a creator makes an empty lock, its modification time is in the future. A competing taker gets Duration::MAX, immediately moves the live lock away and can edit at the same time.

Do: Treat an unavailable or future timestamp conservatively as young, or use a recovery mechanism that does not rely on wall-clock file age.

**L4** (blocking): An unknown or future modification time is treated as the oldest possible lock, including when the lock was just created. *When:* If the system clock moves backward after a creator makes an empty lock, its modification time is in the future. A competing taker gets Duration::MAX, immediately moves the live lock away and can edit at the same time. **Do:** Treat an unavailable or future timestamp conservatively as young, or use a recovery mechanism that does not rely on wall-clock file age.
@ -63,0 +75,4 @@
/// is looked at first: a fresh lock another taker made since the read goes back in its place, never removed.
fn move_stale(path: &Path, held: &str) -> bool {
let aside = path.with_extension(format!("stale-{}", std::process::id()));
if std::fs::rename(path, &aside).is_err() {
Member

L1 (blocking): Moving a fresh lock away before checking it leaves the lock path available to another editor, so putting it back cannot ensure mutual exclusion.

When: Two takers judge a dead lock stale. After the first replaces it and starts editing, the second renames that fresh lock aside; a third taker creates the now-missing path and starts editing too. The restore then fails with AlreadyExists and removes the first holder's lock from the aside path.

Do: Use a cross-process locking or stale-recovery protocol that never makes a live holder's lock path available to another taker, and add a controlled concurrent test covering this interleaving.

**L1** (blocking): Moving a fresh lock away before checking it leaves the lock path available to another editor, so putting it back cannot ensure mutual exclusion. *When:* Two takers judge a dead lock stale. After the first replaces it and starts editing, the second renames that fresh lock aside; a third taker creates the now-missing path and starts editing too. The restore then fails with AlreadyExists and removes the first holder's lock from the aside path. **Do:** Use a cross-process locking or stale-recovery protocol that never makes a live holder's lock path available to another taker, and add a controlled concurrent test covering this interleaving.
@ -63,0 +78,4 @@
if std::fs::rename(path, &aside).is_err() {
return false;
}
let moved = std::fs::read_to_string(&aside).unwrap_or_default();
Member

L2 (blocking): Restoring a moved lock by copying its current contents loses a holder's subsequent write to the original file.

When: A stale-lock taker renames a fresh lock after its owner creates the file but before it writes its text. It reads and restores an empty file, then removes the aside; the owner writes to the moved file and returns a guard, while the visible lock remains empty and can be reclaimed after two seconds during that edit.

Do: Keep the original lock object and its ownership intact throughout recovery, including while its creator is writing, and test this interleaving.

**L2** (blocking): Restoring a moved lock by copying its current contents loses a holder's subsequent write to the original file. *When:* A stale-lock taker renames a fresh lock after its owner creates the file but before it writes its text. It reads and restores an empty file, then removes the aside; the owner writes to the moved file and returns a guard, while the visible lock remains empty and can be reclaimed after two seconds during that edit. **Do:** Keep the original lock object and its ownership intact throughout recovery, including while its creator is writing, and test this interleaving.
@ -111,2 +139,2 @@
if std::fs::rename(&path, &aside).is_ok() {
let _ = std::fs::remove_file(&aside);
Ok(held) if stale(&held, age(&path), SystemTime::now(), alive) => {
if move_stale(&path, &held) {
Member

L5 (should fix): The Windows held-open-file recovery path still needs the run listed in the pull request.

When: A Windows program holds a stale lock without delete sharing; the launcher must stop retrying at its deadline and report the profile busy.

Do: Run the stated Windows case and record the result after the recovery protocol is corrected.

**L5** (should fix): The Windows held-open-file recovery path still needs the run listed in the pull request. *When:* A Windows program holds a stale lock without delete sharing; the launcher must stop retrying at its deadline and report the profile busy. **Do:** Run the stated Windows case and record the result after the recovery protocol is corrected.
Author
Contributor

@fix

The lock recovery protocol (L1–L4): make lock publication and stale recovery mutually safe for concurrent takers, and treat an unreadable or future modification time as young rather than ancient.

@fix The lock recovery protocol (L1–L4): make lock publication and stale recovery mutually safe for concurrent takers, and treat an unreadable or future modification time as young rather than ancient.
PedroRossi force-pushed fix/profile-edit-lock-holders from 9b9def088a
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to ff9c6d922a
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
2026-12-04 19:22:22 +00:00
Compare
PedroRossi changed title from fix(builder): the profile edit lock takes a stale lock only when it is one, and puts back one moved in error to fix(builder): the profile edit lock is an OS advisory lock, freed on exit 2026-12-04 19:23:23 +00:00
Author
Contributor

Reworked after the review. Rather than patch the four races in the stale-detection scheme, I replaced the mechanism with an OS advisory lock (std::fs::File::try_lock, as build-core's WorkLock/GameLock/ProfileLock already use): one holder at a time, released by the OS when the guard drops or the process ends, so there is no stale detection left to race and a crashed edit leaves no file that blocks the next one. ~100 lines of pid/time/stale/move-aside code gone; the public API is unchanged and build-driver compiles against it. New title and description above.

Reworked after the review. Rather than patch the four races in the stale-detection scheme, I replaced the mechanism with an OS advisory lock (std::fs::File::try_lock, as build-core's WorkLock/GameLock/ProfileLock already use): one holder at a time, released by the OS when the guard drops or the process ends, so there is no stale detection left to race and a crashed edit leaves no file that blocks the next one. ~100 lines of pid/time/stale/move-aside code gone; the public API is unchanged and build-driver compiles against it. New title and description above.
Owner
@review
BeanBot left a comment

Recommendation: Approve. The advisory lock removes the four stale-recovery races, and the reported Linux tests exercise exclusion and release. Windows concurrent editing and the pending CI checks still need results before merge. Nothing blocking is left. Recommend approval; not approved on the forge.

Profile edits use an OS-managed lock that remains on disk and is released when its holder exits. This removes the stale-file recovery code and its races, at the cost of changing the lock-file lifecycle.

Since the last review (on 9b9def088a)
Resolved: L1 (Moving a fresh lock away before checking it leaves the lock path available to another edit…); L2 (Restoring a moved lock by copying its current contents loses a holder's subsequent write t…); L3 (A partially written holder record can already parse as a PID and timestamp, bypassing the…); L4 (An unknown or future modification time is treated as the oldest possible lock, including w…); L5 (The Windows held-open-file recovery path still needs the run listed in the pull request.)

Checks: Still running: 10 checks.

Also noticed (4; not asked for, not blocking)
  • The build-driver tests in game_ops.rs and channel/tests.rs still assert that the released lock file does not exist, although the new guard leaves it in place.
  • The build reference still describes PID and timestamp stale detection.
  • The Windows concurrent-editor run remains outstanding.
  • The network-confirmation path in channel.rs proceeds with its trust-file write even if taking the edit lock fails.
More: does it help, other systems, switches, what was read

Does it help: Yes on Linux: the reported launcher-profile tests cover exclusion, waiting and release, and the new code removes the stale-recovery paths. Windows behavior remains untested.

Other systems: The builder, mod commands and launcher share this profile lock on Linux and Windows; the game rendering path is unaffected. Windows concurrent editing has not been run. Existing build-driver tests still expect the lock file to be deleted.

Switches: None.

Reviewed: ff9c6d922a against b77c2f4b3e: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the full changed edit.rs, the diff and commit, and build-core's lock implementation. Read relevant build-driver callers and tests and the build reference; other callers were located and skimmed. Tooling's AGENTS.md was unavailable; no review checklist was found.; nothing run (a code review).

Checked and fine:

  • The guard retains the open file until drop, and contention is retried until the deadline.
  • The existing Rust workspace version supports the file-lock API.
  • No game files, generated files or third-party files are changed.

Testing: No commands were run beyond read-only inspection. The author reports launcher-profile tests, clippy and formatting passing on Debian; the Windows run is outstanding and CI is still running.

Overlaps and merge order: None found in the supplied information.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The advisory lock removes the four stale-recovery races, and the reported Linux tests exercise exclusion and release. Windows concurrent editing and the pending CI checks still need results before merge. Nothing blocking is left. Recommend approval; not approved on the forge. Profile edits use an OS-managed lock that remains on disk and is released when its holder exits. This removes the stale-file recovery code and its races, at the cost of changing the lock-file lifecycle. **Since the last review** (on 9b9def088a7f) Resolved: L1 (Moving a fresh lock away before checking it leaves the lock path available to another edit…); L2 (Restoring a moved lock by copying its current contents loses a holder's subsequent write t…); L3 (A partially written holder record can already parse as a PID and timestamp, bypassing the…); L4 (An unknown or future modification time is treated as the oldest possible lock, including w…); L5 (The Windows held-open-file recovery path still needs the run listed in the pull request.) **Checks:** Still running: 10 checks. <details> <summary>Also noticed (4; not asked for, not blocking)</summary> - The build-driver tests in game_ops.rs and channel/tests.rs still assert that the released lock file does not exist, although the new guard leaves it in place. - The build reference still describes PID and timestamp stale detection. - The Windows concurrent-editor run remains outstanding. - The network-confirmation path in channel.rs proceeds with its trust-file write even if taking the edit lock fails. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes on Linux: the reported launcher-profile tests cover exclusion, waiting and release, and the new code removes the stale-recovery paths. Windows behavior remains untested. **Other systems:** The builder, mod commands and launcher share this profile lock on Linux and Windows; the game rendering path is unaffected. Windows concurrent editing has not been run. Existing build-driver tests still expect the lock file to be deleted. **Switches:** None. **Reviewed:** ff9c6d922ae6 against b77c2f4b3e41: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the full changed edit.rs, the diff and commit, and build-core's lock implementation. Read relevant build-driver callers and tests and the build reference; other callers were located and skimmed. Tooling's AGENTS.md was unavailable; no review checklist was found.; nothing run (a code review). **Checked and fine:** - The guard retains the open file until drop, and contention is retried until the deadline. - The existing Rust workspace version supports the file-lock API. - No game files, generated files or third-party files are changed. **Testing:** No commands were run beyond read-only inspection. The author reports launcher-profile tests, clippy and formatting passing on Debian; the Windows run is outstanding and CI is still running. **Overlaps and merge order:** None found in the supplied information. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/profile-edit-lock-holders 2026-12-05 18:43:13 +00:00
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
MagicBeanDev/Longshot!3020
No description provided.