Skip to content

Serialize MCP session DO startup#1313

Merged
RhysSullivan merged 4 commits into
mainfrom
fix/session-onstart-serialization
Jul 4, 2026
Merged

Serialize MCP session DO startup#1313
RhysSullivan merged 4 commits into
mainfrom
fix/session-onstart-serialization

Conversation

@RhysSullivan

@RhysSullivan RhysSullivan commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Problem

McpAgent.onStart can be invoked from more than one code path when a session durable object wakes with an existing session id: the explicit session-validation restore path, and the agents SDK serve handler's own wake path. Nothing serialized the two, so two concurrent requests on the same session (e.g. an SSE GET and a POST arriving together) could both drive server.connect(), and the second throws Already connected to a transport. Because the failure left the runtime partially initialized without cleanup, the session stayed in that state for every subsequent request instead of recovering.

#1302 serialized the explicit restore path, but the SDK wake path doesn't go through it.

Fix

Serialize at the one point every caller shares: override onStart in McpAgentSessionDOBase with a single in-flight promise, so concurrent callers coalesce onto one initialization regardless of entry path. The start path closes any prior runtime before connecting, and a failed start closes the partial runtime and clears the gate so the next request retries cleanly. The now-redundant restore-level single-flight from #1302 is removed.

Tests

  • New e2e regression: a session that idles past the timeout must survive a concurrent SSE GET + POST reconnect, including follow-up calls. Fails with the exact transport error without the fix; passes 6/6 consecutive runs with it.
  • Existing DO unit tests and MCP client-session e2e scenarios stay green; full typecheck passes.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
executor-marketing 228367d Commit Preview URL

Branch Preview URL
Jul 04 2026, 08:37 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 4, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
executor-cloud 228367d Jul 04 2026, 08:38 AM

@RhysSullivan RhysSullivan force-pushed the fix/session-onstart-serialization branch from 0275f97 to 0e86933 Compare July 4, 2026 08:12
@RhysSullivan RhysSullivan changed the title Serialize MCP session startup to fix concurrent-reconnect brick Serialize MCP session DO startup Jul 4, 2026
@RhysSullivan RhysSullivan force-pushed the fix/session-onstart-serialization branch from 78058e1 to 275c406 Compare July 4, 2026 08:15
@RhysSullivan RhysSullivan force-pushed the fix/session-onstart-serialization branch from cfcce57 to 228367d Compare July 4, 2026 08:36
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Cloudflare preview

Torn down — the PR is closed.

@pkg-pr-new

pkg-pr-new Bot commented Jul 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@executor-js/cli

npm i https://pkg.pr.new/@executor-js/cli@1313

@executor-js/config

npm i https://pkg.pr.new/@executor-js/config@1313

@executor-js/execution

npm i https://pkg.pr.new/@executor-js/execution@1313

@executor-js/sdk

npm i https://pkg.pr.new/@executor-js/sdk@1313

@executor-js/codemode-core

npm i https://pkg.pr.new/@executor-js/codemode-core@1313

@executor-js/runtime-quickjs

npm i https://pkg.pr.new/@executor-js/runtime-quickjs@1313

@executor-js/plugin-file-secrets

npm i https://pkg.pr.new/@executor-js/plugin-file-secrets@1313

@executor-js/plugin-graphql

npm i https://pkg.pr.new/@executor-js/plugin-graphql@1313

@executor-js/plugin-keychain

npm i https://pkg.pr.new/@executor-js/plugin-keychain@1313

@executor-js/plugin-mcp

npm i https://pkg.pr.new/@executor-js/plugin-mcp@1313

@executor-js/plugin-onepassword

npm i https://pkg.pr.new/@executor-js/plugin-onepassword@1313

@executor-js/plugin-openapi

npm i https://pkg.pr.new/@executor-js/plugin-openapi@1313

executor

npm i https://pkg.pr.new/executor@1313

commit: 228367d

@RhysSullivan RhysSullivan marked this pull request as ready for review July 4, 2026 08:40
@RhysSullivan RhysSullivan merged commit fb808c8 into main Jul 4, 2026
21 checks passed
@RhysSullivan RhysSullivan deleted the fix/session-onstart-serialization branch July 4, 2026 08:45
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.

1 participant