ps_oracle: exit 77 when the oracle becomes unavailable during run() (PS-ORACLE-UNAVAILABLE-EXIT) #917

Merged
TuroYT merged 1 commit from upstream-pr/917 into main 2026-11-29 01:36:09 +00:00
TuroYT commented 2026-11-24 15:10:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TuroYT on 2026-11-24T15:10:51Z.


Claimed in the coordination issue as: PS-ORACLE-UNAVAILABLE-EXIT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135530775)

What was wrong

tools/ps_oracle.py documents exit code 77 for a missing tool. main() catches Unavailable only around the Oracle(...) constructor (line 822). The o.run(...) call in the next try block does not catch it. assemble() raises Unavailable when no AMD clang is found (line 629), and run_harness() raises it when vk_harness returns 77 (line 618). Both happen during run(), so the user gets a traceback and exit 1.

Reproduction on origin/main, with the oracle constructor stubbed (no vk_harness build here) and PATH reduced:

$ env -i PATH=/nonexistent /usr/bin/python3 -I driver.py; echo exit=$?
pixel stage wave64 on stub
Traceback (most recent call last):
  ...
ps_oracle.Unavailable: no AMD clang (set LEONIDA_AMD_CLANG; `pip install rocm-sdk-core` from https://stable.repo.amd.com/rocm/whl-next/ provides one)
exit=1

What changed

main() gets a first handler on the o.run(...) try block: except Unavailable as e: prints ps_oracle unavailable: {e} to stderr and returns 77. This is the same message the constructor handler already prints. The ValueError/KeyError/IndexError/TypeError and RuntimeError handlers are unchanged.

tests/test_ps_oracle.py (class Cli): test_unavailable_during_run_is_77 makes Oracle.run raise Unavailable and checks exit 77 and the exact stderr line. test_value_error_during_run_is_still_2 checks that a ValueError still returns 2.

Tested

  • Same driver as above, after the fix: ps_oracle unavailable: no AMD clang (...) on stderr, then exit=77.
  • python3 -I tests/test_ps_oracle.py Cli on the fixed code: OK (5 tests).
  • test_unavailable_during_run_is_77 on the unfixed tools/ps_oracle.py (checked out from origin/main): ERROR with the same ps_oracle.Unavailable: no AMD clang (test) traceback.
  • python3 -I tests/test_ps_oracle.py: 25 tests, OK, 2 skipped (hardware tests need LEONIDA_PS_ORACLE_BUILD).
  • python3 -I tests/test_ps_helper_probe.py: 6 tests, OK, 1 skipped.
  • python3 -m unittest discover -s tests/semantic -p test_export_valid_mask.py: 24 tests, OK.
  • python3 -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python3 -I scripts/check_no_game_data.py tools/ps_oracle.py tests/test_ps_oracle.py: no issues.
  • python3 -m compileall -q tools tests: OK. git diff --check: clean.

Not tested

  • A real vk_harness exit 77 reaching run_harness (the test raises Unavailable from run() directly, not through subprocess).
  • Any run with a real AMD clang or GPU.
  • --show-template on RADV with a missing llvm-mc. That path is outside run() and was not changed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474842337 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917). Originally posted by [TuroYT](https://github.com/TuroYT) on 2026-11-24T15:10:51Z. --- Claimed in the coordination issue as: PS-ORACLE-UNAVAILABLE-EXIT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135530775) ## What was wrong `tools/ps_oracle.py` documents exit code 77 for a missing tool. `main()` catches `Unavailable` only around the `Oracle(...)` constructor (line 822). The `o.run(...)` call in the next try block does not catch it. `assemble()` raises `Unavailable` when no AMD clang is found (line 629), and `run_harness()` raises it when vk_harness returns 77 (line 618). Both happen during `run()`, so the user gets a traceback and exit 1. Reproduction on origin/main, with the oracle constructor stubbed (no vk_harness build here) and PATH reduced: ``` $ env -i PATH=/nonexistent /usr/bin/python3 -I driver.py; echo exit=$? pixel stage wave64 on stub Traceback (most recent call last): ... ps_oracle.Unavailable: no AMD clang (set LEONIDA_AMD_CLANG; `pip install rocm-sdk-core` from https://stable.repo.amd.com/rocm/whl-next/ provides one) exit=1 ``` ## What changed `main()` gets a first handler on the `o.run(...)` try block: `except Unavailable as e:` prints `ps_oracle unavailable: {e}` to stderr and returns 77. This is the same message the constructor handler already prints. The `ValueError`/`KeyError`/`IndexError`/`TypeError` and `RuntimeError` handlers are unchanged. `tests/test_ps_oracle.py` (class `Cli`): `test_unavailable_during_run_is_77` makes `Oracle.run` raise `Unavailable` and checks exit 77 and the exact stderr line. `test_value_error_during_run_is_still_2` checks that a `ValueError` still returns 2. ## Tested - Same driver as above, after the fix: `ps_oracle unavailable: no AMD clang (...)` on stderr, then `exit=77`. - `python3 -I tests/test_ps_oracle.py Cli` on the fixed code: `OK` (5 tests). - `test_unavailable_during_run_is_77` on the unfixed `tools/ps_oracle.py` (checked out from origin/main): ERROR with the same `ps_oracle.Unavailable: no AMD clang (test)` traceback. - `python3 -I tests/test_ps_oracle.py`: 25 tests, OK, 2 skipped (hardware tests need LEONIDA_PS_ORACLE_BUILD). - `python3 -I tests/test_ps_helper_probe.py`: 6 tests, OK, 1 skipped. - `python3 -m unittest discover -s tests/semantic -p test_export_valid_mask.py`: 24 tests, OK. - `python3 -I tests/test_text_write_line_endings.py`: 3 tests, OK. - `python3 -I scripts/check_no_game_data.py tools/ps_oracle.py tests/test_ps_oracle.py`: no issues. - `python3 -m compileall -q tools tests`: OK. `git diff --check`: clean. ## Not tested - A real vk_harness exit 77 reaching `run_harness` (the test raises `Unavailable` from `run()` directly, not through `subprocess`). - Any run with a real AMD clang or GPU. - `--show-template` on RADV with a missing llvm-mc. That path is outside `run()` and was not changed. AI-assisted (Claude Code).
MoonEyes commented 2026-11-24 17:39:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-24T17:39:33Z.

Review: APPROVED


LGTM. Measured on Windows 11, Python 3.14, against main cf4c00cba:

  • python -I tests/test_ps_oracle.py: main Ran 23, OK (skipped=2); this PR and a local merge into main Ran 25, OK (skipped=2).
  • Mutation: with main's tools/ps_oracle.py and this PR's tests, test_unavailable_during_run_is_77 errors, because Unavailable escapes run(). The new handler (tools/ps_oracle.py:836) sits before the ValueError / RuntimeError ones, and the other Unavailable paths already returned 77.

AI-assisted: yes (Claude Code ran the checks; I read them).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6044345078 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917#pullrequestreview-6044345078). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-24T17:39:33Z. **Review:** APPROVED --- LGTM. Measured on Windows 11, Python 3.14, against main cf4c00cba: - `python -I tests/test_ps_oracle.py`: main `Ran 23, OK (skipped=2)`; this PR and a local merge into main `Ran 25, OK (skipped=2)`. - Mutation: with main's `tools/ps_oracle.py` and this PR's tests, `test_unavailable_during_run_is_77` errors, because `Unavailable` escapes `run()`. The new handler (`tools/ps_oracle.py:836`) sits before the `ValueError` / `RuntimeError` ones, and the other `Unavailable` paths already returned 77. AI-assisted: yes (Claude Code ran the checks; I read them).
zmasi commented 2026-11-28 20:55:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T20:55:38Z.


#917 | head 9dde66b432 (merged cleanly with main 1bc055e6c2) | python -I tests/test_ps_oracle.py | red on main: FAILED (errors=1, skipped=2) (Cli.test_unavailable_during_run_is_77 raised an uncaught ps_oracle.Unavailable traceback from o.run(...) instead of exiting 77) | green on PR+main: 25 ran, OK (skipped=2) (23/23 CPU/CLI tests OK) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/ps_oracle.py and tests/test_ps_oracle.py on Windows 11, verifying Unavailable raised during o.run(lines, sets) prints a single-line ps_oracle unavailable: ... message to stderr and returns skip code 77 without a traceback while ValueError during run() continues to return 2. Also verified tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245645706 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917#issuecomment-7245645706). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T20:55:38Z. --- #917 | head 9dde66b4323b10d454034ae8f894bd5d49395524 (merged cleanly with main 1bc055e6c2) | `python -I tests/test_ps_oracle.py` | red on main: `FAILED (errors=1, skipped=2)` (`Cli.test_unavailable_during_run_is_77` raised an uncaught `ps_oracle.Unavailable` traceback from `o.run(...)` instead of exiting `77`) | green on PR+main: `25 ran, OK (skipped=2)` (`23/23` CPU/CLI tests `OK`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/ps_oracle.py` and `tests/test_ps_oracle.py` on Windows 11, verifying `Unavailable` raised during `o.run(lines, sets)` prints a single-line `ps_oracle unavailable: ...` message to stderr and returns skip code `77` without a traceback while `ValueError` during `run()` continues to return `2`. Also verified `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
merzleckeier commented 2026-11-28 21:06:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-28T21:06:05Z.


I checked the real vk_harness exit path left open in the test notes. CachyOS, Raphael RDNA2 iGPU, RADV Mesa 26.3.1, Clang 23.1.5. A/B on merge base 81bb974c1 and merge 1cd7ceba8 (PR head 9dde66b43). The relevant Python and harness sources on the base also match current main at aa918e5d9.

  • A normal ps_oracle.py --template const --asm constant.s --size 1 1 run returned 0 on both and read back the four float words for (1, 2, 3, 4) from patched ISA.
  • I wrapped the same real vk_harness executable and set VKH_COLOR_FORMAT=124:2 (D16_UNORM) only when VKH_BINARY_IN was present. The template call succeeded and the real draw call returned 77 on both. The base CLI exited 1 with an Unavailable traceback. The PR CLI exited 77 with one stderr line, ps_oracle unavailable: unsupported: format 124 is not a color attachment.
  • Setting LEONIDA_AMD_CLANG to a nonexistent file after a successful template build also went from traceback/1 to one stderr line/77.

Synthetic shader only. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245772195 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917#issuecomment-7245772195). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-28T21:06:05Z. --- I checked the real `vk_harness` exit path left open in the test notes. CachyOS, Raphael RDNA2 iGPU, RADV Mesa 26.3.1, Clang 23.1.5. A/B on merge base `81bb974c1` and merge `1cd7ceba8` (PR head `9dde66b43`). The relevant Python and harness sources on the base also match current `main` at `aa918e5d9`. - A normal `ps_oracle.py --template const --asm constant.s --size 1 1` run returned `0` on both and read back the four float words for `(1, 2, 3, 4)` from patched ISA. - I wrapped the same real `vk_harness` executable and set `VKH_COLOR_FORMAT=124:2` (D16_UNORM) only when `VKH_BINARY_IN` was present. The template call succeeded and the real draw call returned `77` on both. The base CLI exited `1` with an `Unavailable` traceback. The PR CLI exited `77` with one stderr line, `ps_oracle unavailable: unsupported: format 124 is not a color attachment`. - Setting `LEONIDA_AMD_CLANG` to a nonexistent file after a successful template build also went from traceback/`1` to one stderr line/`77`. Synthetic shader only. AI-assisted.
OreoFR commented 2026-11-29 01:31:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:31:30Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 error (Cli.test_unavailable_during_run_is_77) / green 25 OK.

  • PR head 9dde66b43, python -I tests/test_ps_oracle.py from the repository root.
  • Red (main + only this PR's test files): 25 run, 1 error, 2 skips. Cli.test_unavailable_during_run_is_77: an uncaught ps_oracle.Unavailable escapes instead of exit code 77. MEASURED, failing test(s) alone 3 runs, 3/3 fail.
  • Green (main + git merge --no-ff of this PR, no conflict): 25 run, OK, 2 skips. MEASURED, the same test(s) alone 3/3 pass.
  • Skips: OnHardware.test_other_target_formats and OnHardware.test_patched_code_runs_as_the_pixel_shader on both sides ("set LEONIDA_PS_ORACLE_BUILD to a runtime build and select an AMD GPU"), still skipped on macOS.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-917 -- tests/test_ps_oracle.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.

AI-assisted: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248838430 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917#issuecomment-7248838430). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:31:30Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 error (`Cli.test_unavailable_during_run_is_77`) / green 25 OK. - PR head 9dde66b43, `python -I tests/test_ps_oracle.py` from the repository root. - Red (main + only this PR's test files): 25 run, 1 error, 2 skips. `Cli.test_unavailable_during_run_is_77`: an uncaught `ps_oracle.Unavailable` escapes instead of exit code 77. MEASURED, failing test(s) alone 3 runs, 3/3 fail. - Green (main + `git merge --no-ff` of this PR, no conflict): 25 run, OK, 2 skips. MEASURED, the same test(s) alone 3/3 pass. - Skips: `OnHardware.test_other_target_formats` and `OnHardware.test_patched_code_runs_as_the_pixel_shader` on both sides ("set LEONIDA_PS_ORACLE_BUILD to a runtime build and select an AMD GPU"), still skipped on macOS. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-917 -- tests/test_ps_oracle.py`); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched. AI-assisted: Claude Code (Claude Opus 5.5).
MoonEyes commented 2026-11-29 01:36:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:36:11Z.


Merged after OreoFR's red/green check (check) (macOS 27.2.1, Apple M5, Python 3.12) and a local re-check here. Merged after local re-verification: this PR merged onto main a908ad77e without conflict, and its test file(s) (tests/test_ps_oracle.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248891709 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/917#issuecomment-7248891709). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T01:36:11Z. --- Merged after **OreoFR**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/917#issuecomment-7248838430)) (macOS 27.2.1, Apple M5, Python 3.12) and a local re-check here. Merged after local re-verification: this PR merged onto `main` a908ad77e without conflict, and its test file(s) (`tests/test_ps_oracle.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!917
No description provided.