scripts/compute_workers_win: pre-validate job/gate handles, fix child handle close, add tests #2255

Merged
kirigayakazima merged 1 commit from upstream-pr/2255 into main 2026-11-29 00:59:03 +00:00
kirigayakazima commented 2026-11-26 10:40:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T10:40:45Z.


Claimed in the coordination issue as: COMPUTE-WORKERS-WIN-GATE-HANDLE-AND-JOB-SAFETY-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189640162)

What and why

  • Enforce type(mib) is int in job() (scripts/compute_workers_win.py) so bool and non-integer inputs raise ValueError instead of being treated as integers.
  • Guard not h alongside INVALID_HANDLE_VALUE (-1) in output_lock() before yielding and closing the handle.
  • Pre-validate lock, mib, and the serialized 64 KiB ASCII gate length in start() before creating a Job Object, mutating handle inheritability, or spawning Popen.
  • Strictly parse and validate the framed ASCII JSON gate [request, mib, lock] in child(), and wrap verify() inside try ... finally: check(close(lock)) so inherited lock handles are never leaked on verification failure.
  • Add real Windows Job Object / CreateFileW exclusivity tests and mocked child/start edge tests in tests/test_compute_workers_win.py (skipped cleanly when os.name != "nt").

Tested

  • Patched: python -I tests/test_compute_workers_win.py -v -> Ran 4 tests in 0.011s (OK, Windows 11).
  • Baseline check (upstream/main a73a57e1 with tests/test_compute_workers_win.py copied into detached worktree): Ran 4 tests in 13.118s (FAILED (failures=3, errors=11)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.275s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 12.464s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (Windows Job Object, CreateFileW lock, and process gate validation tests)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5508483631 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2255). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T10:40:45Z. --- Claimed in the coordination issue as: COMPUTE-WORKERS-WIN-GATE-HANDLE-AND-JOB-SAFETY-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189640162) ### What and why - Enforce `type(mib) is int` in `job()` (`scripts/compute_workers_win.py`) so `bool` and non-integer inputs raise `ValueError` instead of being treated as integers. - Guard `not h` alongside `INVALID_HANDLE_VALUE` (`-1`) in `output_lock()` before yielding and closing the handle. - Pre-validate `lock`, `mib`, and the serialized 64 KiB ASCII gate length in `start()` before creating a Job Object, mutating handle inheritability, or spawning `Popen`. - Strictly parse and validate the framed ASCII JSON gate `[request, mib, lock]` in `child()`, and wrap `verify()` inside `try ... finally: check(close(lock))` so inherited lock handles are never leaked on verification failure. - Add real Windows Job Object / `CreateFileW` exclusivity tests and mocked child/start edge tests in `tests/test_compute_workers_win.py` (skipped cleanly when `os.name != "nt"`). ### Tested - Patched: `python -I tests/test_compute_workers_win.py -v` -> `Ran 4 tests in 0.011s` (`OK`, Windows 11). - Baseline check (`upstream/main` `a73a57e1` with `tests/test_compute_workers_win.py` copied into detached worktree): `Ran 4 tests in 13.118s` (`FAILED (failures=3, errors=11)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.275s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 12.464s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (Windows Job Object, CreateFileW lock, and process gate validation tests) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
lixonik commented 2026-11-26 10:51:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T10:51:12Z.

Review: COMMENTED


Windows 11: 4/4 Python tests passed. A native smoke check ran two empty shards in separate Windows Job Objects with the configured memory cap and real coordinator/worker startup. Each wrote its own audit report. A second open was denied while the coordinator held the output lock, and reopening succeeded after cleanup. The empty requests exercise worker plumbing without running SPIR-V tools. No findings from these checks.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6072811470 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2255#pullrequestreview-6072811470). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T10:51:12Z. **Review:** COMMENTED --- Windows 11: 4/4 Python tests passed. A native smoke check ran two empty shards in separate Windows Job Objects with the configured memory cap and real coordinator/worker startup. Each wrote its own audit report. A second open was denied while the coordinator held the output lock, and reopening succeeded after cleanup. The empty requests exercise worker plumbing without running SPIR-V tools. No findings from these checks. AI-assisted.
sodove commented 2026-11-28 09:15:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T09:15:22Z.


#2255 | head 2000e9bdeadc124c127c7cbd9ee51f7a1afea12e | py -3.12 -I tests/test_compute_workers_win.py -v | red: 4 tests, 3 assertion failures, 11 errors | green: 4 passed | Red → green

Ran natively on Windows so the Job Object and handle tests executed. Baseline failure/error events include unittest subtests.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237119746 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2255#issuecomment-7237119746). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T09:15:22Z. --- #2255 | head `2000e9bdeadc124c127c7cbd9ee51f7a1afea12e` | `py -3.12 -I tests/test_compute_workers_win.py -v` | red: 4 tests, 3 assertion failures, 11 errors | green: 4 passed | **Red → green** Ran natively on Windows so the Job Object and handle tests executed. Baseline failure/error events include unittest subtests. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
DadaCap commented 2026-11-29 00:59:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T00:59:19Z.


Merged, thank you! Its own tests failed on main without the change and passed with it, and a batch test with eight other tool PRs (main's Python suite plus a game run on an RTX 5080) showed no regression.

AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248484857 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2255#issuecomment-7248484857). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-29T00:59:19Z. --- Merged, thank you! Its own tests failed on main without the change and passed with it, and a batch test with eight other tool PRs (main's Python suite plus a game run on an RTX 5080) showed no regression. AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.
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!2255
No description provided.