Skip to content

fix(subscriptions): stop retrying a subscriptions/listen refused over HTTP - #2730

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2722-listen-http-refusal
Oct 20, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2722-listen-http-refusal

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2722

Problem

On a modern-era server, a subscriptions/listen refused with a bare HTTP 403 was re-sent at the reconnect backoff until the eight-attempt cap and never reported. The refused URI's rollback also cleared the active flag the badge is gated on, so the refusal showed nowhere.

Change

  • core/mcp/subscriptionRefusal.ts (new) classifies a rejected listen() as a deterministic refusal when it is an SdkHttpError with the SDK's generic ClientHttpNotImplemented code and status 400, 403, 404 or 405. The code check is what keeps auth failures out: a 401, and a 403 carrying insufficient_scope, go through the auth flow and surface under the SDK's auth codes. 5xx, 408, 429, network errors and timeouts stay retryable.
  • InspectorClient records the refusal at the rejection site, under the same generation gate as Modern subscriptions: say "the server closed the subscription without acknowledging it" instead of silently retrying eight times #2097's modernNeverAcknowledged. Both failure handlers then settle on a new "refused" stream status that carries refusal: { status, statusText }, with no reconnect. The refusal is reported ahead of the empty-filter check, so it survives a rollback that empties the filter.
  • Web: a red Refused badge on the Subscriptions header, plus a notice reading "The server refused subscriptions/listen (HTTP 403 Forbidden). Not retrying — …". Both show whatever the subscription count. The notice counts as section content, so Subscriptions (0) can be opened to read it.
  • TUI: Listen stream: refused by the server and the same sentence, shown while the stream is inactive.
  • Test server: a new transport.modern.refuseSubscriptionsListen: <status> option, and a subscriptions-listen-refused-http.json showcase (documented in docs/test-servers.md).

Tests

  • Integration (inspectorClient-subscriptions-era.test.ts, 10 new) against the real refusing server for 403/400/404/405: one listen, the refused state with the HTTP status, on subscribe and on connect, and when the rollback empties the filter. Some tests stub listen() with the SdkHttpError the web remote transport rebuilds (Web client: protocol era "auto" does not fall back to legacy when a 2025-only server rejects the probe with HTTP 400 #2660), because the Node transport also fires onerror on a failed POST, which already makes the client error and stops the timer. Those tests prove that a refusal is not retried while the session stays connected, that a 503 still is, and that a reconnect run ends at the first refusal.
  • Disabling the classifier fails 8 of the new integration tests. Removing the "refusal counts as section content" change fails the web panel test.
  • Unit: the classifier and message, the badge presentation, the ResourceControls notice (modern era only), and the TUI pane.
  • npm run local:gate passed.

Screenshots

subscriptions-listen-refused-http.json, Protocol Era = Modern, after clicking Subscribe on resource_1. The Monitor sidebar width was seeded by the capture script.

Before: the listen is re-sent at the backoff, and nothing explains the empty Subscriptions (0):

before

After, on connect: the connect-time listen is refused once, and the badge says so:

after on connect

After Subscribe: one further listen, no retries:

after subscribe

The notice, with the section opened:

notice

The PENDING listen rows in the Protocol tab are #2721, a separate issue.

Deliberately out of scope

  • Retry-After on 429/503 ("consider" in the issue). Transient statuses keep the existing backoff.
  • A 400 that carries a JSON-RPC error body. The SDK delivers it as a protocol error rather than an SdkHttpError, so it stays retryable, as Modern subscriptions: say "the server closed the subscription without acknowledging it" instead of silently retrying eight times #2097 left "a pre-ack error response".
  • The subscribe toast keeps the SDK's message. subscriptionFailureMessage also wraps legacy resources/subscribe failures, where "refused subscriptions/listen" would be wrong, so the explanation lives on the stream state instead.
  • A failed listen POST on the Node transport flips the whole client to error through onerror. That is pre-existing and unchanged here.

🤖 Generated with Claude Code

… HTTP

A modern-era subscriptions/listen refused with a bare 403 (or a 400, 404
or 405) was handed to the reconnect machinery as though it were a drop,
re-sent at the backoff until the eight-attempt cap and never reported. The
refused URI's rollback also cleared the badge's `active` gate, so the
refusal showed nowhere.

Classify the rejection by the HTTP status on the SDK's generic
ClientHttpNotImplemented error (auth-coded 401/403s never carry that
code), settle the stream on a new "refused" status carrying the status,
and surface it in the web Subscriptions section and the TUI pane whatever
the subscription count. Transient statuses (5xx, 408, 429) keep retrying.

Adds a refuseSubscriptionsListen test-server option and the
subscriptions-listen-refused-http showcase.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: cliffhall <[email protected]>

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

The scoped refusal handling and regression coverage address the reported issue without identified blocking defects.

No open issues 🎉

What changed in this PR

Fixes #2722 by stopping automatic retries after deterministic HTTP refusals of subscriptions/listen and displaying the reason even when no subscriptions remain.

Changes:

  • Classifies HTTP 400/403/404/405 refusals while preserving transient-error retries and auth handling.
  • Adds refusal status and explanations to Web and TUI.
  • Adds regression coverage and a configurable test-server showcase.
File Description
test-servers/​src/​test-server-http.ts Injects configured HTTP listen refusals.
test-servers/​src/​load-config.ts Adds the refusal configuration field.
test-servers/​src/​composable-test-server.ts Defines and documents the refusal option.
test-servers/​configs/​subscriptions-listen-refused-http.json Provides a 403 showcase.
docs/​test-servers.md Documents reproduction and expected behavior.
core/​mcp/​types.ts Defines refusal status and HTTP details.
core/​mcp/​subscriptionRefusal.ts Classifies refusals and formats explanations.
core/​mcp/​inspectorClient.ts Records refusals and stops reconnect attempts.
clients/​web/​src/​test/​integration/​mcp/​inspectorClient-subscriptions-era.test.ts Covers refusal, rollback, retry, and reset behavior.
clients/​web/​src/​test/​core/​mcp/​subscriptionRefusal.test.ts Tests classification and messages.
clients/​web/​src/​components/​groups/​ResourceControls/​ResourceControls.tsx Shows refusals in empty subscription sections.
clients/​web/​src/​components/​groups/​ResourceControls/​ResourceControls.test.tsx Tests notice visibility and legacy exclusion.
clients/​web/​src/​components/​elements/​SubscriptionStreamBadge/​subscriptionStreamUtils.ts Adds refusal badge presentation.
clients/​web/​src/​components/​elements/​SubscriptionStreamBadge/​SubscriptionStreamBadge.test.tsx Tests refusal badge and tooltip.
clients/​web/​src/​components/​elements/​SubscriptionStreamBadge/​SubscriptionStreamBadge.stories.tsx Adds a refused-state story.
clients/​tui/​src/​components/​SubscriptionsTab.tsx Displays inactive-stream refusals.
clients/​tui/​__tests__/​SubscriptionsTab.test.tsx Tests TUI refusal visibility.

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 was clean ("No open issues", no inline comments, no suppressed comments), so per the pr-flow exit rule no further round was requested.

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.

Modern subscriptions: a subscriptions/listen refused with HTTP 403 is retried eight times in silence

2 participants