Repository navigation
fix(copy): return read-write descriptors for native clones - #844
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 October 6, 2026, 10:58 PM ET / October 7, 2026, 02:58 UTC (Revision 6). ClawSweeper reviewWhat this changesThe PR makes native copy descriptors readable and writable on Linux and macOS, adds regression coverage, reduces test overhead, and preserves Rust minimum-version compatibility. Merge readiness✅ Ready for maintainer review This repair remains necessary: current main and v0.24.1 retain the descriptor-access defect. The reviewed patch has no actionable correctness or security findings, and the supplied platform-specific proof supports merge readiness. Priority: P2 Review scores
Verification
How this fits togetherfs-safe copies admitted source files into guarded destinations and returns owned descriptors to callers for hashing, reading, and writing. Its native clone paths accelerate copying while preserving filesystem identity and publication checks. flowchart TD
A[Source and destination paths] --> B[Root and source admission]
B --> C[Native clone or ordinary copy]
C --> D[Normalize destination security]
D --> E[Acquire read and write descriptor]
E --> F[Verify identity and publication]
F --> G[Return owned destination descriptor]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep all copy methods consistent with the documented read/write descriptor contract while retaining guarded creation, security normalization, identity checks, and requested destination modes. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the current-main access-mode mismatch, and the supplied Linux/Btrfs and macOS/APFS before/after runs identify concrete failing operations. This review did not execute a reproduction. Is this the best way to solve the issue? Yes, repairing the native descriptor ownership path is a focused solution that preserves the existing API, defaults, permissions, and guarded publication behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c0a54d474c41. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
1dc2f1c to
632ba0f
Compare
|
Resolved the changelog-only conflict with current main in The combined copy/publication validation passed 77 tests with six platform skips, and the final branch autoreview found no actionable P0/P1 findings. This addresses the review’s conflict-resolution and refreshed-validation requests. Exact-head CI is still running. |
What Problem This Solves
Fixes
EBADFwhen a consumer reads or writes the owned descriptor returned by a successful nativecopyRootFileSyncclone. The API promises a readable/writable descriptor, but Linux clones returned a write-only descriptor and macOS clones returned a read-only descriptor.User Impact
Consumers can immediately hash, read, and update cloned copies through the returned descriptor. Read-only source files retain their contents and permissions; the requested destination mode is also preserved.
Why This Change Was Made
Linux now creates the exclusive native destination with read/write access, including the sibling copy-file-range path. macOS retains the original read-only pin while normalizing cloned permissions, flags, and ACLs, then acquires a guarded read/write descriptor inside the private stage and compares its complete security receipt before transferring ownership. This preserves cloning of sources with modes
0400and0444, as well as the existing confinement, cleanup, no-replace publication, and handoff checks.Production adds 20 net lines: 17 for the macOS ownership transition and three for the documented Rust minimum-version allowance below. Tests and fixtures add 29 net lines across the copy, directory-observation, and lock-stress boundaries.
Evidence
0.24.1on Linux/Btrfs under Node 26.8.2 and Bun 1.4.3:clone: "auto"and"always"returned write-only descriptors, and immediate hashing failed withEBADF. Ordinary copy controls passed. The unmodified OpenClaw plugin-source capture caller reproduced the same read failure.EBADFon write, including source modes0400and0444. After rebuilding the native binding,FS_SAFE_NATIVE_MODE=require pnpm test test/copy-root-file-sync.test.ts test/native-publish-equivalence.test.tspassed: 64 tests, 2 platform skips.pnpm native:test --locked darwin_security: 13 passed, covering ACL normalization, parent ACL rejection, security receipts, path replacement, and retained record locks.pnpm checkon the native repair: passed, including 17,223 tests, 777 platform/feature skips, documentation examples, and installed-package checks. The subsequent test-only corrections passed the focused macOS suites and Linux replay below.The initial broader Linux native run exposed an unchanged directory-observation test that assumed adding a child increments the parent link count. Btrfs preserves all four fields observed by the API (
nlink = 1), so the test now requires exact success for that unchanged tuple while retaining rejection for real mode/link-count changes. The same full Rust workspace command then passed, including all 140 native tests. Focused copy checks passed on both Btrfs (52 passed, one platform skip) and real tmpfs (49 passed, four platform/capability skips).Initial CI also caught the test tables using
it.eachwhere their existing capability checks requireTestContext. Those tables now useit.for, including the two matching symlink cases in the same file; assertions and capability gates are unchanged.Intel macOS Bun qualification then exposed avoidable test overhead: eight lock holders each booted a full Vitest process, and one completed child spent 32.98 seconds transforming code for 73 ms of lock work. The stress test now launches small public-API child fixtures while retaining eight processes, the 45-second watchdog, joined cleanup, and overlap assertions. The cancellation test uses the same exact
Buffer.equalscomparison already adopted by neighboring tests; a 128 KiB measurement was 181.84 ms for generic deep equality versus 0.19 ms for byte comparison, with both rejecting a last-byte mismatch. After a fresh package build, the focused Node suites passed 42 tests and full Bun 1.4.2 native qualification passed 1,307 tests across 67 files on macOS arm64. Intel macOS CI passed on the final head.A newer CI compiler also deprecated
fetch_update, but replacing it withtry_updatewould break the declared Rust 1.88 minimum: the replacement was unstable in Rust 1.88 and stabilized in 1.95. A statement-scoped deprecation allowance preserves the existing atomic operation, with an explicit removal condition at minimum Rust 1.95. The exactcargo clippy --workspace --locked -- -D warningscommand passes on Rust 1.100 nightly; the annotated API initializer also compiled and preserved allocation/overflow behavior under-D warningson Rust 1.97.1 and 1.100 nightly. CI policy and runtime behavior are unchanged.On head
bda27bc72ce0bdae994e0127301cec151384d8f6, core CI passed, including Cargo and Intel macOS. Windows Node 22 coverage passed 15,147 tests but exceeded the five-second limit in the unchanged ACL-denial fixture (5.461 seconds). One exact-job diagnostic retry completed successfully on the same head, with code, assertions, ACL principal, and timeout unchanged. All final-head checks passed before merge. The delayed external-command phase was not identified; a future recurrence warrants Windows timing proof before changing the fixture.CHANGELOG.mdupdated when release-relevant