f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards #1646

Merged
IlyassRS3 merged 1 commit from upstream-pr/1646 into main 2026-11-28 11:45:02 +00:00
IlyassRS3 commented 2026-11-25 06:58:22 +00:00 (Migrated from github.com)

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


Item ID: F16-TRANS-SWEEP-JSON-AND-GUARDS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155318176

Summary

Harden CLI parsing, JSON report writing, and oracle result validation in tools/f16_trans_sweep.py:

  • --ops / --modes / --waves / --hw-arch guards: reject empty/trailing comma tokens (v_exp_f16,, keep16,,flush16, 32,), deduplicate repeated ops/modes/waves in first-seen order so 65,536-input sweeps aren't run redundantly, and reject empty/whitespace --hw-arch.
  • Upfront validate_json_path() & atomic write_json_report():
    • Resolve symlinks before validating or staging so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink.
    • Check existing targets for writeability upfront (O_WRONLY), serialize with allow_nan=False and a trailing LF , write non-regular targets like /dev/null directly, and publish regular files atomically via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace.
  • Oracle result guards:
    • Raise RuntimeError in check_modes() when len(got) != len(kernels) or a probe returns an empty word list (instead of crashing with IndexError).
    • Raise RuntimeError in sweep() when len(got) != len(kernels) (instead of returning a truncated array that crashes in classify()).
  • Tests (tests/test_f16_trans_sweep.py): added 3 test methods covering malformed/duplicate selections, empty --hw-arch, atomic/trailing-LF/NaN/symlink//dev/null writes, and short/empty oracle result handling.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU synthetic unit tests + mocked oracle on macOS; no GPU, AMD clang, or game data present)
  • python3 -W error -I tests/test_f16_trans_sweep.py -v: 17 passed, 2 skipped (AMD clang / hardware absent)
  • Mutation check against unpatched main: ran=19 failures=2 errors=9 (skipped=2)
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py: passed
  • python3 -m compileall -q tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py: passed
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486721980 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1646). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T06:58:22Z. --- Item ID: `F16-TRANS-SWEEP-JSON-AND-GUARDS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155318176 ### Summary Harden CLI parsing, JSON report writing, and oracle result validation in `tools/f16_trans_sweep.py`: - **`--ops` / `--modes` / `--waves` / `--hw-arch` guards**: reject empty/trailing comma tokens (`v_exp_f16,`, `keep16,,flush16`, `32,`), deduplicate repeated ops/modes/waves in first-seen order so 65,536-input sweeps aren't run redundantly, and reject empty/whitespace `--hw-arch`. - **Upfront `validate_json_path()` & atomic `write_json_report()`**: - Resolve symlinks before validating or staging so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink. - Check existing targets for writeability upfront (`O_WRONLY`), serialize with `allow_nan=False` and a trailing LF ` `, write non-regular targets like `/dev/null` directly, and publish regular files atomically via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace`. - **Oracle result guards**: - Raise `RuntimeError` in `check_modes()` when `len(got) != len(kernels)` or a probe returns an empty word list (instead of crashing with `IndexError`). - Raise `RuntimeError` in `sweep()` when `len(got) != len(kernels)` (instead of returning a truncated array that crashes in `classify()`). - **Tests (`tests/test_f16_trans_sweep.py`)**: added 3 test methods covering malformed/duplicate selections, empty `--hw-arch`, atomic/trailing-LF/NaN/symlink/`/dev/null` writes, and short/empty oracle result handling. ### Verification - AI-assisted: yes - GPUs tested: none (CPU synthetic unit tests + mocked oracle on macOS; no GPU, AMD clang, or game data present) - `python3 -W error -I tests/test_f16_trans_sweep.py -v`: 17 passed, 2 skipped (AMD clang / hardware absent) - Mutation check against unpatched `main`: `ran=19 failures=2 errors=9 (skipped=2)` - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed - `python3 -I scripts/check_no_game_data.py tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py`: passed - `python3 -m compileall -q tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py`: passed
copilot-pull-request-reviewer[bot] commented 2026-11-25 06:58:33 +00:00 (Migrated from github.com)

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

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:6053157613 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1646#pullrequestreview-6053157613). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T06:58:33Z. **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.
whoalin1 commented 2026-11-25 08:16:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T08:16:26Z.


Independent verification (Windows, Python 3.11.9 -I): diff vs merge-base reviewed — comma-token rejection + first-seen dedup for --ops/--modes/--waves, empty --hw-arch guard, symlink-aware validate_json_path/write_json_report (O_WRONLY probe, allow_nan=False, trailing LF, mkstemp+published_mode+replace_retry), RuntimeError guards on short oracle results — all present. test_f16_trans_sweep.py 19 tests OK (2 skips, matches body), --self-test ok, CLI probes reject --ops "v_exp_f16," and --hw-arch " ", compileall + line-endings + check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156823156 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1646#issuecomment-7156823156). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T08:16:26Z. --- Independent verification (Windows, Python 3.11.9 `-I`): diff vs merge-base reviewed — comma-token rejection + first-seen dedup for `--ops/--modes/--waves`, empty `--hw-arch` guard, symlink-aware `validate_json_path`/`write_json_report` (O_WRONLY probe, `allow_nan=False`, trailing LF, mkstemp+`published_mode`+`replace_retry`), `RuntimeError` guards on short oracle results — all present. `test_f16_trans_sweep.py` 19 tests OK (2 skips, matches body), `--self-test` ok, CLI probes reject `--ops "v_exp_f16,"` and `--hw-arch " "`, compileall + line-endings + `check_no_game_data` clean. AI-assisted verification.
sodove commented 2026-11-28 11:27:28 +00:00 (Migrated from github.com)

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


#1646 | head e7192663f70ae6ebfa9028e8aaa877408f9a68d6 | python3 -I tests/test_f16_trans_sweep.py -v, py -3.12 -I tests/test_f16_trans_sweep.py -v | red: 19 run, 2 failures, 9 errors, 1 class skipped (Linux) / 20 run, 2 failures, 9 errors (Windows) | green: 19 passed, 1 class skipped (Linux) / 20 passed (Windows) | Red → green. Live Radeon case passed on both trees

The PR’s live gfx1036 test passed on both trees, comparing the f16 exponential sweep in wave32 and wave64 and checking exact results for selected integer inputs. 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:7238564014 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1646#issuecomment-7238564014). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:27:28Z. --- #1646 | head `e7192663f70ae6ebfa9028e8aaa877408f9a68d6` | `python3 -I tests/test_f16_trans_sweep.py -v`, `py -3.12 -I tests/test_f16_trans_sweep.py -v` | red: 19 run, 2 failures, 9 errors, 1 class skipped (Linux) / 20 run, 2 failures, 9 errors (Windows) | green: 19 passed, 1 class skipped (Linux) / 20 passed (Windows) | **Red → green. Live Radeon case passed on both trees** The PR’s live gfx1036 test passed on both trees, comparing the f16 exponential sweep in wave32 and wave64 and checking exact results for selected integer inputs. 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:45:05 +00:00 (Migrated from github.com)

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


Merged, thank you @IlyassRS3! This PR (f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards) 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:7238757855 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1646#issuecomment-7238757855). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:45:05Z. --- Merged, thank you @IlyassRS3! This PR (f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards) 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!1646
No description provided.