make_game: stage the runtime install and publish it all or none (RT-249) (OLD-9937) #1446

Open
github-bot wants to merge 5 commits from github-bot/gh-1446 into main AGit
Owner

@⁠LouisRiverstone on GitHub · 2026-11-25 00:24 UTC · original
LouisRiverstone:carry-old-9937 → main · +357 −27 · 2 files · 5 commits · open

Claimed in the coordination issue as: OLD-9937 (#14)

Replaces the carried-over draft #204. I'm the original author of old upstream PR 9937.

What and why

RT-249. The runtime stage of make_game.py copied the files into --out one by one. A failure partway through (disk full, an interrupt, or on Windows a destination file held open by an antivirus scan or another program) could leave a new gta6rt.exe next to an old gta6rt_tls_host.dll.

The stage now writes every file, including game_path.txt, shader_path.txt and gta6rt.sh, to a staging folder inside --out, on the same filesystem. Only once everything is there does publish() move the files into place, all or none: each old file is first moved aside, and any failure puts back the files already published. If the rollback itself is blocked, IncompleteRollback keeps the staging folder, which then holds the old copies as <name>.old, and the error says where they are. On main the stage already refuses an --out where one of the runtime file names is a directory, and that check is kept; it runs before the build.

tests/test_make_game_runtime_staging.py (new, 12 tests) covers a failed copy, a failed game_path.txt write, a failed publish with and without an old copy, a blocked rollback, a missing output folder, a --runtime-build that is the output folder itself, shader_path.txt staged with the rest, and a restore that fails for the file being published, stale staging folders removed by the next install, the BCPack history path, and a successful run that leaves no staging folder.

The old branch's final diff, applied on current main as one commit. It applied cleanly.

Tested

  • python -I tests/test_make_game_runtime_staging.py: 9 tests OK on Linux (Python 3.14.4) and on Windows 11 (Python 3.11).
  • The other 23 tests/test_make_game*.py files pass on Linux. On Windows 11 with Python 3.11, seven of them fail, and they fail the same way on main, so the cause is that environment and not this change.
  • python -m compileall -q make_game.py tools tests: OK.

GPUs tested: n/a

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator rule changes)

On Windows a running gta6rt.exe can be renamed, so it does not block the install; its old copy may stay in a .runtime-staging-* folder, which the next install removes.

**@⁠LouisRiverstone** on GitHub · 2026-11-25 00:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1446) `LouisRiverstone:carry-old-9937` → `main` · +357 −27 · 2 files · 5 commits · open Claimed in the coordination issue as: OLD-9937 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Replaces the carried-over draft #204. I'm the original author of old upstream PR 9937. ### What and why RT-249. The runtime stage of `make_game.py` copied the files into `--out` one by one. A failure partway through (disk full, an interrupt, or on Windows a destination file held open by an antivirus scan or another program) could leave a new `gta6rt.exe` next to an old `gta6rt_tls_host.dll`. The stage now writes every file, including `game_path.txt`, `shader_path.txt` and `gta6rt.sh`, to a staging folder inside `--out`, on the same filesystem. Only once everything is there does `publish()` move the files into place, all or none: each old file is first moved aside, and any failure puts back the files already published. If the rollback itself is blocked, `IncompleteRollback` keeps the staging folder, which then holds the old copies as `<name>.old`, and the error says where they are. On `main` the stage already refuses an `--out` where one of the runtime file names is a directory, and that check is kept; it runs before the build. `tests/test_make_game_runtime_staging.py` (new, 12 tests) covers a failed copy, a failed `game_path.txt` write, a failed publish with and without an old copy, a blocked rollback, a missing output folder, a `--runtime-build` that is the output folder itself, `shader_path.txt` staged with the rest, and a restore that fails for the file being published, stale staging folders removed by the next install, the BCPack history path, and a successful run that leaves no staging folder. The old branch's final diff, applied on current `main` as one commit. It applied cleanly. ### Tested - `python -I tests/test_make_game_runtime_staging.py`: 9 tests OK on Linux (Python 3.14.4) and on Windows 11 (Python 3.11). - The other 23 `tests/test_make_game*.py` files pass on Linux. On Windows 11 with Python 3.11, seven of them fail, and they fail the same way on `main`, so the cause is that environment and not this change. - `python -m compileall -q make_game.py tools tests`: OK. GPUs tested: n/a AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator rule changes) On Windows a running `gta6rt.exe` can be renamed, so it does not block the install; its old copy may stay in a `.runtime-staging-*` folder, which the next install removes.
- make_game: stage the runtime install before replacing the old files (RT-249)
- make_game: publish the staged runtime all or none, with rollback (RT-249, old PR 5278)
- make_game: keep the old runtime files when the rollback itself is blocked (old PR 5278)

