WIP: fix(fs): preserve orphan staging files so saves can complete #2806
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!2806
Loading…
Reference in a new issue
No description provided.
Delete branch "NullMagic/Longshot:fix/orphan-save-staging"
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
A regular
0.longshot-newleft in the committed save directory without a recovery journal makes every later Commit fail with0x2EE202. A manual save then stays on “Saving…” indefinitely, while rendering continues. This reproduced with a player's existing staging-file collision on nightly-920 and the same collision is present in stable v3.2.0.After recovery has finished, preserve a colliding regular staging file under an unused
orphan-<index>-<number>.longshot-newname and sync the directory before staging the new save. The reserved suffix keeps the preserved bytes out of the game's working copy. Pending recovery journals, links and directories remain protected. Existing orphan entries are skipped and a refused rename leaves the original available for retry.Read
save_preserve_orphan()and the neworphan_cases()intests/test_fs_save_commit.pyfirst. See #607 for the original staging design; #2250 concerns a different mount-cleanup refusal.Stable backport: the same test-first fix is available on fix/orphan-save-staging-v3.2.0, based on the v3.2.0 tag (
79d192c655b5): test2bf932e, fixc61370b. There is currently no upstreamrelease/v3.2branch to target with a second PR. No release/tag is changed by this proposal.Testing
Tested: Ubuntu 26.04.1, Ryzen 7 8700G, Radeon RX 7900 XTX, RADV Mesa 26.0.8.
orphan staging files must not block every subsequent Commit.nn_fs.cwith the real Linux file layer, including crash/journal recovery and process ownership tests.01d6878. Most require missing Vulkan/SPIR-V/shader tools or a newer Rust compiler; others are existing fixture/source mismatches and timeouts. Baseline failure rerun used a 30 s timeout; the full run used 120 s. All save-related checks in that full run passed; the Windows-specific path test was skipped.Still to test:
Measurements
Verdict: the stale-file collision no longer blocks saving. These are diagnostic observations, not a frame-rate benchmark.
01d6878f6b2e930x2EE202; Saving does not finishThe change runs only during save publication and adds a staging-path attribute lookup when there is no collision. It changes no per-frame renderer work, shader translator or cache format. No performance gain is claimed. An orphan collision adds a rename and a directory sync; its bytes remain on disk.
Risks
Linux's existing
MoveFileExAcompatibility function uses a destination check followed by rename. The save ownership lock excludes other Longshot instances, but this patch does not add protection against an external process racing creation of the selected backup path. Windows uses the existing native no-replace move. Windows validation remains pending.Checklist
Ready for review
mise run testpasses (any failure that also fails onmainis named). The equivalent strict Python runner was used; failures are listed below and all reproduced on unchanged main.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
Ready to merge
Possibly related, for context:
@review
Recommendation: Request changes. The fix clears the reported save collision on Linux, but its Linux rename can overwrite another preserved file created concurrently. Windows validation is also still pending.
A stale staging file is moved aside so a new save can complete, while its bytes remain available for recovery. The change adds a filesystem lookup to save publication and a rename and directory sync when a collision occurs.
Blocking (1): must change before merging.
host/nn_fs.c:617: On Linux this move does not atomically enforce the unused destination, so it can overwrite a preserved file created by another process. (more on the line) Do: Use an atomic no-replace move for orphan preservation on Linux, and retry another name when the destination already exists.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
host/nn_fs.c:617: The Windows save-publication path has not yet been validated. (more on the line) Do: Build the host on Windows and run the save-commit suite and an in-game manual save with a stale staging file, including a UTF-8 save path.@fixcan do L1.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the reported Linux case: the PR reports repeated 0x2EE202 results on the base and a successful in-game save with the orphan preserved at this head. The regression test is reported to fail before and pass after. No performance gain is claimed.
Other systems: The change affects staged save publication and recovery on Linux and Windows, independently of GPU. Linux HLE and in-game results are reported; the Windows build and collision case remain untested. The existing ownership lock excludes another Longshot owner but does not exclude external save tools.
Switches: None.
Reviewed:
f6b2e93f4fagainst01d6878b3f: Read the repository rules, PR template, commits, diff, changed save code and its recovery and filesystem helpers, changed test cases and saves documentation. Skimmed the remainder of the large host and test files and the standards document. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The PR reports Linux GCC and Clang HLE runs and an in-game reproduction; CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -604,0 +614,4 @@snprintf(name, sizeof name, "orphan-%u-%u.longshot-new", index, i);if (!save_join(backup, s->committed, name) || !save_attr(backup, &at)) return 0;if (at == INVALID_FILE_ATTRIBUTES) {if (!MoveFileExA(stage, backup, MOVEFILE_WRITE_THROUGH) || !save_sync_directory(s->committed)) return 0;L1 (blocking): On Linux this move does not atomically enforce the unused destination, so it can overwrite a preserved file created by another process.
When: If a save tool creates the selected orphan name after the attribute lookup, the POSIX MoveFileExA compatibility function checks the destination and then calls rename; a creation between its check and rename is replaced, losing that file's bytes.
Do: Use an atomic no-replace move for orphan preservation on Linux, and retry another name when the destination already exists.
L2 (should fix): The Windows save-publication path has not yet been validated.
When: A Windows player with a stale staging file relies on the wide-path move and native no-replace behavior to preserve it and finish saving; the PR reports neither the Windows suite nor the manual collision case has run.
Do: Build the host on Windows and run the save-commit suite and an in-game manual save with a stale staging file, including a UTF-8 save path.
Ran into the same bug independently while reading the save code, so some confirmation for this one:
55773e3), a regular0.longshot-newin the committed folder with no journal still makes the next Commit fail:fs: Commit: 0 files, 1 ops, 0 failed paths, 0 open writers, result 0x2ee202, reproduced game-free intests/test_fs_save_commit.py's harness on Linux. This branch also still merges onto current main without conflicts.Save.cleanupis set insave_replay(after deleting an empty journal and after dropping an incomplete one) but never read anywhere. It looks like an earlier hook for exactly this case.hos_close_finishonly waits for open writes (hos_fs_wait_writes, from #1422), and Commit runs with no file open for writing, so closing the window during an autosave can cut a commit between staging and the journal. I'll look at that separately, without touching this PR's code.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.