Skip to content

Agents window repeatedly prompts for MCP authentication after extension host restart #327137

Closed

Description

  • Copilot Chat Extension Version: Built-in
  • VS Code Version: 1.131.0 main at 3d97feaadbd
  • OS Version: macOS
  • Feature (e.g. agent/edit/ask mode): Agents window, local Agent Host, Copilot provider
  • Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): Model-independent
  • Logs: Agent Host debug export inspected locally; relevant sanitized timeline and AHP facts are below

Steps to Reproduce:

  1. Configure an OAuth-protected remote MCP server that uses dynamic client registration, such as Notion at https://mcp.notion.com/mcp.
  2. Create an Agents window session using the local Copilot Agent Host. Send a message so the MCP servers start.
  3. In the response, select Authenticate in The MCP server notion requires authentication. Authenticate? and complete authentication. Confirm that Notion reaches ready.
  4. Create another session without restarting the extension host. The remembered grant is silently reused and no authentication prompt appears.
  5. Restart the local extension host, or reload the window.
  6. Create another Agents window session and send a message.

Expected

The persisted dynamic OAuth client registration, token, account preference, and MCP access grant are restored non-interactively. Notion should become ready without showing another authentication prompt.

Actual

Every session created after the extension-host restart reports Notion as authRequired and shows the Authenticate prompt. Selecting Authenticate once recreates the provider and makes all currently loaded Notion sessions ready, without requiring a new OAuth login.

Evidence

All timestamps below are normalized to UTC:

  • 11:20:11: local extension host pid 94024 starts.
  • 11:20:25: Notion returns a 401 OAuth challenge and the session reports MCP server 'notion' requires authentication.
  • 13:02:35: the dynamic Notion authentication provider is registered and MCP authentication succeeded for notion; the Notion MCP client initializes.
  • 13:06:34: a later session starts in the same extension-host lifetime without another Notion prompt.
  • 13:48:21, 13:48:37, 13:48:47, and 13:49:11: the local extension host restarts.
  • 13:49:27, 13:50:42, 14:08:55, and 14:17:35: each newly started session again reports Notion as requiring authentication.
  • 14:17:57: selecting Authenticate causes four AHP authenticate RPCs and all four loaded Notion sessions transition to ready.

The Notion authRequired payload has oauthClient: undefined, authorization_servers: ['https://mcp.notion.com'], and no required scopes. This is the dynamically registered OAuth path, not the configured/static-client path.

A separate Eng MS server also fails with HTTP 403 and a VPN REQUIRED response in this capture. That is independent of the Notion persistence failure. File watcher EMFILE errors may have contributed to extension-host instability, but a clean extension-host restart is sufficient to expose the provider-restoration gap.

Root cause analysis

AgentHostSessionHandler silently checks auth-required MCP servers by calling resolveMcpServerAuthentication with allowInteraction: false.

For explicit/static OAuth clients, resolveMcpServerAuthentication obtains IDynamicAuthenticationProviderStorageService and can restore a matching persisted provider. For Notion, oauthClient is undefined, so the storage service is not obtained. getOrCreateProviderForMcpResource instead calls IAuthenticationService.getOrActivateProviderIdForServer.

getOrActivateProviderIdForServer only considers currently registered providers and manifest-declared providers. After the extension host restarts, the dynamic Notion provider is neither active nor declared, even though its client registration and tokens remain persisted. The lookup returns undefined; because the operation is non-interactive, getOrCreateProviderForMcpResource refuses provider creation and returns undefined. Silent authentication therefore returns false and the session surfaces the prompt.

The interactive Authenticate path calls createDynamicAuthenticationProvider. Its extension-host delegate reloads the persisted client registration and tokens, which explains why the server becomes ready without a real login.

PR #326736 restored persisted providers for configured/static OAuth clients, but its logic is entirely inside the oauthClient branch. PR #326881 added session-wide silent MCP authentication and therefore exposes this remaining dynamic-registration gap consistently.

Proposed direction

Permit non-interactive rehydration only when the deterministic dynamic provider ID already has a persisted, usable client registration. Recreate the provider with that stored client ID/secret, then require the existing account preference and MCP server URL access grant before forwarding a token. Do not perform fresh dynamic client registration, rotate an invalid client, prompt for client credentials, create a new login session, or update consent during the silent path.

Add regression coverage for:

  1. An inactive persisted DCR provider with an allowed existing session is restored and its token forwarded without interaction.
  2. No persisted registration means no metadata fetch, provider creation, DCR, or prompt.
  3. Invalid-client/token-refresh failure remains non-interactive and leaves the Authenticate card visible.
  4. Configured public/confidential OAuth client behavior remains unchanged.
  5. Concurrent post-restart sessions restore the provider once.

cc Connor Peet (@connor4312)

Activity

  1. Ben-Home commented on Jul 23, 2026

    @Ben-Home

    This is a clean root-cause analysis. The gap is specific: dynamic client registration (DCR) providers aren't rehydrated on extension-host restart, while static/configured OAuth clients are (thanks to #326736).

    One additional consideration for the fix direction: DCR persistence should treat the client registration record (client_id, client_secret, registration_access_token, registration_client_uri) as the durable artifact — not the provider object. The MCP spec RFC 7591 §3 defines DCR response fields that are explicitly long-lived and meant to survive process boundaries. The client_id and client_secret issued by the authorization server are valid until explicitly revoked, not until the process exits.

    Two patterns we use in our MCP server across 36 connector OAuth flows:

    1. Persist the DCR response, not the runtime provider
    After a successful DCR, write the full registration response to durable storage (VS Code's globalState or a similar extension-persisted store). On startup, scan for existing registrations and restore providers from the serialized records. This avoids re-registering with the auth server (which some servers rate-limit or reject as duplicate).

    2. Check token validity before surfacing the prompt
    If a persisted DCR record exists AND the associated access/refresh token hasn't expired, silently restore the provider. Only surface the Authenticate card if the token is genuinely expired AND the refresh fails. The reporter's "Proposed direction" captures this well — specifically point 2: no persisted registration means no prompt.

    One edge case worth guarding against: if the authorization server rotates the client_secret on re-registration (some IdPs do this), the persisted registration becomes stale. The silent rehydration should detect a 401-with-invalid_client on first use and fall back to a fresh DCR transparently, not surface a prompt to the user.

    The fix should be scoped to DCR providers specifically — static OAuth already works post-#326736, and this gap only affects servers where oauthClient is undefined.

  2. added
    bug
    on Jul 23, 2026
  3. added
    unreleased
    on Jul 23, 2026
  4. added this to the 1.131.0 milestone on Jul 23, 2026
  5. added
    insiders-released
    and removed
    unreleased
    on Jul 24, 2026
  6. locked and limited conversation to collaborators on Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agents-windowbuginsiders-releasedverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions