Repository navigation
feat(core): surface mid-session transport failures via lastError (#1323) - #1489
Conversation
A `connected → error` transition from a transport that dies mid-session (stdio crash, SSE drop, HTTP 5xx) fires the client's `error` event but bypasses the `connect()` rejection path, so App.tsx's handshake-only catch left `errorMessage` stale/unset. - Document `error` on InspectorClientEventMap as the non-awaited (mid-session) failure signal. - Stop dispatching `error` from the awaited `connect()` catch: the caller already gets the reason via the rejected promise, so a second surface would double-report a handshake failure. - Expose `lastError?: string` on `useInspectorClient`, set from the `error` event and cleared at the next connecting edge (and on client swap/null). - Toast mid-session failures in App.tsx, naming the active server via a ref that survives the disconnect-driven activeServerId reset; update the stale TODO(#1323) marker at the connect catch. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@claude review |
|
Claude finished @cliffhall's task in 2m 36s —— View job Review: surface mid-session transport failures via
|
Review follow-up (#1489): the transport listeners are attached before the handshake runs, so an SDK transport that reports a connect-time error via `onerror` — in addition to rejecting `connect()` — would flip status to "error" and dispatch the `error` event during a handshake the awaited `connect()` path already surfaces via its rejection, double-reporting it. Guard `onerror` on `status === "connected"` so the `error` event stays exclusive to post-handshake transport death. Add an integration test covering an `onerror` that fires while status is "connecting". Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for the thorough review! Addressed in 74904df. #1 — baseTransport.onerror = (error: Error) => {
if (this.status !== "connected") return; // mid-session only
this.status = "error";
this.dispatchTypedEvent("statusChange", this.status);
this.dispatchTypedEvent("error", error);
};Now the Added an integration test (covering your nit too): a transport whose #2 — #3 — identical consecutive errors won't re-toast (informational, no change). Correct and intended: every reconnect drives Full |
|
@claude review |
|
Claude finished @cliffhall's task in 1m 37s —— View job Re-review: surface mid-session transport failures via
|
Re-review follow-up (#1489): the prior `!== "connected"` guard regressed the onclose-before-onerror ordering. On a real mid-session crash many transports fire both onclose and onerror in a transport-dependent order; when onclose lands first it flips status to "disconnected", so a "connected"-only guard swallowed the reason the trailing onerror carries (its only surface). Guard on `=== "connecting"` instead — precisely the handshake state with a pending awaited connect() that will reject — so the error event fires from any non-connecting state regardless of onclose/onerror ordering, while still suppressing the handshake double-report. Tests: integration case firing onclose-then-onerror from connected asserts the error event still lands; hook test asserts lastError survives a trailing statusChange("disconnected"). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Great catch — that's a real regression. Fixed in 5cbb1b8.
baseTransport.onerror = (error: Error) => {
// "connecting" is the only state with a pending awaited connect() that
// will reject; suppress just that. connected / disconnected are genuine
// mid-session failures whose reason has no other surface.
if (this.status === "connecting") return;
this.status = "error";
this.dispatchTypedEvent("statusChange", this.status);
this.dispatchTypedEvent("error", error);
};Walking the orderings now: Tests added (both of your suggestions):
|
|
@claude review |
|
Claude finished @cliffhall's task in 1m 28s —— View job Re-review (#1323):
|
|
Thanks for the thorough re-reviews — appreciate the rigor on the On the informational note: you're right that this PR fixes reason-surfacing but the persistent Calling this one done — thanks again. |
Manual smoke test — mid-session crash surfaces the reason ✅Verified the end-to-end path in a real browser against the web dev server on this branch (not just unit/integration tests).
Setup
Trigger
ResultA red toast appeared:
Both halves of the feature are exercised: the named-server title (via Chain confirmed (matches the code under review)Notes
Negative control (path separation)A handshake failure (bad command / unreachable server) still produces the existing |

Closes #1323
Background
useInspectorClientexposesstatusdriven by the OAuth/XState machine insideInspectorClient. The status can transitionconnected → errorwhen a transport dies mid-session (stdio subprocess crash, SSE stream drop, HTTP 5xx). Before this change, callers saw thestatusflip but not the reason: #1244 wiredApp.tsxto captureerrorMessageonly fromclient.connect()'s rejection (handshake-only), so a state-machine transition to"error"after a successful connect left the UI's error stale or unset.What changed
InspectorClientEventMap.error— documented as the signal forstatus → "error"transitions that happen outside an awaited promise (the transport'sonerror). TheErrorcarries the reason (.message, optional.cause).inspectorClient.ts— the awaitedconnect()catch no longer dispatcheserror. The caller already gets the reason via the rejected promise, so a second dispatch would double-report a handshake failure. The transportonerrorpath (the genuine mid-session case) still dispatches, unchanged.useInspectorClient— newlastError?: stringon the return type, set from theerrorevent and cleared at the next connecting edge (and on client swap / null) so a reconnect starts clean.App.tsx— toasts a mid-session failure (red, with the reason), naming the active server via a ref that survives thedisconnect-drivenactiveServerIdreset. The staleTODO(#1323)marker at the connect catch is updated.Out of scope
Tests
useInspectorClient.test.tsx: captureslastErrorfrom the event, clears it on the connecting edge, keeps it across theerrorstatus transition, and resets on client swap / null.inspectorClient.test.ts(integration): the transportonerroremitserror+ setsstatus: "error"; a handshake rejection setsstatus: "error"without emittingerror.App.test.tsx: generic "Connection lost" toast when no server is active, and a server-named toast after a session has connected.Full
validate, unit (2332), integration (128), storybook (362), CLI (88), and TUI (2) suites pass.🤖 Generated with Claude Code