Skip to content

Refactor AgentService instantiation - #331861

Merged
roblourens merged 15 commits into
mainfrom
roblou/agents/refactor-agentservice-instantiation
Aug 20, 2026
Merged

Refactor AgentService instantiation#331861
roblourens merged 15 commits into
mainfrom
roblou/agents/refactor-agentservice-instantiation

Conversation

@roblourens

@roblourens roblourens commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

  • construct AgentService through dependency injection in one strict Agent Host service scope
  • expose one createAgentHostRuntime composition function that always builds the same complete shared service graph
  • build the complete AgentService core and collaborator graph in agentServiceComposition.ts; AgentService has no service collection, instantiation service, services.set, createInstance, or service-class construction
  • use one guarded initialization bundle for the few genuine callbacks into the fully constructed AgentService
  • make the only host-specific graph choice explicit: renderer BYOK or unavailable BYOK; quiet mode no longer changes the DI graph
  • register the shared authentication service directly for Git state and changeset operations
  • replace the test-only AgentService clock callback with runWithFakedTimers
  • keep only entry-point policy—logging, SDK overrides, provider enablement, and transports—in the two main files
  • keep protocol integration fixtures compatible with the uniform runtime graph by separating provider-owned config keys from host-owned worktree config and using a real containment root

Validation

  • npm run typecheck-client
  • npm run core-ci
  • npm run valid-layers-check
  • AgentService unit tests: 346 passing, 17 pending
  • Agent Host protocol integration tests: 12 passing
  • full product compile via npm run compile
  • standalone agent host startup in quiet/mock and full provider modes
  • real Agents window launch: authenticated account, all three providers registered, models loaded, sessions listed, protocol clients connected, and an existing session restored
  • Agent Host inspector and WebSocket listener probes

(Written by Copilot)

