Skip to content

fix(copy): recover from initial zero Linux offload results - #306

Merged
steipete merged 2 commits into
mainfrom
codex/copy-offload-eof
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/copy-offload-eof

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where consumers using Root.copyIn(..., { clone: "auto" }) on Linux could publish an empty file when copy_file_range initially returned zero despite readable source data. The shared range-copy path could also make exclusive publication fail instead of selecting its ordinary-copy fallback.

Why This Change Was Made

The native helper now confirms an initial zero result with a one-byte positional read. Confirmed EOF keeps the existing empty-file result; readable data selects the existing fallback outcome. The probe checks cancellation before and after reading, retries EINTR, and preserves file positions and caller-owned cleanup.

Rust std and Go likewise distinguish an initial zero offload result from ordinary EOF. The regression exercises our own public APIs and native binding; it introduces no production testing hook.

User Impact

Automatic Linux file copies and exclusive publication preserve readable bytes under this offload failure. Empty files, byte limits, source positions, independent destination writes, and cancellation settlement retain their existing contracts. An additional positional read occurs only when the first offload result is zero.

The historical kernel condition is modeled using syscall-result injection confined to a test-owned Node child. The host did not exhibit the fault naturally. The Linux CI job installs strace and runs the same proof after building the package and host binding.

Evidence

  • Before: the canonical proof passed all seven ordinary cases, then failed its first injected case: Root.copyIn returned success with 0 of 262,181 bytes copied. A separate zero-stat-size source reproduced 0 of 167 readable bytes copied.

  • After: node scripts/copy-offload-eof-proof.mjs passed 14 cases on WSL2 Ubuntu, Linux 6.18.33.2, Node 26.8.2. Ordinary files, empty files, readable zero-stat-size files, maxBytes: 0, both publication paths, source offsets, and independent writes were verified with and without injection. Each injected case verifies the actual native syscall was reached and altered.

  • The byte-limit case rejects with too-large and leaves no destination. The offset case preserves the caller's position at seven bytes. Ordinary copies preserve SHA-256 7c3802d20e6c52781d832c75edba896a2f3744eeb52bcdd543743c106fc132ac.

  • Scoped Rust transfer regression and three required-native Root/range-publication sibling tests passed. cargo clippy --workspace --locked -- -D warnings passed.

  • Full pnpm check passed: 274 test files, 6,721 passing tests, and 2,157 existing platform/native skips; build, docs, and package checks passed. Initial runner-only Git metadata/pnpm lifecycle failures were resolved without changing candidate source, then the complete check passed.

  • git diff --check passed. Independent P2 autoreview completed scoped-clean with no actionable P0–P2 findings.

  • Regression coverage added for the changed behavior

  • Compatibility and cancellation/cleanup contracts considered

  • CHANGELOG.md updated

  • No credentials, private paths, private hosts, or sensitive contents included

@steipete
steipete requested a review from a team as a code owner September 13, 2026 14:37
@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.

@clawsweeper clawsweeper Bot added 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. 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 13, 2026, 10:39 AM ET / 14:39 UTC.

ClawSweeper review

What this changes

Confirms initial zero-byte Linux copy-offload results before accepting EOF, and adds syscall-injection coverage to Linux CI.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main and v0.10.0 still accept an initial zero offload result as EOF. The focused repair preserves existing fallback and ownership contracts; no actionable defect was found.

Priority: P2
Reviewed head: f02a846c9da70deacde27c40183e231a6658f7db

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with relevant real-path fault-injection evidence and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.
Evidence reviewed 7 items Applicable repository policy: Read the complete root AGENTS.md and contribution/security guidance. No nested AGENTS.md or maintainer-notes directory was present. Applied filesystem-boundary, compatibility, regression-coverage, and changelog requirements; did not execute autoreview or artifact-producing checks.
Current main still contains the defect: The shared helper returns Complete(offset) for every zero result, including offset zero, without checking whether source bytes remain readable.
Latest-release comparison: The v0.10.0 implementation contains the same unconditional zero-result completion branch, so the latest supplied release does not contain this repair.
Findings None None.
Security None None.

How this fits together

fs-safe copies admitted source files into guarded destinations for Node.js applications. Its native Linux transfer helper serves both Root file copying and exclusive publication, selecting ordinary copying when offload is unavailable.

