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

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

📋 Pull Request Information

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

Base: main ← Head: fix/f16-trans-sweep-json-and-guards


📝 Commits (1)

  • e719266 f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards

📊 Changes

2 files changed (+152 additions, -14 deletions)

View changed files

📝 tests/test_f16_trans_sweep.py (+72 -0)
📝 tools/f16_trans_sweep.py (+80 -14)

📄 Description

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

🔄 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/1646 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/f16-trans-sweep-json-and-guards` --- ### 📝 Commits (1) - [`e719266`](https://github.com/ubiquitarianism/leonida/commit/e7192663f70ae6ebfa9028e8aaa877408f9a68d6) f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards ### 📊 Changes **2 files changed** (+152 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_f16_trans_sweep.py` (+72 -0) 📝 `tools/f16_trans_sweep.py` (+80 -14) </details> ### 📄 Description 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 --- <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#1661
No description provided.