Repository navigation
feat(copy): unify tree copying and add XFS reflinks - #301
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 maintainer review before merge. Reviewed September 12, 2026, 11:44 PM ET / September 13, 2026, 03:44 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR replaces the unreleased clone-only API with policy-controlled directory copying, adds portable byte copying and XFS reflinks, and repairs APFS directory timestamps and POSIX symlink preservation. Merge readiness✅ Ready for maintainer review The PR remains useful: current main lacks its copy policies and XFS support. Both prior blockers are addressed, real behavior proof is sufficient, and no new blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe tree-copy subsystem turns immutable, caller-owned source directories into independent destination trees. It selects native cloning or portable copying while preserving exclusive destination creation and waiting for admitted writes before cancellation settles. flowchart TD
A[Caller-owned source tree] --> C[Validate paths and destination]
B[Copy policy and cancellation] --> C
C --> D{Cloning policy and support}
D --> E[Native filesystem cloning]
D --> F[Portable byte copying]
E --> G[Independent destination tree]
F --> G
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep one policy-controlled tree-copy API with explicit metadata limits, exclusive destinations, and cancellation that settles every admitted write. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature request; captured real-filesystem runs demonstrate the new copy policies, and the previous raw-link defect has explicit before/after evidence. Is this the best way to solve the issue? Yes. Consolidating the unreleased API avoids competing tree-copy entrypoints while retaining strict cloning and explicit byte copying. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2175dcb2d0f6. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
What Problem This Solves
Directory copying and filesystem cloning need one consumer API. The unreleased clone-only API also rejects XFS volumes that support file reflinks.
Why This Change Was Made
Replace the unreleased
/clonesubpath with@openclaw/fs-safe/copyandcopyTree(source, destination, { clone }). The default"auto"tries cloning and falls back to byte copying for unavailable capabilities;"always"requires cloning and"never"uses explicit reads and writes. Permission, I/O, cancellation, and rejected-content errors do not trigger fallback.Add XFS traversal using strict FICLONE operations, bounded native workers, pinned directories, source identity checks, and joined cancellation. XFS preserves regular-file/directory modes, timestamps, xattrs, and ACLs. The existing APFS/Btrfs/ReFS backends remain behind the same API.
User Impact
Consumers choose one copy policy instead of maintaining separate copy and clone calls. The destination must be absent and outside the immutable caller-owned source. Existing destinations are never merged or overwritten.
createCloneSourcestill prepares Btrfs subvolumes and ordinary directories for other clone backends.This changes an unreleased API only; the v0.9.0 package does not export
/clone. APFS descendant ACL limits remain documented. Byte copying does not promise ACL/xattr/ownership/alternate-stream/sparse-layout preservation. Failed or canceled calls can leave caller-owned output after all writes settle.Evidence
Final head
238e813passed CI, coverage, CodeQL, and benchmarks. Native CI lanes cover macOS, Windows, Linux/Btrfs/XFS, and Linux musl; real ReFS proof ran locally as recorded below. Fresh exact-head review found no actionable issues and confirmed both prior findings resolved.Fresh Windows native build, real ReFS/copy/navigation tests: 41 passed, 7 platform/privilege skips.
OpenClaw consumer against the built candidate: 15 backend and real ReFS tests passed, including shared extents and independent writes.
Linux Rust workspace check and clippy with warnings denied passed.
Package public API contract regenerated; package/import checks, documentation examples, and docs site passed.
Real WSL2 XFS volumes: shared physical extents, independent inodes, SHA-256 equality, and independent writes verified through the built public API. A reflink-disabled volume rejects strict cloning and passes auto/never copies with physically separate extents.
Actual native cancellation: observed a created destination file before abort; rejection at 203.67 ms, destination absent, all 8,456 source hashes unchanged, and immediate same-path reuse succeeded.
XFS synthetic 8,456-file / 160 MiB benchmark, one warmup plus three rotated samples: median 1.111 s with one worker, 0.439 s with 16 workers, and 10.314 s with byte copying. Hash verification ran outside timers. These measurements describe this WSL2 fixture, not universal throughput.
Independent P0-P2 review found one older Node 22 Windows symlink issue. Fixed by deriving link type from the source; unresolved Windows links fail explicitly because Node does not expose their link type. Added directory traversal and unresolved-link regression coverage. Other reviewed changes had no actionable findings.
Full Linux
pnpm checkpassed before the final APFS/raw-link repairs: 8,755 tests, zero failures, 95 platform skips; lint, build, docs, and package checks passed. OpenClaw core typecheck and 79 focused tests passed with the candidate alias; its real XFS backend flow verified 1 MiB shared extents and independent edits.macOS CI exposed timestamp loss on the root and nested APFS directories. An iterative native pass now restores directory timestamps after bulk cloning, retaining only active ancestor descriptors and skipping known files and symlinks without stat/open. Independent review found no actionable issues. Root/nested/empty-directory assertions remain unchanged, and a directory-link regression checks that outside metadata is untouched; final macOS native and coverage CI passed on 238e813, including the unchanged timestamp assertions and outside-directory-link regression.
ClawSweeper found raw POSIX symlink targets were UTF-8 decoded. Portable copying now preserves their Buffer bytes. The exact regression fails on 304a01b (ff becomes efbfbd) and passes on the repaired source (ff stays ff); the final source was restored and its hash verified. Windows behavior is unchanged.
Tests added or updated when behavior changed
Security and compatibility impact considered
CHANGELOG.mdupdated when release-relevantNo credentials, private paths, private hosts, or sensitive contents included
Captured XFS VM proof
Verified in a WSL2 Linux VM (not a Crabbox lease): kernel
6.18.33.2-microsoft-standard-WSL2, x86_64, Node 26.8.2. Two disposable 1 GiB XFS loopback volumes used 4 KiB blocks, one withreflink=1and one withreflink=0. Baselinecc10fd89ac8581a96e041330156ae07042c62e54rejected XFS cloning through the public API withunsupported-platformand left the destination absent.The XFS candidate's repository-owned proof runs:
Captured stdout, respectively:
{"backend":"xfs","mode":"reflink","results":[{"policy":"always-one-worker","milliseconds":3.0876379999999983,"sharedBytes":1052673,"separateBytes":0,"hashesMatch":true,"independentWrite":true},{"policy":"always-default-workers","milliseconds":4.083631999999994,"sharedBytes":1052673,"separateBytes":0,"hashesMatch":true,"independentWrite":true},{"policy":"auto","milliseconds":3.776452000000006,"sharedBytes":1052673,"separateBytes":0,"hashesMatch":true,"independentWrite":true},{"policy":"never","milliseconds":15.818287999999995,"sharedBytes":0,"separateBytes":1052673,"hashesMatch":true,"independentWrite":true}]}{"backend":"xfs","mode":"no-reflink","results":[{"policy":"always","unsupported":true,"destinationAbsent":true},{"policy":"auto","milliseconds":19.012953999999993,"sharedBytes":0,"separateBytes":1052673,"hashesMatch":true,"independentWrite":true},{"policy":"never","milliseconds":14.668910000000011,"sharedBytes":0,"separateBytes":1052673,"hashesMatch":true,"independentWrite":true}]}The proof checks complete SHA-256 content, distinct inodes, FIEMAP physical extent offsets and shared flags, and independent writes.
alwaysandautoshare all file data on reflink-enabled XFS;neverhas disjoint extents. On reflink-disabled XFS, strict cloning refuses without creating a destination whileautoandnevercopy normally.A separate public-API cancellation probe aborted after observing the first real destination file event, 140.65 ms after starting a one-worker clone. The promise rejected with the caller's exact abort reason at 203.67 ms total; the destination was absent after rejection, every source hash matched, and retrying the same destination succeeded with matching hashes.
The same synthetic 160 MiB tree (8,456 files, 65 directories) was measured with one warmup per mode and three measured rounds in rotating order. All source and destination hashes were verified outside timed regions. Median times:
clone: "never")For this local WSL2 workload, 16 workers were 2.53x faster than one worker and 23.47x faster than normal copying. These are synthetic workload measurements, not an OpenClaw worktree benchmark or a general performance guarantee. The cancellation and timing fixture contains only regular files and is unaffected by the final portable symlink repair.
Focused tests before the final raw-link/macOS repair: reflink-enabled XFS 32 passed / 4 platform skips; reflink-disabled XFS portable copy 16 passed / 1 Windows skip. Full
pnpm checkpassed before the final raw-link/macOS repair: 271 test files passed, 8,755 tests passed, 95 platform skips, zero failures.git diff --checkalso passed. The first full run exposed two package-lifecycle tests that require the JavaScript pnpm CLI; using the official same-version pnpm 11.25.0 JavaScript distribution resolved them without changing dependencies or sources. Nativecargo check --workspace --lockedandcargo clippy --workspace --locked -- -D warningspassed.A subsequent public-API regression probe confirmed and then verified the POSIX raw-target fix: an ASCII symlink name pointing to raw byte
ffcopied toefbfbdbefore the fix and preservesffafter it. The final package build and focused copy/clone suites on ordinary Linux storage passed: 26 tests passed, 10 platform/filesystem skips, zero failures. The final diff check passed. The complete local suite and mounted XFS proofs were not repeated for that narrow repair; final CI covers the mounted filesystem and macOS lanes.