sandbox_scene: write --out atomically #1669

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

@⁠xel1uz on GitHub · 2026-11-25 07:39 UTC · original
xel1uz:fix/sandbox-scene-atomic-out → main · +103 −4 · 2 files · 1 commits · open

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.
**@⁠xel1uz** on GitHub · 2026-11-25 07:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1669) `xel1uz:fix/sandbox-scene-atomic-out` → `main` · +103 −4 · 2 files · 1 commits · open 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.
Repro on upstream/main: bash -c 'trap "" XFSZ; ulimit -f 1; python3 -I tools/sandbox_scene.py --entities /home/hampa/.hermes/profiles/mikuling/cache/scratch/sandbox-scene-large-repro/entities.jsonl --models /home/hampa/.hermes/profiles/mikuling/cache/scratch/sandbox-scene-large-repro/models --center 0 0 --out /home/hampa/.hermes/profiles/mikuling/cache/scratch/sandbox-scene-large-repro/baseline.bin' returned 2 ([Errno 27] File too large); existing output changed from 20 bytes to 1024 bytes.

After atomic write, the same repro returned 2 and preserved the existing output at 20 bytes; no temporary file remained.

Successful synthetic output matched upstream byte-for-byte (2256 bytes; SHA-256 c456bc9bd29f8f0d4dd36a983fd70c8fb25ebadbb9a4bd6c97672c2f11a09493).

Regression tests: upstream implementation failed test_failed_write_preserves_existing_output (1 failed, 14 passed, 5 subtests); fixed implementation passed (15 passed, 5 subtests).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:06 +00:00
Author
Owner

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

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.

**@⁠whoalin1** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1669#issuecomment-7157575467) 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.
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/1669/head:github-bot/gh-1669'
git switch 'github-bot/gh-1669'

Merge

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