Skip to content

feat(storage): implement Windows directory synchronization (FlushFileBuffers) - #4520

Closed
scs0209 wants to merge 7 commits into
apache:mainfrom
scs0209:feat/storage-windows-directory-sync-3898
Closed

scs0209 wants to merge 7 commits into
apache:mainfrom
scs0209:feat/storage-windows-directory-sync-3898

Conversation

@scs0209

@scs0209 scs0209 commented Sep 2, 2026 •

Copy link
Copy Markdown

Summary

Implements Windows directory durability for syncDirectory(). Node's open() takes libuv uv_fs_open flags, not raw CreateFileW attributes, so the directory is opened with the POSIX read/write mode: libuv maps that to FILE_GENERIC_READ | FILE_GENERIC_WRITE, which is what FlushFileBuffers requires. libuv sets FILE_FLAG_BACKUP_SEMANTICS unconditionally, so no raw attributes are passed.

The earlier attempt on this branch passed 0x02000000 (which libuv interprets as UV_FS_O_DIRECT → FILE_FLAG_NO_BUFFERING, not FILE_FLAG_BACKUP_SEMANTICS) and 0x80000000 (not a libuv sync bit at all) with O_RDONLY, and flushed a FILE_GENERIC_READ-only handle. That combination fails with EPERM and additionally disabled buffering. Both raw flags are removed in this head.

Duplicate local syncDirectory helpers are routed through @maka/storage/stable-storage. This also removes one behavioral inconsistency: the call sites previously mixed a Windows no-op with silent error swallowing, so directory-sync failures were invisible on Windows.

Fixes #3898

Verification

Check Command Result
Storage typecheck tsc -p packages/storage/tsconfig.json --noEmit pass
Storage build npm --workspace @maka/storage run build pass
Storage suite npm --workspace @maka/storage run test:dist 1540 pass, 0 fail, 9 skip (macOS host)
Lint / format npx biome check on changed files pass
Windows directory flush windows_recovery / owner (windows-latest) / CI / CLI package validation NOT YET RUN — see below

Windows verification is outstanding

The four lanes that failed on the prior head are currently sitting in action_required (0s, zero jobs): the workflows require maintainer approval and cannot be started from the branch author. This PR does not claim the Windows durability guarantee yet. The corrected helper and a real behavioural test are pushed, but the only authority on whether a read/write directory open and flush actually succeed on Windows is a green Windows lane.

The previous run's windows_recovery / owner logs have expired, so the failure was re-diagnosed from libuv 1.52.1 source (include/uv/win.h, src/win/fs.c) and the documented FlushFileBuffers GENERIC_WRITE requirement rather than from the log.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: original change (helper, call-site consolidation, docs) was Cursor-authored; the O_RDWR correction, the replacement of the self-referential flag test with a real behavioural test, and the documentation narrowing were produced with AI agent assistance in response to review feedback.

Checklist

  • Tests cover the change and fail without it (the previous flag-constant test compared its own constants against themselves and could not fail; it is replaced by a real directory flush plus a readability assertion)
  • Lint, format, typecheck and the affected suites pass locally
  • Windows lanes green

Does this PR entail a change in behavior?

  • Yes — syncDirectory() now flushes parent directories on Windows instead of returning immediately
  • No

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.

Summary

Implements Windows directory synchronization (FlushFileBuffers) across the storage and runtime-host write paths: a new windows-directory-sync.ts plus call sites in stable-storage, marker-file, credential-store, managed-dependency-environment, skill-catalog transaction/repository, plugin-package-store, access-credential-store, peer-mesh store, registration, startup-diagnostic, client-instance-identity, local-deployment-owner, runtime-host-update-policy-store, and local-remote-access — a genuinely cross-cutting durability fix (rename is not durable on Windows without flushing the parent directory). The coverage of write paths looks complete, and the windows-directory-sync.test.ts covers the new helper.

Findings

  1. [P1] Four lanes fail on this head: test, windows_recovery, owner (windows-latest), and Validate installed CLI Windows x64 / Node 24. A durability change whose own Windows gates are red cannot merge — the failure is almost certainly in the new sync helper or one of its call sites (e.g. a path where the parent directory is opened after rename, or FlushFileBuffers on a network/removable drive erroring). Pull the windows_recovery/owner logs, fix, and show all four green before merge.

Verdict

needs-changes — the right durability fix in shape, but its own Windows validation lanes are red across the board.

scs0209 and others added 2 commits September 29, 2026 08:06
- Add windows-directory-sync helper using backup-semantics directory handles
- Route stable-storage syncDirectory through FlushFileBuffers on Windows
- Replace local win32 no-op syncDirectory copies with the shared helper
- Document the updated Windows durability boundary

Generated-by: Cursor
Co-authored-by: Cursor <[email protected]>
…pache#3898)

The `test` lane failed `format:check` on the two files introduced by
apache#3898. Formatting only, no behavior change:

