f64_omod_probe: harden oracle validation, CLI parsing, f32 overflow, and atomic JSON write #1666

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

@⁠IlyassRS3 on GitHub · 2026-11-25 07:38 UTC · original
IlyassRS3:fix/f64-omod-probe-json-and-cli → main · +253 −15 · 2 files · 1 commits · open

Item ID: F64-OMOD-PROBE-JSON-AND-CLI (claimed in #1608)

Summary

  • Hardware oracle validation & error handling (tools/f64_omod_probe.py):
    • In evaluate(), validate that raw_results is a list/tuple matching len(meta), surface str kernel rejections from hw_oracle.runner.run() as explicit RuntimeErrors instead of iterating characters, require "words" in dict results and integer (non-bool) elements, and require at least len(cases) * len(MODS) * step words per kernel instead of crashing with an uncaught IndexError.
    • In main(), catch ValueError from asm.family(oracle.arch) and runner.Unavailable raised during oracle.run() inside the try/finally block so both exit 77 cleanly while closing the oracle.
  • scalar_bits() f32 overflow handling:
    • Handle OverflowError on struct.pack("<f", value) by returning signed infinity (0x7F800000 / 0xFF800000), matching _f16_bits().
  • CLI validation & deduplication:
    • Reject empty/whitespace --hw-arch and --json, reject empty/trailing-comma entries in --modes and --waves, and deduplicate repeated modes/waves while preserving order so duplicate GPU kernels are not launched.
  • Upfront --json validation & atomic report writing:
    • Added validate_report_path() before opening the oracle so a blocked parent path fails fast with exit 2.
    • Upgraded write_report() to create missing parent folders, serialize strictly (allow_nan=False) with a trailing , support non-regular targets like /dev/null, preserve symlink targets and file permissions via file_mode.published_mode(), fsync temp files, replace atomically via replace_retry.replace(), and emit write errors to stderr.
  • Regression tests (tests/test_f64_omod_probe.py):
    • Added 4 tests covering f32 overflow, malformed oracle results / unknown arch / Unavailable during run(), CLI validation / deduplication / upfront --json parent failure, and nested atomic write_report() behavior.

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/f64_omod_probe.py tests/test_f64_omod_probe.py passed)
  • GPUs tested: none (hostless macOS synthetic/unit test run)
  • Tests run:
    • python3 -W error -I tests/test_f64_omod_probe.py -v: Ran 12 tests ... OK
    • Mutation test (new tests/test_f64_omod_probe.py against unpatched main tools/f64_omod_probe.py): Ran 12 tests ... FAILED (failures=11, errors=1)
    • python3 -m compileall -q make_game.py tools tests: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
**@⁠IlyassRS3** on GitHub · 2026-11-25 07:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1666) `IlyassRS3:fix/f64-omod-probe-json-and-cli` → `main` · +253 −15 · 2 files · 1 commits · open Item ID: `F64-OMOD-PROBE-JSON-AND-CLI` (claimed in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ## Summary - **Hardware oracle validation & error handling (`tools/f64_omod_probe.py`)**: - In `evaluate()`, validate that `raw_results` is a `list`/`tuple` matching `len(meta)`, surface `str` kernel rejections from `hw_oracle.runner.run()` as explicit `RuntimeError`s instead of iterating characters, require `"words"` in dict results and integer (non-bool) elements, and require at least `len(cases) * len(MODS) * step` words per kernel instead of crashing with an uncaught `IndexError`. - In `main()`, catch `ValueError` from `asm.family(oracle.arch)` and `runner.Unavailable` raised during `oracle.run()` inside the `try/finally` block so both exit `77` cleanly while closing the oracle. - **`scalar_bits()` f32 overflow handling**: - Handle `OverflowError` on `struct.pack("<f", value)` by returning signed infinity (`0x7F800000` / `0xFF800000`), matching `_f16_bits()`. - **CLI validation & deduplication**: - Reject empty/whitespace `--hw-arch` and `--json`, reject empty/trailing-comma entries in `--modes` and `--waves`, and deduplicate repeated modes/waves while preserving order so duplicate GPU kernels are not launched. - **Upfront `--json` validation & atomic report writing**: - Added `validate_report_path()` before opening the oracle so a blocked parent path fails fast with exit `2`. - Upgraded `write_report()` to create missing parent folders, serialize strictly (`allow_nan=False`) with a trailing ` `, support non-regular targets like `/dev/null`, preserve symlink targets and file permissions via `file_mode.published_mode()`, fsync temp files, replace atomically via `replace_retry.replace()`, and emit write errors to `stderr`. - **Regression tests (`tests/test_f64_omod_probe.py`)**: - Added 4 tests covering f32 overflow, malformed oracle results / unknown arch / `Unavailable` during `run()`, CLI validation / deduplication / upfront `--json` parent failure, and nested atomic `write_report()` behavior. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/f64_omod_probe.py tests/test_f64_omod_probe.py` passed) - **GPUs tested**: none (hostless macOS synthetic/unit test run) - **Tests run**: - `python3 -W error -I tests/test_f64_omod_probe.py -v`: `Ran 12 tests ... OK` - Mutation test (new `tests/test_f64_omod_probe.py` against unpatched `main` `tools/f64_omod_probe.py`): `Ran 12 tests ... FAILED (failures=11, errors=1)` - `python3 -m compileall -q make_game.py tools tests`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:00 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 07:38 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:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1666#pullrequestreview-6053571232) · **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.
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/1666/head:github-bot/gh-1666'
git switch 'github-bot/gh-1666'

Merge

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