fix(libkernel): keep the Windows vnode watch when the watched file is deleted #5393

Merged
yixx16 merged 1 commit from upstream-pr/5393 into main 2026-10-14 01:25:12 +00:00
yixx16 commented 2026-10-13 18:41:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yixx16 on 2026-10-13T18:41:44Z.


What

On Windows 10 1903 and later, DeleteFileW and _wremove delete with POSIX semantics: a file with open handles is moved into \$Extend\$Deleted until its last handle closes. The EVFILT_VNODE watch thread keeps a handle on the watched file and takes GetFileInformationByHandleEx snapshots every 50 ms, so after the title deletes a watched file the next snapshot sees a new final path (\\?\C:\$Extend\$Deleted\<id>, 0 links, delete pending), replaces the parent directory watch with one on that directory, gets ERROR_ACCESS_DENIED from FindFirstChangeNotification and throws from the detached watch thread, which aborts the process. The path change was also reported as NOTE_RENAME next to NOTE_DELETE.

A snapshot with a pending delete or no links now reports NOTE_DELETE alone and drops the parent directory watch instead of replacing it: the file has no directory left to be renamed or removed from, and its own handle keeps reporting until the knote is deleted. The vnode entry in docs/dev/debt/libkernel.md records the behaviour.

Measured on Windows 11 with a probe (second handle with FILE_SHARE_DELETE, then DeleteFileW or _wremove): GetFinalPathNameByHandleW returns \\?\C:\$Extend\$Deleted\<id>, FileStandardInfo reports NumberOfLinks 0 and DeletePending 1, and FindFirstChangeNotificationW on \\?\C:\$Extend\$Deleted\ fails with error 5. The same abort appeared as an intermittent guest_kqueue failure (EVFILT_VNODE: FindFirstChangeNotification failed, error=5, exit 0xc0000409) on a Windows CI run of my fork at the end of a vnode test, where the kqueue is closed and the file removed right after, with the watch thread still in a snapshot.

Tested

guest_kqueue gains DeleteWatchedFile, registered on Linux and Windows: a watched file is unlinked while open, NOTE_DELETE is reported once without NOTE_RENAME, nothing more is reported afterwards, and the descriptor and the kqueue close normally.

