REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION #2346

Merged
kirigayakazima merged 2 commits from upstream-pr/2346 into main 2026-11-28 10:46:31 +00:00
kirigayakazima commented 2026-11-26 14:21:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T14:21:06Z.


Claimed in the coordination issue as: REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194632590)

What and why

  • Add Windows ERROR_LOCK_VIOLATION (33) alongside 5 and 32 in _TRANSIENT_WINERRORS in tools/replace_retry.py so transient byte-range lock conflicts retry cleanly instead of failing immediately.
  • Validate optional seconds up front in replace() so booleans, non-numeric values, negative numbers, NaN, and infinities raise ValueError before calling os.replace or entering the retry loop (avoiding silent no-sleep returns or infinite NaN deadline loops).
  • Add unit tests in tests/test_replace_retry_bounds.py.

Tested

  • python -I tests/test_replace_retry_bounds.py -v: 3 passed, 0 failed (detached upstream/main baseline with only the new test file fails: 6 failures, 2 errors across subtests).
  • python -I tests/test_replace_retry.py -v: 10 passed, 0 failed.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/replace_retry.py tests/test_replace_retry_bounds.py, and git diff --cached --check: passed.

GPUs tested: n/a

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:5511721952 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T14:21:06Z. --- Claimed in the coordination issue as: REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194632590) ### What and why - Add Windows `ERROR_LOCK_VIOLATION` (`33`) alongside `5` and `32` in `_TRANSIENT_WINERRORS` in `tools/replace_retry.py` so transient byte-range lock conflicts retry cleanly instead of failing immediately. - Validate optional `seconds` up front in `replace()` so booleans, non-numeric values, negative numbers, `NaN`, and infinities raise `ValueError` before calling `os.replace` or entering the retry loop (avoiding silent no-sleep returns or infinite `NaN` deadline loops). - Add unit tests in `tests/test_replace_retry_bounds.py`. ### Tested - `python -I tests/test_replace_retry_bounds.py -v`: 3 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails: 6 failures, 2 errors across subtests). - `python -I tests/test_replace_retry.py -v`: 10 passed, 0 failed. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/replace_retry.py tests/test_replace_retry_bounds.py`, and `git diff --cached --check`: passed. GPUs tested: n/a 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 15:37:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:37:26Z.

Review: COMMENTED


Windows 11: 13/13 replace-retry tests passed. One numeric input falls through the new validation with a different exception, detailed inline. Error 33 coverage here uses a mocked replace.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6076879875 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#pullrequestreview-6076879875). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:37:26Z. **Review:** COMMENTED --- Windows 11: 13/13 replace-retry tests passed. One numeric input falls through the new validation with a different exception, detailed inline. Error 33 coverage here uses a mocked replace. AI-assisted.
lixonik commented 2026-11-26 15:37:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:37:26Z.

Code review location: tools/replace_retry.py; line 26

@@ -21,7 +22,10 @@ def _transient(error):
 def replace(src, dst, *, seconds=None):
     """os.replace(src, dst), retried with a doubling delay for `seconds` (default RETRY_SECONDS) on a transient
     Windows PermissionError; the last error is raised once the time is up."""
-    deadline = time.monotonic() + (RETRY_SECONDS if seconds is None else seconds)
+    budget = RETRY_SECONDS if seconds is None else seconds
+    if isinstance(budget, bool) or not isinstance(budget, (int, float)) or not math.isfinite(budget) or budget < 0:

[P3] Convert an unrepresentable numeric budget to the same validation error.

