feature_scan: write --out atomically and keep the existing report on failure #1648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1648"
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?
Imported from ubiquitarianism/leonida. Originally posted by xel1uz on 2026-11-25T07:00:08Z.
Item ID:
FEATURE-SCAN-ATOMIC-OUT(new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here)Claimed as:
FEATURE-SCAN-ATOMIC-OUT- a failed--outwrite truncates an existing report and leaves a partial file. Reproduced on42537e7b.What and why
feature_scanwrote its report withopen(a.out, "w")followed byjson.dump, so the target was truncated the moment the file was opened, before anything had been serialized. A write that then fails (EFBIG, ENOSPC, an interrupt) leaves a partial JSON behind and the previous report gone - the failure path printsERROR: cannot write ...and returns 2, but the damage is already done and invisible to the caller.The write is now atomic: the JSON goes to a
tempfile.mkstempfile in the same directory as the target, is flushed and closed, and is moved into place withos.replace; on any failure the temp file is removed and the existing report is left untouched. The error message, the exit code 2 and themakedirsbehaviour for a missing parent folder are unchanged.Reproduction (synthetic input, 32-byte existing report,
ulimit -f 1forcing a short write):Tested
pytest tests/test_feature_scan.py -qwith the tool at42537e7b: 1 failed, 15 passed - the failure isFeatureScanAtomicOutputTests::test_failed_write_keeps_existing_report(assertEqual(stream.read(), original)).git diff --checkclean;python3 -I scripts/check_no_game_data.py tools/feature_scan.py tests/test_feature_scan.pyclean.GPUs tested: n/a - CPU only, no Vulkan device involved.
AI-assisted: Yes.
Checklist
main(42537e7b) and merges cleanly.docs/design.md- not applicable, no translator change.Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T10:02:10Z.
Independent verification (Windows, Python 3.11.9): tool change is correct and Windows-safe — mkstemp in target dir + os.replace is atomic, failure leaves the existing report untouched (verified live:
--outpointing at a directory -> exit 2, directory preserved, no stray temp). Two test problems though:FeatureScanAtomicOutputTestsfailure-injection tests are POSIX-only (import resource,signal.SIGXFSZ,preexec_fn) — under pytest on Windows: 2 failed / 14 passed.__main__runner only collects module-leveltest_*functions, sopython -I tests/test_feature_scan.py(what the windows-latest check job runs) passes vacuously without running the new class at all.Suggest: skip POSIX-only failure injection on Windows AND make the tests collectible (module-level functions or pytest marker/
unittest.main()). Minor nits: mkstemp files are mode 0600 on POSIX (no published_mode chmod like sibling tools); os.replace replaces a symlink itself rather than writing through it — behavior change vs old open(). AI-assisted verification.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T03:04:01Z.
Hi @xel1uz, thanks for this pull request.
CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post
claiming: <ID>there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one.The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.
Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:16:54Z.
Tested
362b85400merged (no commit) withmain829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.Blocker: the new tests do not run the way the file is run, and fail on Windows when they do.
python -I tests/test_feature_scan.py(the file's own__main__runner, line 633) runs only the existing checks. The newFeatureScanAtomicOutputTestsclass is never called, so the file passes with and without the fix.python -m unittest discover -s tests -p test_feature_scan.py, 2 of its 3 tests error on Windows:ValueError: preexec_fn is not supported on Windows platforms(RLIMIT_FSIZEthroughresource).Hooking the class into the file's runner and skipping the size-limit cases where
resourceis missing would cover both points.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:22:23Z.
Native Windows 11 Verification (
362b854007)Diff-audited
tools/feature_scan.py(+16/-2) andtests/test_feature_scan.py(+68/-0) and verified merged ontoorigin/main(48bae6cad) on Windows 11 (10.0.26200, NTFS, Python3.12.10).Live NTFS Read-Only Probe
report.jsonread-only (stat.S_IREAD) on NTFS and ranpython -I tools/feature_scan.py <shaders> --out <report.json>: exited2(ERROR: cannot write ...: Access is denied), preservedreport.jsonbyte-for-byte, and unlinked the temporary file (0leftover temp files).Three Issues Found in
tests/test_feature_scan.py&tools/feature_scan.pyFeatureScanAtomicOutputTestsnever runs underpython -I tests/test_feature_scan.py(CI's stdlib test loop):tests/test_feature_scan.py's__main__block only collects module-leveldef test_*functions viarun_tests(...), soclass FeatureScanAtomicOutputTests(unittest.TestCase):is silently skipped (0/3tests executed) when run as a script!ValueError: preexec_fn is not supported on Windows platformsunderunittest:python -m unittest tests/test_feature_scan.pyon Windows 11 fails2/3tests (FAILED (errors=2)): (resource.RLIMIT_FSIZEandsignal.SIGXFSZinsidefail_file_writesare also Unix-only.) Converting the 3 new tests to module-leveldef test_*functions (or runningunittest.TextTestRunnerfrom__main__) and triggering write failure portably — e.g. mockingjson.dumpto raiseOSErrormid-write in-process, or pointing--outat a read-only destination — makes all 3 tests run and pass on both Linux and Windows.os.close(fd)intools/feature_scan.pywhenos.replaceraises:with os.fdopen(fd, "w", ...) as f:wrapsfd, exiting thewithblock closesfd. Whenos.replace(temporary, a.out)subsequently raisesPermissionError(as on a read-only NTFS target),except BaseException:callsos.close(fd)a second time on an already-closed integer FD. Clearing a localfd_owned = Falseflag onceos.fdopensucceeds avoids closing a potentially reused descriptor.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T11:51:49Z.
Before a merge: the blocker in my comment above still stands (the new test class never runs from the file's own runner, and under unittest 2 of its 3 tests error on Windows with
preexec_fn). Your claim in the coordination issue #2570 is missing too.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T17:11:17Z.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main
4364a4fa6, PR head362b85400: red 1 failure / green 16 OKgit merge-tree). Reviews: none. No game data in the diff. Skipped on the merge: none.tools/feature_scan.py(2 lines) since the PR base; the merge is clean and the test file is unchanged on main.FeatureScanAtomicOutputTests::test_failed_write_keeps_existing_report.test_feature_scan_*x5,test_inner_coverage_metadata,test_json_bom_inputs): 21 passed on main and merge.mkstempcreates the file as 0600, so the report loses its usual 0644 mode (#1668 keeps the mode); ifos.replacefails, theexceptcallsos.close(fd)on an fd already closed by thewith(theoretical double close).Verdict: READY (two nits above)
AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T18:28:21Z.
Thank you! Merged into
mainwith a merge commit. It was verified ready on its current head (362b85400) by OreoFR's Mac agent (macOS, red/green on main + PR); see the verification comment above. (AI-assisted, posted for DadaCap.)