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
MCP authentication required for every new session #329223
Does this issue occur when all extensions are disabled?: Yes
VS Code Version: 1.132.0 (system setup)
OS Version: Windows_NT x64 10.0.26200
I'm using Agents Window with Agent Host enabled and Copilot CLI harness.
For every new session I create, I have to go into the MCP section and re-authenticate all MCP servers.
As I understand, agent host maintains the MCP auth tokens, but they're not propagated to newly created sessions.
It would make it more convenient if agent host could reuse the same authentication tokens for every new session and not require re-authentication.
Reacted by Ariel Silverman, Maximilian Birkner and Benjamin Lyon
Sharing media and context from merged PR #334593 for verification:
Root cause
The Copilot runtime intentionally keeps host-injected MCP bearer tokens session-scoped: the embedding host owns refresh, revocation, persistence, and per-server consent. Agent Host therefore has to deliver the workbench's persisted grant to every SDK session that challenges.
Two races could lose that delivery:
A CopilotAgentSession can issue onMcpAuthRequest while initializeSession() is still running. The session was added to _chatEntriesBySdkId only after initialization completed, while handleAuthenticationToken() searched only that live map.
Workbench silent MCP authentication coalesced by server identity across sessions. A session challenging after the shared operation's host-side fan-out had been snapshotted reused the promise but did not perform its own delivery.
Before/after evidence
Before — shipped Insiders, pre-fix
A real new Agent Host chat on the affected build immediately challenged again for an MCP whose VS Code authentication session and access grant already existed:
[Copilot:<new-session>] MCP server 'vscode-slack' requires authentication for https://mcp.slack.com
[AgentHost] MCP authentication succeeded for vscode-slack
The same startup trace contained repeated requires authentication → renderer token-delivery pairs for other previously authorized MCPs. This shows that persistence was intact in the workbench, but the token still had to be recovered again for each new SDK session—and could be lost in the initialization/coalescing races above.
After — this branch
Real signed-in Slack OAuth E2E
I loaded an isolated plugin containing only the github-slack MCP definition, authorized it once through the real Slack browser OAuth flow, and then started two brand-new Agent Host sessions. Isolating the definition prevents a second Slack client registration from changing the provider identity during the test.
Before the one-time authorization, VS Code correctly showed the server as requiring authentication. After authorization, both later sessions completed without an auth card, browser redirect, or other user interaction, and the server remained running:
Before one-time authorization
After authorization and two new sessions
The two later sessions are visible here as separate completed chats:
Each new SDK session still issued its expected session-scoped challenge. The workbench silently resolved that challenge from the persisted grant, and Slack reached connected (ready) in 326 ms and 350 ms respectively:
Session 1
08:30:55.171 MCP server 'github-slack' requires authentication
08:30:55.176 [AgentHost] MCP authentication succeeded for github-slack
08:30:55.497 MCP server 'github-slack' connected (ready)
Session 2
08:32:34.101 MCP server 'github-slack' requires authentication
08:32:34.123 [AgentHost] MCP authentication succeeded for github-slack
08:32:34.451 MCP server 'github-slack' connected (ready)
The separate workspace-local vscode-automation-mcp error visible in the server list is unrelated to this test; the isolated test target is github-slack.
Deterministic lifecycle regression coverage
The regression tests start real CopilotAgent chat creation/resume paths with the fake SDK blocked inside onMcpAuthRequest, then deliver the persisted token through the real Agent Host authentication service:
Two concurrently initializing new chats both receive { kind: 'token', accessToken: 'mcp-token' } and both become live from one host-side fan-out.
A later new chat performs its own persisted-token delivery instead of sharing an already-completed cross-session operation.
Provisional materialization, default cold resume, and peer-chat resume all receive the token before registration completes.
Insufficient scopes are rejected.
Shutdown while blocked on authentication, and shutdown during post-initialization metadata work, both cancel without registering or leaking the session.
Workbench coverage verifies two simultaneous sessions perform two target deliveries while the existing provider-level sequencer still serializes authentication-provider access.
That final lifecycle matrix passed 30/30 repeated executions. No interactive Authenticate path is used in these successful cases.
Change
Track every Copilot session in a DisposableSet from SDK initialization until atomic ownership transfer to the live-session map.
Centralize all four initializeSession() paths in one initialize/register helper so future paths cannot bypass tracking.
Keep final client and working-directory validation synchronous with registration.
Dispose initialization-blocked sessions during shutdown and reject registration when shutdown already removed ownership.
Scope workbench silent-auth coalescing by URI comparison identity for the target session, so every session independently delivers its persisted grant while provider setup remains serialized by the existing authentication sequencer.
Add production-path coverage for concurrent immediate creation, later repeated delivery, provisional materialization, default cold resume, peer resume, scope mismatch, authentication-blocked shutdown, and shutdown during post-initialization metadata work.
No protocol, SDK/runtime token-storage, token refresh, scope, consent, or revocation semantics are changed.
Validation
npm run typecheck-client
Targeted ESLint on all changed files
npm run hygiene (full repository)
copilotAgent.test.ts: 363 passing, 1 pending
CopilotAgentSession MCP inventory: 27 passing
Agent service authentication suite: 12 passing
Agent Host MCP auth-prompt suite: 5 passing
Agent Host service graph: 6 passing
Final MCP lifecycle matrix: 30/30 repeated executions passed
Copilot Agent Host E2E replay, run twice after the final lifecycle changes: 177 passing, 21 pending on each run
Real signed-in Slack OAuth E2E: one interactive authorization followed by two independent sessions with silent persisted-token delivery and connected (ready) in 326 ms and 350 ms
Full Agent Host E2E replay: Copilot and Codex passed. Two conformance changeset failures and one Claude fixture mismatch were reproduced unchanged from a clean origin/main worktree.
GitHub CI: all jobs passed after rerunning the macOS Electron job, including the full Windows, Linux, and macOS Electron matrices.
Azure product build 471451: succeeded across every stage after retrying only the flaky macOS Electron job and its downstream-canceled Windows Electron job. Quality, Copilot, Linux, Windows, macOS, browser, remote, CLI, Electron, node_modules, and SDL checks are all green.
Final focused code review: no introduced issues or release blockers
The public AHP E2E harness cannot inject authenticate while createSession is still in flight, so the exact race is covered at the strongest deterministic layer: real CopilotAgent create/resume paths with the SDK auth callback blocked until Agent Host delivers the token.
Activity
vs-code-engineering commentedon Sep 8, 2026
Sharing media and context from merged PR #334593 for verification:
Root cause
The Copilot runtime intentionally keeps host-injected MCP bearer tokens session-scoped: the embedding host owns refresh, revocation, persistence, and per-server consent. Agent Host therefore has to deliver the workbench's persisted grant to every SDK session that challenges.
Two races could lose that delivery:
CopilotAgentSessioncan issueonMcpAuthRequestwhileinitializeSession()is still running. The session was added to_chatEntriesBySdkIdonly after initialization completed, whilehandleAuthenticationToken()searched only that live map.Before/after evidence
Before — shipped Insiders, pre-fix
A real new Agent Host chat on the affected build immediately challenged again for an MCP whose VS Code authentication session and access grant already existed:
The same startup trace contained repeated
requires authentication→ renderer token-delivery pairs for other previously authorized MCPs. This shows that persistence was intact in the workbench, but the token still had to be recovered again for each new SDK session—and could be lost in the initialization/coalescing races above.After — this branch
Real signed-in Slack OAuth E2E
I loaded an isolated plugin containing only the
github-slackMCP definition, authorized it once through the real Slack browser OAuth flow, and then started two brand-new Agent Host sessions. Isolating the definition prevents a second Slack client registration from changing the provider identity during the test.Before the one-time authorization, VS Code correctly showed the server as requiring authentication. After authorization, both later sessions completed without an auth card, browser redirect, or other user interaction, and the server remained running:
The two later sessions are visible here as separate completed chats:
Each new SDK session still issued its expected session-scoped challenge. The workbench silently resolved that challenge from the persisted grant, and Slack reached
connected (ready)in 326 ms and 350 ms respectively:The separate workspace-local
vscode-automation-mcperror visible in the server list is unrelated to this test; the isolated test target isgithub-slack.Deterministic lifecycle regression coverage
The regression tests start real
CopilotAgentchat creation/resume paths with the fake SDK blocked insideonMcpAuthRequest, then deliver the persisted token through the real Agent Host authentication service:{ kind: 'token', accessToken: 'mcp-token' }and both become live from one host-side fan-out.Observed fixed-run result:
That final lifecycle matrix passed 30/30 repeated executions. No interactive Authenticate path is used in these successful cases.
Change
DisposableSetfrom SDK initialization until atomic ownership transfer to the live-session map.initializeSession()paths in one initialize/register helper so future paths cannot bypass tracking.No protocol, SDK/runtime token-storage, token refresh, scope, consent, or revocation semantics are changed.
Validation
npm run typecheck-clientnpm run hygiene(full repository)copilotAgent.test.ts: 363 passing, 1 pendingCopilotAgentSessionMCP inventory: 27 passingconnected (ready)in 326 ms and 350 msorigin/mainworktree.The public AHP E2E harness cannot inject
authenticatewhilecreateSessionis still in flight, so the exact race is covered at the strongest deterministic layer: realCopilotAgentcreate/resume paths with the SDK auth callback blocked until Agent Host delivers the token.Source PR: #334593