d3d12_device_calls: validate --out upfront and publish reports atomically #2262

Merged
kirigayakazima merged 1 commit from upstream-pr/2262 into main 2026-11-28 15:05:33 +00:00
kirigayakazima commented 2026-11-26 11:35:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:35:43Z.


Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7190884297)

What and why

tools/d3d12_device_calls.py previously read and scanned the PE image before validating --out or same_report_path(...), and wrote <image>.device_calls.json and .txt directly in place with open(..., "w"). An unusable --out or self-overwrite path wasted a full PE decode (or created an empty --out directory on unreadable images), and an interrupted or failing write could truncate or partially update the report pair.

  • Check --out (non-empty and directory ancestors), input/report path collisions (same_report_path), and directory-occupied report paths before reading or scanning the input image, deferring os.makedirs until scan output is ready to write.
  • Stage both .json and .txt outputs into UTF-8 LF temp files inside --out, copy/probe permissions via file_mode.published_mode(...), replace both via replace_retry.replace(...), and clean up any leftover staged files on error.
  • Add CLI tests covering upfront --out / collision / directory-target errors, unopened invalid images, and preservation of prior reports on staging failure.

Tested

  • python -I tests/test_d3d12_device_calls.py -v (19 tests passed)
  • Detached upstream/main baseline negative control: failed with the new CLI tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509302562 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2262). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T11:35:43Z. --- Claimed in the coordination issue as: D3D12-DEVICE-CALLS-UPFRONT-OUT-AND-ATOMIC-REPORTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7190884297) ### What and why `tools/d3d12_device_calls.py` previously read and scanned the PE image before validating `--out` or `same_report_path(...)`, and wrote `<image>.device_calls.json` and `.txt` directly in place with `open(..., "w")`. An unusable `--out` or self-overwrite path wasted a full PE decode (or created an empty `--out` directory on unreadable images), and an interrupted or failing write could truncate or partially update the report pair. - Check `--out` (non-empty and directory ancestors), input/report path collisions (`same_report_path`), and directory-occupied report paths before reading or scanning the input image, deferring `os.makedirs` until scan output is ready to write. - Stage both `.json` and `.txt` outputs into UTF-8 LF temp files inside `--out`, copy/probe permissions via `file_mode.published_mode(...)`, replace both via `replace_retry.replace(...)`, and clean up any leftover staged files on error. - Add CLI tests covering upfront `--out` / collision / directory-target errors, unopened invalid images, and preservation of prior reports on staging failure. ### Tested - `python -I tests/test_d3d12_device_calls.py -v` (19 tests passed) - Detached `upstream/main` baseline negative control: failed with the new CLI tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
real-rusher commented 2026-11-26 12:23:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:38Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_d3d12_device_calls.py: 19 tests OK. The PR's test file against main's tool: 2 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191943517 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2262#issuecomment-7191943517). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:38Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_d3d12_device_calls.py: 19 tests OK. The PR's test file against main's tool: 2 failures and 1 error, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
tiguan26 commented 2026-11-27 04:36:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:36:47Z.

Review: APPROVED


Approving 6dd813ddb.

--out and its existing ancestors are checked before the scan, and both reports are staged as temp files and replaced only once all are written.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_d3d12_device_calls.py: 19 passed (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083540144 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2262#pullrequestreview-6083540144). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:36:47Z. **Review:** APPROVED --- Approving 6dd813ddb. `--out` and its existing ancestors are checked before the scan, and both reports are staged as temp files and replaced only once all are written. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_d3d12_device_calls.py`: 19 passed (main: 15). AI-assisted (Claude Code, Claude Opus 5.5).
zmasi commented 2026-11-28 10:35:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:35:16Z.


#2262 | head 6dd813ddb1 (merged cleanly with main 6c7f79343) | python -I tests/test_d3d12_device_calls.py | red on main: FAILED (failures=2, errors=1) (scan ran before validating --out / hardlink self-overwrite / directory report targets, and report writes were non-atomic) | green on PR+main: 19 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited _check_out_dir_ancestors, upfront same_report_path + directory-target checks before opening/scanning the PE image (avoiding empty --out creation on invalid images and catching Windows 11 NTFS os.link collisions), and staged UTF-8 LF atomic publishing via published_mode + replace_retry.replace in tools/d3d12_device_calls.py. Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237993133 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2262#issuecomment-7237993133). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T10:35:16Z. --- #2262 | head 6dd813ddb1eedbac60c30af41403ae99f83f45f4 (merged cleanly with main 6c7f79343) | `python -I tests/test_d3d12_device_calls.py` | red on main: `FAILED (failures=2, errors=1)` (`scan` ran before validating `--out` / hardlink self-overwrite / directory report targets, and report writes were non-atomic) | green on PR+main: `19 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `_check_out_dir_ancestors`, upfront `same_report_path` + directory-target checks before opening/scanning the PE image (avoiding empty `--out` creation on invalid images and catching Windows 11 NTFS `os.link` collisions), and staged UTF-8 LF atomic publishing via `published_mode` + `replace_retry.replace` in `tools/d3d12_device_calls.py`. Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 15:05:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:05:30Z.


Red/green: the PR tests fail on main 09c153948 and pass on head 6dd813ddb1 (cloud 2).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241193072 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2262#issuecomment-7241193072). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T15:05:30Z. --- Red/green: the PR tests fail on main 09c153948 and pass on head 6dd813ddb1ee (cloud 2). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!2262
No description provided.