Repository navigation
feat(root): add guarded file copies and clone strategies - #302
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: blocked before merge. Reviewed September 13, 2026, 1:11 AM ET / 05:11 UTC (Revision 4). ClawSweeper reviewWhat this changesExtends guarded file copying with Root sources, exclusive publication, cancellation, publication receipts, and optional native cloning. Merge readiness⛔ Blocked before merge - 3 items remain This PR provides distinct functionality absent from current main. Earlier documentation and archive-test findings are resolved, and no new blocking code defect was found; the intentional recovery-contract change still needs maintainer acceptance. Priority: P2 Review scores
Verification
How this fits togetherfs-safe's Root API confines filesystem operations to a trusted directory. File copies admit a source descriptor, prepare independent destination data, and publish it through guarded native or JavaScript writers. flowchart TD
A[Path or source Root] --> B[Source admission and identity checks]
B --> C[Bounded copy or native clone]
C --> D[Private destination stage]
D --> E[Authority and destination checks]
E --> F[Atomic publication and receipt]
F --> G[Preserve published destination]
D --> H[Clean unpublished stage on failure]
Decision needed
Why: This deliberately changes an existing recovery contract; documentation and tests establish the behavior but cannot establish maintainer acceptance of the upgrade impact. Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep completed publications protected from rollback deletion, with explicit maintainer acceptance and clear recovery guidance for existing callers. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature request; current main lacks the proposed options, and the supplied public-API cancellation output demonstrates the changed runtime path. Is this the best way to solve the issue? Yes, extending the existing guarded writer and sharing clone policy is a coherent solution; the intentional recovery change needs explicit acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1aa2149e27f5. 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 (3 earlier review cycles)
|
dee07a2 to
f8e1920
Compare
f8e1920 to
e9ee8d7
Compare
e9ee8d7 to
4602173
Compare
What Problem This Solves
Consumers cannot currently copy a file exclusively through
Root.copyIn, copy directly from another guarded Root, or cancel an in-flight copy. They must buffer the entire file forRoot.createor manage source admission, copying, permissions, and cleanup themselves. This affects worktree provisioning and workspace attachments in OpenClaw.Why This Change Was Made
Extends the existing
Root.copyInowner with guarded source capabilities, completed-file exclusive publication, bounded positional reads, cancellation, and optional native file cloning. Copying uses the shared guarded write loop and existing staged-file lifecycle. File data remains independent between source and destination.The source capability needs only
openandstat; callers can supply their existing read-only Root facade. An omittedsourceHardlinksoption retains that Root's read default, while explicit allow/reject overrides remain effective. Source read policies and destination mutation policies stay with their respective Root owners, including final-symlink checks before publication.Root.copyInandcopyTreefrom #301 share theCopyCloneModepolicy and validation through a small module that does not load the tree runtime. Root keeps its guarded regular-file admission and publication contract;copyTreekeeps its separate caller-owned immutable-tree and metadata contract. File cloning does not introduce Btrfs subvolume semantics into ordinary file copies.User Impact
Existing pathname sources, replacement defaults, mode selection, and durability behavior remain supported.
overwrite: falsepreserves existing files, including unreadable files, and publishes only completed contents. The native writer uses no-replace rename; the guarded Node fallback links the completed private stage and removes its temporary name in the same JavaScript turn. That fallback requires filesystem hardlink support and never links the source file to the destination.cloneacceptsauto,always, ornever. Root defaults tonever, using ordinary positional reads and writes without explicit cloning or copy offload; tree copying retains itsautodefault. Automatic file copying may use native cloning or Linux copy offload before ordinary byte copying. APFS and supported Linux filesystems can clone files. Windows and older native bindings use bounded byte copying forneverandauto;alwaysreports unavailable cloning. Native binding configuration's separaterequiremode is unchanged.preserveSourceModeuses the admitted source descriptor; a numeric per-call mode or Root default takes precedence.Cancellation waits for admitted work to settle before cleanup. A synchronous
onDestinationPublishedcallback records the destination path and exact bigint device/inode identity before later checks can fail. Published destinations are preserved after cancellation or subsequent failure; the receipt records an outcome and does not authorize deleting later edits. Source identity is checked, while coherent snapshots still require the caller to keep source contents unchanged. Existing calls without new options must also account for post-publication source-verification failure rejecting with the completed destination retained. Archive merges remain incremental and never gain a separate rollback owner.The native transfer retains close-on-exec descriptors, keeps ownership of failed-copy descriptors through settlement, and reports incomplete clone cleanup instead of hiding it behind automatic fallback. The existing Linux copy-range source-inspection failure also no longer leaves a newly created file. On Windows, file copies preserve their published destination when final permissions or synchronization fail; existing buffer and stream write cleanup behavior remains intact.
Evidence
The combined required-native selection passed every file-copy, tree-copy, clone, TAR-buffer, source-policy, authority, and publication case. Its sole failure was the unchanged append-authority test's expensive Buffer comparison. Full
pnpm checklikewise passed 8,896 tests with 101 skips and failed only that comparison. Replacing it with exactBuffer.equalspreserved all dispatch, refusal, length, and content assertions; the same isolated command then passed all four tests. No timeouts, thresholds, retries, or expected failures changed.Public
Root.copyIntests observe actual native transfer methods:neveruses ordinary copying and APFSautouses cloning. Strictalwayscopying verifies APFS shared clone IDs, complete contents despite an advanced source offset, and independent subsequent writes. The Rust Linux matrix requiresneverto report ordinary copying, so copy-offload dispatch is covered on CI.The combined current-main native addon and package builds passed. All 80 Rust workspace tests passed, including file strategies, source growth limits, descriptor ownership, and cancellation. Documentation examples, regenerated public API inventory, package checks, filesystem boundary checks, size limits, and whitespace checks passed.
A public-API run canceled an observed in-flight 256 MiB native copy and found no remaining temporary or destination entry after rejection:
{"bytes":268435456,"observedRunningStage":true,"outcome":"canceled","remainingEntries":0}Four Windows-writer permission/sync failure regressions reproduced a missing published destination before the repair and then passed with preserved receipts, data, and settled handles. Existing native and musl CI jobs explicitly run the copy, parent-policy, authority, dispatch, and publication suites; runner fanout is unchanged.
Source-swap coverage still requires
path-mismatchand verifies the retained published inode, admitted bytes or later edit, replacement source, and moved original source. Guarded sources retain omitted hardlink defaults while explicit allow/reject overrides remain effective.The copy matrix's 262,175-byte fixtures remain byte-identical. Seed filling and exact
Buffer.equalsassertions reduced the four focused coverage cases from 1,462–1,839 ms to 34–56 ms without changing timeouts or coverage thresholds.Fresh independent reviews are clean through P2 for the full copy composition and Windows repair, source/default recovery corrections, unified file/tree policy, and the final one-line append comparison repair. Final exact-head cross-platform CI and coverage are green.
Related: #296, #297. No version bump or release is included.
CHANGELOG.mdupdated when release-relevantCurrent-main integration
Rebased onto #303 without changing any executable or test patch in this PR; the only conflict was release-note context. The combined source preserves structured Windows permission checks and encoded append handling. Focused copy, authority, encoded-append, and permission verification passed 187 tests with four platform skips; build, docs, package, boundary, and size checks passed. The previous exact copy head passed all 15 CI jobs, platform coverage and aggregate thresholds, CodeQL, and benchmarks. The rebased head passed its complete CI and coverage runs on the first attempt.
Maintainer decision: accept the documented publication-retention contract for existing and new
copyIncalls. Completed destinations remain after late verification, cancellation, or metadata failure; caller-owned recovery must inspect current state before taking another action. Incremental archive merges follow that same contract. File and tree copying shareCopyCloneModeand retain their separate admission, metadata, and publication responsibilities.Final head
460217368a5ed841100b6eb2a427ec24739e067cpassed all 15 CI jobs, every platform and aggregate coverage, CodeQL, and benchmarks, without retries or cancellations. Earlier macOS setup-only cancellations on the prior head were recovered before its checks passed; no source failure was attributed to those cancellations.