fix(fs): closing the game waits for a save being committed, and starts none after #3017
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3017
Loading…
Reference in a new issue
No description provided.
Delete branch "PedroRossi/Longshot:fix/close-waits-for-commit"
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?
Summary
Closing the game while an autosave is being committed cuts the commit short. Every way out of the game (the window's
close, the control bridge's
quit, the Windows stop worker) ends inhos_close_finish, which waits at most 3 s for afile open for writing; a commit has none open (
nn_fs.crefuses to commit with one), so the game exits mid-commit. Thesave is lost, and its staged
<n>.longshot-newstays in the committed folder, where it refuses every later commit ofthat profile (
fs: Commit: 0 files, 2 ops ... result 0x2ee202) until someone deletes it by hand.hos_fs_hold_saves()(host/nn_fs.c), called right afterhos_fs_wait_writes()inhos_close_finish(
host/hos_relaunch.c), takessave_lockand keeps it, waiting at most 3 s as the wait for writes does: a commitalready running finishes first, and none starts after.
How to see it on main: quit (window close, or the bridge's
quit) at the moment an autosave's commit stages its firstfile. The committed save folder keeps
1.longshot-new, and the next start of that profile can't save.It builds on #1422, which made the close wait for a file being written. This complements #2806, which makes a later commit recover from a staged file left behind; this keeps it from being
left at all. The two apply together with no conflict (tested together, below).
Read first:
hos_fs_hold_savesinhost/nn_fs.c, thenhos_close_finishinhost/hos_relaunch.c.Testing
Tested: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless with the control bridge. A script started the Market entrance repository save,
teleported until the Transition autosave wrote, and quit at the moment the commit staged its first file ("stage") or
the game wrote its work copy ("write"); then it read the save folder and started the same profile again, which had to
save.
55773e3: 8 runs. The close never waited; each of the 4 "stage" runs left1.longshot-new, and each next startcould not save at all (10 of 10 commits
result 0x2ee202).55773e3: 8 runs, all clean. In 5 the close waited for the commit (stop: a save was being committed: waited 20 ms for it); every next start saved; exit 0 every time.56823e27: test_fs_save_commit.py (36 PASS: #2806's cases and this one) andtest_windows_stop.py pass; the game built from main @
56823e27with #2806 and this change, 4 runs of the same script: 4 quits while a save was written or committed, in 2 the close waited for the commit, nothing left behind, every next start saved, exit 0.Checks: the new close case of test_fs_save_commit.py fails on main (the close returns while a commit holds
save_lock)and passes here; test_windows_stop.py passes; the host's C compiled for Windows with llvm-mingw (check_host_compile.py:
0 failed);
mise run test(--strict) on main @1938a302, and on main with this change merged (together with #3018, #3019, #3020, #3021, #3022, from the same audit): 775 passed, 145 failed, 10 skipped both ways, so none fails only with it. The 145 are named at the end.Still to test:
no crash (the close now also waits for a save being committed, at most 3 s)
start to save (two starts: not something the Test Farm plays)
Measurements
Nothing to measure: a close waits for a commit already running, at most 3 s (20 ms in the runs above).
Risks
A close during a commit now lasts as long as the commit (tens of milliseconds here; past 3 s it logs that and exits as
before). A commit asked after the close no longer runs: the game is exiting. A revert undoes it. After updating, players
notice only that a save survives a close.
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.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.The 145 checks of
mise run testthat fail on main @1938a302on this PC too, with or without this change97 need a tool this PC doesn't have on PATH (
--strictfails them):48 fail on main itself: test_blocks_at_start.py, test_bug_report.py, test_cloth_kernels.py, test_cloth_loops.py, test_cloth_sphere.py, test_cloth_step12.py, test_cloth_step8.py, test_cloth_step9.py, test_control_picture.py, test_crash_record.py, test_crt_options.py, test_dev_update.py, test_dlssg_pace.py, test_draw_stream_visibility.py, test_framegen_resources.py, test_fsr_uniform_ownership.py, test_game_boundary.py, test_guest_holes.py, test_image_reaper_threads.py, test_image_view_retry.py, test_input_background.py, test_keyboard_option.py, test_linux_pressure.py, test_loaded_modules_drop.py, test_log_levels.py, test_menu_keys.py, test_menu_save_atomic.py, test_mesh_first_types.py, test_oot_occ_raster.py, test_option_ids.py, test_perf_send.py, test_pipeline_tour.py, test_present_acquire_ahead.py, test_present_image_free.py, test_present_source_crop.py, test_program_cache_cleanup.py, test_program_cache_one_variant.py, test_readback_timeout_reuse.py, test_recording_admission.py, test_screensaver.py, test_switch_table.py, test_target_retention.py, test_tex_desc_memo.py, test_thinlto_tls.py, test_upscaler_round_trip.py, test_vram_compact.py, test_windows_display_startup.py, test_windows_on_linux.py
Found in an AI-assisted audit of the repository. The test, the fix, the runs and this description were made with Claude Code; I reviewed them.
Co-Authored-By: Claude Opus 5.5 [email protected]
🤖 Generated with Claude Code
Tested in game: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless: from the Market entrance repository save, teleports until the Transition autosave wrote, then the control bridge's quit the moment the commit staged its first file, 8 times: the close waited for the commit (20 ms), nothing was left behind and the next start saved every time; on main the same left 1.longshot-new and the next start could not save
WIP: fix(fs): closing the game waits for a save being committed, and starts none afterto fix(fs): closing the game waits for a save being committed, and starts none afterPedroRossi referenced this pull request2026-12-02 17:54:18 +00:00
@Beanstalk Windows and Linux: play, then quit the game normally; expecting the quit as quick as on main and no crash. The close now also waits for a save being committed (at most 3 s).
@PedroRossi only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was ford3925c5, and the PR has changed since (0cf92d1), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.@review
Recommendation: Request changes. The reported Linux runs show that the change prevents the reproduced interrupted commit, but the new regression test depends on the caller’s profile environment.
The close path waits up to three seconds for the save lock and retains it until exit, protecting an in-progress staged commit. It can extend shutdown by up to three seconds and can still time out.
Blocking (1): must change before merging.
tests/test_fs_save_commit.py:1023: The new close worker inherits the caller’s profile selection, so its save files can be redirected away from the temporary test root. (more on the line) Do: Pass a sanitized environment to the close worker, removing LONGSHOT_PROFILE and other save-location overrides as the save-directory cases do.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
host/hos_relaunch.c:226: The Windows save and shutdown paths still need the in-game run identified in the pull request. (more on the line) Do: Run the stated Windows transition-autosave close and restart check, plus the requested normal-close smoke test, and report the results.@fixcan do L1.Questions (1) (not confirmed from the code; they don't hold the recommendation)
tests/test_fs_save_commit.py:1088: Is there a Windows-specific failure of the close path that this missing regression case would catch?Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes, for the reported Linux reproduction: four staged-commit quits on main left a staged file and later commits failed; eight runs with the change were clean and subsequent saves succeeded. The reported wait was 20 ms. Windows in-game verification remains outstanding.
Other systems: The lock is shared by staged save operations and bridge save reads on both platforms, not just commits. Windows OS-ending events also have a four-second watchdog that can terminate the process before the two sequential three-second waits finish. Windows gameplay and normal-close runs remain outstanding; no GPU-specific behavior is apparent.
Switches: None added, changed or removed.
Reviewed:
d3925c51c2against1938a302fe: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, both commits, the complete diff, hos_relaunch.c, windows_stop.c and test_windows_stop.py. Read the changed portions and relevant lock, commit, close and test paths in nn_fs.c and test_fs_save_commit.py; their full output was truncated. Skimmed the changed documentation and test runner. docs/review-checklist.md and the sibling Tooling checkout were absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: No commands that build, run tests or execute project scripts were run. The pull request reports Linux game runs and game-free checks; CI is still running.
Overlaps and merge order: #2806 addresses recovery from a staged file left behind; the description reports testing it together with this change. No other overlap was established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -223,2 +223,4 @@void hos_fs_wait_writes(void); /* (nn_fs.c: a file the game is writing, up to 3 s) */hos_fs_wait_writes();void hos_fs_hold_saves(void); /* (nn_fs.c: then a save being committed, up to 3 s; none starts after) */hos_fs_hold_saves();L2 (should fix): The Windows save and shutdown paths still need the in-game run identified in the pull request.
When: A Windows close during an autosave exercises native SRW locks and Windows file publication; the supplied successful game runs cover Linux only.
Do: Run the stated Windows transition-autosave close and restart check, plus the requested normal-close smoke test, and report the results.
@ -974,0 +1020,4 @@def close_cases(libpath, tmp):subprocess.run([sys.executable, "-I", "-B", str(Path(__file__).resolve()), "--close-worker", str(libpath),L1 (blocking): The new close worker inherits the caller’s profile selection, so its save files can be redirected away from the temporary test root.
When: With LONGSHOT_PROFILE set to a valid profile, the subprocess inherits it; mount selects that profile’s saves while the test creates and checks files under tmp/close. The test fails or operates on the selected profile instead of its isolated fixture.
Do: Pass a sanitized environment to the close worker, removing LONGSHOT_PROFILE and other save-location overrides as the save-directory cases do.
@fix
d3925c51c20cf92d1460Recommendation: Approve. The code is ready: only testing is left. The close worker now uses the temporary save root even when the caller selects a profile. The native Windows save-and-shutdown run is still needed. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
0cf92d1460. I rebased it ontomain(3e8105ebf8).Changed
Nothing was built or run: the checks run again on the new head.
The change waits for an in-progress save commit during shutdown and prevents a later commit from starting when the lock is acquired. This protects saves at the cost of up to three seconds of additional waiting.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
host/hos_relaunch.c:226: The Windows save and shutdown paths still need the in-game run identified in the pull request. When: A Windows close during an autosave exercises native SRW locks and Windows file publication; the supplied successful game runs cover Linux only. Do: Run the stated Windows transition-autosave close and restart check, plus the requested normal-close smoke test, and report the results.Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Yes on the tested Linux setup: the author reports clean saves and successful subsequent saves in eight runs, compared with four staged files and failed subsequent saves in four stage-triggered runs on main. Windows behavior remains unverified in game.
Other systems: The shutdown path runs on Windows and Linux. Linux was tested in game; the host was reportedly cross-compiled for Windows, but the native Windows save-and-shutdown run remains outstanding.
Switches: None.
Reviewed:
0cf92d1460against3e8105ebf8: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the rebased pull request diff and fix diff. Read the changed test worker, its environment setup, save-directory selection and the shutdown tail; skimmed the remaining changed code, documentation and recorded runs. The other changed files were not read in full. Tooling's AGENTS.md was unavailable locally.; nothing run (a code review).Checked and fine:
Testing: No commands that execute project code or tests were run. CI has not yet run on this head.
Overlaps and merge order: The description identifies #2806 as complementary and reports testing both changes together.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.