replace(..., seconds=10**1000) passes the int/float check and throws OverflowError from math.isfinite on CPython 3.12. The value cannot be used as a float deadline. Handling the conversion overflow as ValueError would keep the new validation contract consistent.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4710545533 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2346#discussion_r4710545533). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:37:26Z. **Code review location:** `tools/replace_retry.py`; line 26 ~~~~diff @@ -21,7 +22,10 @@ def _transient(error): def replace(src, dst, *, seconds=None): """os.replace(src, dst), retried with a doubling delay for `seconds` (default RETRY_SECONDS) on a transient Windows PermissionError; the last error is raised once the time is up.""" - deadline = time.monotonic() + (RETRY_SECONDS if seconds is None else seconds) + budget = RETRY_SECONDS if seconds is None else seconds + if isinstance(budget, bool) or not isinstance(budget, (int, float)) or not math.isfinite(budget) or budget < 0: ~~~~ --- [P3] Convert an unrepresentable numeric budget to the same validation error. `replace(..., seconds=10**1000)` passes the int/float check and throws `OverflowError` from `math.isfinite` on CPython 3.12. The value cannot be used as a float deadline. Handling the conversion overflow as `ValueError` would keep the new validation contract consistent.
Rezn0r27 commented 2026-11-26 16:39:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Rezn0r27 on 2026-11-26T16:39:03Z.


Tested commit 8d0c27886 on Windows 11 (build 26300.9974) with Python 3.12.

  • py -3.12 -I tests/test_replace_retry_bounds.py -v — 3/3 passed, including the simulated WinError 33 retry case.
  • py -3.12 -I tests/test_replace_retry.py -v — 10/10 passed, including both real Windows file-lock tests: test_real_source_lock and test_real_destination_lock.
    No tests were skipped. Both commands exited with code 0. I ran the tests locally. AI-assisted setup and reporting.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7197921372 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2346#issuecomment-7197921372). Originally posted by [Rezn0r27](https://github.com/Rezn0r27) on 2026-11-26T16:39:03Z. --- Tested commit 8d0c27886 on Windows 11 (build 26300.9974) with Python 3.12. - py -3.12 -I tests/test_replace_retry_bounds.py -v — 3/3 passed, including the simulated WinError 33 retry case. - py -3.12 -I tests/test_replace_retry.py -v — 10/10 passed, including both real Windows file-lock tests: test_real_source_lock and test_real_destination_lock. No tests were skipped. Both commands exited with code 0. I ran the tests locally. AI-assisted setup and reporting.
wavehs commented 2026-11-26 18:37:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:37:03Z.

Review: COMMENTED


macOS arm64 check of #2346 (REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION). A tools-only change; the Windows error path cannot be produced here.

Tested head 8d0c27886 with its diff applied to a copy of main bdbc7e923 (branch 82 commits behind; git apply / git merge-tree clean).

Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.

Result

  • python -I tests/test_replace_retry_bounds.py: 3 tests, OK.
  • Existing python -I tests/test_replace_retry.py: OK (skipped=2; the Windows path is skipped here).
  • Negative control (new test kept, tools/replace_retry.py put back to main's): 8 failures and 2 errors - winerror 33 is not retried (test_retries_lock_violation_winerror_33 errors with the faked PermissionError), and every invalid seconds (nan, ±inf, -0.5, True, False, "1") is accepted instead of raising ValueError. The seconds=0 case passes on main too, which is expected because the old loop already tried once.
  • python -I scripts/run_semantic_tests.py tests/semantic: 500 files / 6,367 tests / 0 failed, the same as main.
  • GPU fixtures not run: tools/replace_retry.py is not on the shader path (rg replace_retry finds only make_game-side callers).

Review

  • The validation is placed before time.monotonic() and before any os.replace, so a bad seconds cannot move or delete anything; it rejects bools before the int branch, which the test pins.
  • seconds=0 keeps one attempt and no sleep, as the re-raise happens before the first time.sleep; the test checks call count and that the same exception object comes out.
  • Callers pass real numbers: tools/calibrated_texture.py:467 forwards its own seconds, the other two call sites use the default. math.isfinite on an int is fine.

Finding
The winerror 33 half is only exercised with a hand-built PermissionError(winerror=33). On CPython a real os.replace failure with ERROR_LOCK_VIOLATION has to arrive as PermissionError for _transient() to retry it, and I cannot check that mapping on macOS. If CPython maps 33 to a plain OSError (or a different subclass), the new tuple entry does nothing in production while the fake test stays green. A Windows-only test that makes a real second handle hold the destination (as tests/test_rdna2spirv_spawn_quota.py does for the job object in #2367) would settle it; otherwise saying in the docstring that 33 was added from the Win32 table, not from a reproduced rename, is enough.

No game files. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6079060113 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#pullrequestreview-6079060113). Originally posted by [wavehs](https://github.com/wavehs) on 2026-11-26T18:37:03Z. **Review:** COMMENTED --- **macOS arm64 check of #2346** (REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION). A tools-only change; the Windows error path cannot be produced here. Tested head `8d0c27886` with its diff applied to a copy of `main` `bdbc7e923` (branch 82 commits behind; `git apply` / `git merge-tree` clean). Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2. **Result** - `python -I tests/test_replace_retry_bounds.py`: 3 tests, OK. - Existing `python -I tests/test_replace_retry.py`: OK (skipped=2; the Windows path is skipped here). - Negative control (new test kept, `tools/replace_retry.py` put back to `main`'s): 8 failures and 2 errors - winerror 33 is not retried (`test_retries_lock_violation_winerror_33` errors with the faked `PermissionError`), and every invalid `seconds` (`nan`, `±inf`, `-0.5`, `True`, `False`, `"1"`) is accepted instead of raising `ValueError`. The `seconds=0` case passes on `main` too, which is expected because the old loop already tried once. - `python -I scripts/run_semantic_tests.py tests/semantic`: 500 files / 6,367 tests / 0 failed, the same as `main`. - GPU fixtures not run: `tools/replace_retry.py` is not on the shader path (`rg replace_retry` finds only `make_game`-side callers). **Review** - The validation is placed before `time.monotonic()` and before any `os.replace`, so a bad `seconds` cannot move or delete anything; it rejects bools before the `int` branch, which the test pins. - `seconds=0` keeps one attempt and no sleep, as the re-raise happens before the first `time.sleep`; the test checks call count and that the same exception object comes out. - Callers pass real numbers: `tools/calibrated_texture.py:467` forwards its own `seconds`, the other two call sites use the default. `math.isfinite` on an `int` is fine. **Finding** The winerror 33 half is only exercised with a hand-built `PermissionError(winerror=33)`. On CPython a real `os.replace` failure with ERROR_LOCK_VIOLATION has to arrive as `PermissionError` for `_transient()` to retry it, and I cannot check that mapping on macOS. If CPython maps 33 to a plain `OSError` (or a different subclass), the new tuple entry does nothing in production while the fake test stays green. A Windows-only test that makes a real second handle hold the destination (as `tests/test_rdna2spirv_spawn_quota.py` does for the job object in #2367) would settle it; otherwise saying in the docstring that 33 was added from the Win32 table, not from a reproduced rename, is enough. No game files. AI-assisted.
tiguan26 commented 2026-11-27 04:42:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:42:57Z.

Review: APPROVED


Approving 8d0c27886.

ERROR_LOCK_VIOLATION (33) joins 5 and 32 as a transient os.replace failure, which is what a byte-range lock on the source or destination returns, and the retry budget is checked to be a finite non-negative number before it is used.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_replace_retry_bounds.py: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083579057 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#pullrequestreview-6083579057). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:42:57Z. **Review:** APPROVED --- Approving 8d0c27886. `ERROR_LOCK_VIOLATION` (33) joins 5 and 32 as a transient `os.replace` failure, which is what a byte-range lock on the source or destination returns, and the retry budget is checked to be a finite non-negative number before it is used. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_replace_retry_bounds.py`: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).
kirigayakazima commented 2026-11-27 12:02:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:02:45Z.

Code review location: tools/replace_retry.py; line 26

@@ -21,7 +22,10 @@ def _transient(error):
 def replace(src, dst, *, seconds=None):
     """os.replace(src, dst), retried with a doubling delay for `seconds` (default RETRY_SECONDS) on a transient
     Windows PermissionError; the last error is raised once the time is up."""
-    deadline = time.monotonic() + (RETRY_SECONDS if seconds is None else seconds)
+    budget = RETRY_SECONDS if seconds is None else seconds
+    if isinstance(budget, bool) or not isinstance(budget, (int, float)) or not math.isfinite(budget) or budget < 0:

Fixed: wrapped math.isfinite(budget) in except OverflowError so unrepresentable integers like 10**1000 raise ValueError consistently, and added 10**1000 / -10**1000 coverage in tests/test_replace_retry_bounds.py. All 13 replace-retry tests + 5 repo checks pass.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4719130079 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2346#discussion_r4719130079). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-27T12:02:45Z. **Code review location:** `tools/replace_retry.py`; line 26 ~~~~diff @@ -21,7 +22,10 @@ def _transient(error): def replace(src, dst, *, seconds=None): """os.replace(src, dst), retried with a doubling delay for `seconds` (default RETRY_SECONDS) on a transient Windows PermissionError; the last error is raised once the time is up.""" - deadline = time.monotonic() + (RETRY_SECONDS if seconds is None else seconds) + budget = RETRY_SECONDS if seconds is None else seconds + if isinstance(budget, bool) or not isinstance(budget, (int, float)) or not math.isfinite(budget) or budget < 0: ~~~~ --- Fixed: wrapped `math.isfinite(budget)` in `except OverflowError` so unrepresentable integers like `10**1000` raise `ValueError` consistently, and added `10**1000` / `-10**1000` coverage in `tests/test_replace_retry_bounds.py`. All 13 replace-retry tests + 5 repo checks pass.
lixonik commented 2026-11-27 14:23:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T14:23:19Z.

Review: COMMENTED


Re-checked at f478f4c6b (merged onto main ec91d695c).

The OverflowError guard around math.isfinite(budget) and the 10**1000 / -10**1000 regression tests in tests/test_replace_retry_bounds.py cleanly address the earlier note.

Verified locally on Windows 11 (Python 3):

  • tests/test_replace_retry.py: 10/10 passed
  • tests/test_replace_retry_bounds.py: 3/3 passed
  • scripts/check_no_game_data.py and git diff --check: clean

No remaining findings.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6089569850 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#pullrequestreview-6089569850). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T14:23:19Z. **Review:** COMMENTED --- Re-checked at `f478f4c6b` (merged onto `main` `ec91d695c`). The `OverflowError` guard around `math.isfinite(budget)` and the `10**1000` / `-10**1000` regression tests in `tests/test_replace_retry_bounds.py` cleanly address the earlier note. Verified locally on Windows 11 (Python 3): - `tests/test_replace_retry.py`: 10/10 passed - `tests/test_replace_retry_bounds.py`: 3/3 passed - `scripts/check_no_game_data.py` and `git diff --check`: clean No remaining findings. AI-assisted.
sodove commented 2026-11-28 10:12:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:12:59Z.


#2346 | head f478f4c6b88000fb6bb6b6021f4a0d3d7eb579c0 | python3 -I tests/test_replace_retry_bounds.py -v, py -3.12 -I tests/test_replace_retry_bounds.py -v | red: Linux 3 run, 6 failures, 4 errors / Windows 3 run, 6 failures, 4 errors | green: Linux 3 passed / Windows 3 passed | Red → green

Invalid retry intervals and a simulated Windows lock violation were covered. Counts include subtests.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and Windows 11 Pro, Python 3.12.10. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237750049 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#issuecomment-7237750049). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:12:59Z. --- #2346 | head `f478f4c6b88000fb6bb6b6021f4a0d3d7eb579c0` | `python3 -I tests/test_replace_retry_bounds.py -v`, `py -3.12 -I tests/test_replace_retry_bounds.py -v` | red: Linux 3 run, 6 failures, 4 errors / Windows 3 run, 6 failures, 4 errors | green: Linux 3 passed / Windows 3 passed | **Red → green** Invalid retry intervals and a simulated Windows lock violation were covered. Counts include subtests. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 and 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-7237628300).
DadaCap commented 2026-11-28 10:46:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:46:33Z.


Merged, thank you @kirigayakazima!

What it does: REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION

How it was checked: sodove tested this PR at head f478f4c6b on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (6 failures, 4 errors); with the PR, green (3 OK).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238113929 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2346#issuecomment-7238113929). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:46:33Z. --- Merged, thank you @kirigayakazima! **What it does:** REPLACE-RETRY-LOCK-VIOLATION-AND-SECONDS-VALIDATION **How it was checked:** sodove tested this PR at head `f478f4c6b` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (6 failures, 4 errors); with the PR, green (3 OK). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. 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!2346
No description provided.