ReviewOS

home-lang/home

Bun.write File-to-File: port optimized Blob copy semantics

#676
Closed chris opened this 9 days ago ·
9 days ago

Follow-up to #66. While validating the poll-parked Blob I/O ownership work in #569, the unchanged pinned Bun file corpus exposed a distinct FileCopier gap.

Authoritative reproduction in the installation-shaped Home runtime:

  • Create a 200-byte regular file a.
  • Evaluate await Bun.write(Bun.file(b), Bun.file(a)).
  • Home returns 0 and leaves b at zero bytes; the source remains 200 bytes.
  • The unchanged js/bun/io/bun-write.test.js therefore fails its Bun.file -> Bun.file sequence when it expects the destination to equal exampleHtml.

This is separate from byte-backed WriteFile and ReadFile polling: the exact bun-file-read.test.ts, blob-write.test.ts, and worker_blob.test.ts files pass 16/16, and #569 covers blocked read/write task ownership.

Required completion:

  • port the regular-file Blob-to-Blob optimized copy path without falling back to JS or byte materialization;
  • preserve source/destination slice offset and length semantics;
  • return the exact copied byte count;
  • preserve truncate/createPath/error behavior and metadata updates;
  • run the complete unchanged js/bun/io/bun-write.test.js file and focused regular/sliced file-copy controls in Debug and ReleaseFast;
  • do not weaken concurrency, assertions, workloads, deadlines, or skips.
9 days ago

Completed and pushed directly to main in 2a58fe9.

What landed:

  • explicit Blob slice identity, independent of lazy cached file size, preserved by structured-clone version 4 with v1-v3 decoding compatibility;
  • exact source and destination offset/length propagation, exact copied byte counts, prefix preservation, zero-length ranges, and final truncation;
  • optimized whole-file clone/copy paths retained, with bounded Darwin/FreeBSD fallbacks and corrected Linux EOF iteration;
  • the shared NodeFS bounded read/write loop no longer falls through into the unbounded loop;
  • Windows receives the same explicit range model and uses positioned libuv I/O for ranges while retaining uv_fs_copyfile for whole files;
  • truncation/createPath/mode/error behavior remains native; truncation failures now propagate.

Verification from installation-shaped Home binaries:

  • Debug and ReleaseFast runtime builds: pass;
  • focused native file-copy matrix, including observed destination sizes, source/destination/combined/empty ranges, exact counts, and structured-cloned slices: pass in Debug and ReleaseFast;
  • unchanged upstream bun-write.test.js: 33/33;
  • unchanged Blob-name ownership + structured-clone files: 37/37;
  • full runtime regression aggregate: 69/69 in Debug and ReleaseFast;
  • native home_rt: 1,827 passed / 19 skipped / 0 failed;
  • Zig formatting and diff checks: clean;
  • scoped Pickier: 0 errors, with the existing 21 parity-plan markdown warnings only.

No assertion, workload, deadline, or skip was weakened. Execution evidence is Darwin; a Windows cross-build cannot reach runtime compilation on this host because the workspace lacks Windows zlib/Brotli/zstd link inputs, so that limitation is not represented as execution coverage. The unrelated current-main default home-tool build failure discovered during this work is tracked separately in #677.

Sign in to comment on this issue.