fix(profiles): take the profile's edit lock as Longshot's builder does, so installs and updates finish again #427
No reviewers
Labels
No labels
area/build
area/install
area/mods
area/saves
area/tooling
area/ui
area/updates
ci: approved
good first issue
gpu/amd
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
platform/linux
platform/steam-deck
platform/windows
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/LongshotLauncher!427
Loading…
Reference in a new issue
No description provided.
Delete branch "llun/LongshotLauncher:fix/profile-edit-lock-os-lock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Since Longshot nightly-1179, every install and update in the Launcher stops at its last step with "Another editor is changing this profile. Try again in a moment.", and trying again stops the same way (#426). The Launcher now takes the profile's edit lock the way Longshot's builder does.
Why it happens
The Launcher, Longshot's builder and the mod tools share one lock file per profile,
.longshot-edit.lock. Longshot #3020 (merged 2026-12-05, first in nightly-1179) changed the builder's side to an operating-system lock on that file (File::try_lock), and the file now stays in place, empty, once the lock is let go. Everylongshot-builder build --profiletakes it, sinceplay::ensure_builtfirst writes copied mods into the profile (modtool::record_mods).The Launcher took any existing file as held, and only moved one aside when its second word was a time more than 30 seconds old. An empty file has none, so after each build
remember_build_options(src/game/wizard.rs) waited 2 seconds and failed. By then the build was in place and the version registered, but the build options, the game language, the settings and the clean-up of old builder downloads were skipped. Any other Launcher edit of that profile (save names, mods, language) failed the same way while the file was there, and every Play made it again.What changes
src/players/profiles.rs: the edit lock opens.longshot-edit.lock(made when missing, never emptied),try_locks it for up to 2 seconds as before, and leaves the file in place: the same rule as the builder'slauncher-profileand the mod tools. A file nobody holds never keeps an edit out, and a holder that ends however it ends lets go with its process, so the time stamp, the 30-second rule and the moving aside are gone.<pid> <epoch seconds>in it, free again when it is gone, unreadable or over 30 seconds old. While the Launcher holds the OS lock the file carries that text too, and it is emptied before the lock is let go, so an old builder waits for the Launcher's edit and finds the file free after it (on Windows it can't even read a locked file, so it waits either way). A fresh text of that form keeps the Launcher waiting in turn. Where an old builder could move the file aside as stale between the Launcher's lock and its text (not on Windows), the Launcher checks the path still names its file and takes it again if not. The 1179 builder ignores the text.Tested
a_lock_file_the_builder_left_does_not_keep_an_edit_out(the file as the builder leaves it, made and locked with the builder's ownOpenOptionsandtry_lock) andan_edit_waits_for_the_builder_while_it_holds_the_lock(an edit waits and fails while the builder holds it, goes through once it lets go, and the builder can take it again). Both fail on main with "Another editor is changing this profile" and pass with the fix.a_lock_an_old_builder_holds_keeps_an_edit_out_until_it_is_stale(a fresh<pid> <time>keeps the edit out; one 60 s old, or one ahead of the clock, doesn't, and the file is empty after) andan_old_builder_waits_while_the_launcher_edits_and_finds_the_lock_free_after(during the edit the file can't be read on Windows and holds this process's id and the time elsewhere; after it the file is empty, which an old builder takes as free, and the 1179 builder takes the lock again).cargo clippy --locked --all-targets -- -D warningsclean, rustfmt clean,python -I tests/test_launcher_core.py(353 passed, 0 failed, 5 ignored), Tooling'stests/test_release.py(46 tests, OK).flockand the path check) andcargo clippy --locked --all-targets -- -D warningsclean..longshot-edit.lockwas there, 0 bytes.fast check: current,seconds: 0.0, "Registering the installation", then the same error 2 s later: the player's log line for line.fast check: current, "Registering the installation", "Checking unused builder downloads", "Build completed" 0.2 s later; the profile now names nightly-1179 and its game file, and the builder's empty lock file is still in place.fast check: current, "Build completed" 0.2 s after). Both times the lock file was left in place and empty.Not covered
🤖 Generated with Claude Code
The hand test in a scratch portable library (Windows 11, real nightly-1179 builder):
Main's Launcher, fresh install of nightly-1179: the build finished, then the error.

Main's Launcher, update to nightly-1179 (

fast check: current,seconds: 0.0, as in the player's log):This branch, the same update: finished, "Build completed".

WIP: fix(profiles): take the profile's edit lock as Longshot's builder does, so installs and updates finish againto fix(profiles): take the profile's edit lock as Longshot's builder does, so installs and updates finish againRecommendation: Request changes. The recorded Windows update shows that the new lock fixes the nightly-1179 failure, but it breaks profile edits by older installed builders and no longer excludes their concurrent edits. Linux interoperability has not yet been exercised.
The launcher uses the builder’s operating-system lock, allowing installs and updates to finish when an empty lock file remains. The cost is a compatibility regression for profiles still used by pre-nightly-1179 games.
Blocking (1): must change before merging.
src/players/profiles.rs:106: The new lock protocol is incompatible with installed builders that still use the existence of this file as their lock. (more on the line) Do: Provide a safe transition for profiles used by older builders, coordinating with both lock protocols or preventing incompatible versions from using the profile until they are updated. Cover both an old holder and an old builder starting after a launcher edit.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
src/players/profiles.rs:110: The changed platform locking path has not been exercised on Linux with the actual builder. (more on the line) Do: Run a Linux install or update with the nightly-1179 builder and check contention and release between the builder and launcher.@fixcan do L1.Checks: Still running: 5 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the reported Windows update: the author reports that main failed after a two-second wait, while this branch completed the same update in 0.2 seconds. A fresh install with this branch and Linux have not been run by hand.
Other systems: The lock is shared by profile edits, mod operations, language changes and builders on Windows and Linux. New builders use the same OS-lock protocol; older builders use file existence and are incompatible with the new behavior. Linux uses the intended flock mechanism but has no recorded run.
Switches: None.
Reviewed:
47f688fe8fagainst48e2d127a6: Read AGENTS.md, CONTRIBUTING.md, the commit messages and both changed files; traced FileLease and profile-edit callers, including build registration, language and mod edits. Read docs/pull-requests.md. The named review checklist and pull request template are absent. Screenshots were not accessible; their accompanying run descriptions were read. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code or tests were run. The author reports Windows clippy, formatting, core and release tests passing, plus the recorded Windows update run. CI is still running.
Overlaps and merge order: None found in the supplied review context.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as llun took it out of WIP. Nothing was run; a maintainer decides.
@ -115,0 +103,4 @@.truncate(false).read(true).write(true).open(dir.join(".longshot-edit.lock"))L1 (blocking): The new lock protocol is incompatible with installed builders that still use the existence of this file as their lock.
When: After any launcher profile edit, the empty file remains in place, so a pre-nightly-1179 builder cannot acquire its old-style lock for the game's mod prompts or switches. Conversely, if an old builder already holds its timestamped file, the launcher takes an OS lock on it anyway, allowing concurrent profile edits and potentially lost changes.
Do: Provide a safe transition for profiles used by older builders, coordinating with both lock protocols or preventing incompatible versions from using the profile until they are updated. Cover both an old holder and an old builder starting after a launcher edit.
@ -115,0 +107,4 @@.context("Could not lock profile.json for editing.")?;let deadline = Instant::now() + Duration::from_secs(2);loop {match file.try_lock() {L2 (should fix): The changed platform locking path has not been exercised on Linux with the actual builder.
When: Linux installs and updates rely on the launcher and builder excluding one another and accepting a released lock file; the recorded hand test covers Windows only.
Do: Run a Linux install or update with the nightly-1179 builder and check contention and release between the builder and launcher.
Thanks, BeanBot. Pushed
d251ab1.L1: fixed for the case that was real. One half didn't hold: after a Launcher edit, a builder from before nightly-1179 does take the lock, since its
stale()(Longshot nightly-981,builder/crates/launcher-profile/src/edit.rs) treats a file it can't parse, the empty one included, as free and moves it aside. The other half was right: an old builder holding its<pid> <time>file didn't keep the Launcher out. Now:<pid> <epoch seconds>, and it is emptied before the lock is let go: an old builder waits for the Launcher's edit (on Windows it can't even read the locked file) and finds the file free after it;The 1179 builder ignores the text, so nothing changes with it. Two new tests cover an old holder and an old builder starting after a Launcher edit. On Windows: Clippy, rustfmt, the suite (353 passed), and the Launcher again with this commit (a fresh install of nightly-1179 and the update with
fast check: current, both "Build completed", the lock file left empty).L2: the players tests (25, the four lock tests among them) and Clippy pass on Linux (Ubuntu 24.04 in WSL 2). A run of the Launcher itself with the real Linux builder isn't possible here, so:
@Beanstalk On Linux, with this PR's Launcher: install or update a version to nightly-1179 (or newer) and check it ends with "Build completed", not "Another editor is changing this profile". Then rename a save or change the game language in the Launcher, and check it goes through.
@review
Recommendation: Request changes. The new lock fixes the reported nightly-1179 failure in the Windows install and update runs, but it still permits an old builder and the Launcher to edit the same profile concurrently on Linux.
The Launcher now uses the builder’s OS lock and writes a legacy lock record for older builders. This restores the reported install and update flow, but the compatibility protocol retains a race that can lose profile edits.
Blocking (1): must change before merging.
src/players/profiles.rs:106: The path check can complete before an old builder acts on a stale read of the lock file. When: On Linux, an old builder reads the empty file as free and pauses. The Launcher locks it, writes its token and passes the path check; the builder then moves that file aside, creates its own lock and edits the profile concurrently, allowing one edit to overwrite the other. Do: Use an interoperability protocol that prevents a legacy builder’s pending stale-file rename from displacing the lock during an edit, and cover the delayed-rename interleaving.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
src/players/profiles.rs:110: The changed platform locking path has not been exercised on Linux with the actual builder. When: Linux installs and updates rely on the launcher and builder excluding one another and accepting a released lock file; the recorded hand test covers Windows only. Do: Run a Linux install or update with the nightly-1179 builder and check contention and release between the builder and launcher.@fixcan do L1.Since the last review (on
47f688fe8f)Still open: L1 (The path check can complete before an old builder acts on a stale read of the lock file.); L2 (The changed platform locking path has not been exercised on Linux with the actual builder.)
Checks: Still running: 5 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes. The reported Windows runs show both a fresh install and an update completing after registration; main failed at that step. Linux lock tests passed, but a real Linux builder interoperability run is still outstanding.
Other systems: The lock also protects save-name, language, mod and build-option edits. The reported Windows and Linux tests exercise the lock, but do not cover the delayed legacy-builder rename race on Linux.
Switches: None.
Reviewed:
d251ab1888against48e2d127a6: Read AGENTS.md, CONTRIBUTING.md, the full diff, profiles.rs, the changed tests and FileLease; skimmed the remaining tests and lock callers. No review checklist or pull request template was found.; nothing run (a code review).Checked and fine:
Testing: No commands that run project code were executed. The author reports Windows suite, lint and real-builder install and update runs, plus Linux player tests and lint; CI is still running.
Overlaps and merge order: None identified from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
L1 (delayed rename on Linux): right, and it stays, deliberately. The window can't be closed from the Launcher's side:
flockis advisory and the old builder never asks for it. The Launcher's text, its path check and its OS lock all happen before a rename an old builder already decided on.So this PR keeps the old builders out everywhere the Launcher can see them (a fresh old-style text, and on Windows a locked file they can't read), and the description's Not covered now names the window. A maintainer decides whether that is enough.
L2: still with the Test Farm (asked above).