Repository navigation
feat(copy): add a synchronous guarded clone-capable file copy - #839
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 changes before merge. Reviewed October 6, 2026, 4:00 AM ET / 08:00 UTC (Revision 3). ClawSweeper reviewWhat this changesAdds a synchronous guarded file copy with optional native cloning, byte limits, identity checks, and an owned destination descriptor. Merge readiness⛔ Needs changes before merge - 2 items remain The synchronous copy capability remains useful and is absent from current main. The export and benchmark findings are resolved, but the previously reported writable-descriptor contract mismatch remains. Priority: P2 Review scores
Verification
How this fits togetherfs-safe guards filesystem operations on untrusted paths. This helper admits source and destination roots, copies through retained descriptors, and returns the destination descriptor for capture reads or hashing. flowchart TD
A[Source and destination paths] --> B[Root and identity admission]
B --> C[Retained source descriptor]
C --> D{Native copying available}
D --> E[Clone or native copy]
D --> F[Guarded byte copy]
E --> G[Verify identities and limits]
F --> G
G --> H[Owned destination descriptor]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Guarantee readable descriptor access across platforms while retaining the shared guarded clone and copy engine. Do we have a high-confidence way to reproduce the issue? Yes, by source inspection: successful APFS cloning returns an O_RDONLY descriptor despite the writable guarantee. No runtime reproduction was executed. Is this the best way to solve the issue? Yes, composing existing admission and copy owners is a focused solution for synchronous hooks; the descriptor documentation must match the APFS implementation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 47fc59892b45. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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 (2 earlier review cycles)
|
c285127 to
930a18d
Compare
Bind fs-safe's own admitted source descriptor to an optional exact bigint expectedSourceIdentity before destination creation, and return the verified sourceIdentity for clone, copy-file-range, and byte copies. Preserve existing admission, copying, ownership, and end-of-copy checks when the option is omitted. Close the source-identity gap between OpenClaw's caller pin and synchronous plugin capture copying. Follow-up to #839 for openclaw/openclaw#161739. Update documentation, installed-package declaration checks, regression tests, and the Unreleased changelog; regenerate the unchanged export-name API snapshot. Validation: focused portable and native APFS tests; pnpm check (17,220 passed); pnpm pack:check; isolated Codex review clean at P0-P2; exact-head all-OS CI, coverage, CodeQL, and benchmarks. One Windows package-consumer PowerShell timeout passed on a targeted same-head retry. No release.
Synchronous plugin module hooks cannot await
Root.copyIn, and fd-to-fd byte copying cannot use APFS's name-creating clone operation. AddcopyRootFileSyncto@openclaw/fs-safe/advancedfor openclaw/openclaw#161739. It retains the admitted source, creates an exclusive destination under its admitted root, and returns the owned destination descriptor for capture hashes and receipts.The public surface is one function and two types:
Both roots and paths are absolute, parents must already exist, and the destination must be absent. Source identity is checked before and after copying. Destination identity and single-link status are checked through both its descriptor and name. Failure attempts identity-checked cleanup; replacements are preserved. This is direct exclusive creation, so callers should use a private capture directory; it does not promise atomic publication, crash durability, or a coherent snapshot of concurrent in-place edits.
The N-API source inspection revealed that only
cloneFileExclusivewas synchronous:copyFileExclusiveandcopyFileRangeExclusivereturned async tasks. The new internal synchronous entry shares the existing boundedFileCopyTaskengine, including APFS cloning, Linux FICLONE/copy_file_range, the #829/#835 capability classification, and its cleanup owner. Windows and native-disabled operation compose the existing synchronous descriptor copier with guarded creation and #824's dangling-leaf preflight. Mandatory cloning without that capability reportsunsupported-platform.OpenClaw migration
In
plugin-source-file.ts, replace the descriptor-pathcopyFileSyncoptimization and descriptor byte loop insidecopyPluginSourceFilewith:Retain the existing
too-largeerror translation. The copier now performs admission itself; the copy path no longer needs the surroundingwithPluginSourceFileopen. Hashing reads the owned output, including for the clone path, and descriptor disposal does not delete the successful capture.In
plugin-generation-file-capture.ts, passcaptureRoot: directory,expectedSize: Number(stat.size), andmode: 0o600 | Number(stat.mode & 0o100n)for a new source. KeepcopiedContentasreceipt.file({ prepared: native?.content ?? copiedContent, ... }); the separate target-path chmod is absorbed by the copy. For thecapturedalias branch, call the same helper withsource: captured,boundary: directory, and the existing capture's size/mode facts, rather than the later live source's metadata. Preserve the native materialization branch and the existing path/addition/receipt bookkeeping.Validation
Rust workspace tests, Clippy, native/TypeScript builds, package and declaration checks, and 101 focused tests pass locally. Coverage includes byte, native clone and copy-range routes; the existing isolated seccomp FICLONE-EPERM test now uses the shared synchronous task preparation; maxBytes; source replacement; destination collisions; dangling Windows leaves; destination-parent substitution before fallback creation; and destination replacement/hardlink creation during mode finalization. The hosted macOS test requires
method === "clone"on APFS and verifies matching clone IDs.A preliminary local APFS run copied a synthetic 1 GiB file in 18.3 s with
never, versus 254 ms withauto, which selectedcloneand shared the source's clone ID. The clone produced no measured decrease in available filesystem space. This was under concurrent test load, not an isolated performance comparison. The optional Tart image pull was cancelled after ten minutes without an allocated lease; cleanup confirmed no remaining lease or VM.Rebased onto #838 after the native move work landed; the only conflict was the changelog, where both entries were retained. The final branch passes Codex autoreview at P0–P2. Full serial
pnpm checkpassed 17,211 tests and the package/declaration gate; a separatepnpm pack:checkalso passed. The rebased Rust workspace tests, Clippy, native/TypeScript builds, and 101 focused tests passed again.CI initially caught the missing benchmark registration and slow deep Buffer assertions under coverage. Both are fixed: 12 synchronous copy benchmark cases pass with native support off/required, and the focused native suite passes under V8 coverage using full byte equality through
Buffer.equals. Earlier local parallel-check timeouts in unchanged suites disappeared under the repository's serial setting.Final head:
930a18d50243d09245c6e52b3dd3b64c8528a3cd. All-OS CI, coverage, and CodeQL all passed on this exact head. No admin override or CodeQL rerun was needed. No release.