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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1666 into main 2026-11-28 14:48:30 +00:00
IlyassRS3 commented 2026-11-25 07:38:22 +00:00 (Migrated from github.com)

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


Item ID: F64-OMOD-PROBE-JSON-AND-CLI (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156055033)

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
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487191312 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1666). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:38:22Z. --- Item ID: `F64-OMOD-PROBE-JSON-AND-CLI` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156055033) ## 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`
copilot-pull-request-reviewer[bot] commented 2026-11-25 07:38:30 +00:00 (Migrated from github.com)

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

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:6053571232 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1666#pullrequestreview-6053571232). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T07:38:30Z. **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.
zmasi commented 2026-11-28 10:47:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:47:24Z.


#1666 | head 456497d709 (merged cleanly with main 95b2e6c67) | python -I tests/test_f64_omod_probe.py | red on main: FAILED (failures=11, errors=1) (OverflowError in scalar_bits(1e40, "f32"), false 0 exit / uncaught IndexError on malformed oracle batch/word payloads, duplicate --modes/--waves running kernels twice, and blocked --json parent not checked upfront) | green on PR+main: 12 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited scalar_bits signed-infinity OverflowError handling, evaluate batch/type/bool/length validation, validate_report_path, atomic write_report (allow_nan=False, published_mode, replace_retry), and asm.family / runner.Unavailable -> exit 77 in tools/f64_omod_probe.py. Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238123385 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1666#issuecomment-7238123385). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T10:47:24Z. --- #1666 | head 456497d7091b607d65bae6669798217b68edbbb0 (merged cleanly with main 95b2e6c67) | `python -I tests/test_f64_omod_probe.py` | red on main: `FAILED (failures=11, errors=1)` (`OverflowError` in `scalar_bits(1e40, "f32")`, false `0` exit / uncaught `IndexError` on malformed oracle batch/word payloads, duplicate `--modes`/`--waves` running kernels twice, and blocked `--json` parent not checked upfront) | green on PR+main: `12 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `scalar_bits` signed-infinity `OverflowError` handling, `evaluate` batch/type/bool/length validation, `validate_report_path`, atomic `write_report` (`allow_nan=False`, `published_mode`, `replace_retry`), and `asm.family` / `runner.Unavailable -> exit 77` in `tools/f64_omod_probe.py`. Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 14:48:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:48:27Z.


Red/green: pytest tests/test_f64_omod_probe.py fails on main (12 failed, 8 passed) and passes on head 456497d709 merged with main (12 passed, 8 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240945424 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1666#issuecomment-7240945424). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:48:27Z. --- Red/green: `pytest tests/test_f64_omod_probe.py` fails on main (12 failed, 8 passed) and passes on head 456497d7091b merged with main (12 passed, 8 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!1666
No description provided.