Skip to content

agentHost: scope client customizations to session working directories - #330378

Merged
Connor Peet (connor4312) merged 1 commit into
mainfrom
connor4312/agenthost-scoped-customizations
Aug 12, 2026
Merged

Connor Peet (connor4312) merged 1 commit into
mainfrom
connor4312/agenthost-scoped-customizations

Conversation

@connor4312

Copy link
Copy Markdown
Member

The synthetic vscode-synced-customization plugin was keyed only by session type, so one bundle identity was shared by every session of a provider and resolved against whatever workspace folder happened to be ambient. In the Agents window the ambient folder is swapped on every active-session change, so switching sessions re-resolved and re-published customizations to every live session, and one repository's instructions, prompts, skills and workspace MCP servers leaked into sessions running in another. The agent host then re-materialized and re-bound plugins each time, and the nonce cache never hit because ping-ponging between two repos evicted each bundle in turn.

What changed

Customizations are keyed by the session's working-directory set. IAgentHostActiveClientService hands out refcounted IAgentCustomizationScopes, shared between sessions with identical roots, each owning its own bundler with an authority derived from the normalized root set. IWorkspaceContextService is gone from the service. IPromptsService.listPromptFilesForStorage takes an optional explicit root; omitted, it behaves exactly as before.

Publishing is consolidated. Four separate activeClientSet dispatch sites in the session handler became one debounced per-session reconciler, held in a self-contained ActiveClientEntry. The claim/no-claim distinction is now explicit: the client publishes only where it is already an active client, or where it explicitly claimed the session at open.

Publishing is gated on resolution. A freshly acquired scope reports an empty customization set until it resolves; publishing that would transiently wipe the host's state, so nothing publishes from an unresolved scope, and session creation waits for the pending publish to settle.

Verification

Validated against Agent Host log captures of the same flow (message a session, switch to a session in another repo, switch back):

before after scoping after consolidation
client→server dispatches 16 5 4
empty-customization publishes 7 0 0
consecutive duplicate dispatches — 3 0

Each repository resolves to its own authority and nonce, byte-stable across app restarts, with no re-materialization on return and no cross-repo content in either session.

A later capture caught a dispatch loop (344 identical actions in 8s) when a plugin was disabled, the UI switched, and the plugin re-enabled: an identical payload is now never re-sent, so a payload the server does not acknowledge costs one dispatch rather than spinning.

Notes

  • Tools remain workspace-independent today but now live on the scope, delegating to a shared per-sessionType derived so identical computations are not duplicated per scope.
  • The AI Customization management UI deliberately keeps ambient (window-scoped) behaviour via an empty root set; only sessions are folder-scoped.
  • The bundle URI shape changes, so sessions running against the old identity re-materialize once on first launch after this lands.

The synthetic vscode-synced-customization plugin was keyed only by session type, so one bundle identity was shared by every session of a provider and resolved against whatever workspace folder happened to be ambient. In the Agents window the ambient folder is swapped on every active-session change, so switching sessions re-resolved and re-published customizations to every live session and leaked one repository's files into sessions running in another.

Customization state is now keyed by the session's working-directory set. Scopes are refcounted and shared by sessions with identical roots, so each repository gets a stable bundle authority and nonce and the agent host's plugin cache stops re-materializing on every switch. Prompt enumeration takes an explicit root instead of reading the ambient workspace.

Publishing is consolidated into a single debounced per-session reconciler, replacing four separate dispatch sites that each compared against not-yet-updated session state and produced redundant actions. Publishing is gated on the scope having resolved so a freshly acquired scope cannot transiently wipe the host's customizations, an identical payload is never re-sent, and undefined-valued keys are omitted from published payloads so a value round-tripped through the wire compares equal to the one that produced it.
Copilot AI balanced review requested due to automatic review settings August 12, 2026 03:02
@connor4312
Connor Peet (connor4312) enabled auto-merge (squash) August 12, 2026 03:03

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.

Pull request overview

Scopes agent-host customizations to each session’s working directories and consolidates active-client publishing.

Changes:

  • Adds ref-counted, root-scoped customization bundles.
  • Debounces and deduplicates active-client reconciliation.
  • Extends prompt discovery and tests for explicit roots.
Show a summary per file
File Description
promptsService.test.ts Tests explicit-root discovery.
mockPromptsService.ts Updates mock API.
resolveCustomizationRefs.test.ts Updates root-aware tests.
enumerateLocalCustomizationsForHarness.test.ts Tests multi-root enumeration.
agentHostUntitledProvisionalSessionService.test.ts Updates scoped-client mock.
agentHostClientTools.test.ts Tests scope sharing.
agentHostChatContribution.test.ts Tests reconciliation behavior.
promptFilesLocator.ts Adds explicit-root resolution.
promptsServiceImpl.ts Forwards optional roots.
promptsService.ts Extends prompt service API.
syncedCustomizationBundler.ts Uses URI-aware origin mapping.
agentHostUntitledProvisionalSessionService.ts Adds provisional-session scopes.
agentHostToolUtils.ts Omits undefined schemas.
agentHostSessionHandler.ts Consolidates client publishing.
agentHostLocalCustomizations.ts Enumerates scoped roots.
agentHostChatContribution.ts Adds ambient management scope.
agentHostActiveClientService.ts Implements scoped customization lifecycle.
remoteAgentHostSessionsProvider.test.ts Updates remote scope mock.
remoteAgentHost.contribution.ts Adds remote ambient scope.
localAgentHostSessionsProvider.test.ts Tests resolution gating.
baseAgentHostSessionsProvider.ts Scopes provider client state.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (1)

src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostUntitledProvisionalSessionService.ts:745

  • Updating the binding here can publish the new folder's customizations to the still-live old provisional backend. _reconcileGeneration deliberately leaves entry.generation pointing at the old session until a replacement is ready, while ActiveClientBinding calls _publishActiveClient(entry) as soon as the new scope resolves; that method dispatches to the current (old-root) generation. This transiently recreates the cross-repository leak this change is intended to prevent. Keep the scope associated with each generation/backend URI and only switch the published binding atomically when the replacement generation is installed (the workspace-folder-change path has the same ordering issue).
		this._updateActiveClientScope(entry);
  • Files reviewed: 21/21 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment on lines +448 to +449
function createScopeAuthority(sessionType: string, roots: readonly URI[]): string {
return `${sessionType}-${hash(getScopeKey(roots))}`;
if (!entry.usesWorkspaceRootSet && (this._computeWorkingDirectories(entry.workingDirectory, entry.provider)?.length ?? 0) > 1) {
entry.usesWorkspaceRootSet = true;
}
this._updateActiveClientScope(entry);
@connor4312
Connor Peet (connor4312) merged commit c14ff79 into main Aug 12, 2026
29 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor4312/agenthost-scoped-customizations branch August 12, 2026 03:17
@vs-code-engineering vs-code-engineering Bot added this to the 1.134.0 milestone Aug 12, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants