shader: extract main(argv), atomic output writes, and OSError/struct guards in mesh_dynamic_aot with CLI suite #2399
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2407"
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 R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T15:35:08Z.
Change
Harden
tools/mesh_dynamic_aot.pyfor programmatic and CLI execution while preserving its HLSL translation behavior,--sampler-heap-sgprexit-2 validation, and error prefix format:__main__block intomain(argv=None) -> intforwardingargvtoparser.parse_args(argv).--sampler-heap-sgprout-of-range / reserved-SGPR checks returning exit 2 viaparser.error(...).--outputbeing an existing directory, lacking a.hlslsuffix, or colliding withcontainervia_same_path()(Path.resolve()equality andPath.samefile()for hardlinks/aliases).tempfile.TemporaryDirectory(dir=args.output.parent)before committing withos.replace()so write/replace failures leave no partial files or leftover staging directories.(OSError, ValueError, KeyError, struct.error, zlib.error)cleanly viaparser.exit(1, f"{type(error).__name__}: {error}\n")with no raw Python tracebacks.tests/mesh_dynamic_aot_cli_check.pyand registermesh_dynamic_aot_cli_checkinCMakeLists.txt.Verification
Verified on commit
971333c6(based onupstream/main7092683a):out/pe-env/Scripts/python.exe -B tests/mesh_dynamic_aot_cli_check.py -v->Ran 7 tests in 2.853s - OK(exit 0)out/pe-env/Scripts/python.exe -B tests/mesh_dynamic_aot_check.py->Runtime mesh specializations matched the CPU cases and rejected unproven uses(exit 0)out/pe-env/Scripts/python.exe -B tests/mesh_lane_spill_check.py-> exit 0out/pe-env/Scripts/python.exe -B tests/mesh_heap_sampler_check.py-> passed (16 refusals + 3 guard-removal controls; exit 0)out/pe-env/Scripts/python.exe -B tests/mesh_clip_cull_check.py-> passed (40 refusal checks + 7 guard-removal controls; exit 0)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 464 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1724 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Spot mutation checks against
tools/mesh_dynamic_aot.py(9/9 killed bytests/mesh_dynamic_aot_cli_check.py, restored cleanly):argvforwarding, bypass--sampler-heap-sgprcheck, bypass existing-directory check, bypass.hlslsuffix check, bypassresolve()collision check, bypasssamefile()collision check, bypassTemporaryDirectory+os.replace()staging, drop{type(error).__name__}:prefix, and dropstruct.errorhandler (all returned exit 1).Evidence and follow-up
translate(MIT, repo-authored; no game files, dumps, binaries, or GPU/LLVM prerequisite).--sampler-heap-sgpr(exit 2), existing-directory--output, non-.hlslsuffix, path collisions via..alias and hardlink, missing container,ValueError/KeyError/struct.error/zlib.errorwith{type(error).__name__}:prefix, andos.replace()/ staging write failures leaving zero temp directories.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T15:54:08Z.
APPROVED: Clean refactoring of mesh_dynamic_aot.py — extracts main(argv), atomic writes via TemporaryDirectory+os.replace(), _same_path() hardlink detection, and broadened error handling. Tested with 442-line synthetic suite (9/9 mutations killed). No game files, follows project patterns.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T16:56:12Z.
Seven mutations: six caught, one survivor —
encoding="ascii"is a deliberate guard that nothing exercisesBaseline on this branch:
tests/mesh_dynamic_aot_cli_check.py→Ran 7 tests in 2.775s … OK, exit 0.tools/mesh_dynamic_aot.pymain(argv=None)→main()(the entry stops forwarding argv)_same_pathloses thesamefilearm.hlslsuffix check disabled_same_path(output, container)refusal disabledos.replace(staged, output)replaced by a directoutput.write_text(...)staged.write_text(hlsl, encoding="ascii")→encoding="utf-8"The sixth one is the one I did not expect: an atomic-write change where a direct write passes the tests would be a real hole, and yours catches it — presumably because one case asserts the destination is untouched when the run fails. That is the case worth keeping.
The survivor is behaviour-changing, just not reachable from the current fixtures
asciiis the stricter contract: the emitted HLSL is written for DXC, and a symbol name that survives from the container into the text would raiseUnicodeEncodeErrorat write time instead of landing in the.hlslas UTF-8. With the mutant, a container whose symbol table contains a non-ASCII name writes the file successfully and the failure moves to the compile step — the same class of "clean error" this PR is about, moved one stage later.UnicodeEncodeErroris aValueError, so the existing handler already gives it a cleanparser.exit(1, …); nothing in production needs to change. What is missing is a case: a container with a non-ASCII identifier should exit 1 with that message, not write the file. If you would rather not construct one, droppingencoding="ascii"and letting the fixture's ASCII content pass is honest too — but then the choice ofasciishould not be presented as pinned.Two smaller things from reading the diff
_same_pathcomparesleft.resolve() == right.resolve()first, andresolve()on a missing path is fine, butPath.samefilewould raise for one. The ordering is right; a comment saying so (resolvehandles the not-yet-existing output,samefilehandles a case/symlink difference on Windows) would stop someone "simplifying" it tosamefilealone.except (OSError, ValueError, KeyError, struct.error, zlib.error)now covers five families and the message prefixestype(error).__name__, so a truncated container and a permission error are distinguishable in the log. Good — that matters for the triage path, where a refusal census groups by this text.What the PR gets right that is easy to miss
args.output.parent.mkdir(parents=True, exist_ok=True)happening inside the try, and the staging directory being created underargs.output.parentrather than the system temp — the rename stays on the same volume, soos.replaceis actually atomic. A staging directory under%TEMP%would have needed a fallback copy and lost the guarantee invisibly.AI-assisted; the seven mutations were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T17:01:56Z.
Addressed both points in commit
debf4d40:test_non_ascii_hlsl_rejected_before_replace_and_preserves_existing_outputintests/mesh_dynamic_aot_cli_check.py, exercisingencoding="ascii"with non-ASCII HLSL output (\u00e9) and verifying exit code1withUnicodeEncodeError:, no traceback,os.replacenot called, existing destination contents untouched, and zero leftover staging directories. Verified locally that mutatingencoding="ascii"toencoding="utf-8"is now killed (exit1)._same_pathintools/mesh_dynamic_aot.pyexplaining whyresolve()runs beforesamefile().Verification on
debf4d40(out/pe-env/Scripts/python.exe -B):tests/mesh_dynamic_aot_cli_check.py:Ran 8 tests in 4.100s(OK, exit0)tests/mesh_dynamic_aot_check.py: passed (exit0)tests/form_coverage_check.py,tests/docs_links_check.py(19 MD, 464 links),tests/bidi_controls_check.py(1724 tracked): all exit0AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:22:41Z.
Review: COMMENTED
Review of head
debf4d40(Linux checks only; no Windows run by me, and I did not see author Windows results for this SHA).Checked:
tools/mesh_dynamic_aot.py:main(argv)extraction, directory/suffix/same-path guards (_same_pathalso catches aliases viasamefile), staged write +os.replacein the output directory, widened error handling (OSError, struct, zlib) that exits 1 with a one-line message. The--sampler-heap-sgprrange check is kept. Logic reads correct.mesh_dynamic_aot_cli_checkis registered next tomesh_dynamic_aot_cpu.Commands run:
python3 -B tests/mesh_dynamic_aot_cli_check.py-> 8 tests OKpython3 tests/docs_links_check.py-> OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanos.replace(staged, args.output)withpass-> failuresMinor, non-blocking:
parser.error; they now exit 1. Only matters to scripts that check the code.add_testhas noTIMEOUTproperty; consider adding one.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:57:21Z.
Review: COMMENTED
Review of head
470c9786(merge of main into the branch; the PR's own change is the same asdebf4d40).Checked against origin/main:
tools/mesh_dynamic_aot.py:main(argv)is extracted cleanly. Output checks (directory,.hlslsuffix, same path as the container) run before translation. The write is staged in a temp dir next to the output and committed withos.replace, so a failure leaves no partial file. The sibling testmesh_dynamic_aot_check.pystill passes, and the translation code itself is untouched.mesh_dynamic_aot_cpu.parser.error, and the prefixmesh_dynamic_aot:. Now: exit 1 with<ExceptionType>: msg. The PR text only promises to keep the exit 2 for--sampler-heap-sgpr, and that is kept. I found no caller in the repo that depends on the old prefix.Commands run locally on this head (Linux):
python3 -B tests/mesh_dynamic_aot_cli_check.py-> Ran 8 tests, OKpython3 -B tests/mesh_dynamic_aot_check.py-> OKpython3 tests/docs_links_check.py-> OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanos.replacewith a direct write -> new suite fails (2 failures).zlib.errorfrom the caught errors -> new suite fails (1 error).No blocking findings. The Win2025 run on this head is still to come.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:09:31Z.
Win2025 WARP receipt for head
c4dd51d8after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
c4dd51d855f9522ff7b2d13fe27bbac8882840fb:--preset dev):cmake --build --preset dev -- -j 2):155.34s(configure3.59s)ctest --preset dev -R 'mesh_dynamic_aot' --parallel 2 --no-tests=error --output-on-failure): 4/4 passed (4.56s:mesh_dynamic_aot_draw_hardware2.17s,mesh_dynamic_aot_draw_warp2.25s,mesh_dynamic_aot_cpu1.26s,mesh_dynamic_aot_cli_check2.17s)/O2(--preset release):cmake --build --preset release -- -j 2):228.12s(configure2.15s)ctest --preset release -R 'mesh_dynamic_aot' --parallel 2 --no-tests=error --output-on-failure): 4/4 passed (5.74s:mesh_dynamic_aot_draw_hardware2.54s,mesh_dynamic_aot_draw_warp2.63s,mesh_dynamic_aot_cpu1.45s,mesh_dynamic_aot_cli_check2.85s)tests/mesh_clip_cull_check.pyok (7.1s),tests/mesh_dynamic_aot_check.pyok (1.5s),tests/mesh_heap_sampler_check.pyok (1.1s),tests/mesh_lane_spill_check.pyok (0.4s)sccache: 502/1669 hits; wall419.7sAI-assisted; commands listed were executed locally.