[PR #1680] interp_hw_probe: harden CLI parsing, oracle batch/word validation, and error lifecycle #1694

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

📋 Pull Request Information

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

Base: main ← Head: fix/interp-hw-probe-cli-and-oracle


📝 Commits (1)

  • 73e9627 interp_hw_probe: harden CLI parsing, oracle batch/word validation, and error lifecycle

📊 Changes

2 files changed (+145 additions, -11 deletions)

View changed files

📝 tests/test_interp_hw_probe.py (+103 -0)
📝 tools/interp_hw_probe.py (+42 -11)

📄 Description

Item ID: INTERP-HW-PROBE-CLI-AND-ORACLE (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156453676)

Summary

  • CLI validation & seed deduplication (tools/interp_hw_probe.py):
    • Reject empty/whitespace --arch, non-positive --kernels < 1, and empty/trailing-comma --seeds tokens with argparse exit code 2.
    • Deduplicate repeated --seeds while preserving order so identical random kernel batches are not run twice.
  • Hardware oracle batch/word validation & lifecycle:
    • Added _validate_batch() used for both the random kernel batches and the tie kernel to verify that o.run() returns a list/tuple matching the exact kernel count and that each non-string entry is a list/tuple of at least expected_words non-bool int words (masking to 32 bits), preventing false passes on empty/short responses and uncaught IndexError/TypeError.
    • Catch runner.Unavailable (exit 77) and RuntimeError (exit 2) raised during o.run() inside try ... finally: o.close().
    • Fail with exit 2 if tally is empty (no checks executed).
    • Mask (o[i2] & 0xFFFFFFFF) >> 16 == 0xDEAD in check_random().
  • Regression tests (tests/test_interp_hw_probe.py):
    • Added tests covering empty --arch, non-positive --kernels, malformed/deduplicated --seeds, malformed oracle batch/word responses, runner.Unavailable -> exit 77, RuntimeError -> exit 2, and 32-bit canary masking in check_random().

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/interp_hw_probe.py tests/test_interp_hw_probe.py passed)
  • GPUs tested: none (hostless macOS synthetic/unit test run)
  • Tests run:
    • python3 -W error -I tests/test_interp_hw_probe.py -v: Ran 24 tests ... OK
    • Mutation test (new tests/test_interp_hw_probe.py against unpatched main tools/interp_hw_probe.py): Ran 24 tests ... FAILED (failures=8, errors=5)
    • 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/1680 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/interp-hw-probe-cli-and-oracle` --- ### 📝 Commits (1) - [`73e9627`](https://github.com/ubiquitarianism/leonida/commit/73e962741df29d97dade8213e52f631124fdeee0) interp_hw_probe: harden CLI parsing, oracle batch/word validation, and error lifecycle ### 📊 Changes **2 files changed** (+145 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_interp_hw_probe.py` (+103 -0) 📝 `tools/interp_hw_probe.py` (+42 -11) </details> ### 📄 Description Item ID: `INTERP-HW-PROBE-CLI-AND-ORACLE` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156453676) ## Summary - **CLI validation & seed deduplication (`tools/interp_hw_probe.py`)**: - Reject empty/whitespace `--arch`, non-positive `--kernels < 1`, and empty/trailing-comma `--seeds` tokens with argparse exit code `2`. - Deduplicate repeated `--seeds` while preserving order so identical random kernel batches are not run twice. - **Hardware oracle batch/word validation & lifecycle**: - Added `_validate_batch()` used for both the random kernel batches and the tie kernel to verify that `o.run()` returns a `list`/`tuple` matching the exact kernel count and that each non-string entry is a `list`/`tuple` of at least `expected_words` non-bool `int` words (masking to 32 bits), preventing false passes on empty/short responses and uncaught `IndexError`/`TypeError`. - Catch `runner.Unavailable` (exit `77`) and `RuntimeError` (exit `2`) raised during `o.run()` inside `try ... finally: o.close()`. - Fail with exit `2` if `tally` is empty (no checks executed). - Mask `(o[i2] & 0xFFFFFFFF) >> 16 == 0xDEAD` in `check_random()`. - **Regression tests (`tests/test_interp_hw_probe.py`)**: - Added tests covering empty `--arch`, non-positive `--kernels`, malformed/deduplicated `--seeds`, malformed oracle batch/word responses, `runner.Unavailable` -> exit `77`, `RuntimeError` -> exit `2`, and 32-bit canary masking in `check_random()`. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/interp_hw_probe.py tests/test_interp_hw_probe.py` passed) - **GPUs tested**: none (hostless macOS synthetic/unit test run) - **Tests run**: - `python3 -W error -I tests/test_interp_hw_probe.py -v`: `Ran 24 tests ... OK` - Mutation test (new `tests/test_interp_hw_probe.py` against unpatched `main` `tools/interp_hw_probe.py`): `Ran 24 tests ... FAILED (failures=8, errors=5)` - `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#1694
No description provided.