Skip to content

fix(copy): return read-write descriptors for native clones - #844

Merged
steipete merged 4 commits into
mainfrom
codex/fix-clone-descriptor-access
Oct 7, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/fix-clone-descriptor-access

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes EBADF when a consumer reads or writes the owned descriptor returned by a successful native copyRootFileSync clone. 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 0400 and 0444, 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

  • Synthetic reproduction with published 0.24.1 on Linux/Btrfs under Node 26.8.2 and Bun 1.4.3: clone: "auto" and "always" returned write-only descriptors, and immediate hashing failed with EBADF. Ordinary copy controls passed. The unmodified OpenClaw plugin-source capture caller reproduced the same read failure.
  • The isolated fixed Linux build passes the same synthetic Node/Bun replay: clone descriptors are read/write, immediate hashes match the 65,537-byte fixture, descriptor writes succeed, and source contents remain unchanged. The unmodified consumer also passes; the focused Btrfs copy suite passed 52 tests with one platform skip.
  • Four macOS/APFS regression cases failed against the published binding with EBADF on write, including source modes 0400 and 0444. After rebuilding the native binding, FS_SAFE_NATIVE_MODE=require pnpm test test/copy-root-file-sync.test.ts test/native-publish-equivalence.test.ts passed: 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 check on 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.
  • Independent source review and isolated Codex autoreview found no actionable P0/P1 findings. Exact-head CI passed before merge.

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.each where their existing capability checks require TestContext. Those tables now use it.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.equals comparison 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 with try_update would 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 exact cargo clippy --workspace --locked -- -D warnings command passes on Rust 1.100 nightly; the annotated API initializer also compiled and preserved allocation/overflow behavior under -D warnings on 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.

  • 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

@clawsweeper

clawsweeper Bot commented Oct 7, 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 October 7, 2026 01:13
@steipete
steipete requested a review from a team as a code owner October 7, 2026 01:13
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 10:58 PM ET / October 7, 2026, 02:58 UTC (Revision 6).

ClawSweeper review

What this changes

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with convincing cross-platform behavior evidence and preserved safety checks is ready for ordinary landing gates.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured evidence exercises the changed native copy paths on Linux/Btrfs and macOS/APFS, showing published-version descriptor failures followed by successful reads, hashes, writes, and preserved source modes/content with the repair. No stored-data format changes require migration proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured evidence exercises the changed native copy paths on Linux/Btrfs and macOS/APFS, showing published-version descriptor failures followed by successful reads, hashes, writes, and preserved source modes/content with the repair. No stored-data format changes require migration proof.
Evidence reviewed 7 items Policy and patch scope: Read the full root AGENTS.md and CONTRIBUTING.md. Only the root AGENTS.md exists; no maintainer-notes directory was present. Applied the guarded-helper, identity, compatibility, regression-test, and release-note guidance.
Introduced changes and existing contract: Inspected the complete pinned introduced diff. docs/copy.md promises a readable/writable owned descriptor. Linux changes exclusive creation to RDWR; macOS retains the original pin during normalization, compares the replacement descriptor's complete security receipt, and preserves post-publication handoff checks.
Still necessary on main and release: Current main still creates Linux clone targets with WRONLY and returns the original read-only macOS clone pin. Inspection of v0.24.1 also confirms Linux WRONLY creation; this PR is open and unmerged.
Findings None None.
Security None None.

How this fits together

fs-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]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +20 net lines; tests and fixtures +29 net lines Production growth supports the guarded macOS descriptor transition and scoped Rust compatibility allowance.

Technical review

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded public copy-contract defect affecting immediate reads or writes through native clone descriptors.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured evidence exercises the changed native copy paths on Linux/Btrfs and macOS/APFS, showing published-version descriptor failures followed by successful reads, hashes, writes, and preserved source modes/content with the repair. No stored-data format changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence exercises the changed native copy paths on Linux/Btrfs and macOS/APFS, showing published-version descriptor failures followed by successful reads, hashes, writes, and preserved source modes/content with the repair. No stored-data format changes require migration proof.

Evidence

What I checked:

  • Policy and patch scope: Read the full root AGENTS.md and CONTRIBUTING.md. Only the root AGENTS.md exists; no maintainer-notes directory was present. Applied the guarded-helper, identity, compatibility, regression-test, and release-note guidance. (AGENTS.md:1, bda27bc72ce0)
  • Introduced changes and existing contract: Inspected the complete pinned introduced diff. docs/copy.md promises a readable/writable owned descriptor. Linux changes exclusive creation to RDWR; macOS retains the original pin during normalization, compares the replacement descriptor's complete security receipt, and preserves post-publication handoff checks. (native/src/unix.rs:1166, bda27bc72ce0)
  • Still necessary on main and release: Current main still creates Linux clone targets with WRONLY and returns the original read-only macOS clone pin. Inspection of v0.24.1 also confirms Linux WRONLY creation; this PR is open and unmerged. (native/src/unix.rs:475, b749881fd7a6)
  • Real platform behavior proof: The captured PR body reports published-version EBADF failures and successful fixed-build replay through copyRootFileSync on Linux/Btrfs under Node and Bun, including matching hashes, successful descriptor writes, unchanged source contents, and an unmodified consumer. It also reports macOS/APFS before/after failures and recovery for read-only source modes 0400 and 0444. These exercise the changed native clone owner; tests and CI are supplemental. (bda27bc72ce0)
  • Feature history and routing: Merged feat(copy): add a synchronous guarded clone-capable file copy #839 added the synchronous copy API; subsequent current-main history includes expected-source-identity support. GitHub commit metadata identifies steipete as the author of the merged feature commit. Deeper local blame and follow-history inspection encountered unavailable historical blobs, so no source-line introduction pointer is asserted. (src/copy-root-file-sync.ts:89, 3bdcb003d6a1)
  • Review continuity and check state: The prior completed review examined this same head and retained no findings or published rank-up moves. The changelog conflict was reported resolved in the supplied discussion. Live GitHub inspection confirms the PR remains open at the pinned head; the Windows diagnostic retry remains in progress at https://github.com/openclaw/fs-safe/actions/runs/37561700942. The reported timeout concerns an unchanged ACL fixture and supplies no introduced defect. (bda27bc72ce0)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (5 earlier review cycles)
  • reviewed 2026-10-07T01:17:23.361Z sha a760dea :: needs changes before merge. :: none
  • reviewed 2026-10-07T01:35:33.567Z sha 1dc2f1c :: blocked before merge. :: none
  • reviewed 2026-10-07T01:50:10.649Z sha 632ba0f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T02:18:26.513Z sha f539cfb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T02:35:42.873Z sha bda27bc :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient Contributor real behavior proof is sufficient. label Oct 7, 2026
@steipete
steipete force-pushed the codex/fix-clone-descriptor-access branch from 1dc2f1c to 632ba0f Compare October 7, 2026 01:37
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the changelog-only conflict with current main in 632ba0fb8591f187c7d31cfb70a7426313a1f419, preserving both release-note entries. The native repair and regression-test contents are unchanged from the Linux-verified files.

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.

@steipete
steipete merged commit 2c527ef into main Oct 7, 2026
55 of 56 checks passed
@steipete
steipete deleted the codex/fix-clone-descriptor-access branch October 7, 2026 03:12
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