Skip to content

fix(core): a deliberate disconnect no longer ends in "error" (#2817) - #2819

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2817-tui-disconnect-abort-error
Oct 28, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2817-tui-disconnect-abort-error

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2817

Problem

In the TUI, d on a Streamable HTTP connection reached ○ disconnected, then about a millisecond later flipped to ✗ error with This 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 onerror just after disconnect() has settled "disconnected". A probe against a real server recorded: disconnect() at 333 ms, disconnected at 339 ms, error at 340 ms (AbortError: This operation was aborted). InspectorClient's onerror sets "error" from every state except "connecting". It does that on purpose, so a crash's trailing onerror keeps its reason (#1490).

Fix (core/mcp/inspectorClient.ts)

onerror now 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.
  • The transport has been released (this.baseTransport !== baseTransport): disconnect() and dropCachedTransport() null baseTransport, and a reconnect replaces it, so nothing that transport reports describes the connection the client now holds.

A crash still errors the connection. onclose leaves baseTransport in place, so the crash's onerror still lands. onclose itself is unchanged.

Tests

inspectorClient-peer-handler-timing.test.ts, under transport onerror after a deliberate disconnect (#2817), beside #2776's onerror cases:

  • the released transport's AbortError after disconnect(): the client stays disconnected, with no error event
  • an error raised from inside transport.close() during disconnect(): ignored
  • the released transport's error after a reconnect to a fresh transport: the new connection stays connected
  • control: the live transport's onclose then onerror (a crash) still gives error plus the event

The 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 expect against web-tabs-http.json, with keys c and then d, held for 5 s:

Build Status sequence (3 runs each)
published 2.12.0 disconnected → connecting → connected → disconnected → error
this branch disconnected → connecting → connected → disconnected

On this branch, d then c reconnects normally, back to Tools (2).

Screenshots

The final TUI frame after d, replayed from the captured pty output into xterm.js at 140×40.

Before (2.12.0):

before

After:

after

🤖 Generated with Claude Code

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]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 28, 2026
@cliffhall
cliffhall requested a balanced review from Copilot October 28, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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

@cliffhall

Copy link
Copy Markdown
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.

@cliffhall
cliffhall merged commit d8b4cb1 into v2/main Oct 28, 2026
11 checks passed
@cliffhall
cliffhall deleted the v2/fix/2817-tui-disconnect-abort-error branch October 28, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: a deliberate disconnect ends in '✗ error — This operation was aborted'

2 participants