Repository navigation
fix(core): a deliberate disconnect no longer ends in "error" (#2817) - #2819
Merged
Merged
Conversation
Closing a Streamable HTTP transport aborts its standalone GET stream, and the SDK reports that abort through onerror just after disconnect() has settled "disconnected". InspectorClient's onerror flipped the status to "error", so the TUI showed "✗ error — This operation was aborted" after every `d`. onerror now ignores errors raised while disconnect() owns the teardown, and errors from a transport the client has released (disconnect() and dropCachedTransport() null baseTransport; a reconnect replaces it). A crash still errors the connection: onclose leaves baseTransport in place, so the trailing onerror still lands. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the MCP disconnect error-handling change.
No open issues 🎉
What changed in this PR
Fixes #2817 in the shared MCP client so a deliberate disconnect stays disconnected instead of showing an abort error in the TUI.
Changes:
- Ignores transport errors during deliberate teardown or from a released transport.
- Preserves error reporting for crashes of the current transport.
- Adds regression tests for teardown errors, stale errors after reconnect, and live transport crashes.
| File | Description |
|---|---|
core/mcp/inspectorClient.ts |
Guards transport error handling during teardown and after release. |
clients/web/src/test/core/mcp/inspectorClient-peer-handler-timing.test.ts |
Adds four tests covering disconnect, reconnect, and crash behavior. |
Review effort: Balanced
Member
Author
|
Copilot review loop closed after round 1. It was clean: approval recommended, no inline comments, nothing suppressed. Nothing was pushed, so there is no further round. |
This was referenced Oct 28, 2026
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.
Closes #2817
Problem
In the TUI,
don a Streamable HTTP connection reached ○ disconnected, then about a millisecond later flipped to ✗ error withThis operation was aborted. The release smoke for v2.13.0 found it (#2816). The published 2.12.0 behaves the same, so this is not a regression.Cause
Closing a Streamable HTTP transport aborts its standalone GET stream, and the SDK reports that abort through the transport's
onerrorjust afterdisconnect()has settled "disconnected". A probe against a real server recorded:disconnect()at 333 ms,disconnectedat 339 ms,errorat 340 ms (AbortError: This operation was aborted).InspectorClient'sonerrorsets "error" from every state except "connecting". It does that on purpose, so a crash's trailingonerrorkeeps its reason (#1490).Fix (
core/mcp/inspectorClient.ts)onerrornow also ignores an error when either of these holds:disconnect()owns the teardown (this.disconnecting): an error raised while it closes the transport is the teardown itself.this.baseTransport !== baseTransport):disconnect()anddropCachedTransport()nullbaseTransport, and a reconnect replaces it, so nothing that transport reports describes the connection the client now holds.A crash still errors the connection.
oncloseleavesbaseTransportin place, so the crash'sonerrorstill lands.oncloseitself is unchanged.Tests
inspectorClient-peer-handler-timing.test.ts, undertransport onerror after a deliberate disconnect (#2817), beside #2776's onerror cases:AbortErrorafterdisconnect(): the client staysdisconnected, with noerroreventtransport.close()duringdisconnect(): ignoredconnectedonclosethenonerror(a crash) still giveserrorplus the eventThe first three fail without the fix, and the control passes either way.
npm run local:gate: green.Driven by hand (production build)
The TUI ran in a pty through
expectagainstweb-tabs-http.json, with keyscand thend, held for 5 s:disconnected → connecting → connected → disconnected → errordisconnected → connecting → connected → disconnectedOn this branch,
dthencreconnects normally, back toTools (2).Screenshots
The final TUI frame after
d, replayed from the captured pty output into xterm.js at 140×40.Before (2.12.0):
After:
🤖 Generated with Claude Code