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

Merged
LouisRiverstone merged 5 commits from upstream-pr/1446 into main 2026-11-28 14:41:40 +00:00
LouisRiverstone commented 2026-11-25 00:24:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by LouisRiverstone on 2026-11-25T00:24:14Z.


Claimed in the coordination issue as: OLD-9937 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148463379)

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5482701415 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1446). Originally posted by [LouisRiverstone](https://github.com/LouisRiverstone) on 2026-11-25T00:24:14Z. --- Claimed in the coordination issue as: OLD-9937 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148463379) 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.
Diegobecker07 commented 2026-11-25 14:09:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Diegobecker07 on 2026-11-25T14:09:16Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7164839361 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1446#issuecomment-7164839361). Originally posted by [Diegobecker07](https://github.com/Diegobecker07) on 2026-11-25T14:09:16Z. --- 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.
Diegobecker07 commented 2026-11-25 20:12:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Diegobecker07 on 2026-11-25T20:12:25Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7173334449 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1446#issuecomment-7173334449). Originally posted by [Diegobecker07](https://github.com/Diegobecker07) on 2026-11-25T20:12:25Z. --- 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.
DadaCap commented 2026-11-28 07:21:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T07:21:15Z.


Thanks for this! Staging the runtime install and publishing it all at once, with rollback, avoids a mixed old/new install.

During maintainer testing (local, 2026-11-28) (head 6a721500a, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found:

  • Review finding: the cleanup at the start of each install deletes the .old recovery copies left by a failed rollback, while the error tells the user to run the stage again, so a second failure loses the old files.

To get this merged:

  • Keep the .old copies until a later install succeeds, or tell the user how to restore them.

AI-assisted (Claude Code), posted for DadaCap (maintainer).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235879804 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1446#issuecomment-7235879804). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T07:21:15Z. --- Thanks for this! Staging the runtime install and publishing it all at once, with rollback, avoids a mixed old/new install. During maintainer testing (local, 2026-11-28) (head 6a721500a, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found: - Review finding: the cleanup at the start of each install deletes the `.old` recovery copies left by a failed rollback, while the error tells the user to run the stage again, so a second failure loses the old files. To get this merged: - Keep the `.old` copies until a later install succeeds, or tell the user how to restore them. _AI-assisted (Claude Code), posted for DadaCap (maintainer)._
MoonEyes commented 2026-11-28 14:41:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:41:34Z.


Red/green: pytest tests/test_make_game_runtime_staging.py fails on main (1 failed, 1 passed) and passes on head 6a721500ae merged with main (12 passed, 6 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240859668 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1446#issuecomment-7240859668). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:41:34Z. --- Red/green: `pytest tests/test_make_game_runtime_staging.py` fails on main (1 failed, 1 passed) and passes on head 6a721500ae7e merged with main (12 passed, 6 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1446
No description provided.