Keep agent host alive while there are active websocket connections#304271
Merged
roblourens merged 2 commits intomainfrom Mar 24, 2026
Merged
Keep agent host alive while there are active websocket connections#304271roblourens merged 2 commits intomainfrom
roblourens merged 2 commits intomainfrom
Conversation
Instead of shutting it down whenever there are no agents running Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
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
ServerAgentHostManagerto 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 allowsMaxRestarts + 1restart 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`);
}
DonJayamanne
approved these changes
Mar 24, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Instead of shutting it down whenever there are no agents running
Co-authored-by: Copilot copilot@github.com