You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Web: one held connection per tab, and warn a tab starved by the browser's connection limit - #3108
Chrome allows six HTTP/1.1 connections per host, and every tab of the origin shares them. Each Inspector tab held up to three SSE responses open: /api/servers/events, /api/events/webhook/deliveries, and /api/mcp/events for each connected session. Two connected tabs therefore used all six connections. The second tab's initialize then queued in the browser until the client gave up after 30s.
Approach
As discussed on the issue: one combined stream per tab, plus a clear warning when a tab is still starved. We chose not to move the streams to WebSockets, to avoid a second transport and a wider attack surface.
One stream per tab.GET /api/tab/stream opens with a hello { tabId } frame. It then carries the servers change signal, webhook deliveries, and mcp { sessionId, event } for every session attached to it with POST /api/tab/attach. When a session's events end, the tab gets a session_end { sessionId } frame instead of a closed stream. The wire format is in core/mcp/remote/tabStream.ts. Attaching keeps the existing /api/mcp/events behaviour:
The per-purpose routes remain for callers outside the browser.
Browser side.TabEventChannel (core/mcp/remote/tabEventChannel.ts, browser-safe) is created once per page by src/lib/tabEventChannel.ts. It reopens the stream after a drop, and a drop ends every attached session the way a dropped /api/mcp/events stream did. Three things now use it:
RemoteClientTransport, through a new eventChannel option. With the option it attaches its session to the channel; without it, it opens its own stream as before. The event handling moved into handleRemoteEvent / handleEventStreamEnd, which both paths share.
useServers, through a new subscribeServerChanges option.
useWebhookDeliveries, which now only routes frames. The stream, its retries and its error toast moved to the channel. listenForWebhookDeliveries and WEBHOOK_STREAM_ERROR_NOTIFICATION_ID are removed.
Starvation warning. A browser queues requests it has no connection for; it doesn't fail them, so the channel measures the delay instead. If the stream's hello, or a GET /api/tab/ping sent after it, takes more than 5s against the local backend, the tab is starved. It then opens Active Sessions with the warning. The warning clears when the slow request finally completes, because that is exactly when a connection frees up. A tab also re-probes whenever it comes back into view, since tabs opened while it was hidden can starve it.
The wording says "until another Inspector tab is closed" rather than "another session". Each tab now holds one connection however many sessions it has, so ending a session frees nothing.
Behaviour change to note
Every open tab now listens for webhook deliveries. Before, only a tab with a session listened. So if a delivery arrives while some other Inspector tab is open, the receiver acknowledges it even when that tab has no matching subscription and drops it. Before, it would have answered 503 and the server would retry. This only matters when the subscribing tab is gone while another tab is open.
Verification
Real browser (Chromium via Playwright, one profile, dev server):
Tab 1 connects to everything-server-default, and tab 2 then connects to filesystem-server-default in about 1s. That is the original hang.
Tabs 3–5 load normally.
Tab 6 opens Active Sessions with the warning (screenshot below).
Closing another tab clears it.
Tests: a new integration suite (tab-stream.test.ts) runs the routes end to end against real stdio children. There are also unit suites for the channel, the transport's channel path, useTabStarved, the page-level channel, the useServers option and the modal alert.
npm run format and npm run local:gate both pass.
Screenshot
The starved tab. It was captured over CDP because the tab is starved and can't load its fonts, so the font is a fallback.
…er limit (#3107)
A browser shares six HTTP/1.1 connections per host across every tab of
the origin, and each tab held up to three SSE responses open
(/api/servers/events, /api/events/webhook/deliveries, /api/mcp/events).
Two connected tabs therefore exhausted the pool, and the second tab's
initialize queued in the browser until the client timed out.
- GET /api/tab/stream: one stream per tab carrying the mcp.json change
signal, webhook deliveries and every attached session's events;
POST /api/tab/attach routes a session onto it (same detach-grace reap,
crash-on-startup and terminate semantics as /api/mcp/events).
- TabEventChannel (core, browser-safe) is the browser end; the remote
transport, useServers and useWebhookDeliveries share it.
- The channel times its hello and a GET /api/tab/ping probe; past 5s the
tab is starved and opens Active Sessions with a warning, which clears
when the request completes. A tab re-probes when it becomes visible.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Two critical lifecycle leaks remain: disconnecting during the hello write can retain the handler and subscriptions, while normal session disconnects leave attachments retaining sessions and transports in an open tab.
This PR addresses #3107 by consolidating the web client’s event streams into one connection per tab, reducing pressure on the browser’s HTTP/1.1 connection limit.
Changes:
Adds a shared tab stream for server-list changes, webhook deliveries, and MCP session events while preserving standalone routes.
Detects delayed backend requests and opens Active Sessions with a connection-limit warning.
Adds channel, transport, hook, UI, and integration coverage, plus documentation.
File
Description
core/react/useServers.ts
Supports a caller-provided change subscription.
core/mcp/remote/tabStream.ts
Defines tab-stream routes and event types.
core/mcp/remote/tabEventChannel.ts
Manages shared events, retries, and starvation detection.
- Send the tab stream's hello as primeAndHoldSseStream's priming write,
so a disconnect during it still runs the tab's cleanup.
- Mark a session ended on /api/mcp/disconnect, which releases its route
on an open tab instead of keeping it until the tab closes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Abort during the hello write leaks subscriptions: fixed. The hello is now primeAndHoldSseStream's priming write, so it goes out only after the abort cleanup is registered. A regression test is added.
Disconnect leaves stale attachments on open tabs: fixed. /api/mcp/disconnect now calls session.terminate(), which releases the route and sends session_end. A regression test covers repeated cycles on one open tab.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Detaching removes only the browser-side handler, leaving the old backend session attached so its transport and stdio child can remain alive until the tab closes.
Detaching a session from the tab channel now tells the backend
(POST /api/tab/detach), which takes it off the tab's stream and arms its
detach grace, as aborting its own /api/mcp/events stream used to.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Session switch leaves the old backend transport attached: fixed. A channel detach now posts /api/tab/detach, which removes the session's route on an open tab and arms its detach grace. Regression tests are added.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A rapid stop/start can let stale reader cleanup clear the restarted channel’s state and open an extra untracked stream, violating the one-connection guarantee.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Prevent stale reader cleanup from disrupting a restarted channel
core/mcp/remote/tabEventChannel.ts:309
If stop() is followed immediately by start(), the old reader's asynchronous cleanup still clears the restarted channel's tab ID and session handlers, then schedules an extra stream. This can leave two streams open while only one is tracked by this.abort, defeating the one-connection guarantee. Make cleanup generation-aware, settle the stopped generation's handlers and waiters before restarting, and add a rapid stop/start regression test.
A stream's end only touches the channel when no newer stream has opened
since, so a quick stop()/start() cannot let the old stream clear the new
one's tab id and sessions or queue a second stream beside it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Copilot round 3, addressed in c24d722. The finding was in the review's previously-missed section, so it has no thread to reply in:
Stale reader cleanup can disrupt a restarted channel: fixed. Each open() bumps a generation counter, and a stream's end touches the channel only if no newer stream has opened since. A regression test ("ignores the end of a stream a restart replaced") fails without the fix and passes with it. In the app, only the test reset calls stop(), but the race was real.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate lifecycle edge cases that can leak tab connections and backend sessions during hot reloads or lost attach responses.
Copilot review loop closed. Round 4 had no inline comments and no suppressed findings. Its headline asks for a human look at two lifecycle edge cases without naming a defect:
Dev hot reload: a hot reload of src/lib/tabEventChannel.ts can leave the old module's stream open until the page reloads.
Lost attach response: if the response to an attach is lost, the session stays attached on the backend until the tab closes, and is reaped after that.
Neither has been reproduced, and both are left to the reviewer. Three earlier rounds fixed a real defect each (rounds 1–3).
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
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 #3107
Problem
Chrome allows six HTTP/1.1 connections per host, and every tab of the origin shares them. Each Inspector tab held up to three SSE responses open:
/api/servers/events,/api/events/webhook/deliveries, and/api/mcp/eventsfor each connected session. Two connected tabs therefore used all six connections. The second tab'sinitializethen queued in the browser until the client gave up after 30s.Approach
As discussed on the issue: one combined stream per tab, plus a clear warning when a tab is still starved. We chose not to move the streams to WebSockets, to avoid a second transport and a wider attack surface.
One stream per tab.
GET /api/tab/streamopens with ahello { tabId }frame. It then carries theserverschange signal,webhookdeliveries, andmcp { sessionId, event }for every session attached to it withPOST /api/tab/attach. When a session's events end, the tab gets asession_end { sessionId }frame instead of a closed stream. The wire format is incore/mcp/remote/tabStream.ts. Attaching keeps the existing/api/mcp/eventsbehaviour:transport_error.The per-purpose routes remain for callers outside the browser.
Browser side.
TabEventChannel(core/mcp/remote/tabEventChannel.ts, browser-safe) is created once per page bysrc/lib/tabEventChannel.ts. It reopens the stream after a drop, and a drop ends every attached session the way a dropped/api/mcp/eventsstream did. Three things now use it:RemoteClientTransport, through a neweventChanneloption. With the option it attaches its session to the channel; without it, it opens its own stream as before. The event handling moved intohandleRemoteEvent/handleEventStreamEnd, which both paths share.useServers, through a newsubscribeServerChangesoption.useWebhookDeliveries, which now only routes frames. The stream, its retries and its error toast moved to the channel.listenForWebhookDeliveriesandWEBHOOK_STREAM_ERROR_NOTIFICATION_IDare removed.Starvation warning. A browser queues requests it has no connection for; it doesn't fail them, so the channel measures the delay instead. If the stream's hello, or a
GET /api/tab/pingsent after it, takes more than 5s against the local backend, the tab is starved. It then opens Active Sessions with the warning. The warning clears when the slow request finally completes, because that is exactly when a connection frees up. A tab also re-probes whenever it comes back into view, since tabs opened while it was hidden can starve it.The wording says "until another Inspector tab is closed" rather than "another session". Each tab now holds one connection however many sessions it has, so ending a session frees nothing.
Behaviour change to note
Every open tab now listens for webhook deliveries. Before, only a tab with a session listened. So if a delivery arrives while some other Inspector tab is open, the receiver acknowledges it even when that tab has no matching subscription and drops it. Before, it would have answered
503and the server would retry. This only matters when the subscribing tab is gone while another tab is open.Verification
everything-server-default, and tab 2 then connects tofilesystem-server-defaultin about 1s. That is the original hang.tab-stream.test.ts) runs the routes end to end against real stdio children. There are also unit suites for the channel, the transport's channel path,useTabStarved, the page-level channel, theuseServersoption and the modal alert.npm run formatandnpm run local:gateboth pass.Screenshot
The starved tab. It was captured over CDP because the tab is starved and can't load its fonts, so the font is a fallback.
🤖 Generated with Claude Code