serverAgentHostManager.ts ×7

Frontier kind: Joint frontier

unlabeled · c_ddc2af5d634b

7 tests · 20704 LOC · 71 files · introduces 1 test · 138 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
8 ranges138 lines · 2 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1914 ranges20704 lines · 71 files · Browse complete extent
All tests (intent)
7 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 138 introduced LOC across 8 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/server/node/serverAgentHostManager.ts 104 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- serverAgentHostManager.ts
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) {
89 this._hasActiveSessions = false;
107 }
108 }
110 >
111 > this._register(toDisposable(() => connection.store.dispose()));
112 > } catch (error) {
113 if (this._store.isDisposed) {
114 return;
129 }
130 }
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') {
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;
147 this._updateLifetimeToken();
149 > }
150 >
151 > private _updateLifetimeToken(): void {
152 if (this._hasActiveSessions || this._connectionCount > 0) {
153 this._lifetimeToken.value ??= this._serverLifetimeService.active('AgentHost');
src/vs/platform/agentHost/common/agentHostProcessTelemetry.ts 34 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostProcessTelemetry.ts
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 { packErrorForTelemetry } from '../../telemetry/common/errorTelemetry.js';
7 > import { ITelemetryService } from '../../telemetry/common/telemetry.js';
8 >
9 > export type AgentHostProcessErrorData = {
10 > kind: 'unexpectedExit' | 'startFailed';
11 > code?: number;
12 > restartCount: number;
13 > willRestart: boolean;
14 > };
15 >
16 > type AgentHostProcessErrorEvent = AgentHostProcessErrorData & {
17 > isError: true;
18 > callstack?: string;
19 > msg?: string;
20 > };
21 >
22 > type AgentHostProcessErrorClassification = {
23 > kind: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The kind of agent host process failure.' };
24 > code?: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The agent host process exit code, when available.' };
25 > restartCount: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The number of agent host restart attempts before this failure.' };
26 > willRestart: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'Whether VS Code will attempt to restart the agent host after this failure.' };
27 > isError: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'Whether this is an error event.' };
28 > callstack?: { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth'; comment: 'The callstack of an agent host process start failure.' };
29 > msg?: { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth'; comment: 'The message of an agent host process start failure.' };
30 > owner: 'bryanchen-d';
31 > comment: 'Tracks agent host process failures that cannot be reported reliably from inside the agent host process.';
32 > };
33 >
34 > export function reportAgentHostProcessError(telemetryService: ITelemetryService, data: AgentHostProcessErrorData, error?: unknown): void {
35 const errorData = error === undefined ? undefined : packErrorForTelemetry(error);
36 telemetryService.publicLogError2<AgentHostProcessErrorEvent, AgentHostProcessErrorClassification>('agentHost.processError', {