Repository navigation
fix(cloudflare): Keep framework-managed methods when a Durable Object constructor throws - #25851
Conversation
… constructor throws Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Read through On the open question: keeping the snapshot until a construction succeeds is the right call. Caching the result of a failed attempt would record an empty managed set whenever the throw happens before the framework installs its wrappers, and that would be permanent. With the snapshot held, a framework that wraps on attempt one and skips on attempt two (your test), or re-wraps on every attempt, is detected either way, since the comparison is always against the pre-wrapper originals. |
… Object constructor throws
JPeer264
left a comment
There was a problem hiding this comment.
Thanks a lot for fixing that.
I keep the snapshot until the first successful construction rather than caching the result of a failed one. A framework that installs its wrappers on a later attempt would still be detected.
That's fine and I think even the best solution for it
On top I actually adapted our e2e test that this is also covered
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #25851 Co-authored-by: JPeer264 <10677263+JPeer264@users.noreply.github.com>
… goes (#42) @sentry/cloudflare 11.4.0 -> 11.12.0, which ships getsentry/sentry-javascript#25851, the upstream form of our patch. The patch and its patchedDependencies entry are gone. agent-recovery.test.ts fails on 11.4.0 without the patch and passes on 11.12.0. What upstream changed, 11.5-11.12, and what in Mise reads it: - Durable Objects now run Sentry.init() inside construction (#26218). Household (instrumentAgentWithSentry) gets it: errors thrown while a Household is being constructed now reach Sentry, so the weekly `bun run sentry` sweep can show issues that were invisible before. sentryOptions sets no cacheClient, so this applies. The repeated-init warning (11.5) does not fire in the worker tests. - Spans for SQL on pi_ and cf_ tables are skipped (11.6). agentLog.ts reads pi_entries, so /agent-log's queries leave no db spans. Nothing in Mise reads db spans; row counts come from metering.ts cursors, not spans. - Request spans set client.address from CF-Connecting-IP (11.11) only when dataCollection.userInfo is on; sentryOptions turns it off. Response header attributes follow the same SAFE_HEADERS allow-list. - Workers skip spans for GETs of common static assets (11.10). Static assets are served before the Worker runs, so the sweep's http.server rows lose nothing they had. - Aborted http client spans are no longer errors (11.7): node:http only. Mise fetches, so the sweep's failed spans are unchanged. - Queues, KV, Workflows, cron monitoring, logs and metrics, tunnels, MCP, Vite instrumentation: Mise uses none of them. The other fixes are in span timestamps, client reports, linked errors and stack paths, which nothing in Mise reads. Closes #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Why: When a Durable Object's constructor throws after a framework has already installed its method wrappers, the next construction reads those wrappers as the originals. Nothing then looks framework-managed, so Sentry wraps them again, and the framework's identity-keyed dispatch breaks. With the
agentsSDK,@callable()methods are wrapped before storage initialization, so a constructor that fails once (for example at a storage quota limit) leaves later RPCs failing withMethod callTool is not callable.The fix keeps the methods collected before the first construction attempt until a construction succeeds, then drops them; after that, the existing
frameworkManagedMethodsCachetakes over.How to review:
resolveMethodsBeforeFirstConstructionindurableobject.ts, plus the new test in theframework-managed methodsblock, which fails ondevelop.Unsure about: I keep the snapshot until the first successful construction rather than caching the result of a failed one. A framework that installs its wrappers on a later attempt would still be detected.
The same change, applied as a
pnpm patchto 11.4.0, fixes the failure in our app's Agent recovery test.Closes #25728
🤖 Generated with Claude Code