Record why an MCP request was cut off with "session was reset" - #8
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Last-Event-IDfor the same stream makes the object close the old bridge with1000 "Superseded by resumed stream".What changed
mcp_post_stream_lostnow also logsbridge(closeorerror),closeCode,closeReasonandwasClean, or the error message. This is done inpatches/agents@0.17.3.patch, regenerated withbun patch --commit. It also drops empty.bun-tag-*marker entries thatbun patchhad recorded in the patch, which only created empty files.Testing
packages/hosts/cloudflare129,apps/host-cloudflare60 andpackages/hosts/mcp251 tests pass. The patch reapplies from a cleannode_modules.b387b27b. Since then: zeromcp_post_stream_lostin 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.