- collapse the backup-semantics flag assertion onto a single line
- split the over-long stable-storage import in marker-file.ts

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Windows directory-sync change at this commit. It replaces the Windows no-op with a shared directory fsync across storage and runtime callers, and updates the durability documentation. The Windows path is currently broken (P1, inline): the prior-head Windows recovery run failed with EPERM: operation not permitted, fsync in this unchanged helper, while this head only changes formatting. Linux Node 24.18.1 clean install and build pass; focused storage tests pass 32/32 with five Windows-specific skips. There are no current-head hosted checks, and this branch conflicts with current main in the desktop local-access and storage credential-store files. The Windows durability claim is therefore unverified and the PR is not ready to merge. I did not independently run this head on Windows or perform a power-loss test.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

export const WINDOWS_DIRECTORY_WRITE_THROUGH_FLAG = 0x80000000;

export function windowsDirectoryOpenFlags(): number {
return constants.O_RDONLY | WINDOWS_DIRECTORY_OPEN_FLAG | WINDOWS_DIRECTORY_WRITE_THROUGH_FLAG;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] The flags passed to Node open() are libuv uv_fs_open flags, not raw CreateFileW flags. In libuv 1.52.1, 0x02000000 is UV_FS_O_DIRECT (FILE_FLAG_NO_BUFFERING); backup semantics is already added unconditionally. More importantly, O_RDONLY opens with FILE_GENERIC_READ, then handle.sync() calls FlushFileBuffers. The previous commit’s Windows recovery run 33576960727 fails at this unchanged helper with EPERM: operation not permitted, fsync during managed-dependency acquisition. This head only reformats other files, so Windows persistence operations still fail. Use a Windows-supported directory flush path/rights and make its real Windows test pass before claiming the durability guarantee; the current flag-constant test only checks its own values.

@scs0209 scs0209 Sep 29, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I traced the issue back through the libuv implementation and fixed it on 4ab5931cb.

The main issue was that the flags passed to Node's open() are libuv uv_fs_open flags, not raw CreateFileW flags. In libuv 1.52.1, 0x02000000 maps to UV_FS_O_DIRECT / FILE_FLAG_NO_BUFFERING, while FILE_FLAG_BACKUP_SEMANTICS is already added by libuv itself. The other 0x80000000 flag was not used by libuv either, so both raw flags have been removed.

The EPERM during fsync was also explained by the access mode. O_RDONLY gives the Windows handle read access, but FlushFileBuffers requires write access. The helper now opens the directory with O_RDWR, so the handle has the access needed for the flush.

I also replaced the previous flag-constant test with a behavioral test. It now flushes an actual directory and verifies that the payload can still be read afterwards, so an EPERM/EACCES from the Windows implementation will fail the test instead of passing based on our own constants.

I haven't claimed the Windows durability guarantee yet. The Windows lanes are currently waiting for maintainer approval and have no jobs running, so I can't verify the behavior on the actual Windows runner from this branch. The previous recovery logs have also expired, so the fix was re-validated against the libuv source and the documented FlushFileBuffers requirements.

One remaining question is whether opening a directory with read/write access is supported consistently across the Windows environments we care about. I’ve intentionally left that as a real test rather than adding a fallback that swallows the error, since that would make the regression test meaningless again.

Once the Windows lane can run, that should give us the final confirmation of whether this directory flush path is supported as expected.

FlushFileBuffers requires the handle to hold GENERIC_WRITE, so the
previous read-only open failed with EPERM on every Windows lane.

Node's open() takes libuv uv_fs_open flags, not raw CreateFileW
attributes. The 0x02000000 passed as FILE_FLAG_BACKUP_SEMANTICS is
actually UV_FS_O_DIRECT (FILE_FLAG_NO_BUFFERING), and 0x80000000
is not a libuv sync flag at all, so both were wrong. libuv already
sets FILE_FLAG_BACKUP_SEMANTICS unconditionally, which is what makes
a directory handle openable. Reopen with the POSIX read/write mode so
libuv maps FILE_GENERIC_READ | FILE_GENERIC_WRITE, and pass no raw
attributes.

The flag-constant test only compared those constants against
themselves and could never fail. Replace it with a real directory
flush plus a readability assertion that the Windows lane exercises.

Narrow the docs claim: Microsoft does not document FlushFileBuffers
as a supported operation for directory handles, so this is a
best-effort fence rather than a POSIX-equivalence guarantee.
@scs0209
scs0209 force-pushed the feat/storage-windows-directory-sync-3898 branch from 429ec29 to 4ab5931 Compare September 29, 2026 00:19

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head. The prior EPERM cause is addressed in code: the helper now opens the directory read/write without passing raw Win32 flags as libuv flags. Current-head Windows recovery run 36502537487 passes the managed-dependency and recovery paths, although I did not independently run Windows or power-loss tests. One P1 remains (inline): the new POSIX-only skip makes the checked Windows test inventory stale, and current-head test fails at that gate. Linux Node 24.18.1 clean install and build pass; focused storage tests pass 28/28 with five Windows skips. The diff check and static merge against main 2f322055 are clean. The PR is not ready to merge while the required test check is red.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

}

