Repository navigation
fix(cloudflare): Initialize the SDK before constructing a Durable Object - #26218
Conversation
A Durable Object that opens a pi-durable Harness in its constructor ran before `init()`, so the pi-durable integration had not subscribed yet and the Harness was never instrumented. This happens in any isolate where no Worker handler called `init()` first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦Compared: 83a6099 (PR test merge using develop at 83f29b7) Against: 83f29b7 (develop) · base run #65541 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 7 not successful, 50 successful. See the run.
Successful checks
|
| // that runs only this Durable Object has no earlier handler that called it. A per-invocation | ||
| // client (`cacheClient: false`) would have no invocation to flush it, so it waits for one. | ||
| if (options.cacheClient !== false) { | ||
| init({ ...options }); |
There was a problem hiding this comment.
Could we fork the scope here too or skip init() when getClient() already returns a client? Otherwise this init here swaps the client on the current scope?
There was a problem hiding this comment.
init already has a guard inside to return the cached one, so it's safe to just run init here
Edit: just realized that's about the scope, maybe even worth to test this scenario
There was a problem hiding this comment.
Yes, the guard is about the scope. With cacheClient: false, init() would make a new client on the construction scope, and no invocation would flush it. Added a test for both cases in 88b239f.
There was a problem hiding this comment.
I added a test for this.
What
The Durable Object wrapper now starts the SDK before the constructor runs. A pi-durable Harness opened in the constructor is now traced.
Why
In an isolate where no Worker handler had called
init()yet, the Harness opened before the pi-durable integration subscribed, so no agent, chat or tool spans were sent.