Carried over from old-pr/9937 (old upstream PR 9937), rebased on main.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:40 +00:00
Author
Owner

@⁠Diegobecker07 on GitHub · 2026-11-25 14:09 UTC · original

Reviewed 354142d90, merged with main 71a769d7d, on Windows 11 with Python 3.14. All 27 tests/test_make_game_*.py files pass, along with test_dstorage_history.py and the line-endings test. The three points below came from probes on synthetic folders (no game files), not from the test suite.

1. Regression from the merge of main (354142d90): the BCPack history profile moves. runtime() now asks for

profile = os.path.join(os.path.abspath(work), "bcpack", "history.bcph")

On main this is os.path.join(os.path.dirname(shader_dir), "bcpack", "history.bcph"), which resolves to <work>/shaders/bcpack/history.bcph. That is where the runtime reads it (runtime/shims/dstorage.cpp:474, shaders.parent_path() / "bcpack" / "history.bcph"), and also the path in docs/directstorage.md:180 and tests/test_dstorage_history.py:100. I called runtime() with ttpf_mips.find_pools and make_game.py's py() patched: main passes --out work/shaders/bcpack/history.bcph, this PR passes --out work/bcpack/history.bcph. The stage would then build the profile where nothing reads it. Fix: os.path.join(os.path.abspath(work), "shaders", "bcpack", "history.bcph"). A test that patches py and checks that --out argument would stop it from moving again.

2. publish() loses the old file when its own restore fails. I patched os.replace so that moving the new gta6rt.exe in fails and putting the old one back fails too. The inner except re-raises that error, and the outer handler only rolls back the names in done, so it raises a plain PermissionError rather than IncompleteRollback. install_runtime() then removes the staging folder, which held the only copy, as gta6rt.exe.old. --out ends up with no gta6rt.exe at all. The fix is to count a failed restore of the current name as a rollback failure, so that it raises IncompleteRollback and the stage is kept.

3. A running gta6rt.exe does not block the install on Windows; it leaves a folder behind. Windows lets a running image be renamed. I ran a process from <out>\gta6rt.exe (a copy of PING.EXE). On main, shutil.copy2 over it fails with WinError 32. With this PR, publish() succeeds: the old image moves to <stage>\gta6rt.exe.old and the new file takes its place. The final shutil.rmtree(stage, ignore_errors=True) cannot remove the file that is still in use, so a .runtime-staging-* folder holding the old exe stays in --out. That happens once per install while the game runs, and nothing removes it later. This is still better than main. Two suggestions: remove stale .runtime-staging-* folders at the start of install_runtime(), and change the description and the OSError message, which name a running gta6rt.exe as a cause of a failed install.

The rest read fine to me: the move order in publish(), the --runtime-build == --out case, and the bytes of shader_path.txt, which are unchanged from main.

Recommendation: fix 1 before merging (it is a one-line change); 2 and 3 are small.

AI-assisted review.

