Skip to content

Register FULL hydration so reads and writes wait for the whole file - #13

Merged
dkgs2000 merged 2 commits into
mainfrom
claude/full-hydration
Nov 26, 2026
Merged

dkgs2000 merged 2 commits into
mainfrom
claude/full-hydration

Conversation

@dkgs2000

Copy link
Copy Markdown
Owner

Replaces #12, rebuilt on main now that #11 is merged. It registers FULL hydration and updates #11's test, comment and docs to match.

Why FULL

The drive registered PARTIAL hydration. Microsoft's reference says PARTIAL "is not currently supported" and behaves like PROGRESSIVE, which programs get by default anyway (sync engine docs). Under PROGRESSIVE, Windows completes a read as soon as its bytes arrive and finishes the download a moment later. A write in that gap can lose the downloaded bytes. That is the intermittent CI failure in UpdatePlaceholderContractTest, where a file came back as "\0\0\0\0\0\0\0\0\0\0\0-edited" (runs 45843777423 attempt 1 and 45879816676). Any program that reads a file and writes to it at once could hit it, and the engine would then upload the zeros as an edit.

It only failed on CI. On a PC, Defender's real-time protection downloads the whole file as soon as a program opens it, so the test's own read never starts the download. GitHub's runners turn real-time monitoring off (Configure-WindowsDefender.ps1).

Local reproduction, with temporary experiments not included here: the reader was opened while the file was downloaded, the file was freed up through a WRITE_DAC-only handle, and then the reader read it.

PARTIAL (before) FULL (after)
Download still unfinished right after the read 100 of 100 0 of 100
Read back as 11 zeros + -edited (8 workers × 400 rounds × 3 runs) 9 of 9,600 0 of 9,600

Nextcloud registers CF_HYDRATION_POLICY_FULL (src/libsync/vfs/cfapi/cfapiwrapper.cpp), and OneDrive's sync roots on the test PC are Full.

What it means for #11's hold

Under FULL, every local change tried on an online-only file downloads it first: append, write at the start, truncate, extend, truncate-on-open, and memory-mapped writes. An overwrite makes it a plain file. So a file that is not fully on disk holds nothing local. #11's hold, which stops a server change from replacing such a file while another program has it open, is kept. That program can have a write waiting for the download, which could land between the engine's check and its replace.

Changes

  • SyncRootRegistrar registers FULL in both the shell path and the CfRegisterSyncRoot fallback. Existing drives pick it up when the service re-registers at startup.
  • New ARead_ReturnsOnlyOnceTheWholeFileIsHere fails 8/8 under PARTIAL and passes 8/8 under FULL.
  • New AWrite_ToAFileNotFullyOnDisk_DownloadsAllOfItFirst fails under PARTIAL for an online-only file. Under PARTIAL, the bytes appended to a 70 KB online-only file were also lost; that is fixed too.
  • UpdateFromRemote_UnchangedFrom_RefusesAFileNotFullyOnDiskWhileOpenInAnotherProgram (Hold a file not fully on disk before replacing it; clear leftover test drives #11) now holds the file open without writing. With FULL, its write downloaded the file.
  • The comment in CloudPlaceholderService.UpdateFromRemote and the architecture doc say why the hold stays.
  • E2E mount check 4 now expects the download to be finished right after the read, instead of waiting for it.

Test plan

  • dotnet test .\OpenCfDrive.slnx --settings coverage.runsettings: 297 passed locally
  • Both new tests fail with PARTIAL
  • CI: unit job with coverage, and the four E2E jobs

🤖 Generated with Claude Code

dkgs2000 and others added 2 commits November 26, 2026 22:07
…oaded

The drive registered PARTIAL hydration, which Microsoft documents as not
supported and which Windows runs as PROGRESSIVE (the default for
programs; the higher of the two applies). PROGRESSIVE lets a read through
as soon as its bytes arrive and finishes the download a moment later. A
write in between could lose the downloaded bytes: on CI, the read and
append in UpdatePlaceholderContractTest read back as 11 zeros followed by
the appended text (runs 45843777423 and 45879816676).

It showed only on CI. On a PC, Defender's real-time protection downloads
a file as soon as a program opens it for reading, so the test's own read
never drove the download; CI runners turn real-time monitoring off.
Reproduced locally by reading through a handle opened before the file was
freed up: 9 of 9600 rounds read back as zeros with PARTIAL, none with FULL.

FULL is what Nextcloud (cfapiwrapper.cpp) and OneDrive register: the
platform completes a read only once the whole file is local. It also
keeps what a program appends to an online-only file, which PARTIAL lost
for a 70 KB file.

ARead_ReturnsOnlyOnceTheWholeFileIsHere pins it and fails every time with
PARTIAL. The E2E mount check now expects the mark to be gone right after
the read instead of waiting for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With FULL hydration, a program's write to a file that is not fully on
disk makes Windows download all of it first, so such a file holds
nothing local. The test that wrote to one without downloading it
(#11) can no longer do so. The hold stays: a program that has the file
open can have a write waiting for that download, which could land
between the check and the replace.

That test now holds the file open without writing to it. A new one,
AWrite_ToAFileNotFullyOnDisk_DownloadsAllOfItFirst, pins that a write
downloads the whole file first; it fails with PARTIAL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkgs2000
dkgs2000 merged commit 033d4f9 into main Nov 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant