src/vs/server/node/serverAgentHostManager.ts

158 LOC · 149 covered · 9 uncovered · 17 ranges · 10 concepts · 7 introducers · 7 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/agentHost/common/agentHostProcessTelemetry.ts · 41 LOCcommon/agentHostProcessT…src/vs/platform/telemetry/common/errorTelemetry.ts · 175 LOCcommon/errorTelemetry.tsserverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1 · 0 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 2 introduced LOCserverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1 · 0 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×2 · 19 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 2 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 4 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×2 · 4 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×3 · 19 introduced LOCserverAgentHostManager.t…agentHostProcessTelemetry.ts ×1 · 7 introduced LOCagentHostProcessTelemetr…serverAgentHostManager.ts ×7 · 138 introduced LOCserverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager acquires token when sessions become active|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager acquires token when sessions become active|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager acquires token when standalone WebSocket clients connect|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager acquires token when standalone WebSocket clients connect|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager releases token only when both sessions and standalone WebSocket connections are zero|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager releases token only when both sessions and standalone WebSocket connections are zero|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports process start failure|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager reports process start failure|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1serverAgentHostManager.t…Focused file · src/vs/server/node/serverAgentHostManager.ts · 158 LOCnode/serverAgentHostMana…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- serverAgentHostManager.ts ×7
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { Event } from '../../base/common/event.js';
7 > import { Disposable, MutableDisposable, toDisposable } from '../../base/common/lifecycle.js';
8 > import { ProxyChannel } from '../../base/parts/ipc/common/ipc.js';
9 > import { IAgentHostConnection, IAgentHostStarter } from '../../platform/agentHost/common/agent.js';
10 > import { reportAgentHostProcessError } from '../../platform/agentHost/common/agentHostProcessTelemetry.js';
11 > import { AgentHostIpcChannels, IAgentService } from '../../platform/agentHost/common/agentService.js';
12 > import { createDecorator } from '../../platform/instantiation/common/instantiation.js';
13 > import { ILogService, ILoggerService } from '../../platform/log/common/log.js';
14 > import { RemoteLoggerChannelClient } from '../../platform/log/common/logIpc.js';
15 > import { ITelemetryService } from '../../platform/telemetry/common/telemetry.js';
16 > import { IServerLifetimeService } from './serverLifetimeService.js';
17 >
18 > export const IServerAgentHostManager = createDecorator<IServerAgentHostManager>('serverAgentHostManager');
19 >
20 > /**
21 > * Server-specific agent host manager. Eagerly starts the agent host process,
22 > * handles crash recovery, and tracks active agent sessions plus incoming
23 > * WebSocket clients to the spawned standalone agent host via
24 > * {@link IServerLifetimeService}.
25 > *
26 > * Renderer-to-agent-host proxy connections handled by `AgentHostChannel`
27 > * deliberately do not participate here.
28 > */
29 > export interface IServerAgentHostManager {
30 > readonly _serviceBrand: undefined;
31 > }
32 >
33 > /**
34 > * Proxy interface for the connection tracker IPC channel exposed by the agent
35 > * host process. This is NOT part of the agent host protocol -- it is a
36 > * server-only process-management concern.
37 > */
38 > interface IConnectionTrackerService {
39 > readonly onDidChangeConnectionCount: Event<number>;
40 > }
41 >
42 > enum Constants {
43 > MaxRestarts = 5,
44 > }
45 >
46 > export class ServerAgentHostManager extends Disposable implements IServerAgentHostManager {
47 > declare readonly _serviceBrand: undefined;
48 >
49 > private _restartCount = 0;
50 >
51 > /** Lifetime token held while sessions are active or standalone WebSocket clients are connected. */
52 > private readonly _lifetimeToken = this._register(new MutableDisposable());
53 >
54 > private _hasActiveSessions = false;
55 > private _connectionCount = 0;
56 >
57 > constructor(
58 > private readonly _starter: IAgentHostStarter,
59 > @ILogService private readonly _logService: ILogService,
60 > @ILoggerService private readonly _loggerService: ILoggerService,
61 > @IServerLifetimeService private readonly _serverLifetimeService: IServerLifetimeService,
62 > @ITelemetryService private readonly _telemetryService: ITelemetryService,
63 > ) {
64 > super();
65 > this._register(this._starter);
66 > this._start();
67 > }
68 >
69 > private async _start(): Promise<void> {
70 > try {
71 > const connection = await this._starter.start();
72 >
73 > if (this._store.isDisposed) {
74 connection.store.dispose();
75 return;
76 }
78 > this._logService.info('ServerAgentHostManager: agent host started');
79 >
80 > // Connect logger channel so agent host logs appear in the output channel
81 > connection.store.add(new RemoteLoggerChannelClient(this._loggerService, connection.client.getChannel(AgentHostIpcChannels.Logger)));
82 >
83 > this._trackActiveSessions(connection);
84 > this._trackClientConnections(connection);
85 >
86 > // Handle unexpected exit
87 > connection.store.add(connection.onDidProcessExit(e => {
88 > if (!this._store.isDisposed) { serverAgentHostManager.ts ×2
89 > this._hasActiveSessions = false;
90 > this._connectionCount = 0;
91 > this._lifetimeToken.clear();
92 >
93 > const willRestart = this._restartCount <= Constants.MaxRestarts;
94 > reportAgentHostProcessError(this._telemetryService, {
95 > kind: 'unexpectedExit',
96 > code: e.code,
97 > restartCount: this._restartCount,
98 > willRestart,
99 > });
100 > if (willRestart) {
101 > this._logService.error(`ServerAgentHostManager: agent host terminated unexpectedly with code ${e.code}`);
102 > this._restartCount++;
103 > connection.store.dispose();
104 > this._start();
105 > } else {
106 this._logService.error(`ServerAgentHostManager: agent host terminated with code ${e.code}, giving up after ${Constants.MaxRestarts} restarts`);
107 }
110 >
111 > this._register(toDisposable(() => connection.store.dispose()));
112 > } catch (error) {
113 > if (this._store.isDisposed) { serverAgentHostManager.ts ×3
114 return;
115 }
117 > const willRestart = this._restartCount <= Constants.MaxRestarts;
118 > reportAgentHostProcessError(this._telemetryService, {
119 > kind: 'startFailed',
120 > restartCount: this._restartCount,
121 > willRestart,
122 > }, error);
123 > if (willRestart) {
124 > this._logService.error('ServerAgentHostManager: agent host failed to start', error);
125 > this._restartCount++;
126 > this._start();
127 > } else {
128 this._logService.error(`ServerAgentHostManager: agent host failed to start, giving up after ${Constants.MaxRestarts} restarts`, error);
129 }
132 >
133 > private _trackActiveSessions(connection: IAgentHostConnection): void {
134 > const agentService = ProxyChannel.toService<IAgentService>(connection.client.getChannel(AgentHostIpcChannels.AgentHost));
135 > connection.store.add(agentService.onDidAction(envelope => {
136 > if (envelope.action.type === 'root/activeSessionsChanged') { serverAgentHostManager.ts ×1
137 > this._hasActiveSessions = envelope.action.activeSessions > 0;
138 > this._updateLifetimeToken();
139 > }
141 > }
142 >
143 > private _trackClientConnections(connection: IAgentHostConnection): void {
144 > const connectionTracker = ProxyChannel.toService<IConnectionTrackerService>(connection.client.getChannel(AgentHostIpcChannels.ConnectionTracker));
145 > connection.store.add(connectionTracker.onDidChangeConnectionCount(count => {
146 > this._connectionCount = count; serverAgentHostManager.ts ×1
147 > this._updateLifetimeToken();
149 > }
150 >
151 > private _updateLifetimeToken(): void {
152 > if (this._hasActiveSessions || this._connectionCount > 0) { serverAgentHostManager.ts ×2
153 > this._lifetimeToken.value ??= this._serverLifetimeService.active('AgentHost');
154 > } else {
155 > this._lifetimeToken.clear(); serverAgentHostManager.ts ×1
156 > }