sandbox_scene: write --out atomically #1669

Merged
xel1uz merged 1 commit from upstream-pr/1669 into main 2026-11-29 18:59:15 +00:00
xel1uz commented 2026-11-25 07:39:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by xel1uz on 2026-11-25T07:39:24Z.


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

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

What and why

The scene was written straight to the target with open(args.out, "wb"), so an interrupted or failed write left a half-written binary and the previous baseline was lost.

The scene is now written to a temp file in the destination directory and moved into place with os.replace, which also keeps the target's existing permissions; a failure removes the temp file and leaves the previous output intact.

Tested

  • pytest tests/test_sandbox_scene.py -q with the tool at 42537e7b: 1 failed, 14 passed, 5 subtests passed - the failure is test_failed_write_preserves_existing_output.

  • With this branch: 15 passed, 5 subtests passed.

  • Repro with ulimit -f 1: exit 2 and the file went 20 -> 1024 bytes on the original, versus 20 -> 20 bytes here with no temp file left. A successful run produces the same 2256 bytes (identical SHA-256) before and after.

  • 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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487204060 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669). Originally posted by [xel1uz](https://github.com/xel1uz) on 2026-11-25T07:39:24Z. --- Item ID: `SANDBOX-SCENE-ATOMIC-OUT` (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here) Claimed as: `SANDBOX-SCENE-ATOMIC-OUT` - a failed `--out` write truncates an existing file and leaves a partial one behind. Reproduced on 42537e7b. ### What and why The scene was written straight to the target with `open(args.out, "wb")`, so an interrupted or failed write left a half-written binary and the previous baseline was lost. The scene is now written to a temp file in the destination directory and moved into place with `os.replace`, which also keeps the target's existing permissions; a failure removes the temp file and leaves the previous output intact. ### Tested - `pytest tests/test_sandbox_scene.py -q` with the tool at 42537e7b: **1 failed, 14 passed, 5 subtests passed** - the failure is `test_failed_write_preserves_existing_output`. - With this branch: **15 passed, 5 subtests passed**. - Repro with `ulimit -f 1`: exit 2 and the file went **20 -> 1024 bytes** on the original, versus **20 -> 20 bytes** here with no temp file left. A successful run produces the same **2256 bytes** (identical SHA-256) before and after. - `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 08:52:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T08:52:16Z.


Heads-up from independent verification (Windows, Python 3.11.9): the tool change itself is correct (mkstemp + chmod + os.replace, LF endings, check_no_game_data clean), but the 3 new tests are POSIX-only and fail on Windows — python -I tests/test_sandbox_scene.py gives 2 failures: test_failed_write_preserves_existing_output needs ulimit -f/SIGXFSZ, and test_successful_write_preserves_scene_bytes asserts st_mode == 0o640 which Windows chmod cannot produce (got 0o666). The windows-latest CI leg runs exactly python -I on this file, so this will fail Windows CI unless the tests get skipUnless(os.name == "posix") or platform-aware assertions. Should pass on the Linux/pytest leg per your report. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157575467 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1669#issuecomment-7157575467). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T08:52:16Z. --- Heads-up from independent verification (Windows, Python 3.11.9): the tool change itself is correct (mkstemp + chmod + os.replace, LF endings, check_no_game_data clean), **but the 3 new tests are POSIX-only and fail on Windows** — `python -I tests/test_sandbox_scene.py` gives 2 failures: `test_failed_write_preserves_existing_output` needs `ulimit -f`/SIGXFSZ, and `test_successful_write_preserves_scene_bytes` asserts `st_mode == 0o640` which Windows chmod cannot produce (got 0o666). The windows-latest CI leg runs exactly `python -I` on this file, so this will fail Windows CI unless the tests get `skipUnless(os.name == "posix")` or platform-aware assertions. Should pass on the Linux/pytest leg per your report. AI-assisted verification.
MoonEyes commented 2026-11-28 03:04:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T03:04:39Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232778785 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669#issuecomment-7232778785). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T03:04:39Z. --- 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:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:38:33Z.


Tested 24278bbdc 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: two of the new tests in tests/test_sandbox_scene.py fail here, with and without the fix. The 15 others pass.

  • test_failed_write_preserves_existing_output starts the tool through bash to set a file-size limit. Here that launch fails, so File too large never appears in stderr.
  • test_successful_write_preserves_scene_bytes expects st_mode & 0o777 == 0o640, but Windows reports 0o666 (438 != 416).

Skipping these two where the platform cannot give them (no POSIX shell or chmod modes), or checking only what Windows supports, would make the file pass here. The atomic write itself is not red/green-testable on this machine for that reason.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247566751 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669#issuecomment-7247566751). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:38:33Z. --- Tested `24278bbdc` 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:** two of the new tests in `tests/test_sandbox_scene.py` fail here, with and without the fix. The 15 others pass. - `test_failed_write_preserves_existing_output` starts the tool through `bash` to set a file-size limit. Here that launch fails, so `File too large` never appears in stderr. - `test_successful_write_preserves_scene_bytes` expects `st_mode & 0o777 == 0o640`, but Windows reports `0o666` (`438 != 416`). Skipping these two where the platform cannot give them (no POSIX shell or `chmod` modes), or checking only what Windows supports, would make the file pass here. The atomic write itself is not red/green-testable on this machine for that reason. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 01:26:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:26:10Z.


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

  • PR head 24278bbdc, python -I tests/test_sandbox_scene.py.
  • On macOS both tests that blocked on Windows run: bash sets the file-size limit, and chmod modes are real.
  • Red: 15 run, 1 failure. On main a write that fails part-way leaves a truncated scene in place of the existing file (b'LSB1...' != b'pre-existing scene contents'). MEASURED, TestAtomicSceneOutput alone 3 runs, 3/3 fail.
  • test_successful_write_preserves_scene_bytes (the 0o640 mode check) passes on both sides here, so it guards the mode but is not a red test.
  • Green: 17 run, OK, 0 skipped. MEASURED, 3/3 pass.
  • Verdict: READY (the Windows blocker above is a platform limit of those two tests, not a fault of the change).

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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248780709 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669#issuecomment-7248780709). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:26:10Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (TestAtomicSceneOutput.test_failed_write_preserves_existing_output) / green 17 OK. - PR head 24278bbdc, `python -I tests/test_sandbox_scene.py`. - On macOS both tests that blocked on Windows run: bash sets the file-size limit, and `chmod` modes are real. - Red: 15 run, 1 failure. On main a write that fails part-way leaves a truncated scene in place of the existing file (`b'LSB1...' != b'pre-existing scene contents'`). MEASURED, TestAtomicSceneOutput alone 3 runs, 3/3 fail. - `test_successful_write_preserves_scene_bytes` (the 0o640 mode check) passes on both sides here, so it guards the mode but is not a red test. - Green: 17 run, OK, 0 skipped. MEASURED, 3/3 pass. - Verdict: READY (the Windows blocker above is a platform limit of those two tests, not a fault of the change). 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:54:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T17:54:40Z.


Re-verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 4364a4fa6, PR head 24278bbdc (unchanged since my earlier check) : red 1 failure / green 17 OK

python3.12 -I tests/test_sandbox_scene.py:

  • Merge: clean (git merge-tree). main changed this test file since the PR base (#2442 and two other commits), so red = the merged test file against main's code: 17 tests, 1 failure: TestAtomicSceneOutput.test_failed_write_preserves_existing_output (MEASURED n=3). The raw red (PR's older test file, 15 tests) shows the same failure.
  • Green (main + git merge --no-ff): 17/17 OK, skipped 0.

Verdict: READY (still missing the author's claim in the coordination issue).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260059370 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669#issuecomment-7260059370). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T17:54:40Z. --- Re-verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 4364a4fa6, PR head 24278bbdc (unchanged since my earlier check) : red 1 failure / green 17 OK `python3.12 -I tests/test_sandbox_scene.py`: - Merge: clean (`git merge-tree`). main changed this test file since the PR base (#2442 and two other commits), so red = the merged test file against main's code: 17 tests, 1 failure: `TestAtomicSceneOutput.test_failed_write_preserves_existing_output` (MEASURED n=3). The raw red (PR's older test file, 15 tests) shows the same failure. - **Green** (main + `git merge --no-ff`): 17/17 OK, skipped 0. **Verdict: READY** (still missing the author's claim in the coordination issue). AI-assisted: Claude Code
MoonEyes commented 2026-11-29 18:59:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T18:59:11Z.


Merging. Head 24278bbdc has red/green verdicts from reviewers other than the author (above), merges cleanly with main bcbbd9a9c, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (translator-tests mesh, semantic-tests f16) are pre-existing. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260914580 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1669#issuecomment-7260914580). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:59:11Z. --- Merging. Head `24278bbdc` has red/green verdicts from reviewers other than the author (above), merges cleanly with `main` `bcbbd9a9c`, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (`translator-tests` mesh, `semantic-tests` f16) are pre-existing. Merged by MoonEyes. AI-assisted (Claude Code).
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!1669
No description provided.