Title: instrumentAgentWithSentry: @callable() methods are lost after a constructor throws once · Issue #25728 · getsentry/sentry-javascript · GitHub
Open Graph Title: instrumentAgentWithSentry: @callable() methods are lost after a constructor throws once · Issue #25728 · getsentry/sentry-javascript
X Title: instrumentAgentWithSentry: @callable() methods are lost after a constructor throws once · Issue #25728 · getsentry/sentry-javascript
Description: Package: @sentry/cloudflare 11.4.0, with agents 0.30.1, Workers compatibility date 2026-10-01 What happens If an Agent's constructor throws once (in our case the Durable Objects free tier's rows-read limit during storage initialization),...
Open Graph Description: Package: @sentry/cloudflare 11.4.0, with agents 0.30.1, Workers compatibility date 2026-10-01 What happens If an Agent's constructor throws once (in our case the Durable Objects free tier's rows-re...
X Description: Package: @sentry/cloudflare 11.4.0, with agents 0.30.1, Workers compatibility date 2026-10-01 What happens If an Agent's constructor throws once (in our case the Durable Objects free tier's...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25728
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"instrumentAgentWithSentry: @callable() methods are lost after a constructor throws once","articleBody":"**Package:** `@sentry/cloudflare` 11.4.0, with `agents` 0.30.1, Workers compatibility date 2026-10-01\n\n## What happens\n\nIf an Agent's constructor throws once (in our case the Durable Objects free tier's rows-read limit during storage initialization), the next construction of the same class loses its `@callable()` methods. RPC calls from a connected client then fail with `Method callTool is not callable`.\n\n## Why\n\nIn `constructInstrumentedDurableObject` (`build/*/durableobject.js`), `methodsBeforeConstruction` is resolved from the prototype on every construction until `frameworkManagedMethodsCache` holds an entry for that prototype. That entry is only written after `Reflect.construct` returns. When the constructor throws, the Agents SDK has already replaced the prototype's methods with its wrapped versions, but no cache entry is written. On the next construction, Sentry snapshots the *wrapped* methods as the originals, so it no longer recognizes them as framework-managed, and the callable registration is lost.\n\n## Reproduction (vitest-pool-workers)\n\nThe test needs a Durable Object binding named `MyAgent` in the Worker's test config, bound to any Agent class; it only borrows that object's `state`, and the test's own `RecoveryAgent` does the rest.\n\n```ts\nimport { runInDurableObject } from \"cloudflare:test\";\nimport { env } from \"cloudflare:workers\";\nimport * as Sentry from \"@sentry/cloudflare\";\nimport { Agent, callable } from \"agents\";\nimport { expect, test } from \"vitest\";\n\ntest(\"callable methods survive construction retry after a constructor failure\", async () => {\n await runInDurableObject(env.MyAgent.getByName(crypto.randomUUID()), async (_obj, state) => {\n let fail = true;\n class RecoveryAgent extends Agent\u003cEnv> {\n constructor(ctx: DurableObjectState, bindings: Env) {\n super(ctx, bindings);\n if (fail) {\n fail = false;\n throw new Error(\"Exceeded allowed rows read in Durable Objects free tier.\");\n }\n }\n @callable()\n async read() {\n return \"ready\";\n }\n }\n const Wrapped = Sentry.instrumentAgentWithSentry(() => ({ dsn: \"\" }), RecoveryAgent);\n expect(() => new Wrapped(state, env)).toThrow(\"Exceeded allowed rows read\");\n const recovered = new Wrapped(state, env);\n expect(recovered.getCallableMethods().has(\"read\")).toBe(true); // fails on 11.4.0\n });\n});\n```\n\n## Workaround we are running\n\nCache the pre-construction snapshot per prototype, so a retry after a failure reuses the first snapshot:\n\n```diff\n- const methodsBeforeConstruction = cachedFrameworkManagedMethods ? void 0 : resolvePrototypeMethods(prototype);\n+ let methodsBeforeConstruction = methodsBeforeConstructionCache.get(prototype);\n+ if (!cachedFrameworkManagedMethods && !methodsBeforeConstruction) {\n+ methodsBeforeConstruction = resolvePrototypeMethods(prototype);\n+ methodsBeforeConstructionCache.set(prototype, methodsBeforeConstruction);\n+ }\n ...\n const frameworkManagedMethodsCache = /* @__PURE__ */ new WeakMap();\n+const methodsBeforeConstructionCache = /* @__PURE__ */ new WeakMap();\n```\n\nHappy to open a PR with this and the test if the approach looks right.\n","author":{"url":"https://github.com/nuntz","@type":"Person","name":"nuntz"},"datePublished":"2026-10-24T15:02:36Z","url":"https://github.com/getsentry/sentry-javascript/issues/25728"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c47ffbd0-5b21-bf31-631f-d69c294bfd5f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8100:2A3275:752B8D:A4B397:6B044D8F |
| html-safe-nonce | 635baa7d64b087f90a6d037665a3b20c7ae2faa593c22dea2887fa9665ae4e5c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTAwOjJBMzI3NTo3NTJCOEQ6QTRCMzk3OjZCMDQ0RDhGIiwidmlzaXRvcl9pZCI6IjYyOTE3NjQwODQwOTQ1NTM0ODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 16ce8c86ca8e96b57f1b4e06f18ca986516a082a0031a691f28ec0a4f79234b9 |
| hovercard-subject-tag | issue:6014301420 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/25728/issue_layout |
| twitter:image | https://opengraph.githubassets.com/82936c1cb3ffbf204193e82b0f7070b9c293a270c8cf5dc3a44fa767e266301f/getsentry/sentry-javascript/issues/25728 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/82936c1cb3ffbf204193e82b0f7070b9c293a270c8cf5dc3a44fa767e266301f/getsentry/sentry-javascript/issues/25728 |
| og:image:alt | Package: @sentry/cloudflare 11.4.0, with agents 0.30.1, Workers compatibility date 2026-10-01 What happens If an Agent's constructor throws once (in our case the Durable Objects free tier's rows-re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nuntz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 002aa6b95ffa730b0aec436a5c383f536ad677284e60056037fb120afe37b730 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 059f24c781e3a0d7df3f27a97da0e93fab06ae39 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width