make_game: stage the runtime install before replacing the old files (RT-249) #204

Closed
github-bot wants to merge 5 commits from github-bot/gh-204 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:43 UTC · original
ubiquitarianism:old-pr/9937 → main · +307 −27 · 2 files · 5 commits · closed without merging

Carried over from old PR 9937 by LouisRiverstone in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9937, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
LouisRiverstone: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

RT-249: the runtime stage of make_game.py can leave --out half replaced.

Re-submission of #5278. #5278 was closed unmerged during the 2026-11-23 22:45 UTC cleanup, along with the other open PRs. This is the same branch, now merged with current main.

Checked on #5278 by: King1565 (Linux), Atomic258 (Windows Server 2022), JRamos1993 (Windows 11), kapitche (Linux).

No game files.

AI-assisted (Claude Code): I reviewed the change and re-ran its tests on the merge with main.

**@⁠Andretuta** on GitHub · 2026-11-24 02:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/204) `ubiquitarianism:old-pr/9937` → `main` · +307 −27 · 2 files · 5 commits · closed without merging > Carried over from **old PR 9937** by `LouisRiverstone` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9937`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `LouisRiverstone`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): RT-249: the runtime stage of `make_game.py` can leave `--out` half replaced. Re-submission of `#5278`. `#5278` was closed unmerged during the 2026-11-23 22:45 UTC cleanup, along with the other open PRs. This is the same branch, now merged with current `main`. Checked on `#5278` by: King1565 (Linux), Atomic258 (Windows Server 2022), JRamos1993 (Windows 11), kapitche (Linux). No game files. AI-assisted (Claude Code): I reviewed the change and re-ran its tests on the merge with `main`.
The runtime stage copied gta6rt.exe and gta6rt_tls_host.dll straight into --out
and then wrote game_path.txt and gta6rt.sh there, so a failure part way (disk
full, a DLL locked by a running gta6rt.exe, an interrupt) left a new exe next
to an old DLL. install_runtime() now writes everything to a staging folder
inside --out (same filesystem) and only then moves each file into place with
os.replace; on failure the old install is untouched and the staging folder is
removed. A --runtime-build that is --out itself is still left in place.

tests/test_make_game_runtime_staging.py: success, a failed second copy, a
failed game_path.txt write, --runtime-build == --out, a fresh --out.
@shdann and @Flyander on #5278: staging protected the copy phase but not the
publish loop. When the second os.replace failed (on Windows, the destination
DLL held open by a reader: WinError 32), gta6rt.exe was already new next to the
old DLL. publish() now moves each old file aside into the staging folder before
putting the new one in place, and on any failure takes the published files
back out and restores the old ones. runtime() turns the error into a fail()
that says the previous files are unchanged.

Tests: a failed replace at every step in turn, and a file with no old copy
being taken back out. On Windows 11 (CPython 3.11) the reader-holds-the-DLL
probe now leaves all three old files; on main the stage completes there, here
it refuses.
@Desamodeth on #5278: if another reader opens the newly published gta6rt.exe
before a later replace fails, Windows also refuses to move the old exe back;
the rollback then dropped that error, deleted the staging folder with the old
copy in it, and reported the previous files as unchanged. The rollback now tries
every step, and if any fails raises IncompleteRollback naming each file and the
staging folder, which is kept (the old copies are there as <name>.old).
runtime() says so instead of 'unchanged'.

Test: the DLL held while moving it aside, then the exe's restore blocked. On
Windows 11 with two real readers the old exe is kept and the message names it.
# Conflicts:
#	make_game.py
main replaced the fixed WINE_LAUNCHER with wine_launcher(out, work, image).
runtime() now builds that text and passes it to install_runtime(), which writes
it into the staging folder with the other files (None on Windows); the staging
tests pass their own launcher text.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:48:37 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 06:25 UTC · original · edited 2026-11-24 06:31 UTC

Native Windows finding on 560c3fa924, Windows 11 build 26100, Python 3.12. The nine stock runtime-staging tests pass.

The current file's recovery copy is lost if the new install and the inner rollback are both blocked. I used two synthetic files and inserted a synchronization point after moving the second old file to staging. At that point a contender created the destination and held it without FILE_SHARE_DELETE. The actual Windows renames for publishing and restoring that file both failed.

The first file rolled back correctly. The second old file had never been added to the rollback list, so publish raised PermissionError and install_runtime deleted staging, including the only .old copy. The expected result here is IncompleteRollback with that copy preserved.

I verified a temporary local correction. Record an old file in the rollback list immediately after moving it aside, and let the outer rollback handle it if publishing fails. For a file with no previous copy, add it to the list only after successfully publishing it. The lock tests went from 2/3 to 3/3 with this change and the stock suite stayed at 9/9. The test with no previous copy also confirmed that rollback leaves a contending file alone.

Synthetic files only. AI-assisted verification.

Current main comparison at 8f481cf16f. With the second of two synthetic destinations already locked for reading, main raises PermissionError after replacing the first file, leaving mixed versions. This PR leaves both originals in place for that case. The separate test that locks the destination after the backup rename still reproduces the missing recovery copy on this PR head.

**@⁠sodove** on GitHub · 2026-11-24 06:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/204#issuecomment-7123912053) · edited 2026-11-24 06:31 UTC Native Windows finding on 560c3fa9246a2f07d1c75c449f1c2fe7376e1aa8, Windows 11 build 26100, Python 3.12. The nine stock runtime-staging tests pass. The current file's recovery copy is lost if the new install and the inner rollback are both blocked. I used two synthetic files and inserted a synchronization point after moving the second old file to staging. At that point a contender created the destination and held it without FILE_SHARE_DELETE. The actual Windows renames for publishing and restoring that file both failed. The first file rolled back correctly. The second old file had never been added to the rollback list, so publish raised PermissionError and install_runtime deleted staging, including the only .old copy. The expected result here is IncompleteRollback with that copy preserved. I verified a temporary local correction. Record an old file in the rollback list immediately after moving it aside, and let the outer rollback handle it if publishing fails. For a file with no previous copy, add it to the list only after successfully publishing it. The lock tests went from 2/3 to 3/3 with this change and the stock suite stayed at 9/9. The test with no previous copy also confirmed that rollback leaves a contending file alone. Synthetic files only. AI-assisted verification. Current main comparison at 8f481cf16f261c7f37458aeb45e8f4e19994146d. With the second of two synthetic destinations already locked for reading, main raises PermissionError after replacing the first file, leaving mixed versions. This PR leaves both originals in place for that case. The separate test that locks the destination after the backup rename still reproduces the missing recovery copy on this PR head.
Author
Owner

@⁠LouisRiverstone on GitHub · 2026-11-25 00:24 UTC · original

Taken over by its author in #1446 (rebased on main). This draft can be closed.

**@⁠LouisRiverstone** on GitHub · 2026-11-25 00:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/204#issuecomment-7148479753) Taken over by its author in #1446 (rebased on main). This draft can be closed.
github-bot closed this pull request 2026-11-27 04:04:13 +00:00
Author
Owner

@⁠Andretuta on GitHub · 2026-11-27 04:01 UTC · original

Closing carried-over draft: taken over by original author in #1446 (OLD-9937).

**@⁠Andretuta** on GitHub · 2026-11-27 04:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/204#issuecomment-7209461188) Closing carried-over draft: taken over by original author in #1446 (OLD-9937).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.