flowchart TD
 A[Admitted source file] --> B[Linux copy offload]
 B --> C{Initial result is zero?}
 C -->|Yes| D[Positional EOF probe]
 D -->|Readable data| E[Existing ordinary copy fallback]
 D -->|Confirmed EOF| F[Complete empty copy]
 C -->|No| G[Continue bounded transfer]
 E --> H[Existing verification and publication]
 F --> H
 G --> H
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and regression growth Production +24 lines; regression harness +164 lines The production addition is limited to EOF confirmation, with most growth devoted to exercising real native fallback behavior.
Reported runtime coverage 7 scenarios × 2 syscall modes = 14 cases Normal and injected runs cover content preservation, empty files, byte limits, publication, and source position.

Technical review

Best possible solution:

Retain the narrow EOF confirmation and reuse the established bounded-copy fallbacks without changing public options or publication ownership.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source establishes false completion when the first copy_file_range call returns zero for readable data, and the contributor reports a matching injected before-fix failure. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: probing the admitted descriptor distinguishes true EOF and feeds both callers into existing fallbacks without introducing another transfer implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ebc673d41bd3.

Labels

Label changes:

  • add P2: This repairs a concrete Linux offload edge case with bounded scope; the supplied environment reproduced it through syscall injection rather than a naturally occurring production failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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): The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.

Label justifications:

  • P2: This repairs a concrete Linux offload edge case with bounded scope; the supplied environment reproduced it through syscall injection rather than a naturally occurring production failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied before/after WSL2 results exercise Root.copyIn, exclusive publication, and the real native binding under verified syscall-result injection, reporting recovered bytes and preserved limit/offset behavior across 14 cases; the inspected harness matches the changed transfer owner.

Evidence

What I checked:

  • Applicable repository policy: Read the complete root AGENTS.md and contribution/security guidance. No nested AGENTS.md or maintainer-notes directory was present. Applied filesystem-boundary, compatibility, regression-coverage, and changelog requirements; did not execute autoreview or artifact-producing checks. (AGENTS.md:25, f02a846c9da7)
  • Current main still contains the defect: The shared helper returns Complete(offset) for every zero result, including offset zero, without checking whether source bytes remain readable. (native/src/file_copy.rs:275, ebc673d41bd3)
  • Latest-release comparison: The v0.10.0 implementation contains the same unconditional zero-result completion branch, so the latest supplied release does not contain this repair. (native/src/file_copy.rs:275, ac371ee74846)
  • Bounded repair and fallback composition: The introduced probe uses the already-admitted descriptor, preserves its cursor, retries EINTR, and checks cancellation around the read. Readable data returns the existing Unsupported outcome; Root resumes bounded positional copying, while exclusive publication cleans its attempted target and selects the established ENOTSUP fallback. (native/src/file_copy.rs:275, f02a846c9da7)
  • Real behavior evidence: The supplied PR-body snapshot, sourceRevision 1a4694f10f3d1b5a48180000cc1b8f6ee9ba3fdbd892fef51d6e65da723efd1a, reports a WSL2 Ubuntu run on Linux 6.18.33.2 and Node 26.8.2: before-fix injected copying produced 0 of 262,181 bytes; after-fix execution passed seven ordinary and seven injected cases. Reported observations include matching content hashes, zero-stat-size readable sources, too-large rejection with no destination, publication recovery, and preserved source position. The fully inspected script invokes actual public APIs/native binding and verifies that strace reached and altered copy_file_range. This review did not execute the script. (scripts/copy-offload-eof-proof.mjs:136, f02a846c9da7)
  • Existing feature history and related work: GitHub verifies feat(root): add guarded file copies and clone strategies #302 as merged at this commit, authored by steipete. Its documented contracts cover guarded sources, positional copying, cancellation settlement, and retained publication ownership. Current-main blame and the raw-parent comparison locate the shared helper in that merged work. Recent PR metadata revealed no replacement for this EOF repair. (native/src/file_copy.rs:252, 15d964198fa1)

Likely related people:

  • Peter Steinberger: Raw commit 15d9641 adds native/src/file_copy.rs:252 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 15d964198fa1; files: native/src/file_copy.rs)

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.

@steipete
steipete merged commit 4c49fb7 into main Sep 13, 2026
27 checks passed
@vincentkoc
vincentkoc deleted the codex/copy-offload-eof branch September 25, 2026 11:14
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