Full Linux and Windows builds with every test on my fork's GitHub Actions Build workflow (1077 and 1095 tests, all passed; this branch together with three kqueue branches of mine): https://github.com/yixx16/AnyPS5/actions/runs/38445944846. The Windows abort without the fix is in the first attempt of https://github.com/yixx16/AnyPS5/actions/runs/38437850775 (job windows, guest_kqueue). No title run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code); the author reviewed and ran everything above
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847829636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5393). Originally posted by [yixx16](https://github.com/yixx16) on 2026-10-13T18:41:44Z. --- ### What On Windows 10 1903 and later, `DeleteFileW` and `_wremove` delete with POSIX semantics: a file with open handles is moved into `\$Extend\$Deleted` until its last handle closes. The `EVFILT_VNODE` watch thread keeps a handle on the watched file and takes `GetFileInformationByHandleEx` snapshots every 50 ms, so after the title deletes a watched file the next snapshot sees a new final path (`\\?\C:\$Extend\$Deleted\<id>`, 0 links, delete pending), replaces the parent directory watch with one on that directory, gets `ERROR_ACCESS_DENIED` from `FindFirstChangeNotification` and throws from the detached watch thread, which aborts the process. The path change was also reported as `NOTE_RENAME` next to `NOTE_DELETE`. A snapshot with a pending delete or no links now reports `NOTE_DELETE` alone and drops the parent directory watch instead of replacing it: the file has no directory left to be renamed or removed from, and its own handle keeps reporting until the knote is deleted. The vnode entry in `docs/dev/debt/libkernel.md` records the behaviour. Measured on Windows 11 with a probe (second handle with `FILE_SHARE_DELETE`, then `DeleteFileW` or `_wremove`): `GetFinalPathNameByHandleW` returns `\\?\C:\$Extend\$Deleted\<id>`, `FileStandardInfo` reports `NumberOfLinks` 0 and `DeletePending` 1, and `FindFirstChangeNotificationW` on `\\?\C:\$Extend\$Deleted\` fails with error 5. The same abort appeared as an intermittent `guest_kqueue` failure (`EVFILT_VNODE: FindFirstChangeNotification failed, error=5`, exit 0xc0000409) on a Windows CI run of my fork at the end of a vnode test, where the kqueue is closed and the file removed right after, with the watch thread still in a snapshot. ### Tested `guest_kqueue` gains `DeleteWatchedFile`, registered on Linux and Windows: a watched file is unlinked while open, `NOTE_DELETE` is reported once without `NOTE_RENAME`, nothing more is reported afterwards, and the descriptor and the kqueue close normally. Full Linux and Windows builds with every test on my fork's GitHub Actions `Build` workflow (1077 and 1095 tests, all passed; this branch together with three kqueue branches of mine): https://github.com/yixx16/AnyPS5/actions/runs/38445944846. The Windows abort without the fix is in the first attempt of https://github.com/yixx16/AnyPS5/actions/runs/38437850775 (job `windows`, `guest_kqueue`). No title run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code); the author reviewed and ran everything above
likecrank-dotcom commented 2026-10-13 18:53:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T18:53:57Z.


Independent Windows stress validation by OpenAI Codex (AI-assisted). No code changes were made to this PR.

Validated PR head 50b06110bbac6e37fad8c3dcb55fbecac1843134 on Windows 11 Pro build 26100 with WinLibs MinGW GCC 15.2.0 and CMake 4.4.4. Built guest_kqueue_tests; CTest guest_kqueue passed 20 consecutive full-suite runs (28.18 seconds total, 20/20). This includes the new DeleteWatchedFile regression. tools/check_conventions.py against base 18c438b1092b09cef54e4cfacab441c009a6b501 and git diff --check passed. This is a focused repeated test, not a full build or title run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152842183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5393#issuecomment-6152842183). Originally posted by [likecrank-dotcom](https://github.com/likecrank-dotcom) on 2026-10-13T18:53:57Z. --- Independent Windows stress validation by OpenAI Codex (AI-assisted). No code changes were made to this PR. Validated PR head `50b06110bbac6e37fad8c3dcb55fbecac1843134` on Windows 11 Pro build 26100 with WinLibs MinGW GCC 15.2.0 and CMake 4.4.4. Built `guest_kqueue_tests`; CTest `guest_kqueue` passed 20 consecutive full-suite runs (28.18 seconds total, 20/20). This includes the new `DeleteWatchedFile` regression. `tools/check_conventions.py` against base `18c438b1092b09cef54e4cfacab441c009a6b501` and `git diff --check` passed. This is a focused repeated test, not a full build or title run.
github-actions[bot] commented 2026-10-13 19:10:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:10:24Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4908 docs/dev/debt/libkernel.md L97-98
#4910 docs/dev/debt/libkernel.md L97-98
#5361 docs/dev/debt/libkernel.md L97-98
#5440 core/libs/tests/GuestKqueue.cpp L402, L425
docs/dev/debt/libkernel.md L97-98
#5493 core/libs/tests/GuestKqueue.cpp L402, L425
docs/dev/debt/libkernel.md L98
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153140051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5393#issuecomment-6153140051). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T19:10:24Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4908 | `docs/dev/debt/libkernel.md` [L97-98](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L97-L98) | | | | #4910 | `docs/dev/debt/libkernel.md` [L97-98](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L97-L98) | | | | #5361 | `docs/dev/debt/libkernel.md` [L97-98](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L97-L98) | | | | #5440 | `core/libs/tests/GuestKqueue.cpp` [L402](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/tests/GuestKqueue.cpp#L402), [L425](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/tests/GuestKqueue.cpp#L425)<br>`docs/dev/debt/libkernel.md` [L97-98](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L97-L98) | | | | #5493 | `core/libs/tests/GuestKqueue.cpp` [L402](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/tests/GuestKqueue.cpp#L402), [L425](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/core/libs/tests/GuestKqueue.cpp#L425)<br>`docs/dev/debt/libkernel.md` [L98](https://github.com/boykopovar/AnyPS5/blob/ee9037d85154d0c840517c46c61087a736fe0641/docs/dev/debt/libkernel.md#L98) | | |
yixx16 commented 2026-10-13 20:12:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yixx16 on 2026-10-13T20:12:42Z.


The overlap with #5361 is only the adjacent line of docs/dev/debt/libkernel.md: it edits the kqueue entry and this PR the EVFILT_VNODE entry below it. The code is unrelated, so this does not depend on #5361; whichever lands second rebases the debt line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154270053 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5393#issuecomment-6154270053). Originally posted by [yixx16](https://github.com/yixx16) on 2026-10-13T20:12:42Z. --- The overlap with #5361 is only the adjacent line of `docs/dev/debt/libkernel.md`: it edits the kqueue entry and this PR the EVFILT_VNODE entry below it. The code is unrelated, so this does not depend on #5361; whichever lands second rebases the debt line.
simonbronk commented 2026-10-13 20:50:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T20:50:44Z.


Independent confirmation on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, full build (AI-assisted: Claude Code).

Without the fix, enabling the existing RenameAndDeleteWatchedFile test on Windows (it is under #ifndef _WIN32 today) aborts guest_kqueue deterministically with EVFILT_VNODE: FindFirstChangeNotification failed, error=5, exit 0xc0000409, the same failure as #5435.

With the same change as this PR (Deleted = delete pending or 0 links; no NOTE_RENAME and no parent rewatch when deleted), RenameAndDeleteWatchedFile passes on Windows: NOTE_RENAME after the rename, then NOTE_DELETE alone after the unlink. guest_kqueue passed 30/30 with ctest --repeat until-fail:30, and the full suite 1098/1098.

Since that test now passes on Windows, it could move out of the #ifndef _WIN32 block (only MoveDirectoryEntries needs to stay Linux-only), either here or in a follow-up after this lands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154937515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5393#issuecomment-6154937515). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-13T20:50:44Z. --- Independent confirmation on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, full build (AI-assisted: Claude Code). Without the fix, enabling the existing `RenameAndDeleteWatchedFile` test on Windows (it is under `#ifndef _WIN32` today) aborts `guest_kqueue` deterministically with `EVFILT_VNODE: FindFirstChangeNotification failed, error=5`, exit 0xc0000409, the same failure as #5435. With the same change as this PR (`Deleted` = delete pending or 0 links; no `NOTE_RENAME` and no parent rewatch when deleted), `RenameAndDeleteWatchedFile` passes on Windows: `NOTE_RENAME` after the rename, then `NOTE_DELETE` alone after the unlink. `guest_kqueue` passed 30/30 with `ctest --repeat until-fail:30`, and the full suite 1098/1098. Since that test now passes on Windows, it could move out of the `#ifndef _WIN32` block (only `MoveDirectoryEntries` needs to stay Linux-only), either here or in a follow-up after this lands.
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
boykopovar/AnyPS5!5393
No description provided.