import { Event } from "../../../base/common/event.js"; import { Disposable } from "../../../base/common/lifecycle.js"; /** * Electron's classification of an agent host termination, or `none` when * Electron reported no crash or kill for the process. */ export type AgentHostProcessExitReason = "none" | "clean-exit" | "abnormal-exit" | "killed" | "crashed" | "oom" | "launch-failed" | "integrity-failure" | "memory-eviction" | "other"; /** The most specific fatal condition recognized in the agent host's final stderr output. */ export type AgentHostFatalSignature = "none" | "v8HeapOutOfMemory" | "v8Fatal" | "nativeModuleLoad" | "startupFailure"; /** * How the agent host process ended: through `process.exit()`, because its * event loop drained, or without running Node's exit handlers, as happens for * native crashes and external termination. */ export type AgentHostExitPath = "processExit" | "eventLoopDrained" | "abrupt"; /** An agent host startup failure, reported by the host before it exits. */ export interface IAgentHostStartupFailure { readonly name?: string; readonly code?: string; readonly msg: string; readonly callstack?: string; } /** Diagnostics collected by the parent process about an agent host exit. */ export interface IAgentHostProcessExitDiagnostics { readonly reason: AgentHostProcessExitReason; /** Milliseconds from process spawn until exit, when the spawn was observed. */ readonly uptimeMs?: number; readonly fatalSignature: AgentHostFatalSignature; readonly exitPath: AgentHostExitPath; /** The package or VS Code module that called `process.exit()`. */ readonly exitCaller?: string; readonly startupFailure?: IAgentHostStartupFailure; /** The working set from the most recent memory sample, in megabytes. */ readonly workingSetMb?: number; /** The largest working set observed by memory samples, in megabytes. */ readonly peakWorkingSetMb?: number; /** Milliseconds between the most recent memory sample and the exit. */ readonly memorySampleAgeMs?: number; } /** An agent host process exit, with diagnostics when the starter collects them. */ export interface IAgentHostProcessExitEvent { readonly code: number; readonly signal: string; readonly diagnostics?: IAgentHostProcessExitDiagnostics; } /** Prefix of the stderr line an agent host writes while running Node's exit handlers. */ export declare const AgentHostExitMarker: string; /** Formats the stderr line an agent host writes before exiting because startup failed. */ export declare function formatAgentHostStartupFailure(error: unknown): string; /** Formats the stderr line an agent host writes while running Node's exit handlers. */ export declare function formatAgentHostExit(path: Exclude, caller: string | undefined): string; /** * Reduces the first frame of `stack` to a bounded module identifier: the * containing package in `node_modules` or the packaged `node_modules.asar`, the * module name of a file in VS Code's installation at `appRoot`, `node` for Node * internals, or `external` for any other file, whose name may be user-chosen. * Paths never leave the process. Scoped packages are written as `@scope:name`, * because telemetry cleaning redacts values containing `/` as file paths. */ export declare function identifyAgentHostExitCaller(stack: string | undefined, appRoot: string): string; /** Diagnostics recognized in the agent host's final stderr output. */ export interface IAgentHostStderrDiagnostics { readonly fatalSignature: AgentHostFatalSignature; readonly exitPath: AgentHostExitPath; readonly exitCaller?: string; readonly startupFailure?: IAgentHostStartupFailure; } /** Classifies the agent host's final stderr output without retaining it. */ export declare function parseAgentHostStderr(text: string): IAgentHostStderrDiagnostics; /** The process events {@link AgentHostProcessExitDiagnosticsCollector} observes. */ export interface IAgentHostProcessExitDiagnosticsSource { readonly onSpawn: Event; readonly onStderr: Event; readonly onCrash: Event<{ readonly reason: string; }>; readonly onExit: Event<{ readonly code: number; readonly signal: string; }>; } /** A process memory sample, in kilobytes. */ export interface IAgentHostProcessMemorySample { readonly workingSetKb: number; readonly peakWorkingSetKb?: number; } export interface IAgentHostProcessExitDiagnosticsOptions { /** How long to wait after exit for Electron's crash reason and final stderr. */ readonly gracePeriodMs: number; readonly memorySampleIntervalMs: number; /** How far before exit stderr output is considered part of the exit. */ readonly stderrWindowMs: number; readonly maxStderrLength: number; } /** * Collects diagnostics about one agent host process and reports its exit * after a short grace period, because Electron's crash reason and the * process's final stderr output can arrive after the exit event. */ export declare class AgentHostProcessExitDiagnosticsCollector extends Disposable { private readonly _sampleMemory; private readonly _options; private readonly _onDidExit; readonly onDidExit: Event; private readonly _memoryTimer; private readonly _exitTimer; private readonly _stderr; private _stderrLength; private _spawnTime; private _crashReason; private _lastMemorySample; private _peakWorkingSetKb; constructor(source: IAgentHostProcessExitDiagnosticsSource, _sampleMemory: (pid: number) => IAgentHostProcessMemorySample | undefined, _options?: IAgentHostProcessExitDiagnosticsOptions); private _handleSpawn; private _recordStderr; private _recordMemory; private _handleExit; private _createDiagnostics; }