Skip to content

Register FULL hydration so a read returns only once the file is downloaded - #12

Closed
dkgs2000 wants to merge 1 commit into
mainfrom
claude/vigilant-kowalevski-37df93
Closed

dkgs2000 wants to merge 1 commit into
mainfrom
claude/vigilant-kowalevski-37df93

Conversation

@dkgs2000

Copy link
Copy Markdown
Owner

Fixes the intermittent CI failure in UpdatePlaceholderContractTest, where a file read and then appended to came back as "\0\0\0\0\0\0\0\0\0\0\0-edited" instead of "old-content-edited" (runs 45843777423 attempt 1 and 45879816676). It is a product bug, not only a test race.

Cause

The drive registered the PARTIAL hydration policy. Microsoft's reference says PARTIAL "is not currently supported" and behaves like PROGRESSIVE. The effective policy is the higher of the program's and the provider's, and programs default to PROGRESSIVE (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. Any program that reads a file and writes to it at once could hit this, 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), so there the read starts it and the gap is there. Coverage most likely just changes the timing.

Evidence (local, with temporary experiments not included here)

To get past Defender, the reader is opened while the file is downloaded, the file is freed up through a WRITE_DAC-only handle, and then the reader reads it.

PARTIAL (before) FULL (after)
Download still unfinished (RECALL_ON_DATA_ACCESS set) right after the read 100 of 100 0 of 100
Read back as 11 zeros + -edited (8 parallel 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 registered Full.

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 contract test UpdatePlaceholderContractTest.ARead_ReturnsOnlyOnceTheWholeFileIsHere. It does not depend on timing: it failed 8 of 8 runs under PARTIAL and passed 8 of 8 under FULL.
  • E2E mount check 4 now expects the download to be finished right after the read, instead of waiting for it.
  • docs/architecture.md explains the policy choice.

Side effect: under PARTIAL, appending to a never-downloaded 70 KB file lost the appended bytes. Under FULL the file is downloaded first and they are kept.

Test plan

  • dotnet test .\OpenCfDrive.slnx --settings coverage.runsettings: 282 passed locally (twice, before and after rebasing on main)
  • The new test fails under PARTIAL (8/8) and passes under FULL (8/8)
  • CI: unit job with coverage, and the four E2E jobs

Merges with PR #11 without conflicts (checked with git merge-tree).

🤖 Generated with Claude Code

…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>
@dkgs2000

Copy link
Copy Markdown
Owner Author

Replaced by #13, which is built on main now that #11 is merged and also updates #11's test for FULL hydration.

@dkgs2000 dkgs2000 closed this Nov 26, 2026
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