Repository navigation
agentHost: harden process lifecycle and recovery - #330567
Merged
roblourens merged 4 commits intoAug 13, 2026
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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
marked this pull request as ready for review
August 13, 2026 17:59
roblourens
enabled auto-merge (squash)
August 13, 2026 17:59
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Robo (@deepak1556)Matched files:
|
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]>
Paul (pwang347)
previously approved these changes
Aug 13, 2026
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]>
Dmitriy Vasyura (dmitrivMS)
approved these changes
Aug 13, 2026
roblourens
deleted the
roblou/agents/agent-host-process-refactor-567986eb
branch
August 13, 2026 22:02
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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-clientnpm run valid-layers-checknpm run test-node(Written by Copilot)