Skip to content

agentHost: harden process lifecycle and recovery - #330567

Merged
roblourens merged 4 commits into
mainfrom
roblou/agents/agent-host-process-refactor-567986eb
Aug 13, 2026
Merged

roblourens merged 4 commits into
mainfrom
roblou/agents/agent-host-process-refactor-567986eb

Conversation

@roblourens

Copy link
Copy Markdown
Member

Summary

  • make Agent Host enablement react bidirectionally to AI feature disablement and keep registrations/defaults in sync
  • make local startup single-flight, return explicit MessagePort failures, and reconnect every window after crashes or explicit restarts
  • bound global graceful shutdown while draining protocol and management work, providers, and session persistence
  • preserve active session worktrees and correct desktop/server restart exhaustion behavior

Review notes

Agent Host is shared across windows, unlike extension hosts. Graceful shutdown is therefore owned by the global main-process lifecycle rather than a per-window shutdown joiner. The six-second outer deadline reserves bounded time for request drains, provider shutdown, and the session-data flush before forcing process disposal.

Validation

  • npm run typecheck-client
  • npm run valid-layers-check
  • npm run test-node
  • focused Agent Host/base IPC suites: 493 passing, 17 pending
  • pre-commit hygiene

(Written by Copilot)

Improve Agent Host enablement, startup coordination, reconnect recovery, restart limits, and bounded graceful shutdown. Preserve session worktrees and drain protocol, provider, and persistence work before exit.\n\n(Written by Copilot)\n\nCo-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings August 12, 2026 23:16

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

Hardens Agent Host enablement, process recovery, reconnect behavior, and bounded shutdown across desktop, server, and session layers.

Changes:

  • Makes enablement and registrations react bidirectionally.
  • Adds single-flight startup, explicit connection failures, and multi-window recovery.
  • Drains requests and persistence during bounded graceful shutdown.
Show a summary per file
File Description
src/vs/workbench/services/agentHost/test/electron-browser/agentHostService.test.ts Updates enablement test helper.
src/vs/workbench/services/agentHost/test/browser/editorRemoteAgentHostServiceClient.test.ts Tests enablement-gated remote startup.
src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts Reactively starts remote connections.
src/vs/workbench/contrib/chat/test/common/constants.test.ts Tests disabled-host defaults.
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Tests bidirectional registrations.
src/vs/workbench/contrib/chat/common/constants.ts Excludes disabled Agent Host defaults.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionListContribution.ts Synchronizes session-list registrations.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCopilotCliSettingsContribution.ts Stops forwarding when disabled.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatContribution.ts Synchronizes chat registrations.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostAllowSignedOutWhenUsableContribution.ts Gates configuration forwarding.
src/vs/sessions/contrib/providers/copilotChatSessions/test/browser/copilotChatSessionsProvider.test.ts Tests availability transitions.
src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.ts Refreshes on both transitions.
src/vs/sessions/contrib/providers/agentHost/browser/localAgentHost.contribution.ts Recreates provider registrations.
src/vs/server/test/node/serverAgentHostManager.test.ts Tests restart exhaustion.
src/vs/server/node/serverAgentHostManager.ts Corrects restart limits.
src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts Tests request draining.
src/vs/platform/agentHost/test/node/agentService.test.ts Tests bounded shutdown.
src/vs/platform/agentHost/test/node/agentHostService.test.ts Tests lifecycle and recovery.
src/vs/platform/agentHost/test/electron-browser/remoteAgentHostProtocolClient.test.ts Tests reconnect classification.
src/vs/platform/agentHost/test/browser/agentHostEnablementService.test.ts Tests bidirectional enablement.
src/vs/platform/agentHost/node/protocolServerHandler.ts Tracks in-flight requests.
src/vs/platform/agentHost/node/nodeAgentHostStarter.ts Adds graceful process shutdown.
src/vs/platform/agentHost/node/agentService.ts Settles all provider shutdowns.
src/vs/platform/agentHost/node/agentHostService.ts Serializes lifecycle operations.
src/vs/platform/agentHost/node/agentHostManagementService.ts Coordinates bounded shutdown.
src/vs/platform/agentHost/node/agentHostMain.ts Drains protocol ingress and persistence.
src/vs/platform/agentHost/electron-main/electronAgentHostStarter.ts Reports startup failures and reconnects windows.
src/vs/platform/agentHost/electron-browser/localAgentHostService.ts Rotates clients across reconnects.
src/vs/platform/agentHost/common/state/sessionTransport.ts Defines terminal transport errors.
src/vs/platform/agentHost/common/agentService.ts Clarifies lifecycle ownership.
src/vs/platform/agentHost/common/agentHostEnablementService.ts Updates enablement contract.
src/vs/platform/agentHost/common/agent.ts Extends lifecycle interfaces.
src/vs/platform/agentHost/browser/remoteAgentHostProtocolClient.ts Recovers initial and closed connections.
src/vs/platform/agentHost/browser/agentHostEnablementService.ts Derives live enablement state.
src/vs/code/electron-main/app.ts Moves shutdown ownership globally.
src/vs/base/parts/sandbox/electron-browser/preload.ts Forwards structured port failures.
src/vs/base/parts/ipc/test/common/ipc.test.ts Tests rejected delayed channels.
src/vs/base/parts/ipc/electron-browser/ipc.mp.ts Exposes MessagePort acquisition errors.
src/vs/base/parts/ipc/common/ipc.ts Handles delayed-listener rejection.