test('syncDirectory synchronizes a directory on POSIX', {
skip: process.platform === 'win32' ? 'POSIX-only path' : false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] This new Windows exclusion is not in docs/windows-test-inventory.md. On this exact head, npm run windows:inventory reports the inventory as stale (118 declared vs. 119 actual), and the hosted test run 36502537479 fails in Check Windows test inventory before the remaining tests run. Regenerate the checked inventory alongside this skip, then rerun the required check.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d25b0bb — inventory regenerated alongside the skip (119 declarations); windows:inventory is green locally and the required check reruns on this head.

The POSIX-only skip in windows-directory-sync.test.ts was not declared in
docs/windows-test-inventory.md, so `npm run windows:inventory` reported the
inventory stale (118 declared vs 119 actual) and the required "Check Windows
test inventory" lane failed before any test ran (hqhq1025 review on
apache#4520). Regenerated alongside the skip: 119 declarations.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At exact head d25b0bb5c79c45207a49c07f1516a1c4e11e2418, I found no new substantiated P0–P3 issue. The only change since the prior reviewed head is regeneration of docs/windows-test-inventory.md to include the POSIX-only skip in packages/storage/src/__tests__/windows-directory-sync.test.ts:35-36; the total rises from 118 to 119. npm run windows:inventory now passes (3/3 inventory tests and 119 declarations), and focused storage tests pass 6/6 with the Windows-only case skipped on Linux. The full PR's Windows r+ directory-flush code is unchanged from the prior head, whose Windows recovery run succeeded. The diff check and static merge against current main 2f322055 are clean.

This head has no reported hosted checks, so the Windows durability gate and full CI are not verified for this exact commit; the prior head's green run does not substitute for them. I did not independently execute the Windows flush or power-loss recovery on this host. Re-run the required lanes before treating the PR as merge-ready.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to my earlier review of this exact head: the required test CI lane fails at npm run check:asf-headers, which I did not run before publishing. I reproduced the failure locally. Both packages/storage/src/windows-directory-sync.ts:12-16 and packages/storage/src/__tests__/windows-directory-sync.test.ts:12-16 carry ASF license wording/line wrapping that does not match the repository's canonical renderer in scripts/asf-license-headers.mjs; the command reports both files and exits 1. This is a P2 merge-gate blocker until the headers are reconciled by hand and the current-head CI turns green. The Windows recovery lane has passed, but it does not clear the failing source-header check. My earlier 'no new P0–P3' statement should not be read as a clean current-head gate.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

The two files added by apache#3898 carried the short-form Apache license wrapping,
which npm run check:asf-headers rejects against the repository canonical
renderer (hqhq1025 review on apache#4520): the required check lane fails on
this wording. Re-wrap both headers to the canonical form; comment-only, no
behavior change.

Generated with Codebuff
Co-Authored-By: Codebuff <[email protected]>

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed da7da4667c146d2cbffe7337c2782cbf767c7fed. This commit changes only the ASF license-header text in windows-directory-sync.ts and its test; the Windows durability implementation is unchanged from the preceding head. The previously failing header check now passes. I found no new substantiated P0–P3 issue in this delta or the previously reviewed directory-sync path.

Verification: check:asf-headers passes for the checkout; windows:inventory passes (119 declarations); Storage builds; the POSIX directory-sync test passes (the Windows-only case is skipped on Linux); git diff --check and a merge-tree against main 03237142 are clean. There are no hosted checks for this exact head yet. I did not run native Windows flush or power-loss recovery, so the earlier green Windows run cannot validate this head. GitHub reports BLOCKED; this is not an approval or merge recommendation.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

…solidation

client-instance-identity.ts, registration.ts, skill-catalog-repository.ts
and marker-file.ts no longer branch on win32 since apache#3898 consolidated
their directory-sync helpers into stable-storage, so the windows-recovery
filter retained four entries the closure contract no longer derives.

Addresses the windows-package-source-closure failure behind CI on apache#4520.

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 580e57ecf68e3b05f39ef4f0495820f9d21187e5. The new branch commit removes four stale files from the Windows recovery path filter after directory-sync consolidation; the merge commit incorporates current main and resolves the production dependency audit. The previously failing source-closure check now passes (3/3). I found no new substantiated P0–P3 in the branch delta.

Local checks: clean npm ci, production npm ls, storage build, ASF header check, Windows inventory (119 declarations), source-closure contract (3/3), and the POSIX directory-sync test passed. The Windows-only directory flush test was skipped on Linux. git diff --check and a merge-tree against main 0f98c2a48 are clean. This head has no hosted checks yet, so the native Windows durability claim and the full release gates remain unverified. It should not be treated as ready to merge until the current-head Windows lanes run successfully. This is not a merge approval.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@github-actions github-actions Bot added the stale No qualifying activity within the lifecycle policy window label Oct 30, 2026
@github-actions

Copy link
Copy Markdown

This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed.

Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the pinned label.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request has been closed because it received no new commits during the 7-day grace period. This is not a judgement on the merit of the change; it only keeps the review queue aligned with work that is actively in flight.

The branch and review history are preserved. Push a new commit and reopen the pull request whenever the work is ready to continue.

@github-actions github-actions Bot closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines stale No qualifying activity within the lifecycle policy window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(storage): implement Windows directory synchronization (FlushFileBuffers)

3 participants