fix(builder): play holds the launcher's save lock while the game runs #3174
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3174
Loading…
Reference in a new issue
No description provided.
Delete branch "neotoxic/Longshot:fix/play-holds-save-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?
The launcher can replace a save while the game is running: it edits saves under the profile's save lock, but nothing
holds that lock once the game runs, nor for a game started without the launcher. This is the Longshot follow-up llun
asked for on MagicBeanDev/LongshotLauncher#366: the builder's
playholds the save lock while the game runs.Summary
What was wrong. The launcher (MagicBeanDev/LongshotLauncher#366) changes a save (an import, a copy, an edit on its
Progress page) under the profile's save lock,
<profile>/.longshot-save-transfer.lock. It holds that lock itself onlyfrom just before it starts the builder until the builder runs, then lets it go. From then on, and for a game started
without the launcher (Steam, a shortcut,
longshot-builder play), nothing held it: an edit could replace a save undera running game, which then wrote its own copy back over the edit or read a file that changed under it. llun's request
on that PR: "open the Longshot follow-up, with the builder's
playholding the save lock while the game runs".What this changes.
playtakes the same lock around each run of the game, a restart's too (Restart now, or arestart that asked for a build), and lets it go as the game ends:
players::saves::SaveLock: exclusive (File::try_lock, which thelauncher's
FileLeaseuses too), opened shared with no one on Windows, made when missing, never truncated; a link ora folder in its place refused (
save_lock_invalid, said asprofile_unwritable).for no reason, since no game is running yet. Between two runs of a restart the lock is let go too; no game runs then.
tries again every 25 ms for at most five seconds (as the launcher's
play_lock_within). Still held after that, thegame is not started: "Longshot did not start the game: the launcher is changing a save of the profile in ... Wait for
it to finish, then play again." (
saves_busy, anerrorevent with--output json, exit status 121).Read first:
build_core::lock::SaveLock(builder/crates/build-core/src/lock.rs), the lock taken aroundhost.startinbuild_driver::play::play(builder/crates/build-driver/src/play.rs),Played::SavesBusyinlongshot-builder/src/play.rs. Docs:docs/dev/reference/build.md("The saves held while the game runs") and thecodes in
docs/dev/reference/build-events.md.See MagicBeanDev/LongshotLauncher#366.
Testing
Tested: Windows 11 (x86_64-pc-windows-gnullvm through
scripts/dev.py cargo). In the game too, on this headmerged with #2957 and #3175 (no conflict), built with
longshot_builder.pyand run from the launcher ofLongshotLauncher#366:
Windows 11, in the game (by hand): started the game from the launcher, opened the launcher's Progress page and
marked a line done while the game ran: the edit was refused (the launcher shows "Another launcher may be changing
these saves." with os error 32) and the save is unchanged. The game started and played as before.
build_driver::play::tests::the_game_runs_with_the_saves_held_and_waits_for_an_edit_of_them(new): the saves areheld at each start, a restart's too, and free once
playreturns; an edit holding them as the game is to start iswaited for (let go after 200 ms) and the game then starts with them held; an edit that never lets go gives
Played::SavesBusyand no start. Againstmain's behaviour (the lock taken out ofplay, the test left as it is),it fails:
left: (Exited(0), [false, false]),right: (Exited(0), [true, true]).build_core::lock::tests::the_saves_wait_for_their_holder_and_a_link_is_refused(new): held refuses a second take,take_withinwaits for a holder that lets go, the lock file is never truncated, a folder in its place is refused.The symbolic-link case runs only where the OS lets the test make a link.
cargo test -p build-core -p build-driver -p longshot-builder --locked --no-fail-fast: build-core 201 passed,1 ignored; build-driver lib 225 passed, 1 failed; build-driver
tests/codes.rs(every code in build-events.md) 1 passed,its other integration tests passed; longshot-builder bin 61 passed, 1 failed;
tests/hot_split.rs3 passed, 3 failed;tests/one_copy.rs2 passed. The 5 failures fail the same way onmainon this PC (changes stashed, same command):tools::tests::the_repository_s_lock_and_the_table_agree(the compiler's hash in the table), anddev::site_hooks::tests::every_form_answers_as_its_hook_runsand the 3hot_splittests (no clang on this PC,LONGSHOT_NO_CLANGunset).cargo fmt --all --check: clean.cargo clippy -p build-core -p build-driver -p longshot-builder --all-targets --locked -- -D warnings -A unused-imports:clean. Without
-A unused-importsit stops onnote_linesunused inbuild-core/src/sandbox_windows.rs:384, whichthis PR does not touch (the same on
main).Linux (CachyOS, x86_64), this head:
python -I scripts/dev.py cargo -- test -p build-core -p build-driver -p longshot-builder --locked --no-fail-fast:everything passes but 2, which fail the same way on
main(d6e819e0) there:tools::tests::the_repository_s_lock_and_the_table_agree(the compiler's hash) and
one_copy'sinstalled_versions_reuse_their_own_builds_with_one_profile(a JSON writtenpretty, compared compact). The
cfg(windows)parts are left out there, the rest builds.Linux, this head:
mise run testin full: 878 passed, 8 failed, 13 skipped. 5 fail the same way onmain(d6e819e0)there:
test_check_third_party,test_ci_source_times,test_dev_vcs,test_run_all_output,test_run_all_reap;test_run_all_junittimed out in the full run and passes alone, here and onmain;test_lifterandtest_lifter_semanticsstopped at 600 s under the load of the full run.mise run lint: passes.Still to test:
on a copy of a save).
@Beanstalk start a profile, check <profile>/.longshot-save-transfer.lock is locked while the game runs and free after it exits).Measurements
Nothing to measure: a file lock taken once per start of the game, no change to the game's frames or the build.
Risks
is changing these saves."), not "Close the game first."; the launcher may want to map that error.
starting (exit status 121, said to the player); playing again once it ends works.
.longshot-save-transfer.lockis a link or a folder no longer plays until it is removed (said asprofile_unwritable).settings.tomlor the caches after updating.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: not yet: the builder's tests cover the lock around each start (a test that fails without the change); a run through the launcher with an edit attempted while the game is open comes next.
Possibly related, for context:
WIP: fix(builder): play holds the launcher's save lock while the game runsto fix(builder): play holds the launcher's save lock while the game runsb77c2f4b) into fix/play-holds-save-lock 1b3e8606f5e345b3cab) into fix/play-holds-save-lockBrought up to current
main(e345b3ca) by a merge, nothing rewritten. Windows,run_all.py --changed origin/main: 8 passed, 0 failed.@review
Recommendation: Approve. The code is ready: only testing is left. The game-free tests and Windows game run support the fix, but the launcher interaction still needs an end-to-end Linux run and the remaining Windows release and direct-start checks. Recommend approval; not approved on the forge.
The builder holds the launcher's profile save lock during each game run, preventing concurrent launcher edits. It adds a wait of up to five seconds at startup when the lock is busy.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/build-driver/src/play.rs:1012: The Linux launcher-to-builder lock interaction has not been exercised with a running game. (more on the line) Do: Run the described Linux game and launcher checks, including a direct start and an edit after exit, and report the results.builder/crates/build-driver/src/play.rs:1012: The Windows game run has not yet checked a direct start or an edit after the game exits. (more on the line) Do: Complete the two Windows checks listed in Still to test and report the results.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes: the reported game-free test fails without the lock and passes with it, and a Windows game run refused an edit while preserving the save. Linux end-to-end behavior and the remaining Windows cases have not yet been reported.
Other systems: The lock affects game startup and save transfers on Windows and Linux, including Steam and shortcut starts and restarts. The reported tests exercise restarts and lock release; a Windows launcher run exercised a held lock. Linux launcher interaction and the remaining direct-start and post-exit cases need runs.
Switches: None.
Reviewed:
985387af9fagainste345b3cab4: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the relevant standards, the diff, commits, changed lock and play paths, save migration and process-wait code. Skimmed the unchanged portions of the large play files and the changed reference documentation. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No commands from the pull request or tests were run during review. The author reports passing relevant game-free tests on Windows and Linux apart from named base failures, and one Windows in-game launcher edit check. CI is still running.
Overlaps and merge order: The change coordinates with LongshotLauncher#366; its merge status and ordering are not available in the supplied context.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -995,0 +1009,4 @@// (the saves held while the game runs, the launcher's save lock: no save transfer of the launcher replaces a// save under it, even a game started without the launcher. Taken after the update, not across it, so a build// keeps no edit out; waited for, as the launcher lets its own go once this builder runs)let held = match SaveLock::take_within(&profile, build_core::lock::SAVE_WAIT) {L1 (should fix): The Linux launcher-to-builder lock interaction has not been exercised with a running game.
When: On Linux, a launcher edit and a game started through the launcher or a shortcut must contend on the same profile lock, and edits must work again after the game exits.
Do: Run the described Linux game and launcher checks, including a direct start and an edit after exit, and report the results.
L2 (should fix): The Windows game run has not yet checked a direct start or an edit after the game exits.
When: A shortcut or Steam start must prevent an edit while the game runs, and a subsequent edit must succeed once its lock is released.
Do: Complete the two Windows checks listed in Still to test and report the results.