Skip to content

Use capnweb native ReadableStream support for remote Media bindings#12582

Open
penalosa wants to merge 6 commits intomainfrom
penalosa/test-capnweb-streams
Open

Use capnweb native ReadableStream support for remote Media bindings#12582
penalosa wants to merge 6 commits intomainfrom
penalosa/test-capnweb-streams

Conversation

@penalosa
Copy link
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

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 6d5ad38

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
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
Contributor

claude bot commented Feb 18, 2026

Claude finished @penalosa's task —— View job


Changeset Review

  • Read changeset guidelines
  • Read changeset file
  • Validate changeset
  • Post findings

⚠️ Issues found

The changeset description is too minimal. According to the guidelines:

Bad Examples (avoid these)

  • "update dependency" - Which one? Why? Any user impact?

The current changeset says:

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

This needs more context:

  1. What was the problem? (HTTP-based workaround was being used)
  2. What changed? (Removed HTTP fallback, now uses capnweb's native support)
  3. User impact? (Is this a performance improvement? Does it fix any bugs? Is it purely internal?)

Per the guidelines, aim for "more than one sentence but less than three paragraphs." A good changeset should explain the reason for the change and anything notable about the approach.

Suggested improvement:

---
"miniflare": patch
"wrangler": patch
---

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

Previously, remote Media bindings used an HTTP-based workaround to handle streaming data. With capnweb 0.5.0's native ReadableStream support, we've removed this intermediary HTTP layer and now communicate directly via RPC, simplifying the implementation and improving performance.

@pkg-pr-new
Copy link

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: 6d5ad38

@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 6 times, most recently from fc2e1a3 to 4d0a95b Compare February 19, 2026 00:03
… 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.
@penalosa penalosa force-pushed the penalosa/test-capnweb-streams branch from 4d0a95b to 87328d7 Compare February 19, 2026 09:46
- 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 marked this pull request as ready for review February 19, 2026 18:45
Copy link
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

2 participants

Comments