shader: harden compile_lds_request CLI, path guards, and replay checks with offline unit suite #3138
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3138
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3136"
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?
@Ammmae0x on GitHub · 2026-11-27 16:24 UTC · original
Ammmae0x:shader/compile-lds-request-cli→main· +823 −37 · 4 files · 2 commits · merged 2026-11-28 08:34 UTCChange
Harden
tools/startup/compile_lds_request.pyCLI path validation, entrypoint error handling, and replay bundle verification, and add an offline unit/CLI/mutation suite:main(argv=None) -> intand invokeraise SystemExit(main())underif __name__ == '__main__'._validate_paths(_validate_regular_filefor the.c67marker, all five companion files.root/.data/.desc/.sa/.sb, and--compiler;--sdkexists and is a directory;outputand--cacheare not regular files and are not under a file-backed or dangling-link parent). Symlinked output/cache are allowed: the bundle is written through aTemporaryDirectoryinside the output and moved into place with an atomic rename, so a symlink is the caller's chosen location; only a component that is not a directory at all is refused.CompileLdsRequestError(aValueErrorsubclass);main()catches only(gfx.Unsupported, subprocess.CalledProcessError, CompileLdsRequestError), emitting a conciseerror: ...diagnostic onstderrand returning1. Anything else — including a real translator bug — keeps its traceback instead of being swallowed into a clean error.ComputeStage.body()refuses out-of-range branch targets cleanly withgfx.Unsupported('branch target ... is outside the compute stage')instead of aKeyErrorfrom the block-index lookup.replay.jsonin an existing bundle now reportsdamaged replay artifact replay.json in <dest>instead of re-raising the renameOSError("Directory not empty"); a missing or damaged artifact file in the bundle is reported the same way..c67suitetests/startup_compile_lds_request_cli_check.py(mockingsubprocess.runto cover warm bundle reuse, damaged artifactsha256/replay.jsondetection, missing companion and hostile path refusals,--rw-image/conditionals_barrier/.datamismatch refusals, and 7 fast self-mutations) and registershader_compile_lds_request_cli_checkviatests/cmake/shader_compile_lds_request_cli.cmakeandtests/checks/python-linux/shader_compile_lds_request_cli.txt.Verification
Verified on commit
bd78c395inslot-3:out\pe-env\Scripts\python.exe -B tests/startup_compile_lds_request_cli_check.py -v->Ran 4 tests ... OK(exit 0, including 8 fast self-mutations).out\pe-env\Scripts\python.exe -B tests/native_lds_control_flow_check.py->uniform barrier and wave-level EXEC branch passed; divergent barrier and back edge rejected(exit 0).out\pe-env\Scripts\python.exe -B tests/startup_tools_lint_check.py->PASS: 14 files under tools/startup parse; control snippet rejected and valid snippet accepted(exit 0).out\pe-env\Scripts\python.exe -B tests/run_checks_fragments_check.py->run_checks_fragments_check ok(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 96 Markdown files and 586 links.(exit 0).out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 2311 tracked source, script and build/CI files: no bidirectional controls.(exit 0).tools/startup/compile_lds_request.py: 3/3 mutations killed (disable_validate_paths(args)-> exit 1; disable bundlesha256check -> exit 1, 2 failures; disable symlink guard in_validate_writable_dir-> exit 1, 2 failures).tests/native_lds_request_check.pywas not run locally becausecompile_dxil.exeis not built in thispy_fastworktree or primaryout\build\dev.Review-feedback verification on commit
6b9db222(Linux; no Windows toolchain on this host):python3 -B tests/startup_compile_lds_request_cli_check.py -v->Ran 6 tests ... OK(exit 0, including 7 fast self-mutations, the new FIFO/dangling-symlink-parent refusals, the translator-traceback regression test and the out-of-range branch test).python3 -B tests/native_lds_control_flow_check.py->uniform barrier and wave-level EXEC branch passed; divergent barrier and back edge rejected(exit 0)./tmp/pe-env/bin/python -B tests/form_coverage_check.py->form coverage checks passed(exit 0; system python3 lacksiced_x86, the venv provides it).python3 -B tests/docs_links_check.py->Self-test passed. Checked 96 Markdown files and 586 links.(exit 0).python3 -B tests/bidi_controls_check.py->Self-test passed. Checked 2311 tracked source, script and build/CI files: no bidirectional controls.(exit 0).tools/startup/compile_lds_request.py: 5/5 mutations killed (restore the broadexcept; remove the branch-target guard; re-add the symlink refusal; remove the FIFO guard; bare-raise on damagedreplay.json— each made the suite fail, and the source was restored cleanly after each).tests/native_lds_request_check.pywas not run locally: it needs a builtcompile_dxilbinary and DXC, which are not available on this Linux host. A Windows CTest/compile_dxilrun is still needed.Evidence and follow-up
All
.c67request bundles intests/startup_compile_lds_request_cli_check.pyare synthetically constructed in-test fromtests/startup_gfx2hlsl_compute_check.pycases; no external binaries or game files are used.Checklist
AI-assisted.
github-bot referenced this pull request2026-11-27 17:42:44 +00:00
@JohnConnorNPC on GitHub · 2026-11-27 17:39 UTC · original
Thanks, this is a useful cleanup, and the bundle output is byte-identical to main for Case F at wave sizes 32 and 64. A few things before merge:
excepthides translator bugs.main()now catchesValueError/RuntimeError/OSErrorraised anywhere in translation. WithCASES['F']fromtests/startup_gfx2hlsl_compute_check.pywritten throughwrite_requestand its dword 4 replaced by0xbf84c07f(a backwards_cbranch_scc0), main prints a 24-line traceback ending inValueError: invalid literal for int() with base 16: '0x-fdf0'fromgfx2hlsl.translate. This branch prints one line,error: invalid literal for int() with base 16: '0x-fdf0', which looks just like a deliberateUnsupportedrefusal. Could the guards raise their own exception type (or the catch list namegfx.Unsupported,CalledProcessErrorand the guard/damaged-artifact errors explicitly), so unexpected exceptions keep their traceback?CASES['extracted-tid']with dword 9 set to0xbf852005(thes_cbranch_scc1offset moved past the end) still exits withKeyError: 32828from the block-index lookup inComputeStage.body. It predates this PR, but since the PR claims the property, couldbody()refuse out-of-range targets withUnsupported(plus a case in the suite), or could the claim be dropped?--cache.ctest --preset prfilter doesn't includenative_lds_request,native_lds_control_flowor the newshader_compile_lds_request_cli_check, and the body says native_lds_request wasn't run locally. Could you add a Windows run ofctest --preset dev --no-tests=error -R '^(native_lds_request|native_lds_control_flow|shader_compile_lds_request_cli_check)$' -Vto the PR?'request marker'to"request marker"givesAssertionError: 0 != 1 : target not unique. Mutating the tool and running the other three tests is the stronger control. They already catch most guard removals.Smaller points:
replay.jsonreportsDirectory not empty(a rename error) rather than naming the file._validate_writable_dirdoesn't check that the directory is writable.shader_vsstartup_for the test, ctest name and commit prefix.This comment was AI-assisted.
@KelboLive on GitHub · 2026-11-27 18:49 UTC · original · approved these changes
Solid hardening of the CLI entrypoint and path validation. The extracted
main(argv)signature makes testing straightforward, and the try-except block prevents uncaught tracebacks on bad input or runtime errors. The new offline test suite covers warm-reuse, damaged artifacts, missing companions, and hostile paths effectively. Approved.@KelboLive on GitHub · 2026-11-27 23:56 UTC · original
Agree with KelboLive's APPROVED review: clean CLI hardening. The extracted
main(argv=None) -> intmakes testing straightforward,_validate_pathscatches bad inputs upfront before any file operations, and the try-except block prevents uncaught tracebacks while preserving exact diagnostics expected by existing tests.@JohnConnorNPC on GitHub · 2026-11-28 07:33 UTC · original
Thanks for the update. The head is still
bd78c395, whose only commit (16:16Z) predates my 17:39Z comment, so none of those points are addressed yet. I re-ran them on this head, and all five still reproduce. A trial merge intomain(c3204a9c) is clean, and the new test passes there (Ran 4 tests ... OK).One thing needs fixing before this can land:
exceptmakes translator bugs look like refusals.except (OSError, ValueError, gfx.Unsupported, RuntimeError, subprocess.CalledProcessError)catches a translatorValueError. On Case F with dword 4 =0xbf84c07f,maingivesrc=1with a 24-line traceback endingValueError: invalid literal for int() with base 16: '0x-fdf0'. This head givesrc=1with one line,error: invalid literal for int() ..., the same form as anUnsupportedrefusal. Catchinggfx.Unsupported,CalledProcessErrorand a tool-specific error for the guards, and letting anything else keep its traceback, would fix it.Non-blocking:
0xbf852005still ends inKeyError: 32828(13 lines, on head and on main). Refusing out-of-range branch targets inComputeStage.body(), or dropping the claim, would settle it.rc=0and writes into the target. The tool never writes--cache, so the rule could go there.prpreset matches none of the three ctest names. A Windows run ofctest --preset dev --no-tests=error -R '^(native_lds_request|native_lds_control_flow|shader_compile_lds_request_cli_check)$' -Vwould cover them.'request marker'to"request marker"fails them (target not unique for drop_marker_guard) while behaviour is unchanged. Of 17 tool mutants I ran against the 3 behavioural tests, 2 survive: an output that is a FIFO, and a dangling-symlink parent.Environment: Linux, Python, trial merge and pure-Python runs only. I did no compile_dxil/DXC, Windows ctest or GPU run.
This comment was AI-assisted.
@Ammmae0x on GitHub · 2026-11-28 08:16 UTC · original
Addressed the review feedback in
6b9db222e3f4e3ede8937e72a1c235af9c8f3da6:exceptnarrowed:main()now catches only(gfx.Unsupported, subprocess.CalledProcessError, CompileLdsRequestError), a new dedicated guard/artifact exception type. Regression test pins that a translator bug keeps its traceback:CASES['F']with dword 4 =0xbf84c07fnow raisesValueError: invalid literal for int() with base 16: '0x-fdf0'with a traceback instead of a cleanerror:line.ComputeStage.body()out-of-range branch targets are refused cleanly withgfx.Unsupported('branch target ... is outside the compute stage'); regression test usesCASES['extracted-tid']with dword 9 =0xbf852005, which previously exited withKeyError: 32828.--cacherefusal is gone (the tool never writes--cache), and the half-effective last-component--outputcheck is gone too. Both now succeed as the caller's chosen location — the bundle is written through aTemporaryDirectoryand moved with an atomic rename — and the threat model is documented in_validate_writable_dir. Live symlink output/cache tests prove the bundle lands in the link target, and the second run warm-reuses it.output path is not a directory) and dangling-symlink parent paths for output and cache (output/cache parent is not a directory).replay.jsonnow reportsdamaged replay artifact replay.json in <dest>instead of re-raising the renameOSError("Directory not empty"); the positive test asserts the exact message, and a missing/damaged artifact file is reported the same way.main's spelling.Verification (Linux; Windows CTest/
compile_dxilstill needs a Windows run):tests/startup_compile_lds_request_cli_check.py -v6/6 OK,tests/native_lds_control_flow_check.pyexit 0,form_coverage_check.py,docs_links_check.py(96 files, 586 links) andbidi_controls_check.py(2311 files) all exit 0. Spot mutations: 5/5 killed (restore broadexcept; remove branch-target guard; re-add symlink refusal; remove FIFO guard; bare-raise on damagedreplay.json), source restored cleanly after each.tests/native_lds_request_check.pywas not run — it needs a builtcompile_dxiland DXC, unavailable on this Linux host. The_validate_writable_dirwritability check was not added; flagging it as a follow-up.AI-assisted.