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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2255
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/compute-workers-win-safety


📝 Commits (1)

  • 2000e9b Harden compute_workers_win handle/mib checks, gate parsing, and tests

📊 Changes

2 files changed (+142 additions, -12 deletions)

View changed files

📝 scripts/compute_workers_win.py (+32 -12)
➕ tests/test_compute_workers_win.py (+110 -0)

📄 Description

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.

🔄 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/2255 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/compute-workers-win-safety` --- ### 📝 Commits (1) - [`2000e9b`](https://github.com/ubiquitarianism/leonida/commit/2000e9bdeadc124c127c7cbd9ee51f7a1afea12e) Harden compute_workers_win handle/mib checks, gate parsing, and tests ### 📊 Changes **2 files changed** (+142 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `scripts/compute_workers_win.py` (+32 -12) ➕ `tests/test_compute_workers_win.py` (+110 -0) </details> ### 📄 Description 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. --- <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#2259
No description provided.