Repository navigation
fix: pass ReadableStreams through a forwarded or queued call - #296
Conversation
🦋 Changeset detectedLatest commit: 57eef2d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
Superseded by the review of
ac672cbc.
This review, of 45abd58b
✅ Approved — A small, well-reasoned fix that matches the existing "params" branch and has tests that go through the public API; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
In the "owned" branch, getHookForReadableStream (src/core.ts:1039-1041) now creates a fresh hook where it used to throw. This matches the "params" branch. Both callers expect a hook: createPipe in serialize.ts, and the code in core.ts that pushes the hook onto hooks. The new tests cover the return path and the send path through a forwarded stub. WritableStream still throws, as the description says; that is a planned follow-up.
📝 Documentation: ✅ LGTM
The changeset entry and the inline comment describe the change accurately.
Reviewed commit: 45abd58b
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-forward-readable-streams.pr.capnweb.com (commit 57eef2d)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
A ReadableStream threw "owned payload shouldn't contain raw ReadableStreams" whenever it was serialized from an owned payload: passed to or returned from a stub that forwards to another session, or passed in a call made through a pending RpcPromise. The same went for a Request or Response body. The throw asserted an invariant that never held. An owned payload keeps the raw stream, whether parsed off the wire or deep-copied, with a hook in `hooks` only so that disposing the payload cancels a stream nobody read. Create a new hook in that case, as for params. The payload's own hook does not need sharing: it only cancels a stream that is still unlocked, and createPipe() locks the stream while the payload is serialized. WritableStream has the same throw but needs a dup of the payload's existing hook, so it is left for a follow-up.
45abd58 to
ac672cb
Compare
There was a problem hiding this comment.
Superseded by the review of
f0efe7db.
This review, of ac672cbc
✅ Approved — A small, well-reasoned fix with tests for the return and send paths through a forwarded stub; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
In the "owned" branch, getHookForReadableStream in src/core.ts now creates a fresh hook where it used to throw. This is the same thing the "params" branch does. The new tests cover a stream that is returned through a forwarded stub and a stream that is passed through one. Since the last review, only the changeset file has changed.
📝 Documentation: ✅ LGTM
The changeset entry and the inline comment describe the change accurately.
Reviewed commit: ac672cbc
A stream the session returns does not reach the gadget UI frame: capnweb cannot forward one from the server's session into the frame's (cloudflare/capnweb#296). Google states an image's length, which still bounds what is read.
The previous commit let an owned payload hand out a new hook for a stream in every case. That is right when the payload is serialized, since createPipe() locks the stream at once. It is wrong when the stream is deep-copied out of the payload: the copy and its source then each cancel the one stream on disposal, with no shared refcount, and streams arrive empty with no error. Nested map(), map() on a settled result, and `await p.stream` followed by disposing `p` all did this. Throw in deepCopy() instead, as main did, with an accurate message. Sharing a refcount needs a stream-to-hook lookup, which is left for a follow-up along with WritableStream (#297).
There was a problem hiding this comment.
Superseded by the review of
c10a31a5.
This review, of f0efe7db
✅ Approved — A focused fix. The serialize path now gets a new hook, the deep-copy path still refuses with a clear error, and tests cover both paths. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns in this change.
📖 AGENTS.md: ✅ LGTM
No agent instruction files are affected.
📋 Code Quality: ✅ LGTM
The owned branch of getHookForReadableStream (src/core.ts:1038-1042) now creates a new hook, as the params branch does. The serializer hands that hook straight to createPipe, which locks the stream, so the payload's own hook can't cancel it mid-pump. The new guard in deepCopy (src/core.ts:1175-1179) fires only when the owner is owned, so ensureDeepCopied is unaffected: it copies while the source is still params or return. Request and Response bodies go through deepCopy, so they hit the same guard. The tests cover the return and send paths through a forwarded stub, and the refused copy.
⚡ Performance: ✅ LGTM
No performance concerns in this change.
📝 Documentation: ✅ LGTM
The changeset entry and the inline comments match the behavior.
Reviewed commit: f0efe7db
A stream the session returns does not reach the gadget UI frame: capnweb cannot forward one from the server's session into the frame's (cloudflare/capnweb#296). Google states an image's length, which still bounds what is read.
A stream the session returns does not reach the gadget UI frame: capnweb cannot forward one from the server's session into the frame's (cloudflare/capnweb#296). Google states an image's length, which still bounds what is read.
|
@teamchong re the tried dup-ing the existing hook instead. it fixed that case but leaked when the same property was read twice, and missed streams that came in through a nested promise. so f0efe7d keeps that path throwing like it does on main (clearer message, plus a test for the rejection), and this PR is just forwarding. making it actually work is #303, your test would go there. |
A stream the session returns does not reach the gadget UI frame: capnweb cannot forward one from the server's session into the frame's (cloudflare/capnweb#296). Google states an image's length, which still bounds what is read.
ndisidore
left a comment
There was a problem hiding this comment.
🤖 Self-review by an AI agent (Claude Code /code-review, high effort). Five inline comments: one behaviour regression on the new branch, the rest low severity. Each repro was run on the Node project against this head and against main. Cancel, error and dispose-without-reading all propagate through the hop with clean stats in both sessions.
There was a problem hiding this comment.
Superseded by the review of
57eef2d3.
This review, of c10a31a5
✅ Approved — This is a focused fix with no issues found. Serialized streams get a new hook, copying a stream out of an owned payload still throws with a clearer message, and tests cover forwarding, a call through a pending RpcPromise and the refused copy.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns in this change.
📖 AGENTS.md: ✅ LGTM
No agent instruction files are affected.
📋 Code Quality: ✅ LGTM
Serialize path: the owned branch of getHookForReadableStream (src/core.ts:1038-1042) now creates a new hook, the same way the params branch does. The serializer pipes the stream through that hook. The pipe locks the stream immediately, so the payload's own hook can't cancel it.
Deep-copy check: when the owner is owned, the check in deepCopy (src/core.ts:1175-1179) still throws, as on main, now with a clearer message. ensureDeepCopied is unaffected.
Tests: they cover a stream returned and a stream passed through a forwarding stub, a call queued on a pending RpcPromise, and the refused copy.
⚡ Performance: ✅ LGTM
No performance concerns in this change.
📝 Documentation: ✅ LGTM
The changeset entry and the inline comments match the code's behaviour.
Reviewed commit: c10a31a5
There was a problem hiding this comment.
✅ Approved — A focused fix with no issues found. Serializing an owned payload gives the stream a new hook. Copying a stream out of an owned payload still throws, now with a clearer message, and the new tests cover the queued Request body path.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns in this change.
📖 AGENTS.md: ✅ LGTM
This pull request doesn't touch any agent instruction files.
📋 Code Quality: ✅ LGTM
- Serialize path (
src/core.ts:1038-1042): when the payload is owned,getHookForReadableStreamnow creates a new hook, the same way it does for params. Its only callers are the serializer paths insrc/serialize.ts. The pipe locks the stream as soon as it is created, so the payload's own hook can't cancel it. - Deep-copy refusal (
src/core.ts:1175-1179):deepCopythrows for an owned payload before it reachesgetHookForReadableStream. ARequestbody copied out of an owned payload is refused the same way. The message matches what the new test checks for. - Tests: they cover:
- a stream returned through a forwarding stub, and a stream passed through one;
- a
ReadableStreamand aRequestbody sent in a call through a pendingRpcPromise; - the refused copy, which also checks that the result's own stream still reads.
⚡ Performance: ✅ LGTM
No performance concerns in this change.
📝 Documentation: ✅ LGTM
The changeset entry and the inline comments match what the code does.
Reviewed commit: 57eef2d3
A
ReadableStreamthrewowned payload shouldn't contain raw ReadableStreamswhenever it was serialized from an owned payload: passed to or returned from a stub that forwards to another session, or passed in a call made through a pendingRpcPromise. Same for aRequestorResponsebody. The throw asserted an invariant that never held: an owned payload keeps the raw stream, parsed off the wire or deep-copied, with a hook inhooksonly for disposal.Fixes #228.
Requestbody andBlobpaths inserialize.ts.createPipe()locks the stream at once, so the payload's own hook can't cancel it mid-pump. Holds with fix: release call arguments once a forwarded or queued call is sent #294, which disposes forwarded args after send.deepCopy(), with an accurate message. Coversawait p.streamon a settled result andmap()over stream fields.map(),map()on a settled result,await p.streamthen disposep). Dup'ing the payload's hook fixed those but leaked when the same property was read twice, and missed streams delivered through a nested promise. Needs a real stream-to-hook lookup. Follow-up in A ReadableStream can't be read off a settled result or through map() #303, alongside WritableStream cannot be passed or returned through a forwarded stub #297.WritableStreamnot included (WritableStream cannot be passed or returned through a forwarded stub #297). Same throw, but a new hook is wrong there: the stream is already locked by its writer, or is a proxy over an import the payload disposes.Promise.all([p, p.stream]), used to throw; the second stream now hangs or arrives empty. That is Sending a locked ReadableStream hangs the receiver instead of erroring #295 reached a new way.Requestbody passed in a call through a pendingRpcPromise, and the refused copy, which also checks the result's own stream still reads. The first four fail on main; the last fails without the guard.Request/Responsebodies through a hop, the proxy shapes from the ReadableStream cannot be returned through a forwarded stub #228 comment, errors propagating through the hop.