Repository navigation
runtime: observe bodyUsed and match workerd's body errors (#115, #116, #117) - #124
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 21 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
ryuzdev
force-pushed
the
fix/workerd-diff-bodies
branch
from
November 22, 2026 16:52
48ef12d to
c0cb91a
Compare
- bodyUsed is the Fetch observation again: a Response/Request body stream that is disturbed (a read or cancel through any reader) reports true mid-stream, so a guard re-checking it is no longer bypassed (#115). The prototype accessor is getter-only, as workerd's readonly property is; runtime code marks the explicit half (_bodyUsed) through __markBodyUsed: buffered-body consumers, host-stream transfers, subrequest forwards and cache.put(). - clone() of a consumed, disturbed or locked body throws workerd's TypeError("This ReadableStream is currently locked to a reader,") instead of "Body has already been consumed" (#116). The gate stays stricter than workerd's after a manual read plus releaseLock(), which workerd lets through with empty bodies. - A body stream chunk that is not bytes, a view or an ArrayBuffer now rejects every consumer with TypeError("This ReadableStream did not return bytes.") before any bytes are returned, instead of a RangeError from the byte arithmetic (#117). A chunk's window is read from internal slots through the captured %TypedArray%/DataView prototype getters, and the chunk is classified by its prototype chain, so own buffer/byteOffset/byteLength properties a guest defines on a view cannot pad the body, read another window, or throw. - Request.prototype.bytes() and Response.prototype.bytes() exist, so bytes() is covered like the other consumers. - workerd-diff: six new agreeing cases (body-used-reader, res-body-used, clone-consumed, string-chunks, string-chunks-response, body-chunk-shadows); 31/31 agree.
ryuzdev
force-pushed
the
fix/workerd-diff-bodies
branch
from
November 22, 2026 17:23
c0cb91a to
04b1086
Compare
This was referenced Nov 22, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #115, #116, #117.
Three body-lifecycle divergences the workerd differential harness found, fixed
in
crates/cello/js/harness.js, with each repro added to the gate(
scripts/workerd-diff).#115 —
bodyUsedobserves the streamrequest.bodyUsed/response.bodyUsedwere plain state that only theruntime's own consumers set, so a Worker that held a reader, or had read part
of a live request body, still saw
falseand any guard re-checking the flagmid-stream was bypassed.
bodyUsedis now a getter-only prototype accessor onRequestandResponse(spec: true when the body is non-null and its streamis disturbed), as workerd's readonly property is, with
_bodyUsedas theexplicit half that only runtime code marks through
__markBodyUsed(buffered bodies, host-stream transfers,
cache.put()). Merely holding a reader is not a disturbance — workerdreports
falsethere, and the new case pins that too.#116 —
clone()messageBoth clones still refuse a consumed, disturbed or locked body, but now throw
workerd's
TypeError: This ReadableStream is currently locked to a reader,instead of
Body has already been consumed. Workerd gates on the streambeing locked (its own Body consumers leave it locked, which is why a
consumed body reports this message); cello keeps the stricter gate, because
after a manual read plus
releaseLock()workerd lets the clone through andhands both sides empty bytes, dropping the payload already read. That
difference is documented in place; the refusal itself is unchanged.
#117 — non-byte body chunks
text(),json(),formData(),blob(),arrayBuffer(),bytes()anda subrequest body all drain through
__drainBody. A string chunk madelengthNaN, so the target array was empty andbytes.set("alpha", 0)threw the
RangeError: offset is out of boundsthe issue reports. The drainnow validates each chunk and rejects with
TypeError: This ReadableStream did not return bytes.before any byte isreturned, exactly as workerd does;
ArrayBufferand everyArrayBufferViewchunk are accepted.Request.prototype.bytes/Response.prototype.bytesdid not exist (Fetch'sundecoded-bytes accessor); they do now, so the
bytes()consumer path iscovered like the others.
A chunk's window is read from internal slots only: the drain classifies the
chunk by its prototype chain and takes
buffer/byteOffset/byteLengthfrom the captured
%TypedArray%/DataViewprototype getters, so ownbyteLength/byteOffset/bufferproperties a guest can define on a viewcannot pad the body, read another window, or throw.
The response/host path is unchanged on purpose: with string chunks it writes
their UTF-8 bytes, which is what workerd does (verified:
alphabeta).Cello's host pump already settles a mid-stream body error by closing the
host stream — a returning Worker's chunk is written, then the response is
truncated and the connection closed (observed:
curlreturns the partialbody in 29 ms, no hang).
Tests
body-used-reader(drains every chunk),res-body-used,clone-consumed,string-chunks,string-chunks-response,body-chunk-shadows. Full gate: 31/31.crates/cello/js/harness.jsreverted and the new casesin place:
body-used-reader:during/afterfalse vs workerdtrue.res-body-used: same, for buffered and streamed bodies.clone-consumed:Body has already been consumedvs workerd's message.string-chunks: 500 (nobytes();text()reportedRangeError: offset is out of bounds, the transcript in workerd diff: a Response body built from string chunks throws RangeError instead of TypeError #117).body-chunk-shadows: cello padded the body with 4093 NULs from ashadowed
byteLength("abc\u0000…), workerd"abc".cargo test --profile ci --locked -p cello, clippy,cargo fmt --check,node scripts/check-docs.mjs.## Unreleasedindocs/changelog.md.Not changed (found, out of scope)
new Response(["alpha"]).text(): workerd builds a byte stream from theiterable and throws the same
TypeError; cello stringifies iterables whosechunks are not bytes.
Body has already been used....cache.put()over a string-chunk body still reaches theRangeErrorpathin
cache.js's own capped drain.