Repository navigation
agentHost: run project canvas extensions only in trusted folders - #343771
Ulugbek Abdullaev (ulugbekna) merged 8 commits into
Conversation
d5d5389 to
b52ecd0
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved trust-boundary and revocation defects can allow untrusted extensions to run, and reconciliation failures can abort session initialization.
4 open issues
What changed in this PR
This PR restores trust gating for project canvas extensions in the Copilot Agent Host, complementing the runtime trust grant from #343403 while keeping VS Code Workspace Trust as the sole trust store.
Changes:
- Adds canonical-path launch checks with scratch-folder and host-created worktree exemptions.
- Reconciles extensions when trust changes, including during session initialization.
- Adds policy, lifecycle, and real-runtime integration coverage.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/providerIntegration/copilotMockLlm.integrationTest.ts |
Tests extension launch and shutdown across trust changes. |
src/vs/platform/agentHost/test/node/copilotProjectExtensionLaunchPolicy.test.ts |
Covers launch admission, canonical paths, revocation, and inheritance. |
src/vs/platform/agentHost/test/node/copilotAgent.test.ts |
Tests admission exemptions and session reconciliation. |
src/vs/platform/agentHost/node/copilot/copilotProjectExtensionLaunchPolicy.ts |
Implements launch authorization and revocation tracking. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Applies trust changes through extension reload and reconciliation. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Connects launch policy to configuration and session lifecycle. |
Review effort: Balanced
70c2dba to
18a1ebe
Compare
|
Base:
|
6a166ab to
9745a14
Compare
9745a14 to
3a0bdfa
Compare
This comment has been minimized.
This comment has been minimized.
Demo of
|
Before (main) |
After (this pull request) |
|---|---|
![]() Main still offers Project Trust Demo in Restricted Mode after resuming the session. |
![]() Project Trust Demo disappears as soon as the folder loses trust. |
The change, on this pull request's build:
after.mp4
The same steps on main
before.mp4
Recorded by an agent on a build of this pull request merged with main, signed out, with a mock model. It can be wrong. Workflow run
Tip
Was this useful? React to this comment with 👍 or 👎.
On the VS Code team? Say what was wrong or missing.
Project canvas extensions (.github/extensions/*/extension.mjs) launched from any folder a live session admitted, whether or not the user trusted it. Move launch admission into CopilotProjectExtensionLaunchPolicy and also require VS Code workspace trust, read from the mirrored root configuration. This replaces the reverted #342372. - Missing trust information refuses every project launch; disabled workspace trust keeps the previous behavior. - Admitted roots, trusted folders and the entrypoint are compared by canonical path. A decision whose trust changes while roots resolve is re-evaluated, and the canonical entrypoint is what launches. - Only a workspace-less chat's own scratch folder, a direct child of ~/.copilot/chats, is exempt: the agent created its contents. An extension refused here stays refused until its session restarts; the next commit reconciles running sessions when trust changes. Co-authored-by: Copilot <[email protected]>
…hanges The launch policy is consulted only when the runtime starts an extension, so trust granted or revoked while a session runs had no effect until it restarted. Reconcile live canvas sessions instead: - Classify each trust change as an expansion, a contraction or neither (reordering), and apply changes in a throttled pass that coalesces changes arriving while a pass runs. - On contraction, re-check the launches the policy allowed and reload only sessions running an extension whose launch lost trust. The reload relaunches through the policy, which refuses it. - On expansion, call the host-only extensions.reconcile() in sessions with a refused extension. Unlike extensions.enable, it saves no preference, respects the user's current enablement and leaves running extensions alone. - Reconcile a session that is still initializing before and right after it registers, so a trust change cannot fall between the two. Every reconciliation RPC is time-bounded and logged. Co-authored-by: Copilot <[email protected]>
The Copilot launcher already grants the runtime trust for the worktree Agent Host creates on a session's first send when its repository is trusted (#343403): VS Code itself trusts that worktree only after the session reports it. Apply the same rule to project canvas extensions, so a worktree's canvases work on its first turn instead of staying refused until the client's trust arrives. The launch policy takes the launch plan's worktreeRepository with the session's admission. A module under that worktree is trusted while the repository is, by canonical path; the worktree must be a strict descendant of the repository's <repo>.worktrees folder, like the launcher requires. Revoking the repository's trust revokes the worktree's launches, and the inheritance ends with the admission. Worktrees created for other chats, and resumed sessions, get no inheritance, as with the runtime grant: their extensions start once VS Code trusts the worktree, through the live reconciliation. Co-authored-by: Copilot <[email protected]>
…ctory Review follow-up. The launch policy let every admitted directory that is a worktree of the session's repository inherit the repository's trust, including additional working directories, which need not be the worktree the host created or even a real worktree. The runtime grant from #343403 inherits only for the launch plan's working directory. Pass the created worktree together with its repository, and let only that directory inherit, when it is admitted and, both as given and by canonical path, a worktree under the repository's <repo>.worktrees folder. A link named like a worktree but resolving elsewhere no longer inherits; additional directories need workspace trust of their own. Co-authored-by: Copilot <[email protected]>
Review follow-up. The scratch-folder exemption checked the folder's unresolved path, but admission records its canonical one. The default chat's folder, ~/.copilot/chats/<session id>, is created with a recursive mkdir that accepts an existing link, and the chats folder is shared with other Copilot clients. A link there to an untrusted checkout would have exempted that checkout's extensions from workspace trust, for every session using it. The policy now takes the scratch folder with the chats folder and grants the exemption only while the folder is a direct child of the chats folder both as given and by canonical path. Co-authored-by: Copilot <[email protected]>
…isions Review follow-up. The launch policy is shared by every session, but each launch decision for an entrypoint first deleted that entrypoint's allowed-launch record. If chat A runs a project extension and chat B asks to launch it, revoking trust while B's decision resolves found no record: B was refused and A kept running. A refused relaunch erased A's record the same way, so a later revocation missed A too. A launch decision now never removes a record; records are keyed by entrypoint and canonical module and are dropped only once no live session admits the module. A stale record can at most reload a session running a same-named project extension, never miss a revocation. Co-authored-by: Copilot <[email protected]>
Review follow-up. A trust expansion during a session's initialization retries its refused project extensions with extensions.reconcile(). If that rejected, for example on an older runtime without the method, the error aborted an otherwise successful create or resume, while the live and post-registration paths only log it. Log a failed retry during initialization the same way: the extensions stay refused. A failure while trust contracted still fails the session, since a revoked extension may otherwise keep running. Co-authored-by: Copilot <[email protected]>
… retiring sessions Initialization failed a session whose retry of refused project extensions failed whenever the same trust change revoked any extension on the host, even one this session didn't run. A session now logs a failed retry itself, and throws only when it can't stop an extension whose trust was revoked, which still fails initialization. A live reconciliation also kept sending requests to a session that a configuration refresh was replacing, and the SDK addresses them by session id, so they could reach the replacement. Reconciliation now stops once its session starts retiring or changes runtime, and destroying a session lets a reconciliation already in flight finish before it disconnects. Co-authored-by: Copilot <[email protected]>
3a0bdfa to
e35cab2
Compare




Replaces #342372, which was reverted in #342684.
What and why
Project canvas extensions (
.github/extensions/<name>/extension.mjs) are code from the repository, but the Copilot Agent Host launched them in any folder a live session used, whether or not the user trusted it. A session's runtime often starts without passing VS Code's trust prompt: showing a restored chat, listing canvases and MCP App results all resume it.This PR makes the host decide every project extension launch against VS Code workspace trust, keeps running sessions in step when trust changes, and lets a worktree the host creates inherit its repository's trust, following the rule #343403 set for the runtime's own trust grant. VS Code Workspace Trust stays the only trust store; the host keeps no trust records of its own.
Relation to #343403: that PR forwards trust to the Copilot runtime as a create-time
trustWorkingDirectory: 'session'grant, which governs repository plugins, hooks, MCP servers and instructions inside the runtime, and cannot be granted on resume or updated while a session runs. This PR covers project canvas extensions, which the host itself launches through the SDK's extension launch provider, on every create and resume and live as trust changes.Out of scope, tracked as Milestone 2: repository code that can still run when a runtime resumes in an untrusted folder, and loading chat history without starting a runtime.
Review guide
The PR has three main commits, then four small commits answering the Copilot review and one answering a second Astra review. Each commit builds and passes its tests, and reviewing commit by commit is recommended. Further hardening of revocation from that review is left to a follow-up (see Known limitations).
1.
agentHost: launch project canvas extensions only in trusted folders(+567/-96)The security gate. Start with
CopilotProjectExtensionLaunchPolicyinsrc/vs/platform/agentHost/node/copilot/copilotProjectExtensionLaunchPolicy.ts;copilotAgent.tsonly swaps its previous inline admission for the policy.~/.copilot/chats(_acquireProjectExtensionLaunchAdmission). That folder is shared with other Copilot clients, hence the exact check.Worth scrutinizing:
_isLaunchTrusted(re-evaluates when trust changes while roots resolve) and_canonicalTrustedRoot(caches only resolved roots, so a trusted folder created later is honored). The policy compares canonical paths instead of using the sharedisAgentHostWorkspaceTrustedhelper: a symlink or path alias (for example/varand/private/varon macOS) must not decide a launch.2.
agentHost: reconcile project canvas extensions when workspace trust changes(+549/-16)The runtime asks the policy only when it starts an extension, so this commit applies trust changes to running sessions.
updateTrustclassifies a change as an expansion, a contraction or neither (reordering). AThrottlerpass incopilotAgent.tsapplies accumulated changes; changes arriving mid-pass coalesce into one more pass.reconciliationFor), and only sessions running an extension whose launch lost trust reload. Removing an unrelated folder restarts nothing.extensions.reconcile()(main'sCopilotAgentSession.reconcileExtensions). It saves no preference, respects the user's current enablement and leaves running extensions alone.extensions.enablewas rejected because it saves a preference, andenablefollowed byreloaddouble-launches the extension (both observed on the real runtime)._initializeAndRegisterSessionreconciles a session before and right after it registers, closing the window in which live-session reconciliation skips it.3.
agentHost: host-created worktrees inherit trust for canvas extensions(+129/-4)#343403 lets the worktree Agent Host creates on a session's first send inherit its repository's trust for the runtime grant, because VS Code itself trusts that worktree only after the session reports it. This commit applies the same rule to project canvas extensions, so the worktree's canvases work on its first turn.
worktreeRepository(set by main's_createdWorktreeRepository). A module under that worktree is trusted while the repository is, by canonical path, and the worktree must be a strict descendant of<repo>.worktrees, as the launcher requires.4–7. Copilot review follow-ups
Each fixes one Copilot review finding and adds a regression test; the tests for 6 and 7 fail on the earlier code.
inherit worktree trust only for the session's working directory: only the worktree the host created as the working directory inherits its repository's trust. It must also be a worktree of that repository by canonical path, and additional directories need workspace trust of their own.exempt a scratch folder from trust only by canonical path: a link in~/.copilot/chatsthat resolves elsewhere no longer gets the scratch-folder exemption.keep canvas revocation records across sessions' launch decisions: another session's launch decision, allowed or refused, no longer erases the record of an extension that is already running, so revoking trust still stops it.don't fail a session when retrying refused extensions fails: during initialization, a failedreconcile()after trust expanded is logged instead of aborting the session. A failed revocation still fails it.8. Astra review follow-up
separate canvas trust revocation from retries, and stop at retiring sessions(+157/-31): a failed retry of refused extensions no longer fails initialization just because some other extension's trust was revoked elsewhere on the host. A reconciliation stops at a session that is retiring or whose runtime was replaced, so it can't act on a successor's runtime; destroying a session waits for its in-flight reconciliations first. Its regression tests fail on the earlier code.How to test
Unit and integration tests were run from the branch with
COPILOT_CLI_ENABLED_FEATURE_FLAGSunset. Agent shells set it, and an inheritedDYNAMIC_AUTO_TIERSfails an unrelatedCopilotAgenttiers test.On the current base (
mainat817607ae52b,@microsoft/copilot-sdk2.0.1 with runtime 1.0.114, Node 24.22.1):pnpm run typecheck-client, andpnpm run oxlinton the commit's changed files./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotProjectExtensionLaunchPolicy.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.tspnpm run build-fast --client-onlyCopilotAgent,CopilotAgentSessionandCopilotSessionLaunchersuites together./scripts/test-integration.shwith--runforproviderIntegration/copilotMockLlm,providerIntegration/copilotExtensionEnvConsent,providerIntegration/copilotNativeExtensions,copilotSdkCanvasande2e/providers/copilotManagedSettingsAgentHostE2E(.integrationTest.ts, undersrc/vs/platform/agentHost/test/node/)pnpm run valid-layers-checkandgit diff --checkThe canvas integration tests passed in both integration runs on this base, the second after the last change to commit 2. To rerun only them:
The real-runtime test for commit 2 uses an append-only launch log written by the extension itself: no launch before trust, exactly one launch when trust is granted (no host restart), the launched process exits when trust is revoked, and nothing relaunches afterwards.
The first per-commit run, at commit 1 right after a fresh build, hit the 5-second
after eachcleanup timeout in main's "createChat infers workspace-less from omitted workingDirectories" test while the machine was loaded (198 tests in four minutes). The branch doesn't change that test. Both reruns at commit 1 passed every test, in 20 seconds each.Latest rebase: the branch is now on
mainat817607ae52b. Changes on main that the branch adapts to:@microsoft/copilot-sdkv2, and the launch hook is nowextensions.launchProvider.resolve. Commit 1 answers that hook with the policy. Main's inline launch check hadn't changed since the previous base, so the policy still covers everything it did. The trust test's extension fixture imports@microsoft/copilot-sdk/extension, like main's fixtures. The runtime still resolves the old@github/copilot-sdkname.Other related changes on main were checked against the branch:
Earlier rebases adapted to these changes:
canvasRuntimeEnabledgetter toCopilotAgentSession, returningfalsefor a session without an SDK session, so this branch's copy was dropped.onDidReloadRuntimeContributionsto sessions; two hand-made fake sessions in this branch's unit tests now include it.extension.cjsandextension.js. The launch provider still admits onlyextension.mjs, as onmain, so those entrypoints can't bypass the gate.dormantstatus for extensions that start on first use. A dormant extension hasn't launched, and its first-use launch goes through the same gate. agentHost: keep lazily activated canvases open across runtime refreshes #347946 reopens lazily activated canvases in the background after a refresh. That reopen starts the extension through the gate too, so after a revocation its canvas stays unavailable instead of relaunching. Earlier rebases were also checked against Canvases: restore canvases after idle session release #345740, agentHost: let any chat change its workspace or move to a new worktree #345805, agentHost: ask for consent when Copilot extensions request permissions #346395 and chat: Attribute Canvas refresh failures to the failing extension #345297.Code OSS verification (dev build of
e35cab2a788with@microsoft/copilot-sdk2.0.1, macOS arm64, Agents window, local Copilot agent host against a mock LLM, Workspace Trust enabled): six UI scenarios run with thevalidate-ui-scenariorunner, each checked against the agent host log and the protocol (AHP) log. Each project canvas extension appends its pid to a launch log, so launches are counted independently of the UI. In no run did an extension launch from a folder before that folder was trusted (scratch folders are exempt).Main now prewarms new chats by default (#348611): once their folders are trusted, a draft's runtime, and with it its project extensions, starts before the first message. The checks in the first four rows count launches from the first message, so they ran with
chat.agentHost.experimental.prewarmSessionsoff; the others ran with prewarming on, and the last row covers a prewarmed draft. Selectors were updated for main's new UI: canvases are under the editor's Add Tab → Canvas menu, and the trust dialog's button is now "Trust Folders". On this rebase the open-tab scenario also turned prewarming off, and its follow-up turn now cancels the trust dialog while the send is still pending. Its assertions are unchanged. The worktree and no-workspace scenarios each failed once while the machine was heavily loaded, once on a menu that redrew mid-click and once on an extension startup timeout with no trust denial. Both passed when rerun unchanged.vscode/requestWorkspaceTrust; the launcher logs "Granting the runtime 'session' trust … inherited from worktree repository", and the worktree's extension starts once on the first turn.With prewarming on, a draft can launch its extension twice: once in the prewarmed session and again for the first message, when that message discards the prewarmed session (
[warm] Discarded pre-warmed session … reason=clientToolsChanged, main's behavior). Re-trusting a folder while a draft is unsent shows the same pattern. Only one process is left running each time. For the no-workspace scenario, the isolated profile's home folder needsGIT_CEILING_DIRECTORIESwhen it sits inside a git checkout, otherwise the runtime discovers extensions at that checkout's root (see Known limitations).CI pipeline: passed on this tip. Azure build 502140 succeeded on Windows x64, Linux x64 and macOS ARM64, including the Agent Host end-to-end, integration, unit, smoke and Copilot tests. All GitHub test checks passed.
Not covered: a chat whose folder changes during a session (workspace conversion) keeps its old admission until the runtime restarts at the next turn (see Known limitations).
Known limitations
extensions.reconcile()fails with method-not-found on older runtimes. The bundled runtime supports it; on failure the error is logged and the extension stays refused until the session restarts. There is deliberately no fallback to the savingextensions.enable.extensions.reconcile()reportsextension_reconciliation_lifecycle_failedwhenever the launch provider refuses any extension in the chat, although it still applies the other starts and stops. Since Canvases: Verify canvas extension toggle outcomes #344904 and chat: Attribute Canvas refresh failures to the failing extension #345297, toggling a user or plugin canvas extension checks the outcome against the live inventory, and a refused project extension is listed asfailed. Disabling one in an untrusted folder that has project extensions therefore stops it but shows "After disabling '…', this chat couldn't finish updating canvas extensions because '' failed to start". Enabling succeeds without an error. A real-runtime probe confirmed both on SDK 1.0.30, and again on@microsoft/copilot-sdk2.0.1 (runtime 1.0.114). Any failing project extension already triggered this onmain, but this branch makes refusals routine in untrusted folders. The fix belongs in the runtime: report a provider refusal as a non-fatal, blocked outcome (and a distinct status) instead of failing the whole reconciliation. Commit 2's trust-expansion retry hits the same failure when another extension stays refused, and only logs it.createChat/setChatWorkspace/create_sessionwith a worktree) and resumed worktree sessions get no inheritance, matching the runtime grant from Forward VS Code workspace trust to the Copilot runtime #343403. Their canvases start once VS Code trusts the worktree, which it does automatically for a worktree of a trusted repository that is one of the session's folders.Follow-ups for the Copilot SDK/runtime, which would simplify this host logic: include the session id and discovery root in launch requests, report module identity in the extension inventory, and add a non-fatal "blocked" extension status for provider refusals.
Reviews
Before this PR, the changes were reviewed by Opus (
claude-opus-5.5) and Astra (gpt-6-astra), both with 1M-token context and maximum reasoning. All seven findings were verified against the code and fixed; regression tests cover each. Three of Astra's findings concerned the earlier client-request version of commit 3, which the rebase replaced with #343403's inheritance rule.Commit 8 comes from a second Astra review (
gpt-6-astra, 1M-token context, maximum reasoning) split into design, correctness and security reviewers, with an independent code review alongside. Every finding was verified against the code. Its fixes for the other findings, listed under Known limitations, were reviewed to no remaining finding at Medium or above but moved to a follow-up to keep this PR reviewable. Remote hosts with authority-level trust are documented above as a Milestone 2 follow-up.