Repository navigation
fix(native/windows): share FILE_SHARE_DELETE so owned objects can be marked delete-pending - #2445
Conversation
…marked delete-pending
The Windows native authority self-test (`binding.call("inspect", [])`) fails
closed on stock Windows x64 with a non-admin user:
Delete owned object by handle failed (Win32 5): Access is denied.
Reproduced deterministically (15/15 failures) on Windows 11 x64, Node 22.22.2,
non-elevated account. Because `inspect` is a hard gate, every provider-backed
operation is rejected and the whole native authority is unusable.
Root cause: Windows requires that every handle currently open on an object
grants FILE_SHARE_DELETE before that object can be marked delete-pending via
SetFileInformationByHandle(FileDispositionInfo).
`createRelative()` creates the runtime object with FILE_SHARE_READ only, and the
returned handle is retained for the lifetime of the runtime
(`Runtime::directory`). `closeRuntime()` later needs to mark that same object
delete-pending, but the retained handle never shared DELETE, so the transition
is denied (Win32 5).
The child handles opened by `closeRuntime()` for recursive cleanup have the same
defect: they request DELETE access while sharing only FILE_SHARE_READ, so the
subsequent `dispose()` call on those very handles is denied too.
Fix: add FILE_SHARE_DELETE to both share masks, keeping FILE_SHARE_READ and
deliberately not adding FILE_SHARE_WRITE, so the existing write-exclusion
behaviour of the retained leases is preserved while the delete-pending
transition the cleanup path depends on becomes possible.
Verified end-to-end after the change: `inspect` passes, the full runtime
lifecycle (`runtime_create` / `runtime_mkdir` / `runtime_write` / `runtime_open`
/ `runtime_close`) completes with no residual directories, and a real 925 MB
application analysis (4396 files) runs through all stages.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@greptileai review |
|
Rinkia
left a comment
There was a problem hiding this comment.
Verification from a Windows host where the #1701 failure does not reproduce, so this is a regression check rather than a confirmation of the fix: the native lane passes on this PR's base and fails on its head.
Environment
Windows 11 Pro 26100 x64, Node v24.16.0, 12 logical processors, non-elevated, Defender real-time on, no third-party AV, C: NTFS fixed. Addon cross-built with the documented lane (Linux + MinGW-w64 g++ 12 in a container, since this host has no C++ toolchain). Same host, same fixture, same command in both runs — only the addon differs.
A/B
| artifact SHA-256 | verify-windows-native |
controls.cleanupFailureRetainsOwnershipForRetry |
|
|---|---|---|---|
base ca2d15b |
1eecd8e6…01219e |
ok: true, 20/20 filesystem controls, 11/11 process observations | true |
head c81b4a8 |
a1b9137b…eb935c |
fails | assertion thrown |
Command, identical in both:
node scripts/verify-windows-native.mjs . <abs>\process-boundary.exe
npm run verify:windows-native:artifact reports ok: true for both artifacts, and binding.call("inspect", []) passes 30/30 with zero leaked rea-native-probe-* directories on this head — so the self-test itself is unaffected here.
The failure
AssertionError [ERR_ASSERTION]: The input did not match the regular expression
/owned cleanup object|Delete owned object/u. Input:
'Error: Open private object relative to its directory handle failed
[...\rea-native-conformance-5njYKd\cleanup-retry-...\snapshot.bin] (Win32 32):
The process cannot access the file because it is being used by another process.'
at #remove (dist/windows/WindowsPrivateRuntime.js:120:24)
at scripts/verify-windows-native.mjs:442
constraint: 'Open private object relative to its directory handle failed', win32Code: 32.
That scenario holds a reader on snapshot.bin and expects cleanup to fail at the disposition step, retaining ownership for retry with a Delete owned object-shaped constraint. On this head it fails earlier, at the open step, with ERROR_SHARING_VIOLATION: a cleanup open that requests DELETE can no longer be granted while the existing reader does not share delete, so it is refused outright instead of opening and being denied at SetFileInformationByHandle.
So the observable change is the failure mode of cleanup while a reader is live, not just a stale expectation. native/windows/README.md states that failed removal retains the root and ancestor leases for retry and that Windows failures retain their constraint, and the lane asserts that specific constraint, so this looks like a behavioural change worth making deliberate either way — scoping the cleanup child open's share mode, or changing the documented expectation on purpose.
Note this PR has no completed checks yet, so the Windows capability and package lane has not exercised it; that lane runs npm run verify:windows-native and should reproduce the above once a maintainer approves the run.
On the root cause
One data point against the stated mechanism, not against the fix: on this host SetFileInformationByHandle(FileDispositionInfo) succeeds on a directory whose sole handle was created with FILE_SHARE_READ and no FILE_SHARE_DELETE — 30/30 through the addon, and in an isolated CreateFileW replication, including while a second non-sharing reader is held open. Details in #1701. Combined with @liudong-geek's matrix, which shows the opposite on their host, that suggests share-delete is necessary but not sufficient and the enforcement is host-dependent — which does not undermine adding it, but may mean this fix needs confirmation on an affected host rather than only a passing one.
Happy to re-run the lane on any revision; the cross-build lane here takes a few minutes.
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. createRelative now selects its share mask by object role: directories permit delete sharing for owned cleanup, while retained files keep FILE_SHARE_READ only. Their path replacement and competing write/delete exclusions are preserved; closeRuntime releases immutable-file handles before removing files. Source inspected at c81b4a8; git diff --check passed. Tests, builds, source checks and CI reruns were skipped at the user's explicit request. No passing runtime/provider verification is claimed for this update. The cleanup owner now enumerates directories using GetFileInformationByHandleEx on the retained handle and opens each child with NtCreateFile RootDirectory relative to that same handle. Display paths no longer select cleanup objects, and reparse entries are opened and removed as objects rather than traversed. The same relative lookup owner now serves runtimeDirectory, runtime_open and incomplete-snapshot cleanup; the snapshot path retains its recorded volume/file-ID check. Directory record offsets and names are bounded, and failed walks retain the root leases for retry. A second agent independently inspected this source change and found no blocking defect. Windows compilation, NTFS sharing/concurrency and runtime cleanup remain unverified; this source correction does not establish integration readiness. Source inspected at c81b4a8; git diff --check passed. Tests, builds, source checks and CI reruns were skipped at the user's explicit request. No passing runtime/provider verification is claimed for this update. |
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. Source fix: The cleanup retry regression matched diagnostic prose from the old path-based open. The handle-relative open correctly fails earlier when the held reader denies delete sharing. The regression now asserts the native addon's structured Source inspection traced the native failure through the addon error projection and the retry consumer; the assertion no longer depends on cleanup-stage wording. No production cleanup change was needed. Windows compilation/runtime verification, tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested. |
The native directory lease now shares DELETE as intended by #2445, so rename is permitted. Verify retained identity after rename and that retry/teardown remove the owned object while preserving a replacement at its former path. Keep the injected first-disposition failure, recovery, admission-cache and environment-cleanup checks. No native runtime behavior is changed. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
The native directory lease now shares DELETE as intended by #2445, so rename is permitted. Verify retained identity after rename and that retry/teardown remove the owned object while preserving a replacement at its former path. Keep the injected first-disposition failure, recovery, admission-cache and environment-cleanup checks. No native runtime behavior is changed. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
Problem
The Windows native authority self-test (
binding.call("inspect", [])) fails closedon stock Windows x64 under a non-elevated account, so every provider-backed
operation is rejected and the whole native authority is unusable:
Reproduced deterministically on Windows 11 x64 (Node 22.22.2, non-admin):
inspectfailed 15/15 — 100%, not intermittent.Existing reports for this exact failure, both still open: #1701, #2196.
PR #1826 (merged) fixed the symptom — the cached failure plus leaked
rea-native-probe-*directories — but not the root cause; the addon still failshere after that fix.
Root cause
Windows requires that every handle currently open on an object grants
FILE_SHARE_DELETEbefore that object can be marked delete-pending viaSetFileInformationByHandle(FileDispositionInfo). Two sites violate this:createRelative()creates the runtime object withFILE_SHARE_READonly,and the returned handle is retained for the runtime's whole lifetime
(
Runtime::directory).closeRuntime()then has to mark that same objectdelete-pending — but the retained handle never shared DELETE, so the
transition returns Win32 5.
closeRuntime()'s child handles have the same defect: they requestDELETEaccess while sharing onlyFILE_SHARE_READ, so the subsequentdispose()call on those very handles is denied too.Fix
Add
FILE_SHARE_DELETEto both share masks:createRelative()—FILE_SHARE_READ→FILE_SHARE_READ | FILE_SHARE_DELETEcloseRuntime()child open — sameDeliberately not adding
FILE_SHARE_WRITE: the write-exclusion behaviour ofthe retained leases is preserved (the in-code comments at the snapshot and
read-open sites document that exclusion as intentional), while the delete-pending
transition the cleanup path depends on becomes possible. Only the DELETE share bit
is required by the root cause.
Verification
All of the following were run through the real loader path
(
WindowsNativeLoader+ themanifest.jsonSHA-256 check), not by calling theaddon directly:
inspectpasses;jobMemoryLimit/privateDacl/atomicJobAssignmentall report
true.inspectcalls leave zero residualrea-native-probe-*directories.
runtime_create→runtime_mkdir→runtime_write→runtime_open→ read (data read back correctly) →close→runtime_close, with no residual directory.runtime_snapshot(async) resolves with a correct SHA-256.Note on the build this was verified with
Verified with a locally cross-compiled addon (llvm-mingw, Node headers 22.19.0).
Because the local build tracks
mainwhile the installed npm package is 6.4.0,inspectionSchemaindist/windows/WindowsNativeLoader.jsneededjobMemoryLimit: z.literal(true).optional()to accept the newer artifact. That isa packaging/version-skew concern only and is not part of this patch — the
schema fix belongs to whichever branch adds that field.