gen_gdk_runtime_classes: write --out atomically #1668

Merged
leonida/mandy
xel1uz merged 1 commit from fix/gen-gdk-runtime-classes-atomic-out into main 2026-11-29 18:28:24 +00:00

Pull request successfully merged and closed

xel1uz commented 2026-11-25 07:39:20 +00:00

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.
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.
whoalin1 commented 2026-11-25 09:11:24 +00:00

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.

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.
MoonEyes commented 2026-11-28 03:04:25 +00:00

Hi @xel1uz, thanks for this pull request.

CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post claiming: <ID> there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one.

The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.

Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @xel1uz, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post `claiming: <ID>` there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one. The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-28 23:38:35 +00:00

Tested f85de7d95 merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

Blocker on Windows: the new tests/test_gen_gdk_runtime_classes.py imports resource at module level (line 5, for RLIMIT_FSIZE). That module does not exist on Windows, so the file stops with ModuleNotFoundError: No module named 'resource' and none of its tests run, with or without the fix.

Importing it only inside the size-limit test, and skipping that test when the import fails, would let the rest run here.

AI-assisted (Claude Code).

Tested `f85de7d95` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. **Blocker on Windows:** the new `tests/test_gen_gdk_runtime_classes.py` imports `resource` at module level (line 5, for `RLIMIT_FSIZE`). That module does not exist on Windows, so the file stops with `ModuleNotFoundError: No module named 'resource'` and none of its tests run, with or without the fix. Importing it only inside the size-limit test, and skipping that test when the import fails, would let the rest run here. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 01:26:12 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (GenGdkRuntimeClassesTests.test_failed_write_preserves_existing_file) / green 3 OK.

  • PR head f85de7d95, python -I tests/test_gen_gdk_runtime_classes.py.
  • Runs on macOS with the POSIX resource limit the test needs.
  • Red: 3 run, 1 failure. On main a write that fails part-way replaces the previous table with a partial one (b'{\\n "classes": {}, ...' != b'previous table must survive\\n'). MEASURED, the test alone 3 runs, 3/3 fail.
  • Green: 3 run, OK. MEASURED, 3/3 pass.
  • Verdict: READY.

Red = main + only the test file from this PR (git checkout pr-N -- <test>); green = main + git merge --no-ff of this PR, no conflict. Green runs more tests than red because the merge keeps the tests main added to this file since the PR branched; that is the method, not a finding.

AI-assisted: Claude Code (Claude Opus 5.5).

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (GenGdkRuntimeClassesTests.test_failed_write_preserves_existing_file) / green 3 OK. - PR head f85de7d95, `python -I tests/test_gen_gdk_runtime_classes.py`. - Runs on macOS with the POSIX `resource` limit the test needs. - Red: 3 run, 1 failure. On main a write that fails part-way replaces the previous table with a partial one (`b'{\\n "classes": {}, ...' != b'previous table must survive\\n'`). MEASURED, the test alone 3 runs, 3/3 fail. - Green: 3 run, OK. MEASURED, 3/3 pass. - Verdict: READY. Red = main + only the test file from this PR (`git checkout pr-N -- <test>`); green = main + `git merge --no-ff` of this PR, no conflict. Green runs more tests than red because the merge keeps the tests main added to this file since the PR branched; that is the method, not a finding. AI-assisted: Claude Code (Claude Opus 5.5).
OreoFR commented 2026-11-29 17:11:19 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 4364a4fa6, PR head f85de7d95 : red 1 failure / green 3 OK

Re-check on the current main (same head as my earlier verification).

  • Merge: clean (git merge-tree). Reviews: none. No game data in the diff. Skipped on the merge: none.
  • (MEASURED n=3) each red failure reruns alone 3/3.
  • Red: 3 tests, 1 failure: test_failed_write_preserves_existing_file.
  • Green: 3/3 OK. Neighbours (test_gdk_runtime_calls, test_gen_gdk_classes_out_dir): 26 passed on main and merge.
  • Diff: atomic write that keeps the file mode. Nit: same theoretical double os.close(fd) in the failure path as #1648.

Verdict: READY

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 4364a4fa6, PR head f85de7d95 : red 1 failure / green 3 OK Re-check on the current main (same head as my earlier verification). - Merge: clean (`git merge-tree`). Reviews: none. No game data in the diff. Skipped on the merge: none. - (MEASURED n=3) each red failure reruns alone 3/3. - **Red**: 3 tests, 1 failure: `test_failed_write_preserves_existing_file`. - **Green**: 3/3 OK. Neighbours (`test_gdk_runtime_calls`, `test_gen_gdk_classes_out_dir`): 26 passed on main and merge. - Diff: atomic write that keeps the file mode. Nit: same theoretical double `os.close(fd)` in the failure path as #1648. **Verdict: READY** AI-assisted: Claude Code
DadaCap commented 2026-11-29 18:28:26 +00:00

Thank you! Merged into main with a merge commit. It was verified ready on its current head (f85de7d95) by OreoFR's Mac agent (macOS, red/green on main + PR); see the verification comment above. (AI-assisted, posted for DadaCap.)

Thank you! Merged into `main` with a merge commit. It was verified ready on its current head (f85de7d95) by OreoFR's Mac agent (macOS, red/green on main + PR); see the verification comment above. (AI-assisted, posted for DadaCap.)
Sign in to join this conversation.
No description provided.