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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1653 into main 2026-11-28 11:44:45 +00:00
IlyassRS3 commented 2026-11-25 07:15:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T07:15:39Z.


Item ID: SDWA-DIFF-ORACLE-CLI-AND-REF
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155622653

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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486924489 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1653). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:15:39Z. --- Item ID: `SDWA-DIFF-ORACLE-CLI-AND-REF` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155622653 ## 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)
copilot-pull-request-reviewer[bot] commented 2026-11-25 07:15:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T07:15:48Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6053333230 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1653#pullrequestreview-6053333230). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T07:15:48Z. **Review:** COMMENTED --- 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.
whoalin1 commented 2026-11-25 09:32:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T09:32:38Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7158472232 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1653#issuecomment-7158472232). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T09:32:38Z. --- 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.
sodove commented 2026-11-28 11:27:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:27:33Z.


#1653 | head 1d155fe33807e97a7a5229db494ddb5e61630530 | python3 -I tests/test_sdwa_diff.py -v | red: 27 run, 4 failures, 6 errors | green: 27 passed | Red → green

The file exercised CLI/reference input handling, oracle cleanup and restoration of KNOWN. The baseline failed the added checks.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238564841 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1653#issuecomment-7238564841). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:27:33Z. --- #1653 | head `1d155fe33807e97a7a5229db494ddb5e61630530` | `python3 -I tests/test_sdwa_diff.py -v` | red: 27 run, 4 failures, 6 errors | green: 27 passed | **Red → green** The file exercised CLI/reference input handling, oracle cleanup and restoration of KNOWN. The baseline failed the added checks. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:44:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:44:47Z.


Merged, thank you @IlyassRS3! This PR (sdwa_diff: guard asm.family() oracle leak, validate oracle/CLI/reference inputs, and restore KNOWN) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238754745 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1653#issuecomment-7238754745). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:44:47Z. --- Merged, thank you @IlyassRS3! This PR (sdwa_diff: guard asm.family() oracle leak, validate oracle/CLI/reference inputs, and restore KNOWN) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1653
No description provided.