Skip to content

Back off on MCP auth failures across service-worker restarts - #16

Closed
Arkham wants to merge 1 commit into
igrigorik:mainfrom
Arkham:arkham/mcp-auth-backoff
Closed

Arkham wants to merge 1 commit into
igrigorik:mainfrom
Arkham:arkham/mcp-auth-backoff

Conversation

@Arkham

@Arkham Arkham commented Aug 21, 2026

Copy link
Copy Markdown

The MV3 service worker restarts constantly and re-runs remote MCP reconciliation on every wake. A server that rejects the configured credential (HTTP 401/403) was re-attempted forever at that cadence, hammering remote endpoints around the clock.

Auth rejections now record an exponential backoff (1min doubling to a 30min cap) in chrome.storage.session, so it survives worker restarts but never outlives the browsing session. While a window is active the connection attempt is skipped and the server status explains when the retry happens. Editing the server URL or auth token retries immediately, a successful connection resets the state, and storage failures fail open. Non-auth failures keep the existing behavior.

The MV3 service worker restarts constantly and re-runs remote MCP
reconciliation on every wake. A server that rejects the configured
credential (HTTP 401/403) was re-attempted forever at that cadence,
hammering remote endpoints around the clock.

Auth rejections now record an exponential backoff (1min doubling to a
30min cap) in chrome.storage.session, so it survives worker restarts
but never outlives the browsing session. While a window is active the
connection attempt is skipped and the server status explains when the
retry happens. Editing the server URL or auth token retries
immediately, a successful connection resets the state, and storage
failures fail open. Non-auth failures keep the existing behavior.
igrigorik added a commit that referenced this pull request Aug 28, 2026
   The service worker wakes on every navigation in any tab, and module top
   level called loadRemoteTools(), so ordinary browsing with the sidebar
   closed reconnected to every configured MCP server on every page load.
   A stale token made that an unbounded 401 loop paced by browsing.

   Discovery was eager because the catalog had nowhere to live: it was held
   only in worker memory, which dies after ~30s idle, so every wake had to
   rebuild it by connecting. Simply making discovery lazy would have moved
   the cost rather than removed it, because stream start blocks on tool
   readiness -- a cache miss is first-token latency, not background work.

   Cache the catalog in chrome.storage.session and materialize it as a
   dormant RemoteMCPSession: a real session carrying cached capabilities
   with no live client, so hasContext stays true and a stream still
   attaches its revocation listener against the same object-identity
   authority anchor. Servers are contacted on first tool call.

   - discover on intent only: sidebar load warms, stream start ensures
   - bound discovery with a 5s timeout; tool calls keep the SDK default,
     since a slow tool is working rather than failing to answer
   - negatively cache a failed discovery for 60s so one outage does not
     suppress tools for the whole browser session
   - refresh writes the cache and never publishes, so it cannot abort a
     live turn; the next materialization picks it up
   - Options "Test connections" also forces a refresh, always against
     saved configuration so a draft under test cannot become authority

   Supersedes #16, which backs off auth failures across worker restarts:
   correct mitigation at the wrong layer, and coupled to an SDK internal
   that changes as soon as an authProvider is configured.
@igrigorik

Copy link
Copy Markdown
Owner

@Arkham ty for this! Went down a different path that should address the root cause, landed in: 053aa50

@igrigorik igrigorik closed this Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants