cvt_pknorm_f16_probe: harden --ops/--waves, upfront atomic JSON writes, and result count guard #1640

Merged
IlyassRS3 merged 1 commit from upstream-pr/1640 into main 2026-11-28 11:42:52 +00:00
IlyassRS3 commented 2026-11-25 06:47:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T06:47:56Z.


Item ID: CVT-PKNORM-F16-PROBE-JSON-AND-CLI
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155141667

Summary

Harden CLI argument parsing, JSON report writing, and harness error handling in tools/cvt_pknorm_f16_probe.py:

  • --ops / --waves / --hw-arch guards: reject empty/trailing comma tokens (32,, ,v_cvt_pknorm_i16_f16, 32,,64), deduplicate repeated ops/waves so kernels and sweep_words/case_words are not double-counted, and reject empty/whitespace --hw-arch.
  • Upfront --json validation: reject empty/whitespace paths, trailing separators, directories, non-directory parent blockers, and unwritable existing targets before opening hw_oracle and running the 1M-half exhaustive sweep.
  • Atomic write_report(): serialize upfront with allow_nan=False and LF endings, handle non-regular targets like /dev/null directly, resolve symlinks before staging to preserve symlink targets, apply file_mode.published_mode, and publish via replace_retry.replace.
  • Harness guards: return a harness_errors entry when len(raw_results) != len(meta) in evaluate_results() (preventing KeyError after zip() truncation), and catch ValueError from asm.family(oracle.arch) cleanly (exit 77).
  • Tests (tests/test_cvt_pknorm_f16_probe.py): added 3 test methods covering malformed/duplicate --ops/--waves, empty --hw-arch/--json, upfront blocker/trailing-sep rejection, atomic/symlink/NaN//dev/null writes, result count mismatch, and unknown arch family.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU synthetic unit tests + FakeOracle on macOS; no GPU, AMD clang, or game data present)
  • python3 -W error -I tests/test_cvt_pknorm_f16_probe.py -v: 9 passed, 1 skipped (AMD clang absent)
  • Mutation check against unpatched main: ran=10 failures=1 errors=11 (skipped=1)
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/cvt_pknorm_f16_probe.py tests/test_cvt_pknorm_f16_probe.py: passed
  • python3 -m compileall -q tools/cvt_pknorm_f16_probe.py tests/test_cvt_pknorm_f16_probe.py: passed
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486605950 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1640). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T06:47:56Z. --- Item ID: `CVT-PKNORM-F16-PROBE-JSON-AND-CLI` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155141667 ### Summary Harden CLI argument parsing, JSON report writing, and harness error handling in `tools/cvt_pknorm_f16_probe.py`: - **`--ops` / `--waves` / `--hw-arch` guards**: reject empty/trailing comma tokens (`32,`, `,v_cvt_pknorm_i16_f16`, `32,,64`), deduplicate repeated ops/waves so kernels and `sweep_words`/`case_words` are not double-counted, and reject empty/whitespace `--hw-arch`. - **Upfront `--json` validation**: reject empty/whitespace paths, trailing separators, directories, non-directory parent blockers, and unwritable existing targets *before* opening `hw_oracle` and running the 1M-half exhaustive sweep. - **Atomic `write_report()`**: serialize upfront with `allow_nan=False` and LF endings, handle non-regular targets like `/dev/null` directly, resolve symlinks before staging to preserve symlink targets, apply `file_mode.published_mode`, and publish via `replace_retry.replace`. - **Harness guards**: return a `harness_errors` entry when `len(raw_results) != len(meta)` in `evaluate_results()` (preventing `KeyError` after `zip()` truncation), and catch `ValueError` from `asm.family(oracle.arch)` cleanly (exit `77`). - **Tests (`tests/test_cvt_pknorm_f16_probe.py`)**: added 3 test methods covering malformed/duplicate `--ops`/`--waves`, empty `--hw-arch`/`--json`, upfront blocker/trailing-sep rejection, atomic/symlink/NaN/`/dev/null` writes, result count mismatch, and unknown arch family. ### Verification - AI-assisted: yes - GPUs tested: none (CPU synthetic unit tests + FakeOracle on macOS; no GPU, AMD clang, or game data present) - `python3 -W error -I tests/test_cvt_pknorm_f16_probe.py -v`: 9 passed, 1 skipped (AMD clang absent) - Mutation check against unpatched `main`: `ran=10 failures=1 errors=11 (skipped=1)` - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed - `python3 -I scripts/check_no_game_data.py tools/cvt_pknorm_f16_probe.py tests/test_cvt_pknorm_f16_probe.py`: passed - `python3 -m compileall -q tools/cvt_pknorm_f16_probe.py tests/test_cvt_pknorm_f16_probe.py`: passed
copilot-pull-request-reviewer[bot] commented 2026-11-25 06:48:11 +00:00 (Migrated from github.com)

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

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:6053057681 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1640#pullrequestreview-6053057681). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T06:48:11Z. **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.
GeorgiyDemo commented 2026-11-25 06:50:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T06:50:22Z.


Tested 4446d1ac5 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 42537e7b6 (Python GPU probe; hardware oracle not run):

  • pytest 9.2.0 on tests/test_cvt_pknorm_f16_probe.py: 9 passed, 1 skipped, 9 subtests passed at this head.
  • The same file on main: 12 failed, 6 passed, 1 skipped — the --ops/--waves token guards, dedup, upfront atomic JSON validation and the result-count guard are not there.
  • Not run: the hardware oracle on a real AMD GPU (none here); the skip is the hardware-dependent test.

AI-assisted; synthetic fixtures only, no game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7155211885 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1640#issuecomment-7155211885). Originally posted by [GeorgiyDemo](https://github.com/GeorgiyDemo) on 2026-11-25T06:50:22Z. --- Tested `4446d1ac5` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `42537e7b6` (Python GPU probe; hardware oracle not run): - pytest 9.2.0 on `tests/test_cvt_pknorm_f16_probe.py`: **9 passed, 1 skipped, 9 subtests passed** at this head. - The same file on `main`: **12 failed**, 6 passed, 1 skipped — the `--ops`/`--waves` token guards, dedup, upfront atomic JSON validation and the result-count guard are not there. - Not run: the hardware oracle on a real AMD GPU (none here); the skip is the hardware-dependent test. AI-assisted; synthetic fixtures only, no game data.
whoalin1 commented 2026-11-25 09:52:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T09:52:49Z.


Independent verification (Windows, Python 3.11.9 -I -W error): same hardening pattern confirmed — CLI token guards, dedup, upfront --json validation (blocked parent -> exit 2 pre-oracle), atomic writes, result-count guard, asm.family->77. test_cvt_pknorm_f16_probe.py 10 OK (1 skip, matches claim); --self-test ok (33 cases, 65,536 f16 entries); hygiene checks clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7158924040 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1640#issuecomment-7158924040). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T09:52:49Z. --- Independent verification (Windows, Python 3.11.9 `-I -W error`): same hardening pattern confirmed — CLI token guards, dedup, upfront `--json` validation (blocked parent -> exit 2 pre-oracle), atomic writes, result-count guard, `asm.family`->77. `test_cvt_pknorm_f16_probe.py` 10 OK (1 skip, matches claim); `--self-test` ok (33 cases, 65,536 f16 entries); hygiene checks clean. AI-assisted verification.
sodove commented 2026-11-28 11:27:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:27:10Z.


#1640 | head 4446d1ac52903de3a5e0d40324b6f74532f443d5 | python3 -I tests/test_cvt_pknorm_f16_probe.py -v, py -3.12 -I tests/test_cvt_pknorm_f16_probe.py -v | red: 10 run, 1 failure, 11 errors, 1 skipped (Linux) / 10 run, 1 failure, 11 errors (Windows) | green: 9 passed, 1 skipped (Linux) / 10 passed (Windows) | Red → green. Live Radeon case passed on both trees

The full file covers CLI checks, reports and malformed oracle responses. The live gfx1036 test passed on both trees, including the PR’s exhaustive 65,536-input binary16 sweep and its wave comparison. The baseline failures were in other tests.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Windows HIP used AMD Radeon(TM) Graphics, gfx1036, driver 32.0.21045.29003. The WSL run skipped the optional native-hardware case. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238560692 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1640#issuecomment-7238560692). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:27:10Z. --- #1640 | head `4446d1ac52903de3a5e0d40324b6f74532f443d5` | `python3 -I tests/test_cvt_pknorm_f16_probe.py -v`, `py -3.12 -I tests/test_cvt_pknorm_f16_probe.py -v` | red: 10 run, 1 failure, 11 errors, 1 skipped (Linux) / 10 run, 1 failure, 11 errors (Windows) | green: 9 passed, 1 skipped (Linux) / 10 passed (Windows) | **Red → green. Live Radeon case passed on both trees** The full file covers CLI checks, reports and malformed oracle responses. The live gfx1036 test passed on both trees, including the PR’s exhaustive 65,536-input binary16 sweep and its wave comparison. The baseline failures were in other tests. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Windows HIP used AMD Radeon(TM) Graphics, gfx1036, driver 32.0.21045.29003. The WSL run skipped the optional native-hardware case. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:42:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:42:54Z.


Merged, thank you @IlyassRS3! This PR (cvt_pknorm_f16_probe: harden --ops/--waves, upfront atomic JSON writes, and result count guard) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238734174 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1640#issuecomment-7238734174). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:42:54Z. --- Merged, thank you @IlyassRS3! This PR (cvt_pknorm_f16_probe: harden --ops/--waves, upfront atomic JSON writes, and result count guard) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
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!1640
No description provided.