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

Merged
leonida/mandy
quietfold merged 1 commit from fix/f16-trans-sweep-json-and-guards into main 2026-11-28 11:45:02 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 06:58:22 +00:00

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
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] reviewed 2026-11-25 06:58:33 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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.

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

#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.

#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

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.

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 description provided.