Review details

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

  • Files reviewed: 39/39 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Cover structured MessagePort startup failures and management-channel generation rotation across reconnects. Fix the server restart telemetry helper for the CI compiler.\n\n(Written by Copilot)\n\nCo-authored-by: Copilot <[email protected]>
@roblourens
roblourens marked this pull request as ready for review August 13, 2026 17:59
@roblourens
roblourens enabled auto-merge (squash) August 13, 2026 17:59
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

Robo (@deepak1556)

Matched files:

  • src/vs/code/electron-main/app.ts

Resolve Agent Host import overlap while preserving upstream multi-root session support and lifecycle recovery utilities.\n\n(Written by Copilot)\n\nCo-authored-by: Copilot <[email protected]>
Harden MessagePort validation and disposal, drain every protocol ingress path, gracefully restart desktop and server hosts, scope auth/progress work to enablement, and surface remote reconnect success.\n\n(Written by Copilot)\n\nCo-authored-by: Copilot <[email protected]>
@roblourens
roblourens merged commit bd094b5 into main Aug 13, 2026
27 checks passed
@roblourens
roblourens deleted the roblou/agents/agent-host-process-refactor-567986eb branch August 13, 2026 22:02
@vs-code-engineering vs-code-engineering Bot added this to the 1.134.0 milestone Aug 13, 2026
Misha Damjanic (mdamjanic7) added a commit to mdamjanic7/pihub that referenced this pull request Aug 24, 2026
…n (temporary core patch)

Upstream microsoft#329839 (bba5e40, 2026-08-17 sync) made _getManagementService
async resolving to the ProxyChannel.toService proxy; _callManagement awaits
it, so JS treats the proxy as a thenable — .then is proxied as an RPC whose
function arguments serialize to zero-length objects. The agent host fails to
deserialize the frame (SyntaxError: Unexpected end of JSON input on stderr),
never responds, and the awaited call hangs forever (Compact Conversation
spinner, 100% repro).

Split the readiness wait (void) from the proxy accessor (sync) so the proxy
never travels through promise resolution. Superseded by upstream microsoft#330030 /
microsoft#330567 (bd094b5) in the deferred slice — drop on that merge and re-home
compactSession onto the synchronous accessor. Ledger: docs/pihub-patches.md.
Misha Damjanic (mdamjanic7) added a commit to mdamjanic7/pihub that referenced this pull request Aug 24, 2026
Safe tip chosen per the 7-day library-age rule: the next upstream commit
 bumps @vscode/codicons to a build published 2026-08-19 (matures 2026-08-26);
 213 deferred commits remain, also gated on vscode-json-languageservice
 6.0.0-next.3 (matures 2026-08-28). Distro pointer moved (private repo —
 its deps verified separately).

Key resolutions:
- Core patches removed: management-channel thenable-trap workaround
  (upstream microsoft#330567 removed the async accessor; compactSession re-homed
  onto the synchronous _getManagementService), @xterm/* pins (upstream
  carets restored; all in-range versions mature), and the markdown-editor
  pin moved 0.0.2-59 -> 0.0.2-81 (still pinned: the caret's newest
  in-range builds are immature).
- Chat-scoped IAgent migration (microsoft#329633): Pi/omp adapters moved to
  onDidChatProgress/onDidMaterializeChat/getChatMetadata/resolveChatConfig/
  chatConfigCompletions/getChatCustomizations/listLegacyChatBackings;
  session enumeration now announces via onDidDiscoverChats; subagent
  restore is lazy via chats.getMessages with a peer-file claim-index
  fallback; default-chat disposeChat routes to session teardown;
  releaseChat/canReleaseChat wired for idle eviction; eager
  getSubagentSessions retired. Fork arrives via createChat options.
- Fork patches kept and adapted: _resolveFreshestBranchRef worktree
  start point (track=true now keeps upstream's remote resolution),
  _filterStageablePaths retry, 30s diff-pipeline timeouts (extended
  upstream's _runGitStatus with a timeout pass-through), projectTrusted
  trust mirror via eagerCreate's canCreate + getProjectTrusted,
  utilityCompletion title seam (context-object signature),
  bare-layout getWorktreeLayout, model-config carry in
  chatWidget._acceptInput, untitled-draft sessions-list guard,
  ChatSummary.modelId init.
- BYOK env override removed following upstream (root-config gated now);
  preferLongContext removal adopted (both context tiers always shown).
- Copilot fire-and-forget project-resolution store now swallows
  session-teardown rejections (was an unhandled rejection racing dispose).

Validation: compile-check-ts-native, pnpm rebuild, and pnpm run compile
 all green (0 errors); agentHost unit tests 6057 passing / 0 failing.
 Unit suites beyond agentHost not run; app not launched.
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 27, 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.

4 participants