sdwa_diff: guard asm.family() oracle leak, validate oracle/CLI/reference inputs, and restore KNOWN #1653

Open
github-bot wants to merge 1 commit from github-bot/gh-1653 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 07:15 UTC · original
IlyassRS3:fix/sdwa-diff-oracle-cli-and-ref → main · +163 −8 · 2 files · 1 commits · open

Item ID: SDWA-DIFF-ORACLE-CLI-AND-REF
Claim: #1608

Summary

  • Oracle arch validation without leak (tools/sdwa_diff.py): catch ValueError from asm.family(oracle.arch) (e.g. gfx900 or unsupported arch strings), close oracle, print hardware oracle unavailable: ..., and return exit 77 instead of crashing and leaking the oracle handle.
  • Module state restoration: restore module-global KNOWN in main()'s finally block (and handle --list-ops/--self-test before mutating it) so in-process calls do not permanently leak KNOWN = True.
  • Hardware oracle & shrink guards: validate oracle is not None, exact result-list length in hw_prepare(), and 4-word tuples/lists in _diff() (turning short/malformed oracle or shrink responses into clean RuntimeError -> exit 2 instead of AttributeError/IndexError). Catch transient Skip during the final shrunk recheck and fall back to the original failure detail.
  • CLI validation: reject empty/whitespace --hw-arch, --build, and --work.
  • Reference validation: raise RefError on unknown SDWA selectors (src*_sel/dst_sel), unknown dst_unused modes (previously fell through silently to UNUSED_PAD), wrong operand counts, non-VGPR destinations, and unparseable operands.
  • Tests (tests/test_sdwa_diff.py): add 5 regression tests covering all of the above.

Verification

  • python3 -W error -I tests/test_sdwa_diff.py -v: 27 passed, 0 failed (2.469s).
  • Mutation check against unpatched main: ran=27, failures=4, errors=6.
  • python3 -m compileall -q tools/sdwa_diff.py tests/test_sdwa_diff.py, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.

AI-assisted: yes
GPUs tested: none (CPU unit tests with stubbed hardware oracle and spirv_mini_interp; no game data)

**@⁠IlyassRS3** on GitHub · 2026-11-25 07:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1653) `IlyassRS3:fix/sdwa-diff-oracle-cli-and-ref` → `main` · +163 −8 · 2 files · 1 commits · open Item ID: `SDWA-DIFF-ORACLE-CLI-AND-REF` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ## Summary - **Oracle arch validation without leak (`tools/sdwa_diff.py`)**: catch `ValueError` from `asm.family(oracle.arch)` (e.g. `gfx900` or unsupported arch strings), close `oracle`, print `hardware oracle unavailable: ...`, and return exit `77` instead of crashing and leaking the oracle handle. - **Module state restoration**: restore module-global `KNOWN` in `main()`'s `finally` block (and handle `--list-ops`/`--self-test` before mutating it) so in-process calls do not permanently leak `KNOWN = True`. - **Hardware oracle & shrink guards**: validate `oracle is not None`, exact result-list length in `hw_prepare()`, and 4-word tuples/lists in `_diff()` (turning short/malformed oracle or shrink responses into clean `RuntimeError` -> exit `2` instead of `AttributeError`/`IndexError`). Catch transient `Skip` during the final shrunk recheck and fall back to the original failure detail. - **CLI validation**: reject empty/whitespace `--hw-arch`, `--build`, and `--work`. - **Reference validation**: raise `RefError` on unknown SDWA selectors (`src*_sel`/`dst_sel`), unknown `dst_unused` modes (previously fell through silently to `UNUSED_PAD`), wrong operand counts, non-VGPR destinations, and unparseable operands. - **Tests (`tests/test_sdwa_diff.py`)**: add 5 regression tests covering all of the above. ## Verification - `python3 -W error -I tests/test_sdwa_diff.py -v`: **27 passed, 0 failed** (2.469s). - Mutation check against unpatched `main`: **ran=27, failures=4, errors=6**. - `python3 -m compileall -q tools/sdwa_diff.py tests/test_sdwa_diff.py`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. AI-assisted: yes GPUs tested: none (CPU unit tests with stubbed hardware oracle and `spirv_mini_interp`; no game data)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:34 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 07:15 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 07:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1653#pullrequestreview-6053333230) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 09:32 UTC · original

Independent verification (Windows, Python 3.11.9 -I -W error): oracle-leak fix confirmed — asm.family(oracle.arch) ValueError now closes the oracle and exits 77 (previously leaked); hw_prepare/_diff validation, shrink Skip fallback, KNOWN finally-restore, dst_unused unknown->RefError (was KeyError/silent), operand-count checks per form with vopc early-return ordering correct. test_sdwa_diff.py 27 OK (matches body); --self-test ok; --oracle hw --hw-arch gfx900 -> 77 via covered path; compileall + line-endings + check_no_game_data clean. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 09:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1653#issuecomment-7158472232) Independent verification (Windows, Python 3.11.9 `-I -W error`): oracle-leak fix confirmed — `asm.family(oracle.arch)` ValueError now closes the oracle and exits 77 (previously leaked); `hw_prepare`/`_diff` validation, shrink Skip fallback, `KNOWN` finally-restore, `dst_unused` unknown->RefError (was KeyError/silent), operand-count checks per form with vopc early-return ordering correct. `test_sdwa_diff.py` 27 OK (matches body); `--self-test` ok; `--oracle hw --hw-arch gfx900` -> 77 via covered path; compileall + line-endings + check_no_game_data clean. AI-assisted verification.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1653/head:github-bot/gh-1653'
git switch 'github-bot/gh-1653'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1653'
git switch 'github-bot/gh-1653'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1653'
git switch 'github-bot/gh-1653'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1653'
git switch 'main'
git merge --squash 'github-bot/gh-1653'
git switch 'main'
git merge --ff-only 'github-bot/gh-1653'
git switch 'main'
git merge 'github-bot/gh-1653'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.