[PR #1667] build_dstorage_history: write the history report atomically #1680

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/1667
Author: @xel1uz
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/build-dstorage-history-atomic-out


📝 Commits (1)

  • f0239cf build_dstorage_history: write the history report atomically

📊 Changes

2 files changed (+170 additions, -2 deletions)

View changed files

➕ tests/test_build_dstorage_history.py (+142 -0)
📝 tools/build_dstorage_history.py (+28 -2)

📄 Description

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

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

What and why

The report was written with Path.write_text(json.dumps(...)), which truncates the destination before any serialization happens: a report that fails part-way leaves a partial JSON and the previous history is already gone, while the caller only sees the write error.

The JSON now goes to a temporary file in the destination directory and is moved into place with os.replace once it is written; a failure removes the temp file and leaves the existing report untouched.

Tested

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

  • With this branch: 3 passed.

  • Repro with RLIMIT_FSIZE=128 and SIGXFSZ ignored: the build returns 1 (File too large), and the report went 30 -> 128 bytes on the original while staying 30 bytes here, with no temp file left.

  • 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/1667 **Author:** [@xel1uz](https://github.com/xel1uz) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/build-dstorage-history-atomic-out` --- ### 📝 Commits (1) - [`f0239cf`](https://github.com/ubiquitarianism/leonida/commit/f0239cff55602a3b376a0190cf768ffd70f794e1) build_dstorage_history: write the history report atomically ### 📊 Changes **2 files changed** (+170 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_build_dstorage_history.py` (+142 -0) 📝 `tools/build_dstorage_history.py` (+28 -2) </details> ### 📄 Description Item ID: `BUILD-DSTORAGE-HISTORY-ATOMIC-OUT` (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here) Claimed as: `BUILD-DSTORAGE-HISTORY-ATOMIC-OUT` - a failed `--out` write truncates an existing file and leaves a partial one behind. Reproduced on 42537e7b. ### What and why The report was written with `Path.write_text(json.dumps(...))`, which truncates the destination before any serialization happens: a report that fails part-way leaves a partial JSON and the previous history is already gone, while the caller only sees the write error. The JSON now goes to a temporary file in the destination directory and is moved into place with `os.replace` once it is written; a failure removes the temp file and leaves the existing report untouched. ### Tested - `pytest tests/test_build_dstorage_history.py -q` with the tool at 42537e7b: **1 failed, 2 passed** - the failure is `test_failed_write_preserves_existing_report`. - With this branch: **3 passed**. - Repro with `RLIMIT_FSIZE=128` and `SIGXFSZ` ignored: the build returns 1 (`File too large`), and the report went **30 -> 128 bytes** on the original while staying **30 bytes** here, with no temp file left. - `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#1680
No description provided.