Skip to content

feat(copy): unify tree copying and add XFS reflinks - #301

Merged
steipete merged 3 commits into
mainfrom
codex/xfs-tree-clone
Sep 13, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/xfs-tree-clone

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

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 /clone subpath with @openclaw/fs-safe/copy and copyTree(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. createCloneSource still 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 238e813 passed 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 check passed 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.md updated when release-relevant

  • No 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 with reflink=1 and one with reflink=0. Baseline cc10fd89ac8581a96e041330156ae07042c62e54 rejected XFS cloning through the public API with unsupported-platform and left the destination absent.

The XFS candidate's repository-owned proof runs:

node scripts/clone-xfs-proof.mjs "$FIXTURE"
node scripts/clone-xfs-proof.mjs "$NO_REFLINK_FIXTURE" no-reflink

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. always and auto share all file data on reflink-enabled XFS; never has disjoint extents. On reflink-disabled XFS, strict cloning refuses without creating a destination while auto and never copy 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:

Mode Median
Strict clone, 1 worker 1.111 s
Strict clone, 16 workers 0.439 s
Normal copy (clone: "never") 10.314 s

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 check passed before the final raw-link/macOS repair: 271 test files passed, 8,755 tests passed, 95 platform skips, zero failures. git diff --check also 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. Native cargo check --workspace --locked and cargo clippy --workspace --locked -- -D warnings passed.

A subsequent public-API regression probe confirmed and then verified the POSIX raw-target fix: an ASCII symlink name pointing to raw byte ff copied to efbfbd before the fix and preserves ff after 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.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 13, 2026 03:19
@steipete
steipete requested a review from a team as a code owner September 13, 2026 03:19
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 11:44 PM ET / September 13, 2026, 03:44 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: 238e813f3e966380f0e86a62c5484f03057d9f98

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent implementation with strong filesystem proof and both previous review blockers resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Captured WSL2 public-API traces exercise the XFS backend and portable fallback with physical-extent checks, matching hashes, independent edits, and cancellation settlement; the final POSIX target-byte repair also has before/after runtime evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Captured WSL2 public-API traces exercise the XFS backend and portable fallback with physical-extent checks, matching hashes, independent edits, and cancellation settlement; the final POSIX target-byte repair also has before/after runtime evidence.
Evidence reviewed 8 items Applicable repository policy: Read the full root AGENTS.md and contribution/security guidance. No nested AGENTS.md or maintainer-notes directory was found. Applied filesystem identity, explicit fallback, package-contract, and changelog guidance; the review remained read-only.
Current main still needs the contribution: Fetched main exposes cloneTree with required native support and only APFS/Btrfs/ReFS backends. Its tree inventory lacks the new public copy module and XFS backend. Merged #293 supplies the earlier clone implementation, not the requested additions.
Released API compatibility: The v0.9.0 package exports neither /clone nor /copy, confirming that the renamed subpath is unreleased. The tag resolves to 0fc5776. GitHub contents inspection recovered the release blob after local promisor retrieval failed.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Net implementation and validation growth Production +756 lines; tests +362; proof script +216 Growth implements the stated portable-copy and XFS capabilities, with dedicated regression and physical-extent validation.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Captured WSL2 public-API traces exercise the XFS backend and portable fallback with physical-extent checks, matching hashes, independent edits, and cancellation settlement; the final POSIX target-byte repair also has before/after runtime evidence.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded public filesystem-copy improvement with meaningful platform support and no established urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Captured WSL2 public-API traces exercise the XFS backend and portable fallback with physical-extent checks, matching hashes, independent edits, and cancellation settlement; the final POSIX target-byte repair also has before/after runtime evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured WSL2 public-API traces exercise the XFS backend and portable fallback with physical-extent checks, matching hashes, independent edits, and cancellation settlement; the final POSIX target-byte repair also has before/after runtime evidence.

Evidence

What I checked:

  • Applicable repository policy: Read the full root AGENTS.md and contribution/security guidance. No nested AGENTS.md or maintainer-notes directory was found. Applied filesystem identity, explicit fallback, package-contract, and changelog guidance; the review remained read-only. (AGENTS.md:1, 238e813f3e96)
  • Current main still needs the contribution: Fetched main exposes cloneTree with required native support and only APFS/Btrfs/ReFS backends. Its tree inventory lacks the new public copy module and XFS backend. Merged feat(clone): add native APFS, Btrfs, and ReFS directory cloning #293 supplies the earlier clone implementation, not the requested additions. (src/clone.ts:9, 2175dcb2d0f6)
  • Released API compatibility: The v0.9.0 package exports neither /clone nor /copy, confirming that the renamed subpath is unreleased. The tag resolves to 0fc5776. GitHub contents inspection recovered the release blob after local promisor retrieval failed. (package.json:40, 0fc5776a510d)
  • Prior findings addressed: Compared the captured previous review with the current source and GitHub's exact-head commit patch. POSIX readlink now returns Buffer bytes, with a raw-byte regression; APFS timestamp repair now traverses directories bottom-up without following symlinks. Root/nested/empty-directory assertions remain, and the supplied current-head macOS native check is successful. (src/copy-tree-portable.ts:84, 238e813f3e96)
  • Captured production-path proof: The supplied body snapshot records real WSL2 XFS runs through the built public copyTree API. Reflink-enabled runs share 1,052,673 bytes with matching hashes and independent writes; disabled-reflink strict copying refuses with no destination, while auto/never produce separate extents. Cancellation after observed destination activity settles before same-path reuse. The proof script was inspected, not executed. The body also supplies before/after raw-link observations for the final repair. (scripts/clone-xfs-proof.mjs:138, 238e813f3e96)
  • Filesystem and supply-chain review: Inspected native worker settlement, exclusive creation, descriptor-relative traversal, owned cleanup, fallback classification, and the documented immutable-source/caller-controlled namespace boundary. CI adds disposable XFS fixtures without new Action references or broader token permissions; package dependencies and lifecycle scripts are unchanged. (native/src/clone_linux.rs:343, 238e813f3e96)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T03:28:30.893Z sha 304a01b :: blocked before merge. :: [P2] Preserve raw POSIX symlink target bytes

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@steipete
steipete merged commit 6896301 into main Sep 13, 2026
33 checks passed
@vincentkoc
vincentkoc deleted the codex/xfs-tree-clone branch September 25, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant