Skip to content

fix(cloudflare): Instrument DO RPC methods on the prototype, not a Proxy - #23057

Draft
JPeer264 wants to merge 1 commit into
developfrom
jp/cloudflare-agent-rpc-proxy-private-fields
Draft

fix(cloudflare): Instrument DO RPC methods on the prototype, not a Proxy#23057
JPeer264 wants to merge 1 commit into
developfrom
jp/cloudflare-agent-rpc-proxy-private-fields

Conversation

@JPeer264

@JPeer264 JPeer264 commented Aug 5, 2026

Copy link
Copy Markdown
Member

closes #23040
closes JS-3283

This is getting rid completely of the Proxy for methods on the DO entirely. It seems private calls were not working properly with Proxies, therefore we need to switch entirely to a prototype-wrapping. This was in already before in instrumentPrototypeMethods and moved over to a Proxy.

I also did a benchmark on a deployed worker instance and it seems that there is no significant performance difference - they're even mostly the same in performance. So there is only a win doing this.


Clanker description:

The RPC instrumentation returned a Proxy of the Durable Object instance. A Proxy never carries the class's native private-field brand, so any dispatch that resolves a method on the prototype and invokes it with the stored instance as receiver (native RPC/facet dispatch, Agents SDK setName() bootstrap) throws "Cannot read private member #x from an object whose class did not declare it" for classes using native private fields.

Wrap RPC methods on the class prototype chain instead (once per class) and keep per-instance state in a WeakMap keyed on the instance, so the receiver is always the real branded instance on every dispatch path.

@JPeer264 JPeer264 self-assigned this Aug 5, 2026
@linear-code

linear-code Bot commented Aug 5, 2026

Copy link
Copy Markdown

JS-3283

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 30.13 kB - -
@sentry/browser - with treeshaking flags 28.33 kB - -
@sentry/browser (incl. Tracing) 47.54 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.29 kB - -
@sentry/browser (incl. Tracing, Replay) 86.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.33 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.61 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 104.25 kB - -
@sentry/browser (incl. Feedback) 47.45 kB - -
@sentry/browser (incl. sendFeedback) 34.97 kB - -
@sentry/browser (incl. FeedbackAsync) 40.11 kB - -
@sentry/browser (incl. Metrics) 31.2 kB - -
@sentry/browser (incl. Logs) 31.42 kB - -
@sentry/browser (incl. Metrics & Logs) 32.11 kB - -
@sentry/react 31.93 kB - -
@sentry/react (incl. Tracing) 49.8 kB - -
@sentry/vue 35.2 kB - -
@sentry/vue (incl. Tracing) 49.52 kB - -
@sentry/svelte 30.15 kB - -
CDN Bundle 32.14 kB - -
CDN Bundle (incl. Tracing) 47.82 kB - -
CDN Bundle (incl. Logs, Metrics) 33.68 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.02 kB - -
CDN Bundle (incl. Tracing, Replay) 85.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.27 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.59 kB - -
CDN Bundle - uncompressed 95.31 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.81 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.93 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.79 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.73 kB - -
@sentry/nextjs (client) 52.37 kB - -
@sentry/sveltekit (client) 47.99 kB - -
@sentry/core/server 65.55 kB - -
@sentry/core/browser 51.84 kB - -
@sentry/node 120.47 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 84.12 kB +0.01% +1 B 🔺
@sentry/aws-serverless 92.61 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 218.28 kB -0.12% -260 B 🔽
@sentry/cloudflare (withSentry) 538.07 kB -0.12% -623 B 🔽

View base workflow run

Base automatically changed from jp/cloudflare-remove-instrument-prototype-methods to develop August 5, 2026 14:57
The RPC instrumentation returned a Proxy of the Durable Object instance.
A Proxy never carries the class's native private-field brand, so any
dispatch that resolves a method on the prototype and invokes it with the
stored instance as receiver (native RPC/facet dispatch, Agents SDK
setName() bootstrap) throws "Cannot read private member #x from an
object whose class did not declare it" for classes using native private
fields.

Wrap RPC methods on the class prototype chain instead (once per class)
and keep per-instance state in a WeakMap keyed on the instance, so the
receiver is always the real branded instance on every dispatch path.
@JPeer264
JPeer264 force-pushed the jp/cloudflare-agent-rpc-proxy-private-fields branch from f8aa01f to a504b21 Compare August 5, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare Agent RPC proxy breaks native private fields

1 participant