Skip to content

fix(mcp): handle cold wake in handleMcpMessage RPC entry point#1286

Merged
threepointone merged 1 commit intomainfrom
fix-1282
Apr 10, 2026
Merged

fix(mcp): handle cold wake in handleMcpMessage RPC entry point#1286
threepointone merged 1 commit intomainfrom
fix-1282

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented Apr 10, 2026

Summary

Fixes #1282.

  • McpAgent.handleMcpMessage is a native DO RPC method that bypasses PartyServer's fetch/alarm/webSocket entry points where #ensureInitialized() normally runs. When the MCP server DO wakes from hibernation via this path, this.name was never hydrated from storage, causing a crash.
  • Replaced the hand-rolled 15-line cold-start block inside handleMcpMessage with a single await this.__unsafe_ensureInitialized() call, matching the pattern used by _workflow_handleCallback, _workflow_broadcast, _workflow_updateState, and alarm().
  • This eliminates a duplicate initialization path that was both incomplete (missed name hydration) and divergent from onStart (missed Agent-level MCP client restore, workflow checks, etc.).

Test plan

  • Added two regression tests that simulate cold wake by seeding __ps_name directly in storage (bypassing setName/onStart), then calling handleMcpMessage as the first entry point
  • First test verifies initialize message succeeds after cold wake
  • Second test verifies full tool call flow works after cold wake
  • All 26 RPC transport tests pass
  • Build passes
  • Type checks pass

Made with Cursor


Open with Devin

Call __unsafe_ensureInitialized() at the start of McpAgent.handleMcpMessage to hydrate this.name from storage and run onStart before processing native DO RPC messages. This prevents crashes like "Attempting to read .name before it was set" when a Durable Object wakes from hibernation via RPC. Adds unit tests that seed __ps_name and exercise handleMcpMessage for cold-wake initialization and subsequent tool calls, and includes a changeset entry describing the fix.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 3b632d7

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

This PR includes changesets to release 1 package
Name Type
agents 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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1286

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1286

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1286

hono-agents

npm i https://pkg.pr.new/hono-agents@1286

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1286

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1286

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1286

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1286

commit: 3b632d7

@threepointone threepointone merged commit d76f8b9 into main Apr 10, 2026
2 checks passed
@threepointone threepointone deleted the fix-1282 branch April 10, 2026 09:25
@github-actions github-actions bot mentioned this pull request Apr 10, 2026
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.

McpAgent.handleMcpMessage crashes with workerd #2240 on native DO RPC wake path

1 participant