Repository navigation
agentHost: ask before a Copilot extension reads sensitive environment variables - #348216
Merged
Ulugbek Abdullaev (ulugbekna) merged 9 commits intoNov 13, 2026
Conversation
A lazily started Copilot extension that requests a sensitive environment variable makes the runtime ask the host for `extension-env-access` consent while the extension starts, never with a tool call. A person's No fails the extension and is kept for the rest of the runtime session, even across a provider reload. Resuming the session forgets the denial, and forgets a session approval too. The Agent Host consent flow in the following commits relies on this behavior, so pin it against the bundled runtime. Co-authored-by: Copilot <[email protected]>
Before a Copilot extension that requests sensitive environment variables starts, the runtime asks the host for `extension-env-access` consent. It never attaches a tool call, so the host denied every such request, and the extension failed to load. Handle it like `extension-permission-access`, through one consent gate for both kinds: - A saved Always Allow or Never, or an approval for this runtime, answers at once. Otherwise the request waits, without blocking resumes or turns, for the next turn to show it. Allow All approves it and Autopilot declines it. - The prompt names the extension with its source-qualified ID and lists the variable names, never their values. - Always Allow and Never are offered only for user extensions: a project extension is named after its folder, and a plugin after its package, which another repository or source can reuse. Saved environment entries are keyed by the extension and its sorted variable names; capability entries keep their existing keys. - Initialization no longer waits up to 10 seconds for a canvas extension that waits for consent. Readiness telemetry reports `consentPending`. Co-authored-by: Copilot <[email protected]>
Opening a canvas from the UI starts its lazily started extension without a turn, so the consent request waited for the next turn while the open failed at the 30 second control-plane bound. Make a canvas open a two-step exchange over the local IPC: - `openSessionCanvas` returns `consentRequired` with the extension, its source-qualified ID and the requested names while the open keeps waiting. The client calls again with the user's answer and gets the open's outcome. Whichever surface answers first settles the request; a turn that shows the same request completes its confirmation with that answer. - The control-plane bound applies only while nobody is asked. - A declined extension fails the open with `consentDenied`, which tells whether asking again can help: it cannot while a saved Never applies. - An answer continues only the open it was shown for, on the runtime that asked; any other answer fails as no longer pending. Answers bypass the chat queue, which can hold an operation that waits for the extension. - A permission mode changed while the chat was idle applies before the open, so Allow All and Autopilot decide without asking. The renderer ignores the new result until a later commit asks the user. Co-authored-by: Copilot <[email protected]>
Move the credential sponsorship test's environment scrubbing into `replaceCredentialEnvironment`, which removes credential, proxy and provider variables, sets the given sentinels in their place, and returns a function that restores them. Another provider integration test reuses it in a later commit. Co-authored-by: Copilot <[email protected]>
A configuration refresh replaces the chat's runtime, which forgets session approvals. Until then, the runtime keeps a person's No and leaves the extension failed. So an allowed canvas asked again after every refresh, including the background reopen of lazily activated canvases, and a declined canvas could not open again. - CopilotAgent keeps each chat's session approvals and hands them to the runtimes that replace one. A project extension's approval covers only the folder the runtime discovered it in. - A `retry` answer to `openSessionCanvas` replaces the chat's idle runtime when it declined the canvas's extension (refresh reason `extensionConsentRetry`), so opening the canvas asks again. The retry is refused while a turn or background subagents run, since a new runtime would stop them. A saved Never stays final until it is removed from the settings. - A real-runtime test opens canvases the way the UI does, in the default chat and in a peer chat. Co-authored-by: Copilot <[email protected]>
A plugin extension is named after its package, which another marketplace or source can reuse, so a saved decision keyed by that name could let a different plugin read the same secrets. While the request waits, read the install from the runtime's plugin inventory, bounded to 5 seconds, and include it in the saved identity: the plugin's install ID, else its direct source, else name@marketplace. When the install cannot be told, for example because two enabled plugins share the name, Always Allow and Never are not offered and Allow lasts only for that runtime. Capability consent entries are unchanged. The contract test checks that the inventory can be read while the runtime waits for the answer. Co-authored-by: Copilot <[email protected]>
When the extension of a canvas opened from the Agents window, the editor canvas actions or the Canvases customization list waits for consent, show a modal dialog. It names the extension with its source-qualified ID and lists the requested variable names or permissions, never values. It offers Allow, plus Always Allow and Never when the decision can be saved; Escape or Not Now declines for now. A declined open fails with a localized message in a notification that stays open and offers Try Again, which asks the host to replace the runtime that declined the extension and asks again. Try Again stays available after a failed retry, for example while the chat is busy. After Never, the message says to remove the saved decision first. A retry checks again that canvases are still enabled. Co-authored-by: Copilot <[email protected]>
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Joaquín Ruales (@jruales)Matched files:
Sandeep Somavarapu (@sandy081)Matched files:
Ladislau Szomoru (@lszomoru)Matched files:
|
roblourens
previously approved these changes
Nov 13, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Permission-mode synchronization runs before the control-plane timeout, so a stalled RPC can leave canvas opening blocked indefinitely without consent, an error, or a runtime resynchronization marker.
1 open issue
What changed in this PR
This PR extends the earlier lazy-canvas support so Copilot extensions can request consent before reading sensitive environment variables, rather than silently failing to start. It adds consent handling for both model-initiated and UI-initiated canvas opens without changing the Agent Host Protocol.
Changes:
- Unifies extension consent, scopes saved decisions, and preserves chat approvals across runtime refreshes.
- Adds modal consent dialogs and retry notifications across canvas entry points, using local IPC.
- Expands runtime and host tests, shares credential-isolation helpers, and updates readiness telemetry.
| File | Description |
|---|---|
src/vs/workbench/contrib/sessions/providers/agentHost/browser/baseAgentHostSessionsProvider.ts |
Opens session canvases through the consent helper. |
src/vs/workbench/contrib/sessions/common/sessionsProvider.ts |
Adds optional canvas retry options to providers. |
src/vs/workbench/contrib/sessions/common/sessionsManagement.ts |
Extends the management contract with retry options. |
src/vs/workbench/contrib/sessions/browser/sessionsManagementService.ts |
Forwards canvas retry options to providers. |
src/vs/workbench/contrib/chat/browser/aiCustomization/copilotCustomizationsWidget.ts |
Adds denial notifications and retries to Canvases customization. |
src/vs/workbench/contrib/canvases/test/common/agentHostCanvasConsent.test.ts |
Tests consent dialogs, answers, and retry notifications. |
src/vs/workbench/contrib/canvases/test/common/agentHostCanvas.test.ts |
Updates fixtures for dialogs and structured open results. |
src/vs/workbench/contrib/canvases/common/canvas.ts |
Extends canvas definition providers with open options. |
src/vs/workbench/contrib/canvases/common/agentHostCanvasConsent.ts |
Implements shared consent dialogs and denial recovery. |
src/vs/workbench/contrib/canvases/common/agentHostCanvas.ts |
Connects canvas collections to consent handling. |
src/vs/workbench/contrib/canvases/browser/editorCanvasActions.ts |
Adds consent-denial recovery to editor canvas actions. |
src/vs/workbench/common/canvasReference.ts |
Defines shared canvas retry options. |
src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts |
Updates the mock host’s canvas-open result. |
src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasRegistryService.test.ts |
Supplies the registry’s new notification dependency. |
src/vs/sessions/contrib/canvases/electron-browser/sessionCanvasService.ts |
Adds retry handling to Agents window canvas opens. |
src/vs/platform/agentHost/test/node/providerIntegration/copilotMockLlm.integrationTest.ts |
Tests model-initiated environment consent. |
src/vs/platform/agentHost/test/node/providerIntegration/copilotExtensionEnvConsent.integrationTest.ts |
Tests UI opens, retries, and approval continuity against the runtime. |
src/vs/platform/agentHost/test/node/providerIntegration/copilotCredentialTestUtils.ts |
Shares credential-environment isolation and test values. |
src/vs/platform/agentHost/test/node/providerIntegration/copilotCredentialSponsorship.integrationTest.ts |
Reuses the shared environment-isolation helper. |
src/vs/platform/agentHost/test/node/copilotSdkCanvas.integrationTest.ts |
Records runtime consent, denial, and resume behavior. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests consent decisions, scoping, readiness, and competing answers. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests retry-driven runtime replacement and approval retention. |
src/vs/platform/agentHost/test/node/agentService.test.ts |
Updates provider mocks for structured open results. |
src/vs/platform/agentHost/node/copilot/copilotRuntimeRestartTelemetry.ts |
Adds an extension-consent retry refresh reason. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Implements consent gates, pending opens, and scoped approvals. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Routes answers and replaces idle runtimes for retries. |
src/vs/platform/agentHost/node/agentService.ts |
Forwards consent answers and returns open outcomes. |
src/vs/platform/agentHost/node/agentHostTelemetryReporter.ts |
Adds the consent-pending readiness outcome. |
src/vs/platform/agentHost/node/agentHostManagementService.ts |
Carries consent answers through management IPC. |
src/vs/platform/agentHost/electron-browser/localAgentHostService.ts |
Exposes consent-aware opens to local clients. |
src/vs/platform/agentHost/common/agentService.ts |
Updates service and connection contracts. |
src/vs/platform/agentHost/common/agentHostSchema.ts |
Documents environment decisions in the existing approvals setting. |
src/vs/platform/agentHost/common/agent.ts |
Defines consent requests, choices, answers, and open results. |
Review effort: Balanced
An idle chat applies a changed permission mode before it opens a canvas. That sync had no time limit, so a runtime that never answered `permissions.setMode` or `options.update` left the open waiting forever, without showing consent or an error. Bound it like other control-plane requests. On timeout, the open fails before it starts, and the session is marked for resynchronization. The user's consent decision, which comes after the sync, still has no time limit. A failed sync is no longer reported as a consent denial. Co-authored-by: Copilot <[email protected]>
Two tests checked whether a replacement runtime asks again by racing the permission request against a cancelable `timeout(0)`. When the request won, the timer was still pending when the test ended. Under the Node unit test runner, the leak check then failed the test's `after each` hook. Use `raceTimeout`, which leaves nothing to dispose. Co-authored-by: Copilot <[email protected]>
Joaquín Ruales (jruales)
approved these changes
Nov 13, 2026
Ulugbek Abdullaev (ulugbekna)
deleted the
ulugbekna/agents/consent-flow-for-extension-env-access
branch
November 13, 2026 20:46
This was referenced Nov 14, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Follow-up to #347629 and #347946.
The Copilot runtime starts a lazily initialized extension on first use (github/copilot-agent-runtime#28873). If the extension requests sensitive environment variables, the runtime first asks the host for
extension-env-accessconsent. It asks while the extension starts, never with a tool call.The Agent Host denied every permission request without a tool call, except
extension-permission-access. So such an extension never started. Opening its canvas from the Agents window did nothing: no dialog, no canvas, no error. A model-initiatedopen_canvasfailed the same way. The runtime then keeps the person's denial and the failed extension for the rest of the runtime session, so opening the canvas again did nothing either.Changes
Each commit builds and passes the tests it touches, so they can be reviewed one at a time.
extension-permission-accessandextension-env-access.user:my-canvas, and lists the variable names, never their values.extensionPermissionApprovalssetting, keyed by the extension and its sorted variable names. Capability entries keep their existing keys.consentPending.openSessionCanvasreturnsconsentRequiredwhile the open keeps waiting. The client calls again with the user's answer and gets the open's outcome. The Agent Host Protocol doesn't change.consentDenied, which says whether asking again can help. It can't while a saved Never applies.retryanswer replaces the chat's idle runtime when that runtime declined the extension, so the next open asks again. The retry is refused while a turn or background subagents run.How to test
Set
COPILOT_HOMEto an empty folder and add this user extension inextensions/env-consent-demo/inside it:extension.jsonandextension.mjs{ "version": 1, "initialization": "module", "canvases": [{ "id": "env-consent-demo", "displayName": "Env Consent Demo", "description": "Shows whether BLACKBIRD_AUTH_METIS_API_KEY is available. Never shows its value." }] }Launch Code - OSS with that
COPILOT_HOMEand any value forBLACKBIRD_AUTH_METIS_API_KEY, and enablechat.canvases.enabled. Start a Copilot chat in the Agents window and send a message.With no turn running, open Env Consent Demo from the Canvas menu.
Permission request without toolCallId, auto-denying: kind=extension-env-access.user:env-consent-demoand the variable.Choose Not Now. The notification offers Try Again, which asks again. Choose Allow, and the canvas shows the variable as available.
Force a runtime refresh: add
.github/agents/probe.agent.mdto the folder and send a message. The canvas stays open without asking again.In a new chat, ask the model to open the canvas with
open_canvas. The request shows in the turn.Demo, recorded in dev builds of the Agents window: first on
main(nothing happens, and the log shows the automatic denial), then with this change (dialog, Not Now, Try Again, Allow). https://raw.githubusercontent.com/ulugbekna/screenshots/main/attachments/2026/11/13/extension-env-consent-before-after.mp4The parts separately: before, after.
Validation
On this branch, rebased on current
mainwith the bundled@github/copilot-sdk1.0.32-preview.3:./scripts/test.sh --runwith the 11 touched suites (copilotAgentSession,copilotAgent,agentService,agentHostTelemetryReporter,agentHostCanvasConsent,agentHostCanvas,editorCanvasActions,copilotCustomizationsWidget,sessionCanvasRegistryService,sessionCanvasService,localAgentHostSessionsProvider): passed (5005 passing, 28 existing pending)../scripts/test-integration.sh --runwithcopilotSdkCanvas,copilotExtensionEnvConsent,copilotMockLlmandcopilotCredentialSponsorship: passed (16 passing). These run the real bundled runtime.copilotExtensionEnvConsenttests open canvases the way the UI does, in the default chat and in a peer chat. They fail without the Agent Host changes.copilotMockLlmtest covers the model-initiated open in a turn.npm run typecheck-client,npm run oxlint -- <changed files>andnpm run valid-layers-check: passed.open_canvasshowed the request in the turn with the qualified name../scripts/test.sh --runwithcopilotAgentSessionandcopilotAgentpassed (2825 passing, 1 existing pending). The new test makessetModehang on an idle chat, and it fails without the fix. The real-runtime UI-open and in-turn consent tests passed again (3 passing).npm run test-node -- --runwithcopilotAgentSessionandcopilotAgent, the Node runner CI uses: passed (1730 and 1096 passing). Two tests had raced a cancelable timer, which this runner reported as a leak; they now useraceTimeout.Notes
extension-permission-accessstill saves decisions for project extensions by name, as before.