Skip to content

Refactor AgentService instantiation - #331585

Draft
roblourens wants to merge 11 commits into
microsoft:mainfrom
roblourens:roblou/agents/refactor-agentservice-instantiation
Draft

Refactor AgentService instantiation#331585
roblourens wants to merge 11 commits into
microsoft:mainfrom
roblourens:roblou/agents/refactor-agentservice-instantiation

Conversation

@roblourens

@roblourens roblourens commented Aug 19, 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
  • delay Claude SDK environment mutation until the first SDK call so eager graph construction is inert
  • keep only entry-point policy—logging, SDK overrides, provider enablement, and transports—in the two main files

Validation

  • npm run typecheck-client
  • npm run core-ci
  • npm run valid-layers-check
  • Agent Host service and provider proxy tests: 405 passing, 17 pending
  • strict renderer-BYOK runtime construction test
  • standalone agent host startup in quiet/mock and full provider modes
  • WebSocket listener probes returned 426 Upgrade Required

(Written by Copilot)

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>
Copilot AI balanced review requested due to automatic review settings August 19, 2026 00:32

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 AgentService construction around a dedicated child DI scope shared by host services and providers.

Changes:

  • Adds an agent-host application factory and DI-backed AgentService options.
  • Shares scoped services, including ICopilotApiService, across consumers.
  • Updates AgentService tests to use the production construction path.
Show a summary per file
File Description
src/vs/platform/agentHost/node/agentHostApplication.ts Creates the application DI scope.
src/vs/platform/agentHost/node/agentService.ts Converts AgentService to DI construction.
src/vs/platform/agentHost/node/agentHostMain.ts Uses scoped application services.
src/vs/platform/agentHost/node/agentHostServerMain.ts Applies the scope to standalone hosting.
src/vs/platform/agentHost/test/node/agentServiceTestUtils.ts Adds production-style test construction.
src/vs/platform/agentHost/test/node/agentService.test.ts Migrates AgentService tests.
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts Migrates side-effect tests.
src/vs/platform/agentHost/test/node/claudeAgent.test.ts Migrates Claude provider coverage.

Review details

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

  • Files reviewed: 7/8 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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>
roblourens and others added 9 commits August 18, 2026 18:41
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>
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.

2 participants