gen_gdk_runtime_classes: write --out atomically #1668

Open
github-bot wants to merge 1 commit from github-bot/gh-1668 into main AGit
Owner

@⁠xel1uz on GitHub · 2026-11-25 07:39 UTC · original
xel1uz:fix/gen-gdk-runtime-classes-atomic-out → main · +110 −3 · 2 files · 1 commits · open

Item ID: GEN-GDK-RUNTIME-CLASSES-ATOMIC-OUT (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here)

Claimed as: GEN-GDK-RUNTIME-CLASSES-ATOMIC-OUT - a failed --out write truncates an existing file and leaves a partial one behind. Reproduced on 42537e7b.

What and why

The generator opened its target with open(a.out, "w") and then json.dumped into it, so the previous table was truncated the moment the file was opened; a short or failed write left partial JSON behind.

The table is now written to a temp file in the destination directory and published with os.replace; failures clean the temp file up and keep the previous table.

Tested

  • pytest tests/test_gen_gdk_runtime_classes.py -q with the tool at 42537e7b: 1 failed, 2 passed.

  • With this branch: 3 passed.

  • Repro with 128 synthetic classes, a 14-byte existing output and ulimit -f 1: the original grew the file 14 -> 1024 bytes (partial JSON); with this patch it stayed 14 bytes and no temp file remained.

  • git diff --check clean; python3 -I scripts/check_no_game_data.py clean on the changed files.

GPUs tested: n/a - CPU only, no Vulkan device involved.

AI-assisted: Yes.

Checklist

  • Based on current main (42537e7b) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption; synthetic inputs only.
  • A new translator rule in the contract table of docs/design.md - not applicable, no translator change.
**@⁠xel1uz** on GitHub · 2026-11-25 07:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1668) `xel1uz:fix/gen-gdk-runtime-classes-atomic-out` → `main` · +110 −3 · 2 files · 1 commits · open Item ID: `GEN-GDK-RUNTIME-CLASSES-ATOMIC-OUT` (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here) Claimed as: `GEN-GDK-RUNTIME-CLASSES-ATOMIC-OUT` - a failed `--out` write truncates an existing file and leaves a partial one behind. Reproduced on 42537e7b. ### What and why The generator opened its target with `open(a.out, "w")` and then `json.dump`ed into it, so the previous table was truncated the moment the file was opened; a short or failed write left partial JSON behind. The table is now written to a temp file in the destination directory and published with `os.replace`; failures clean the temp file up and keep the previous table. ### Tested - `pytest tests/test_gen_gdk_runtime_classes.py -q` with the tool at 42537e7b: **1 failed, 2 passed**. - With this branch: **3 passed**. - Repro with 128 synthetic classes, a 14-byte existing output and `ulimit -f 1`: the original grew the file **14 -> 1024 bytes** (partial JSON); with this patch it stayed **14 bytes** and no temp file remained. - `git diff --check` clean; `python3 -I scripts/check_no_game_data.py` clean on the changed files. GPUs tested: n/a - CPU only, no Vulkan device involved. AI-assisted: Yes. ### Checklist - [x] Based on current `main` (42537e7b) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption; synthetic inputs only. - [ ] A new translator rule in the contract table of `docs/design.md` - not applicable, no translator change.
Write the generated JSON to a temporary file in the destination directory, then atomically replace the output. Remove the temporary file on write errors and preserve output permissions.

Before: with 128 synthetic classes and an existing 14-byte output, `bash -c 'trap "" XFSZ; ulimit -f 1; python3 -I tools/gen_gdk_runtime_classes.py /home/hampa/.hermes/profiles/mikuling/cache/scratch/gdk-atomic-repro/docs --out /home/hampa/.hermes/profiles/mikuling/cache/scratch/gdk-atomic-repro/out.json'` returned 1 (Errno 27, File too large); output grew to 1024 bytes (partial JSON).

After: the same command returned 1, left the 14-byte sentinel unchanged, and left no temporary file. Tests against upstream/main: 1 failed, 2 passed; against the fix: 3 passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:03 +00:00
Author
Owner

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

Independent verification (Windows, Python 3.11.9): the tool change itself is correct — atomic mkstemp+chmod+os.replace in dest dir, mode preserved, verified on a synthetic docs tree. But the new test file is POSIX-only and breaks Windows CI: top-level import resource, signal.SIGXFSZ, preexec_fn — python -I tests/test_gen_gdk_runtime_classes.py fails at import on Windows (ModuleNotFoundError: No module named 'resource'). The windows-latest check job runs exactly this, so it will fail. Repo convention for this pattern is @unittest.skipUnless(os.name == "posix") + lazy import resource inside a subprocess script — see tests/test_rpf_probe.py. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 09:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1668#issuecomment-7157994610) Independent verification (Windows, Python 3.11.9): the tool change itself is correct — atomic mkstemp+chmod+os.replace in dest dir, mode preserved, verified on a synthetic docs tree. **But the new test file is POSIX-only and breaks Windows CI**: top-level `import resource`, `signal.SIGXFSZ`, `preexec_fn` — `python -I tests/test_gen_gdk_runtime_classes.py` fails at import on Windows (`ModuleNotFoundError: No module named 'resource'`). The windows-latest `check` job runs exactly this, so it will fail. Repo convention for this pattern is `@unittest.skipUnless(os.name == "posix")` + lazy `import resource` inside a subprocess script — see `tests/test_rpf_probe.py`. AI-assisted verification.
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/1668/head:github-bot/gh-1668'
git switch 'github-bot/gh-1668'

Merge

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