Repository navigation
Refresh Agent Host sessions after connector authorization - #338934
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Routine token renewals currently trigger unnecessary SDK session recreation.
Review effort: Balanced
Findings: 1
What changed in this PR
Refreshes live Agent Host sessions after GitHub connector authorization changes.
Changes:
- Triggers Agent Host connector-session refreshes on authentication session events.
- Adds regression coverage for scope upgrades retaining the same token.
| File | Description |
|---|---|
copilotConnectorsService.ts |
Triggers live-session refresh after relevant authentication events. |
copilotConnectorsService.test.ts |
Tests connector authorization scope upgrades. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <[email protected]>
Contributor
Screenshot ChangesBase: Changed (2)2 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details. |
Co-authored-by: Copilot <[email protected]>
Paul (pwang347)
marked this pull request as ready for review
September 30, 2026 18:06
Dmitriy Vasyura (dmitrivMS)
previously approved these changes
Sep 30, 2026
Co-authored-by: Copilot <[email protected]>
Aaron Munger (amunger)
approved these changes
Sep 30, 2026
2 tasks done
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Oct 19, 2026
…ation (#342479) <!-- Thank you for submitting a Pull Request. Please: * Read our Pull Request guidelines: https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests * Associate an issue with the Pull Request. * Ensure that the code is up-to-date with the `main` branch. * Include a description of the proposed changes and how to test them. --> Fixes #341123 ## Problem The runtime sends Copilot Connector MCP requests with **only** the SDK session's GitHub credential (the token set through `gitHubAuth.setCredentials` / `gitHubToken`). When the gateway returned `403 insufficient_scope`, the runtime fell back to a generic `mcp.oauth_required` (`reason=upscope`). VS Code's **Sign In**, and silent auto-auth, then created a GitHub session with only `write:plugin_gateway_connections` and forwarded it as an MCP token. The runtime ignores that token for connector servers, so the server restarted with the old credential, got another 403, and looped. Meanwhile the client logged "MCP authentication succeeded". A second issue made the working path unreachable. `CopilotConnectorsService.authorize()` returned early if **any** same-account session had the connector scope. That includes the narrow session created by MCP Sign In, which never qualifies as the Copilot credential. So Authorize did nothing in exactly the state the issue logs show. ## Changes **Sign In for connector servers goes through Connector authorization** - `authenticateMcpServer` detects connector-owned servers. Detection uses new host-published `vscode.mcpServerConnectorName` metadata, or a `write:plugin_gateway_connections` challenge as a fallback. - For those servers it calls `ICopilotConnectorsService.authorize()`, forwards the Copilot credential (which prefers the full-scope session), then force-reconciles that connector through a new narrow `refreshAgentHostSessions(connectorName)` API. - `resolveMcpServerAuthentication` refuses connector-scope challenges. So neither the silent nor the interactive path creates a narrow session or forwards an MCP token for a connector. - `authorize()` now skips consent only when a session has the connector scope **and** every scope of the default session. **The agent host does not answer connector upscope requests with tokens** - `CopilotAgentSession.resolveMcpAuthentication` skips connector-owned pending requests. - Before a forced reconcile, affected servers are shown as Starting. After the reconcile succeeds, pending requests from before it are cancelled; requests raised by the restarted server are kept. If a turn is active, refresh is deferred, so stale requests are released straight away instead. - #340547's rejected-token suppression is unchanged. **Truthful reporting** - The forwarding log now says the token was forwarded, not that authentication succeeded. - `authenticateMcpServer` reports success only once the server leaves AuthRequired. This is a bounded wait (60s) that is cancellation-safe and cleans up its listeners. Connector servers must reach Ready. - If a connector returns the same challenge after restarting, Sign In returns `false` and shows a localized message. It asks the user to authorize Copilot connectors with the same GitHub account they use for Copilot. - **Behaviour change for non-connector servers:** if a forwarded token leaves the challenge unchanged, Sign In now waits up to 60s and returns `false`. Previously it returned `true` right after forwarding. **`ConnectorStatus.authorizationRequirement`** - Reconcile now reports connector ownership for each runtime server, and `authorizationRequirement`. - A connector server in `needs-auth` with no `mcp.oauth_required` is shown as AuthRequired (insufficient scope). This covers the planned runtime fix that will stop emitting `mcp.oauth_required` for connector 403s. ## Notes for reviewers - **Same token string after Authorize (#338934):** `_applyGitHubToken` skips `setCredentials`. That should be fine, because the runtime re-reads the session credential on every request and the forced reconcile always restarts the server. I have not confirmed against the live gateway that GitHub widens scope on the same token string. - **Forced reconcile:** the runtime's `replace_managed_servers` already cancels its pending OAuth before restarting the server, so cancelling VS Code's stale entry afterwards is safe. - **Mission Control / scoped credentials:** `updateGitHubCredentials` is only called for static-token sessions, so nothing throws. The challenge comes back and Sign In returns `false` with the message. - **Known gaps:** - Connector refresh only exists for the local agent host, so on a remote host Sign In authorizes but usually times out. - Servers identified only by the scope fallback can't get a targeted reconcile. - The end-to-end integration test (coexisting sessions, Sign In through tool discovery) was not added. It needs a real runtime and gateway. ## How to test 1. Use a default GitHub session that lacks `write:plugin_gateway_connections`. Optionally add a narrow session that has only that scope. 2. Open an Agents session with the WorkIQ / Kusto connectors and click **Sign In** on a connector row. 3. Expect a consent prompt for the default scopes plus `write:plugin_gateway_connections` on the same account. Then the connector restarts, reaches Ready, and lists its tools. The gateway's `x-oauth-scopes` should include the connector scope. Validation run locally: | Command | Result | |---|---| | `./scripts/test.sh --run` agentHostAuth, copilotConnectorsService, agentHostCustomizationService, copilotAgentSession, copilotSessionLauncher, agentMetaReaders | 1621 passing | | `./scripts/test.sh --run` mcpCustomizationController, sessions agentHostCustomizationService, agentHostChatContribution, workbenchAgentHostCustomizationService, chatMcpAuthenticationContentPart, chatToolAuthenticationSubPart | 781 passing | | `./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostClientTools.test.ts` | 73 passing | | `npm run eslint -- <changed files>` | passed | | `npm run typecheck-client` | passed | | `npm run valid-layers-check` | passed | Not run: integration tests (`copilotConnectors.integrationTest.ts` was only updated for the new reconcile result shape) and a manual end-to-end run against the live gateway.
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

Related to microsoft/vscode-internalbacklog#9799
Refreshes live Agent Host Copilot sessions when the active GitHub account's connector authorization changes. This covers OAuth scope upgrades that retain the same access-token string: the connector catalog is invalidated as before, and the existing Agent Host refresh path now recreates the SDK session on the next turn so its tool snapshot includes newly available connector tools.
Adds regression coverage for upgrading an active account from ordinary GitHub scopes to
write:plugin_gateway_connectionswithout changing its token.Testing
npm run transpile-client— passed./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/copilotConnectorsService.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --grep "[Cc]onnector"— passed, 59 testsnpm run typecheck-client— passedHow to Test