Repository navigation
fix(nid): retry replacing the patched file on Windows - #23366
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Ran it on a second Windows machine: head
AI-assisted: yes (Claude Code) |
|
Windows 11 22631: builds and patches every |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
I also checked a lock held past the retry deadline on Windows using the NID patcher at AI-assisted: yes (OpenAI Codex). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this change, but Windows behavior remains unverified in this review, so a formal approval is not justified.
What I ran
Reviewed head 0fadc64d705c0c2ad7bca07446a72a422befb0cd. Read description.md, commits.md, manifest.json, diff.patch, and all three changed files: core/libs/CMakeLists.txt, core/libs/nid/src/main.cpp, and core/libs/nid/tests/test_native_paths.py. The manifest lists all three as reviewed; none were excluded. No commands or tests were run. The Windows test results in the PR description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Patch and changed code review | passed | All changed files read |
| Test execution | not run | PR description reports Windows runs |
| Negative control | not run | Not independently reproduced |
Negative control
Could not run the reported red check with the retry removed.
Findings
Blocking
None.
Non-blocking
None.
Sources
The retry loop makes up to 20 rename attempts, sleeping 250 ms between failures, then removes the pending file and reports the final error (core/libs/nid/src/main.cpp:48). The Windows-specific tests cover transient and permanent target locks (core/libs/nid/tests/test_native_paths.py:61, core/libs/nid/tests/test_native_paths.py:78). The test timeout is raised to 30 seconds (core/libs/CMakeLists.txt:565).
Not verified
I did not run tests or verify Windows, Linux, or macOS behavior. The test outcomes and environment stated in the PR description were not independently confirmed.
To get this to a good state
Nothing is required. Optional: independently run the Windows native path tests and their red check.
JJenkx
left a comment
There was a problem hiding this comment.
Reviewed head 0fadc64d70 from the code and its Windows CI log; I didn't build it locally.
- It still merges cleanly with
main957c68fb42, andmain's later permission-preserving step (cdf5776033) is already in its base. The retry wraps only the finalrename, and the existing cleanup and error message stay the same.std::filesystem::rename(..., error_code&)clears the code on success, so the loop exits on the first successful attempt. - The new Windows-only tests did run in this head's
windowsjob:nid_patcher_native_paths ... Passed 5.79 sec. That time fits the permanently-held case going through the full 20 × 250 ms retry bound before reportingcannot write, and the 30 s timeout leaves room for it. - One thing to know: the retry covers every rename error, not just sharing violations. A non-transient failure, such as a missing directory, now takes about 5 s to report. That seems acceptable for a build tool.
- The red
windowscheck (run 44415376409, 2026-11-18) failed onlyguest_libressl3_aes_wrapandguest_libressl3_aes(0xc0000409). This PR doesn't touch LibreSSL, and both pass on currentmainin a full Windows non-device sweep atb5460b9e94(4,576 of 4,576). I haven't checked whichmainchange fixed them. Re-running the check would refresh it.
AI-assisted: yes.
What
nid_patcherwrites the patched library to<file>.patchingand renames it over<file>in a single attempt (core/libs/nid/src/main.cpp#L42-L47). On Windows that rename (MoveFileExWwithMOVEFILE_REPLACE_EXISTING) is refused while any process holds the target without delete sharing, for example a scanner or indexer reading the.prxthatcmake -E copywrote milliseconds earlier, and the build step fails withFAIL: <file>: cannot write: <file>: Permission denied.The patcher now retries the rename up to 20 times, 0.25 s apart, the same bound as the test runtime staging copies in
cmake/CopyRuntimeFiles.cmake#L4and#L18-L29(#18221). The.patchingfile is kept during the retries. After the last attempt it is removed and the patcher fails with the samecannot write: <file>: <error>message and exit code 2 as before. The retry applies to every error code and every platform, with no#ifdef; on POSIX a rename over a file is not refused because of open handles, so a real failure there is only reported 4.75 s later. Reading the input and thecmake -E copystep are unchanged.Tests in
core/libs/nid/tests/test_native_paths.py(Windows only, skipped elsewhere):test_transiently_held_target_is_replaced: the target is held open with Python'sopen(file, "rb"), which shares read and write but not delete, for 0.75 s after the patcher starts. The patcher must exit 0, the file must carry the patched exports, and no.patchingfile may remain.test_permanently_held_target_reports_failure: the target is held for the whole run. The patcher must exit 2 withcannot writeand the path on stderr and noOK:on stdout; the file must be unchanged and no.patchingfile may remain.nid_patcher_native_pathsgetsTIMEOUT 30instead of 20, because the second case alone sleeps 4.75 s.Tested
Windows 11 Pro (10.0.26300), GCC 15.2.0 (WinLibs UCRT), Ninja, Release,
BUILD_TESTING=ON. First run onmain56c87ad; rerun after mergingmain9a50e10 (nid_patcher_native_pathspassed again, andctest -R "^nid_"passed 14/14 three times on the merged tree, for thenid_targets built there).ctest --test-dir <build> -R "^(nid_patcher_native_paths)$" --output-on-failure: passed 3/3 (5.71 s, 5.72 s, 5.72 s).core/libs/nid/src/main.cppreverted tomain(git stash push -- core/libs/nid/src/main.cpp, rebuildnid_patcher), the same command fails intest_transiently_held_target_is_replaced:AssertionError: 2 != 0 : FAIL: C:\Users\...\Temp\tmpwkwlg_5w\library.prx: cannot write: C:\Users\...\Temp\tmpwkwlg_5w\library.prx: Permission denied.test_permanently_held_target_reports_failurepasses on bothmainand this branch.ctest --test-dir <build> -R "nid_" -V: 18/18 passed, includingnid_patcher_macho,nid_patcher_symbol_versions,nid_pe_references,nid_elf_layout,nid_patch_dependenciesandnid_patch_dependencies_helper.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)