roblourens and others added 13 commits August 18, 2026 17:32
Create an agent-host application DI scope, construct AgentService through it, and remove child-to-parent service re-exports. Update tests to use the production construction path. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update newly added AgentService tests to use the DI-backed test factory. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use explicit bootstrap and application names for service collections and instantiation services. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use one strict DI scope and centralize common base and provider service setup for both Agent Host entry points. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve the single-scope bootstrap while integrating Agent Host debug-log collection. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Expose one runtime factory that owns common file, session, DI, AgentService, diagnostics, and optional provider infrastructure initialization. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Integrate Agent Host proxy configuration ownership and terminal-chat session metadata with the streamlined runtime factory. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Construct and register the AgentService core and collaborator graph outside AgentService, use one guarded initialization step for genuine back-references, and replace the test-only clock injection with virtual timers. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve external AgentService composition while integrating state-file resolution, catalog hardening, durable Agent Merge monitoring, and GitHub MCP support. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve external AgentService composition while integrating cold-start state-file resolution and session artifact tooling. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove optional provider-infrastructure setup, make BYOK policy explicit, and defer Claude SDK environment mutation until first use. (Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
#	src/vs/platform/agentHost/test/node/agentService.test.ts
Keep mock-provider configuration distinct from host-owned worktree settings and use an existing workspace for permission containment tests.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 20, 2026 19:03
@roblourens roblourens self-assigned this Aug 20, 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.

Pull request overview

Refactors Agent Host startup around a shared, strict dependency-injection composition root.

Changes:

  • Centralizes runtime and AgentService collaborator construction.
  • Reuses the runtime graph across utility-process, standalone, and test hosts.
  • Updates tests, fixtures, timer handling, and lazy Claude SDK environment setup.
Show a summary per file
File Description
src/vs/workbench/browser/chatDropdownPill.ts Removes trailing whitespace.
src/vs/platform/agentHost/test/node/protocol/toolApproval.integrationTest.ts Uses real containment roots in approval tests.
src/vs/platform/agentHost/test/node/protocol/sessionConfig.integrationTest.ts Separates mock-provider configuration keys.
src/vs/platform/agentHost/test/node/mockAgent.ts Updates mock configuration and permission paths.
src/vs/platform/agentHost/test/node/claudeAgent.test.ts Tests composition helper and lazy environment setup.
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts Uses the shared test composition helper.
src/vs/platform/agentHost/test/node/agentServiceTestUtils.ts Adds strict-DI test service construction.
src/vs/platform/agentHost/test/node/agentService.test.ts Migrates construction and uses fake timers.
src/vs/platform/agentHost/test/node/agentHostBootstrap.test.ts Verifies renderer-BYOK runtime construction.
src/vs/platform/agentHost/node/claude/claudeAgentSdkService.ts Defers environment mutation until SDK use.
src/vs/platform/agentHost/node/agentServiceComposition.ts Defines the complete collaborator graph.
src/vs/platform/agentHost/node/agentService.ts Accepts DI-managed core services and initialization.
src/vs/platform/agentHost/node/agentMergeController.ts Exports composition options.
src/vs/platform/agentHost/node/agentHostServerMain.ts Adopts the shared runtime bootstrap.
src/vs/platform/agentHost/node/agentHostMain.ts Adopts the shared runtime bootstrap.
src/vs/platform/agentHost/node/agentHostBootstrap.ts Builds the unified strict-DI runtime.

Review details

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

  • Files reviewed: 15/16 changed files
  • Comments generated: 0
  • Review effort level: Balanced

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/vs/platform/agentHost/node/agentService.ts
@roblourens
roblourens marked this pull request as ready for review August 20, 2026 23:32
@roblourens
roblourens enabled auto-merge (squash) August 20, 2026 23:32
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

TylerLeonhardt

Matched files:

  • src/vs/platform/agentHost/node/claude/claudeAgentSdkService.ts

@roblourens
roblourens marked this pull request as draft August 20, 2026 23:34
auto-merge was automatically disabled August 20, 2026 23:34

Pull request was converted to draft

Keep the AgentService DI refactor focused by leaving the existing Claude SDK environment setup unchanged.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens
roblourens marked this pull request as ready for review August 20, 2026 23:41
@roblourens
roblourens enabled auto-merge (squash) August 20, 2026 23:41
@roblourens
roblourens merged commit 33e1911 into main Aug 20, 2026
27 checks passed
@roblourens
roblourens deleted the roblou/agents/refactor-agentservice-instantiation branch August 20, 2026 23:59
Comment on lines +484 to 498
private _sideEffects!: AgentSideEffects;
private _agentMergeController!: AgentMergeController;
/** Owns static / per-turn changeset compute, publish, persist, restore. */
private readonly _changesets: IAgentHostChangesetService;
private _changesets!: IAgentHostChangesetService;
/** Shared active changeset subscription registry. */
private readonly _changesetSubscriptions: IAgentHostChangesetSubscriptionService;
/** Owns changeset operation contributions and handler activation. */
private readonly _changesetOperationService: IAgentHostChangesetOperationService;
private readonly _reviewService: IAgentHostReviewService;
private _changesetOperationService!: IAgentHostChangesetOperationService;
private _reviewService!: IAgentHostReviewService;
/** Owns AgentService-side orchestration of the changeset feature. */
private readonly _changesetCoordinator: AgentHostChangesetCoordinator;
private _changesetCoordinator!: AgentHostChangesetCoordinator;
/** Owns session git-state probing and git-backed catalogue decoration. */
private readonly _gitStateService: IAgentHostGitStateService;
private _gitStateService!: IAgentHostGitStateService;
/** Manages PTY-backed terminals for the agent host protocol. */
private readonly _terminalManager: AgentHostTerminalManager;
private _terminalManager!: AgentHostTerminalManager;
/** Persists host-injected `/rename` / `!command` turns for restore & fork/truncate. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lotta bangs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, all these will go away with the next round or two

@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 21, 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