Skip to content

agentHost: ask before a Copilot extension reads sensitive environment variables - #348216

Merged
Ulugbek Abdullaev (ulugbekna) merged 9 commits into
mainfrom
ulugbekna/agents/consent-flow-for-extension-env-access
Nov 13, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 9 commits into
mainfrom
ulugbekna/agents/consent-flow-for-extension-env-access

Conversation

@ulugbekna

@ulugbekna Ulugbek Abdullaev (ulugbekna) commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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-access consent. 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-initiated open_canvas failed 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.

  1. Runtime contract test. Against the bundled runtime: the request has no tool call, a denial is kept across a provider reload until a resume, and a resume also forgets session approvals.
  2. Consent in the turn. One consent gate handles both extension-permission-access and extension-env-access.
    • A saved decision, or an approval for this chat, answers at once. Otherwise the request waits, without blocking resumes or turns, and the next turn shows it. Allow All approves it and Autopilot declines it, as before.
    • The prompt names the extension with its source-qualified ID, such as user:my-canvas, 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, which another repository can reuse; plugins come in commit 6. Saved environment decisions go in the existing extensionPermissionApprovals setting, 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. The readiness telemetry outcome is consentPending.
  3. Consent when a canvas is opened from the UI. Over the local Agent Host's private IPC, openSessionCanvas returns consentRequired while 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.
    • The 30-second control-plane bound applies only while nobody is asked.
    • A declined extension fails the open with consentDenied, which says whether asking again can help. It can't while a saved Never applies.
    • An answer continues only the open it was shown for, on the runtime that asked. Any other answer fails with "no longer pending". Answers bypass the chat queue, which can hold an operation that waits for the same extension.
    • A permission mode changed while the chat was idle applies before the open. That sync is bounded like other control-plane requests. If it times out, the open fails before it starts, and the session is marked for resynchronization.
    • Whichever surface answers first settles the request. A turn that shows the same request completes its confirmation with that answer.
  4. Test refactor. The credential sponsorship test's environment scrubbing moves to a shared helper.
  5. Recovery and refreshes. The Agent Host keeps each chat's approvals and hands them to the runtimes that replace one. A project extension's approval covers only the folder its runtime started in. A retry answer 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.
  6. Plugins. A saved decision for a plugin extension is bound to the plugin's install, read from the runtime's plugin list. When the install can't be told, for example when two enabled plugins share a name, the decision isn't saved, and Allow lasts only for that runtime.
  7. UI. A modal dialog shows the request when a canvas is opened from the Agents window's Canvas menu, the editor canvas actions, or the Canvases customization list. It offers Allow, plus Always Allow and Never when the decision can be saved. Not Now, or Escape, declines. A declined open shows a localized message in a notification that stays open with Try Again, which is offered again if a retry fails.
  8. Review fix. Adds the time limit to the permission mode sync before an open, described under 3.

How to test

  1. Set COPILOT_HOME to an empty folder and add this user extension in extensions/env-consent-demo/ inside it:

    extension.json and extension.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." }]
    }
    import { createServer } from 'node:http';
    import { createCanvas, joinSession } from '@github/copilot-sdk/extension';
    import declaration from './extension.json' with { type: 'json' };
    
    const variable = 'BLACKBIRD_AUTH_METIS_API_KEY';
    const available = () => !!process.env[variable];
    const server = createServer((_request, response) => {
    	response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
    	response.end(`<h1>Env consent demo</h1><p>${variable} is ${available() ? 'available' : 'not available'}. The value is never shown.</p>`);
    });
    await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
    await joinSession({
    	requestedEnvironmentVariables: [variable],
    	canvases: declaration.canvases.map(canvas => createCanvas({ ...canvas, open: ({ instanceId }) => ({ url: `http://127.0.0.1:${server.address().port}/${instanceId}` }) })),
    });
  2. Launch Code - OSS with that COPILOT_HOME and any value for BLACKBIRD_AUTH_METIS_API_KEY, and enable chat.canvases.enabled. Start a Copilot chat in the Agents window and send a message.

  3. With no turn running, open Env Consent Demo from the Canvas menu.

    • Before this change, nothing happens, and the Agent Host log shows Permission request without toolCallId, auto-denying: kind=extension-env-access.
    • With it, a dialog names user:env-consent-demo and the variable.
  4. Choose Not Now. The notification offers Try Again, which asks again. Choose Allow, and the canvas shows the variable as available.

  5. Force a runtime refresh: add .github/agents/probe.agent.md to the folder and send a message. The canvas stays open without asking again.

  6. 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.mp4

The parts separately: before, after.

Validation

On this branch, rebased on current main with the bundled @github/copilot-sdk 1.0.32-preview.3:

  • ./scripts/test.sh --run with 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 --run with copilotSdkCanvas, copilotExtensionEnvConsent, copilotMockLlm and copilotCredentialSponsorship: passed (16 passing). These run the real bundled runtime.
    • The two copilotExtensionEnvConsent tests open canvases the way the UI does, in the default chat and in a peer chat. They fail without the Agent Host changes.
    • The copilotMockLlm test covers the model-initiated open in a turn.
  • npm run typecheck-client, npm run oxlint -- <changed files> and npm run valid-layers-check: passed.
  • Before the rebase, each commit passed the type check, lint and the suites it touches. For each of seven fixes from code review, reverting the fix alone made its new test fail.
  • Manual checks in a dev build of the Agents window:
    • The UI-opened canvas waited past the 30-second bound while the dialog was open.
    • After Allow, a forced refresh kept the canvas open without asking.
    • Never, then removing the entry from Open Host Settings, then Try Again asked again.
    • The model-initiated open_canvas showed the request in the turn with the qualified name.
    • After the rebase, I repeated dialog, Not Now, Try Again and Allow.
  • After the review fix: ./scripts/test.sh --run with copilotAgentSession and copilotAgent passed (2825 passing, 1 existing pending). The new test makes setMode hang 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 -- --run with copilotAgentSession and copilotAgent, 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 use raceTimeout.
  • Not tested on Windows or Linux.

Notes

  • With Allow All, the runtime approves the request before it asks the host, so a saved Never doesn't apply then. This is runtime behavior, unchanged here.
  • The runtime can't forget a person's No without a new runtime session, so Try Again replaces the chat's idle runtime.
  • If the user declines a model-initiated open with Not Now, there's no retry in place. The next open from the UI offers Try Again.
  • extension-permission-access still saves decisions for project extensions by name, as before.

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]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 18:48
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/sessions/contrib/canvases/electron-browser/sessionCanvasService.ts
  • src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasRegistryService.test.ts
  • src/vs/workbench/contrib/canvases/browser/editorCanvasActions.ts
  • src/vs/workbench/contrib/canvases/common/agentHostCanvas.ts
  • src/vs/workbench/contrib/canvases/common/agentHostCanvasConsent.ts
  • src/vs/workbench/contrib/canvases/common/canvas.ts
  • src/vs/workbench/contrib/canvases/test/common/agentHostCanvas.test.ts
  • src/vs/workbench/contrib/canvases/test/common/agentHostCanvasConsent.test.ts

Sandeep Somavarapu (@sandy081)

Matched files:

  • src/vs/workbench/contrib/sessions/browser/sessionsManagementService.ts
  • src/vs/workbench/contrib/sessions/common/sessionsManagement.ts
  • src/vs/workbench/contrib/sessions/common/sessionsProvider.ts

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/workbench/contrib/sessions/browser/sessionsManagementService.ts
  • src/vs/workbench/contrib/sessions/common/sessionsManagement.ts
  • src/vs/workbench/contrib/sessions/common/sessionsProvider.ts

roblourens
roblourens previously approved these changes Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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]>
@ulugbekna
Ulugbek Abdullaev (ulugbekna) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 4be9d86 Nov 13, 2026
37 of 38 checks passed
@ulugbekna
Ulugbek Abdullaev (ulugbekna) deleted the ulugbekna/agents/consent-flow-for-extension-env-access branch November 13, 2026 20:46
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 13, 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.

4 participants