[PR #1669] sandbox_scene: write --out atomically #1683

Open
opened 2026-11-26 20:22:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1669
Author: @xel1uz
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/sandbox-scene-atomic-out


📝 Commits (1)

  • 24278bb sandbox_scene: write --out atomically

📊 Changes

2 files changed (+103 additions, -4 deletions)

View changed files

📝 tests/test_sandbox_scene.py (+76 -0)
📝 tools/sandbox_scene.py (+27 -4)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1669 **Author:** [@xel1uz](https://github.com/xel1uz) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/sandbox-scene-atomic-out` --- ### 📝 Commits (1) - [`24278bb`](https://github.com/ubiquitarianism/leonida/commit/24278bbdc9e1d3feda253f0449663438d71f2cb8) sandbox_scene: write --out atomically ### 📊 Changes **2 files changed** (+103 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_sandbox_scene.py` (+76 -0) 📝 `tools/sandbox_scene.py` (+27 -4) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1683
No description provided.