Repository navigation
feat(clone): add native APFS, Btrfs, and ReFS directory cloning - #293
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 12, 2026, 8:28 PM ET / September 13, 2026, 00:28 UTC (Revision 2). ClawSweeper reviewWhat this changesAdds a public directory-cloning API for APFS, Btrfs, and ReFS, batched APFS metadata reads, documentation, tests, benchmarks, and native CI coverage. Merge readiness⛔ Blocked before merge - 2 items remain This remains useful work not implemented on current main. No blocking code defect was found, but the updated validation summaries do not resolve the previous request for captured real-behavior proof. Priority: P2 Review scores
Verification
How this fits togetherfs-safe provides filesystem primitives for Node.js applications. The new cloning API accepts caller-owned absolute paths, retains directory handles during native work, and produces independent directory trees or a settled failure. flowchart TD
A[Caller-owned source and destination] --> B[Validate paths and pin directories]
B --> C{Supported filesystem}
C --> D[APFS clone or Btrfs snapshot]
C --> E[Parallel ReFS file clones]
C --> F[Unsupported error]
D --> G[Wait for native work and verify identity]
E --> G
G --> H[Independent tree or settled failure]
Before merge
Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep the additive cloning API and its explicit ownership contract, supported by observable native preservation and cancellation-settlement evidence. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds a capability rather than repairing an established failure; no definite introduced bug was identified. Is this the best way to solve the issue? Yes, the additive subpath and shared directory guards provide a coherent implementation without replacing existing publication behavior; runtime proof remains incomplete. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 18f4156e654d. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
What Problem This Solves
Consumers currently need separate native implementations to create copy-on-write directory trees on APFS, Btrfs, and ReFS. OpenClaw duplicates this platform code and makes per-file foreign-function calls on Windows.
Why This Change Was Made
Adds
@openclaw/fs-safe/clonewithcloneTree,createCloneSource, and a filesystem probe. APFS uses one native directory clone, Btrfs uses a subvolume snapshot without a subprocess, and ReFS uses a bounded native worker pool with 16 workers by default. A batched APFS metadata reader supports consumers that validate clone provenance.The API requires immutable caller-owned sources and controlled destination namespaces. It pins directory descriptors, refuses overwrites and unsupported filesystems, preserves independent file data, and waits for admitted work before rejecting cancellation. ReFS rejects named streams and unsupported reparse types instead of silently dropping them. There is no byte-copy fallback or per-file durability sync.
User Impact
Applications can request a directory clone through one portable call and choose their own fallback. Btrfs sources must be subvolumes without nested subvolumes. APFS/Btrfs bulk operations may leave a complete destination after cancellation; recovery remains with the caller.
On a Windows ReFS Dev Drive, repeated raw cloning of 41,723 files had medians of 5.78 seconds with 8 workers and 4.26 seconds with 16 workers. Initial copies at every tested concurrency matched all file hashes. These are copy-only measurements, with observed timing variability; full worktree creation also incurs Git preparation costs.
Evidence
pnpm check: 7,476 passed, 36 failed, 1,228 skipped. The new API documentation omission was fixed and its tests passed afterward. Remaining failures are Windows symlink setup permissions and an existing test-hook mock issue; both categories were reproduced on unchanged main. Package validation was run separately and passed.f62a5a6c4662801d6517650c46b6ff244e5e3532: CI, coverage, CodeQL, and benchmarks. Native CI executes Linux glibc/musl, macOS arm64, and Windows x64; the other release architectures are not execution claims here.Buffer.equalscomparisons fixed that cost without changing payload coverage or timeouts. Final CI and coverage passed without retries.Captured APFS and Btrfs public-facade execution
The committed
test/clone.test.tsimportscloneTreeandcreateCloneSourcefromsrc/clone.tsand calls them against real filesystem fixtures. Data/metadata preservation, independent writes, source admission, and APFS clone provenance use the actual native binding. The separately named descriptor-lifetime test substitutes the native method and is not claimed as native cancellation proof.Captured at the final head:
APFS invocation/output and Btrfs fixture setup/invocation/output. Platform-specific tests skip on the other filesystems; Btrfs's ordinary-directory rejection executes on the mounted Btrfs fixture.
Captured ReFS public-API clone and native cancellation
fs-safe PR #293, checked out at f62a5a6. The built Windows clone API and native implementation are unchanged from the validated build. Run on the local ReFS Dev Drive with Node.js v26.8.2. No mocks or binding substitutions; no dependency operations or production edits.
The script waits up to 10 seconds for a real destination file matching source bytes while another source file is still absent, then aborts. It awaits rejection, verifies the partial destination is absent, immediately reuses that same path, compares every path and file hash, verifies independent writes, and checks that output metadata stays unchanged after a 1-second quiet interval.
Invocation (from the OpenClaw task workspace; paths contain no user identity):
Captured output (exit 0):
Proof script:
Implementation references: Microsoft CopyOnWrite, MSBuild Artifacts, Apple clonefile contract, and Btrfs subvolume semantics. No source code was copied from those projects.
CHANGELOG.mdupdated when release-relevant