Skip to content

Keep agent host alive while there are active websocket connections#304271

Merged
roblourens merged 2 commits intomainfrom
roblou/unnecessary-seahorse
Mar 24, 2026
Merged

Keep agent host alive while there are active websocket connections#304271
roblourens merged 2 commits intomainfrom
roblou/unnecessary-seahorse

Conversation

@roblourens
Copy link
Member

Instead of shutting it down whenever there are no agents running

Co-authored-by: Copilot copilot@github.com

Instead of shutting it down whenever there are no agents running

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings March 23, 2026 21:22
@roblourens roblourens self-assigned this Mar 23, 2026
@vs-code-engineering vs-code-engineering bot added this to the 1.114.0 milestone Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts server-side agent host lifetime management so the agent host process is kept alive while there are active WebSocket clients, not only while there are active agent sessions—aligning shutdown behavior with real client connectivity in the remote agent host architecture.

Changes:

  • Track WebSocket client connection count in the agent host process and expose it to the parent via a new IPC channel.
  • Update ServerAgentHostManager to hold the server lifetime token when either active sessions > 0 or connected clients > 0.
  • Add unit tests for connection counting and lifetime token behavior; expand architecture reference documentation accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vs/server/test/node/serverAgentHostManager.test.ts New tests validating lifetime token acquisition/release based on sessions and client connections.
src/vs/server/node/serverAgentHostManager.ts Holds server lifetime token based on sessions OR WebSocket connection count; listens to new IPC channel.
src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts Adds tests for new connection-count event behavior, including stale reconnect close handling.
src/vs/platform/agentHost/node/protocolServerHandler.ts Emits onDidChangeConnectionCount on connect/disconnect and avoids stale reconnect close decrement.
src/vs/platform/agentHost/node/agentHostMain.ts Wires ProtocolServerHandler connection count to an IPC event exposed to parent process.
src/vs/platform/agentHost/common/agentService.ts Adds AgentHostIpcChannels.ConnectionTracker channel constant.
src/vs/platform/agentHost/architecture.md Updates architecture reference to document the new connection-count signal and revised lifetime rules.
Comments suppressed due to low confidence (1)

src/vs/server/node/serverAgentHostManager.ts:92

  • The restart limit check uses <= Constants.MaxRestarts, which allows MaxRestarts + 1 restart attempts (e.g. with MaxRestarts=5, it can restart 6 times). This also makes the “giving up after {MaxRestarts} restarts” log message inaccurate. Consider switching the condition to < Constants.MaxRestarts (or adjusting the counter/message) so the configured limit matches the behavior.
				if (this._restartCount <= Constants.MaxRestarts) {
					this._logService.error(`ServerAgentHostManager: agent host terminated unexpectedly with code ${e.code}`);
					this._restartCount++;
					connection.store.dispose();
					this._start();
				} else {
					this._logService.error(`ServerAgentHostManager: agent host terminated with code ${e.code}, giving up after ${Constants.MaxRestarts} restarts`);
				}

@roblourens roblourens closed this Mar 23, 2026
@roblourens roblourens reopened this Mar 24, 2026
@roblourens roblourens marked this pull request as ready for review March 24, 2026 00:12
@roblourens roblourens merged commit a2d7169 into main Mar 24, 2026
17 of 19 checks passed
@roblourens roblourens deleted the roblou/unnecessary-seahorse branch March 24, 2026 00:43
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.

3 participants