Skip to content

Record why an MCP request was cut off with "session was reset" - #8

Merged
fforres merged 1 commit into
skywardfrom
fix/mcp-session-reset
Sep 26, 2026
Merged

fforres merged 1 commit into
skywardfrom
fix/mcp-session-reset

Conversation

@fforres

@fforres fforres commented Sep 26, 2026

Copy link
Copy Markdown

Why

Tool calls sometimes fail with "Execution lost: the session was reset before it produced a result." The front worker says this whenever its bridge WebSocket to the session Durable Object closes with anything other than its own 1000 "SSE response delivered". Two very different things end up there, and today's log line cannot tell them apart:

  • The Durable Object really reset. The socket closes with no code, and the next GET answers the orphaned request ids from the previous incarnation.
  • A resumed stream superseded the bridge. A client GET with Last-Event-ID for the same stream makes the object close the old bridge with 1000 "Superseded by resumed stream".

What changed

mcp_post_stream_lost now also logs bridge (close or error), closeCode, closeReason and wasClean, or the error message. This is done in patches/agents@0.17.3.patch, regenerated with bun patch --commit. It also drops empty .bun-tag-* marker entries that bun patch had recorded in the patch, which only created empty files.

Testing

  • packages/hosts/cloudflare 129, apps/host-cloudflare 60 and packages/hosts/mcp 251 tests pass. The patch reapplies from a clean node_modules.
  • Deployed as b387b27b. Since then: zero mcp_post_stream_lost in about 1,200 events. The explicit Docs, Sheets and Forms refreshes that failed earlier all completed, and 8 s and 25 s tool calls completed. The next occurrence will carry the close code and reason.

Requests fail with "session was reset" whenever the front worker's
bridge WebSocket to the session Durable Object closes without its own
"SSE response delivered" code. A real object reset and a resumed stream
superseding the bridge both land there, and the log could not tell them
apart. Log the close code, reason and wasClean (or the error) with
mcp_post_stream_lost. Also drops empty .bun-tag marker entries that
bun patch had recorded in the patch.

Claude-Session: https://claude.ai/code/session_01VMqJkxznzTQaFVHHcttxpJ
@fforres
fforres merged commit 07b9df0 into skyward Sep 26, 2026
4 of 40 checks passed
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