ReviewOS

home-lang/home

Stream validation: diagnose reduced-realm failure and correct pinned read contracts

#512
Open chris opened this 9 days ago ·
9 days ago

Follow-up to #66, discovered during #510 validation. Implemented and verified on Darwin in fde7b7ebc64a2d327a1665578d4b396f8a5e93a1, pushed to codex/runtime-port as Chris Breuer without coauthors. Branch integration and other platforms remain unverified.

Corrected diagnosis

The original request to combine all queued byte chunks for an unsized Readable.read() was incorrect for our target. The exact Bun pin 4982b91e3702094330f3be3883354c52b8c01323, internal/streams/readable.ts::howMuchToRead, deliberately returns the first queued byte chunk. Home already matches that pin. Installed Bun/Node controls differ, but do not override the pinned source. No full-VM concatenation override was added.

The actual reduced-realm JSEvaluateReturnedNull concealed a module-resolution error: earlier router fixtures changed cwd without restoring it, so the stream unit could not find the upstream common module. Fixture construction now restores cwd on success/error and closes directory/file handles. The existing route test explicitly verifies cwd preservation. Node probe helpers now report the actual JavaScript exception.

The old unit’s Uint8Array identity expectation was also invalid. The reduced C-API stream implementation now wraps byte views as Buffers sharing the original backing storage/offset, as specified by pinned internal/stream.ts::_uint8ArrayToBuffer, while object mode retains value identity and Readable.from defaults to object mode. The corrected unit still imports the real unchanged upstream common; it checks normalization, Buffer identity, byte order, sized/unsized and decoded reads, and object-mode identity. The native CLI regression additionally covers DataView offsets, iterable identity and split UTF-8 decoding. The reduced stream implementation is not claimed to be fully ported.

Verification

  • Complete runtime unit suite: 1,819 pass / 19 skip / 0 fail, 1,838 total; one fuzz test discovered, not a full fuzz campaign.
  • Final native build: 17/17 steps.
  • All 54 native regression commands pass, including all 23 native regression files, full spawn (126 pass / 5 skip / 5,484 assertions) and full child-process (32 pass / 1 skip / 1 TODO / 72 assertions).
  • The corrected unit’s exact JavaScript body also returns true in the full native VM.
  • All 252 unchanged Node test-stream* fixtures were checked byte-for-byte against the pin and executed directly. Both the published parent and final binary pass 246/252, with the same six failures and no new failing filenames/statuses. All 63 focused readable/byte/object/decoder files pass.

Remaining native stream failures are separated into #513 (pinned Rust Brotli decoder-code mapping) and #514 (two pipeline timeouts and three missing internal-wrapper modules). Native stream builtins still partly use configured external builtin literals; runtime passes do not establish complete source ownership. #66 remains incomplete.

Evidence: zig-out/stream-unit-{diagnostic,fixed}.log, stream-source-integrity.json, stream-final-{binary,regressions,comparison}.json, stream-final-all-results.json, stream-exact-unit-native.json, and stream-failure-controls.json. Final executable SHA-256: efcec014d5d802ebe551d6a78549fa8b5a38d5958a89f1f39cdf630f8d056c12.

9 days ago

The dotenv checkpoint is now published in 7592a69bf4d268c5e50796e72ef86c8470026733 (#510). It does not change stream behavior or weaken the failing stream-unit assertion.

The full unit gate's exact result is 1,818 pass / 19 skip / 1 fail; both dotenv allocation tests pass. Native stream controls on this binary and parent bfdb5f3188e6a6b8f0bea7070131144f5813c046 return 5 bytes then the queued 10-byte Buffer. Installed Bun and Node return 15 bytes then null. All four runs return false for the old unit body's identity expectation. Results are preserved in zig-out/dotenv-stream-unit-controls.json; the reduced-realm exception remains separately visible as JSEvaluateReturnedNull in dotenv-unit-build3.log. #66 remains incomplete.

9 days ago

Correction to this issue’s premise: inspecting the exact pinned Git object, not inferring from installed Bun/Node, shows that howMuchToRead() at 4982b91e3702094330f3be3883354c52b8c01323 explicitly takes a byte-buffer fast path for unsized reads:

if (NumberIsNaN(n)) {
  if ((state[kState] & kDecoder) === 0 && state.length)
    return state.buffer[state.bufferIndex].length;
  // flowing-mode case, then decoded state.length
}

Home’s 5-byte then 10-byte result matches that pin. The installed Bun/Node result reflects a different implementation and does not establish a missing port. No runtime concatenation change is warranted for that probe. I am retaining both control results, correcting this issue’s scope to the actual reduced-realm exception and invalid Uint8Array identity assertion, and adding explicit pinned-source read contracts. The prior characterization of this result as an open native parity gap was incorrect.

The full unit failure still needs diagnosis and repair; it has not been counted as passing. #66 remains incomplete.

9 days ago

The repair is published in fde7b7ebc64a2d327a1665578d4b396f8a5e93a1. Full runtime units now pass 1,819 / 19 skip / 0 fail, and all 54 native regression commands pass. The issue body has been corrected and updated with the actual cwd leak, source-backed normalization, verification scope, and final binary hash. The corrected unit retains the upstream common import and its exact JavaScript also returns true in the native VM.

The final 252-file stream scan remains 246 pass / 6 fail, matching the parent exactly. Remaining native failures are #513 and #514; #66 remains incomplete. Branch integration and other platforms remain pending.

Sign in to comment on this issue.