Skip to content

feat(miniflare): proxying service binding RPC calls through capnweb#14447

Draft
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/miniflare-capnweb-proxy
Draft

feat(miniflare): proxying service binding RPC calls through capnweb#14447
edmundhung wants to merge 1 commit into
mainfrom
edmundhung/miniflare-capnweb-proxy

Conversation

@edmundhung

Copy link
Copy Markdown
Member

Fixes #[insert GH or internal issue link(s)].

Describe your change...


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because:

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 247181f

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

This PR includes changesets to release 6 packages
Name Type
miniflare Minor
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
wrangler Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jun 26, 2026
@edmundhung edmundhung added ci:e2e Run wrangler + vite-plugin E2E tests on a pull request ci:test-all-node-versions Run the tests on all Node versions for this PR ci:run-remote-tests Run remote/E2E tests that require Cloudflare API credentials labels Jun 26, 2026

@ask-bonk ask-bonk Bot left a comment

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.

I'm Bonk, and I've done a quick review of your PR.

This adds an unsafeCapnwebRpcProxy option to Miniflare that routes Worker service-binding JS RPC calls through a capnweb WebSocket session, while keeping fetch()/legacy bindings on the existing proxy.

Ranked issues:

  1. (medium) #getProxy no longer surfaces the "No binding named X found" error for capnweb bindings, because getEnvBinding() always returns a stub (never undefined).
  2. (low) The get trap drops the receiver argument on the rpcProxy path, inconsistent with the fetchProxy path.

Details in inline comments.

? await (
await this.#getCapnwebProxyClient()
).getEnvBinding(proxyBindingName)
: proxyClient.env[proxyBindingName];

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.

When useCapnwebProxy is true, getEnvBinding(proxyBindingName) returns a capnweb stub that is never undefined, even for a binding/worker name that doesn't exist. That means the if (proxy === undefined) guard below (and its helpful No ... binding named ... TypeError) is silently bypassed for capnweb bindings, so an invalid binding name now returns a broken stub instead of throwing.

getBindings and getWorker avoid this by gating on the resolved fetchProxy first (fetchProxy !== undefined && ...). Consider doing the same here — resolve the legacy proxy first and only swap in the capnweb binding when the fetch proxy exists:

Suggested change
: proxyClient.env[proxyBindingName];
const fetchProxy = proxyClient.env[proxyBindingName];
const useCapnwebProxy =
fetchProxy !== undefined &&
pluginName === CORE_PLUGIN_NAME &&
this.#isCapnwebProxyBinding(
pluginName,
bindingName,
this.#workerOpts[this.#findAndAssertWorkerIndex(workerName)]
);
const proxy = useCapnwebProxy
? await (
await this.#getCapnwebProxyClient()
).getEnvBinding(proxyBindingName)
: fetchProxy;

if (prop === "fetch" || prop === util.inspect.custom) {
return Reflect.get(Object(fetchProxy), prop, receiver);
}
return Reflect.get(Object(rpcProxy), prop);

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.

The fetchProxy branch above forwards receiver, but this branch calls Reflect.get(Object(rpcProxy), prop) without it. For consistency (and so getters resolve this against the proxy), pass receiver here too:

Suggested change
return Reflect.get(Object(rpcProxy), prop);
return Reflect.get(Object(rpcProxy), prop, receiver);

@ask-bonk

ask-bonk Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully to PR #14447 with two inline suggestion comments.

Summary of feedback:

  1. (medium) #getProxy bypasses the "No binding named X found" error for capnweb bindings since getEnvBinding() always returns a stub — suggested gating on fetchProxy first like getBindings/getWorker do.
  2. (low) The get trap drops the receiver argument on the rpcProxy path, inconsistent with the fetchProxy path.

github run

@pkg-pr-new

pkg-pr-new Bot commented Jun 26, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14447

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14447

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14447

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 247181f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run wrangler + vite-plugin E2E tests on a pull request ci:run-remote-tests Run remote/E2E tests that require Cloudflare API credentials ci:test-all-node-versions Run the tests on all Node versions for this PR

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants