tools/ds_permute_probe: write --json report atomically (carry of #2000) #3090
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!3090
Loading…
Reference in a new issue
No description provided.
Delete branch "carry/2000"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: DS-PERMUTE-PROBE-ATOMIC-JSON (the original author's item ID, claimed at https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7170145014)
Depends on: #2000
What and why
Carry of #2000 (Ch1mpleo), unchanged since 2026-11-25. Branch = main + the author's head (commit kept) + conflict resolution; I added no commit of my own. #2000 conflicts with main in
tests/test_ds_permute_probe.py(add/add: main'stest_oracle_closed_on_success_and_failurelanded where the PR adds its tests), and the review on #2000 asks for a rebase.The change:
write_json_reportintools/ds_permute_probe.pynow writes the--jsonreport to a temporary file in the same directory (UTF-8, LF line endings) and moves it into place withos.replace, removing the temporary file on failure. A failed write therefore leaves an existing report untouched instead of truncating it. The PR also adapts the OSError test and addstest_atomic_json_write_and_replace_failure_preserves_existing.Conflict resolution: kept both sides' tests in
tests/test_ds_permute_probe.py.tools/ds_permute_probe.pymerged without conflict. No other review defect was raised on #2000 (the only review asks for a rebase), so there is no review-fix commit.Tested
Windows 11, Python 3.14.0, no GPU, no game files, on main a917c54d6 plus this branch.
python -I tests/test_ds_permute_probe.py: Ran 9 tests, OK.tools/ds_permute_probe.pyrestored to main's version and the branch's tests kept, the same command givesFAILED (failures=1, errors=1):test_atomic_json_write_and_replace_failure_preserves_existingfails andtest_write_json_report_and_main_catch_oserror_cleanlyerrors. Restored afterwards, working tree clean.python -I scripts/check_no_game_data.py tools/ds_permute_probe.py tests/test_ds_permute_probe.py: exit 0.Not run: the full suite, CI.
GPUs tested: n/a (unit tests only)
AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Supersedes #2000 once merged; the original stays open until a maintainer decides.
🤖 Generated with Claude Code
Windows 11, Python 3.13, head
582a4dfafmerged into currentmain: the merge is clean.python -I tests/test_ds_permute_probe.py: 9 tests, OK.One Windows behaviour changes, and it's worth knowing before merge. I wrote a report over an existing one while another handle in the same process held it open for reading, the way a viewer or editor that keeps the file open does. Python's
open()on Windows doesn't share delete access.main'swrite_json_reportNone(written)cannot write --json ...: Access is deniedreport.jsonreport.json(the temporary file was removed)So the PR does what it says: a failed write keeps the old report and leaves nothing behind. On Windows, though, "report open somewhere" becomes a failure where it used to overwrite.
os.replacecan't replace a file held open withoutFILE_SHARE_DELETE, while the old truncatingopen(path, "w")could. That's a fair trade for atomicity, and the message is clear. Maybe say it in the tool's help, or retry once.GPUs tested: n/a (CPU unit tests)
AI-assisted: yes (Claude Code).
Thanks for measuring the Windows case. Addressed in 70caa0dce: the rename now goes through
replace_retry, as the other atomic writers intools/do, so a short hold without share-delete (scanner, indexer, sync client) is ridden out for up to 5 s. A hold that lasts, like your open handle, still fails, keeps the old report and leaves no temporary file, and the message now adds "is the report open in another program? close it and run again". Two tests cover a hold that clears after one try and one that does not; both fail with the previous tool.python -I tests/test_ds_permute_probe.py: 11 tests OK.AI-assisted (Claude Code, Claude Opus 5.5)
RUN (independent run on Windows, #3090 head 70caa0dce, merged locally into
main23a51c494 withgit merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)replace_retrycommit made after Kal0s-design's comment. The counts below are for that head.python -I tests/test_ds_permute_probe.py -v: main 8 tests OK; merge 11 tests OK.python -m pyteston the same file (the only one that namesds_permute_probe) gives the same counts: main 8 passed; merge 11 passed.main'stools/ds_permute_probe.pywith the head's test file gives 11 tests, 2 failures and 2 errors:mainhas notempfileorreplace_retryto patch.test_atomic_json_write_and_replace_failure_preserves_existingfails:mainreports no error, because it writes in place.test_write_json_report_rides_out_a_short_windows_holdfails (0 != 2replace calls).open()for reading (no share-delete), held whilewrite_json_reportrewrites the report:main: the write succeeds while the handle is open and the report gets the new content. That is the in-place truncation Kal0s-design measured.replace_retryrides out a short hold for real, not only under the mock.tools/ds_permute_probe.py, each run with the whole test file and restored afterwards (git statusclean). 4 of 5 are killed:replace_retryreplaced by a plainos.replace: killed (2 tests).main's LF test.dir=None) instead of next to the report. On the same volume the rename still works, but across volumesos.replacewould fail. The tests' folders sit on the system temp volume, so nothing pins "next to the report".Not covered here: Linux and macOS (no
winerrorthere, so the hint and the retry do not apply), and hw_oracle runs (mocked, as in the existing tests).Verdict: PASS. The report is now replaced atomically, a short Windows hold is ridden out and a long one is named, which I checked natively and not only under mocks. Red on
mainand green on the merge hold, and the author's commit is kept. The body's "no commit of my own" is out of date for this head.Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.
Merging. Head
70caa0dcemerges cleanly withmainbf7886746and does not force a rebase of #2566. Independent check on head 70caa0dce: enlight3d's red/green on main + this head (2 failures and 2 errors with main's tool, green 11/11, native NTFS probe with a real open handle: main overwrites in place, the merge returns the error with the hint after 5 s and keeps the old report; 4 of 5 mutations killed), comment 7346366750; Ch1mpleo's commit from #2000 is kept; CI green incl. no-game-data. Merged by MoonEyes.AI-assisted (Claude Code).