Skip to content

Use capnweb native ReadableStream support for remote Media bindings#12582

Merged
penalosa merged 7 commits intomainfrom
penalosa/test-capnweb-streams
Feb 23, 2026
Merged

Use capnweb native ReadableStream support for remote Media bindings#12582
penalosa merged 7 commits intomainfrom
penalosa/test-capnweb-streams

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

@penalosa penalosa commented Feb 17, 2026

Use capnweb's native ReadableStream support for remote Media and Dispatch Namespace bindings.

Build configuration

  • Add conditions: ["workerd", "worker", "browser"] to esbuild embed-worker plugins so capnweb resolves to its workerd entry point

Media bindings

  • Delete the intermediary binding.worker.ts — Media bindings now use remoteProxyClientWorker directly
  • Remove evaluateMediaBinding() / isSpecialCaseMediaBindingRequest() HTTP workaround from ProxyServerWorker.ts

Dispatch namespace bindings

  • Add dispatch-namespace-proxy.worker.ts — proxy client that creates capnweb stubs with dispatch options
  • Refactor dispatch-namespace.worker.ts to delegate to the proxy client via service binding

Shared utilities

  • Add makeRemoteProxyStub() for creating capnweb-backed Fetcher proxies
  • Add remoteProxyClientWorker() script override parameter for custom proxy workers
  • Add ProxyMetadata type and RemoteBindingEnv for consistent typing

Dependencies

  • Update capnweb to ^0.5.0 via pnpm catalog

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because: existing tests cover this code, and should still work
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: Internal plumbing change, no user-facing API changes

@penalosa penalosa requested a review from a team as a code owner February 17, 2026 14:30
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 712e2eb

The changes in this PR will be included in the next version bump.

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 18, 2026

Claude finished @penalosa's task —— View job


Changeset Review

  • Read changeset guidelines
  • Review changeset file
  • Check for cute animals
  • Validate against criteria
  • Post results

⚠️ Issues found

The changeset .changeset/capnweb-streams-media-bindings.md appears to be marked as a patch for an internal refactor with no user-facing changes. According to .changeset/README.md:

When a Changeset is NOT Required

  • Changes that are purely internal refactoring with no user-facing impact

Based on the PR description and the review discussion between @penalosa and @petebacondarwin, this is described as "mostly just an internal refactoring" with the note that "Previously we 'faked' streams with Media Bindings over fetch, but now they will work properly."

Recommendation: If this is purely internal refactoring with no user-facing impact, the changeset should be removed entirely and the PR should be labeled with no-changeset-required. However, if there is a subtle user-facing improvement (streams now work properly for JSRPC calls to remote binding services), then the changeset should stay but the description should be clearer about what the actual user-facing benefit is.

The current description "Internal refactor to use capnweb's native ReadableStream support to power remote Media and Dispatch Namespace bindings" reads as purely internal with no user impact, which contradicts having a changeset at all.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 18, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12582

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12582

miniflare

npm i https://pkg.pr.new/miniflare@12582

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12582

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12582

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12582

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12582

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12582

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12582

wrangler

npm i https://pkg.pr.new/wrangler@12582

commit: 712e2eb

@penalosa penalosa marked this pull request as draft February 18, 2026 09:36
@penalosa penalosa changed the title [miniflare][wrangler] Use capnweb native ReadableStream support for remote Media bindings Use capnweb native ReadableStream support for remote Media bindings Feb 18, 2026
@penalosa penalosa force-pushed the penalosa/test-capnweb-streams branch 7 times, most recently from 4d0a95b to 87328d7 Compare February 19, 2026 09:46
@penalosa penalosa marked this pull request as ready for review February 19, 2026 18:45
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 😄 looks good to me 🙂

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Feb 19, 2026
"wrangler": patch
---

Use capnweb's native ReadableStream support for remote Media and Dispatch Namespace bindings
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any user facing change here? Or is this PR more of an internal refactoring?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly just an internal refactoring. Previously we "faked" streams with Media Bindings over fetch, but now they will work properly. As a consequence, any other JSRPC calls to a remote bings service binding that returns a stream will now also work. I suppose I could remove the changeset? What do you think?

… bindings

This PR updates miniflare to use capnweb's native ReadableStream support
(via workerd entry point) for remote Media and Dispatch Namespace bindings.

Changes:
- Update capnweb to PR 139 (adds Headers/Request/Response + streams support)
- Remove custom Media binding worker - use remote-proxy-client directly
- Simplify dispatch-namespace to use service binding pattern (like Media)
- Add makeRemoteProxyStub() helper for capnweb RPC + fetch interception
- Configure esbuild with workerd conditions for capnweb workers

The dispatch-namespace binding now uses JSRPC with promise pipelining,
so `namespace.get('worker').fetch(request)` works without extra round-trips.
- Add optional workerScript param to remoteProxyClientWorker()
- Use remoteProxyClientWorker() in dispatch-namespace plugin (consistency)
- Fix protocol downgrade: https→wss, http→ws (was always using ws:)
The refactor into makeRemoteProxyStub dropped the bindingType → MF-Binding-Type
forwarding that the AI RPC workaround in ProxyServerWorker depends on.
…b from user worker

Move capnweb out of the dispatch namespace extension module (which runs
in the user's isolate) into a dedicated proxy worker accessed via service
binding. The extension is now a thin shim that delegates .get() calls.

Also: simplify extraContext plumbing in remote-proxy-client, revert
unrelated worker-ts fixture changes.
@penalosa penalosa force-pushed the penalosa/test-capnweb-streams branch from d3969c4 to 712e2eb Compare February 20, 2026 13:38
@penalosa penalosa merged commit c2ed7c2 into main Feb 23, 2026
39 of 42 checks passed
@penalosa penalosa deleted the penalosa/test-capnweb-streams branch February 23, 2026 14:22
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants