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

Open
opened 2026-11-26 20:22:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1666
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/f64-omod-probe-json-and-cli


📝 Commits (1)

  • 456497d f64_omod_probe: harden oracle validation, CLI parsing, f32 overflow, and atomic JSON write

📊 Changes

2 files changed (+253 additions, -15 deletions)

View changed files

📝 tests/test_f64_omod_probe.py (+138 -0)
📝 tools/f64_omod_probe.py (+115 -15)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1666 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/f64-omod-probe-json-and-cli` --- ### 📝 Commits (1) - [`456497d`](https://github.com/ubiquitarianism/leonida/commit/456497d7091b607d65bae6669798217b68edbbb0) f64_omod_probe: harden oracle validation, CLI parsing, f32 overflow, and atomic JSON write ### 📊 Changes **2 files changed** (+253 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_f64_omod_probe.py` (+138 -0) 📝 `tools/f64_omod_probe.py` (+115 -15) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1681
No description provided.