**@⁠Diegobecker07** on GitHub · 2026-11-25 14:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1446#issuecomment-7164839361) Reviewed 354142d90, merged with main 71a769d7d, on Windows 11 with Python 3.14. All 27 `tests/test_make_game_*.py` files pass, along with `test_dstorage_history.py` and the line-endings test. The three points below came from probes on synthetic folders (no game files), not from the test suite. **1. Regression from the merge of main (354142d90): the BCPack history profile moves.** `runtime()` now asks for ```python profile = os.path.join(os.path.abspath(work), "bcpack", "history.bcph") ``` On main this is `os.path.join(os.path.dirname(shader_dir), "bcpack", "history.bcph")`, which resolves to `<work>/shaders/bcpack/history.bcph`. That is where the runtime reads it (`runtime/shims/dstorage.cpp:474`, `shaders.parent_path() / "bcpack" / "history.bcph"`), and also the path in `docs/directstorage.md:180` and `tests/test_dstorage_history.py:100`. I called `runtime()` with `ttpf_mips.find_pools` and `make_game.py`'s `py()` patched: main passes `--out work/shaders/bcpack/history.bcph`, this PR passes `--out work/bcpack/history.bcph`. The stage would then build the profile where nothing reads it. Fix: `os.path.join(os.path.abspath(work), "shaders", "bcpack", "history.bcph")`. A test that patches `py` and checks that `--out` argument would stop it from moving again. **2. `publish()` loses the old file when its own restore fails.** I patched `os.replace` so that moving the new `gta6rt.exe` in fails and putting the old one back fails too. The inner `except` re-raises that error, and the outer handler only rolls back the names in `done`, so it raises a plain `PermissionError` rather than `IncompleteRollback`. `install_runtime()` then removes the staging folder, which held the only copy, as `gta6rt.exe.old`. `--out` ends up with no `gta6rt.exe` at all. The fix is to count a failed restore of the current name as a rollback failure, so that it raises `IncompleteRollback` and the stage is kept. **3. A running `gta6rt.exe` does not block the install on Windows; it leaves a folder behind.** Windows lets a running image be renamed. I ran a process from `<out>\gta6rt.exe` (a copy of `PING.EXE`). On main, `shutil.copy2` over it fails with WinError 32. With this PR, `publish()` succeeds: the old image moves to `<stage>\gta6rt.exe.old` and the new file takes its place. The final `shutil.rmtree(stage, ignore_errors=True)` cannot remove the file that is still in use, so a `.runtime-staging-*` folder holding the old exe stays in `--out`. That happens once per install while the game runs, and nothing removes it later. This is still better than main. Two suggestions: remove stale `.runtime-staging-*` folders at the start of `install_runtime()`, and change the description and the `OSError` message, which name a running gta6rt.exe as a cause of a failed install. The rest read fine to me: the move order in `publish()`, the `--runtime-build` == `--out` case, and the bytes of `shader_path.txt`, which are unchanged from main. **Recommendation:** fix 1 before merging (it is a one-line change); 2 and 3 are small. AI-assisted review.
Author
Owner

@⁠Diegobecker07 on GitHub · 2026-11-25 20:12 UTC · original

Re-checked 6a721500a merged with main 9f9a7c5f3, on Windows 11 Pro (26300) with Python 3.14. All 25 tests/test_make_game_*.py files pass, along with test_dstorage_history.py, the line-endings test, compileall and make_game.py --help. I reran the probes from my review on synthetic folders:

  1. runtime() now passes --out <work>/shaders/bcpack/history.bcph, which is the path the runtime reads.
  2. I blocked both moving the new gta6rt.exe in and putting the old one back. install_runtime() raises IncompleteRollback and keeps the staging folder, with the old file as gta6rt.exe.old. gta6rt_tls_host.dll is untouched.
  3. I ran a copy of ping.exe as gta6rt.exe. Two installs while it was running both succeeded and left one staging folder, and the first install after it exited removed that folder.

All three points from my review are fixed.

AI-assisted.

**@⁠Diegobecker07** on GitHub · 2026-11-25 20:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1446#issuecomment-7173334449) Re-checked 6a721500a merged with main 9f9a7c5f3, on Windows 11 Pro (26300) with Python 3.14. All 25 `tests/test_make_game_*.py` files pass, along with `test_dstorage_history.py`, the line-endings test, `compileall` and `make_game.py --help`. I reran the probes from my review on synthetic folders: 1. `runtime()` now passes `--out <work>/shaders/bcpack/history.bcph`, which is the path the runtime reads. 2. I blocked both moving the new `gta6rt.exe` in and putting the old one back. `install_runtime()` raises `IncompleteRollback` and keeps the staging folder, with the old file as `gta6rt.exe.old`. `gta6rt_tls_host.dll` is untouched. 3. I ran a copy of `ping.exe` as `gta6rt.exe`. Two installs while it was running both succeeded and left one staging folder, and the first install after it exited removed that folder. All three points from my review are fixed. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1446/head:github-bot/gh-1446'
git switch 'github-bot/gh-1446'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1446'
git switch 'github-bot/gh-1446'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1446'
git switch 'github-bot/gh-1446'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1446'
git switch 'main'
git merge --squash 'github-bot/gh-1446'
git switch 'main'
git merge --ff-only 'github-bot/gh-1446'
git switch 'main'
git merge 'github-bot/gh-1446'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.