fix(ghidra): recover stale clients on same-target reopen (#2014)
* fix(ghidra): recover stale clients on same-target reopen * test(ghidra): allow supervised shutdown in health regression * fix(ghidra): read process exit without diagnostic snapshots Health and startup exit checks called the supervisor snapshot, which concatenates retained launcher output only to read the exit code. * test(adb): align fixtures with literal output and directory commands --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
Cursor Agent
morluto
parent
69e097a8ca
commit
4573e8cf35
@@ -78,6 +78,15 @@ export type ProviderProcessLaunch =
|
||||
readonly cleanup?: () => Promise<ProcessCleanupResult>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Process exit recorded by the supervisor.
|
||||
* Independent of retained stream diagnostics.
|
||||
*/
|
||||
export interface ProviderProcessExitObservation {
|
||||
readonly code: number | null;
|
||||
readonly signal: NodeJS.Signals | null;
|
||||
}
|
||||
|
||||
/** Detached diagnostics captured for one supervised provider process. */
|
||||
export interface ProviderProcessSnapshot {
|
||||
/** True only when a configured diagnostic budget excluded output bytes. */
|
||||
@@ -233,10 +242,7 @@ export class ProviderProcessSupervisor {
|
||||
readonly #options: ProviderProcessSupervisorOptions;
|
||||
readonly #stdout = new ProcessOutputCapture();
|
||||
readonly #stderr = new ProcessOutputCapture();
|
||||
readonly #exit = deferred<{
|
||||
readonly code: number | null;
|
||||
readonly signal: NodeJS.Signals | null;
|
||||
}>();
|
||||
readonly #exit = deferred<ProviderProcessExitObservation>();
|
||||
readonly #outputClose = deferred<void>();
|
||||
#outputClosed = false;
|
||||
#stdoutObservedBytes = 0;
|
||||
@@ -271,9 +277,7 @@ export class ProviderProcessSupervisor {
|
||||
readonly #onError = (cause: Error): void => {
|
||||
this.#options.onDiagnostic?.({ type: "error", message: cause.message });
|
||||
};
|
||||
#exitObservation:
|
||||
| { readonly code: number | null; readonly signal: NodeJS.Signals | null }
|
||||
| undefined;
|
||||
#exitObservation: ProviderProcessExitObservation | undefined;
|
||||
#stopPromise: Promise<ProviderProcessStopResult> | undefined;
|
||||
#disposed = false;
|
||||
|
||||
@@ -292,6 +296,16 @@ export class ProviderProcessSupervisor {
|
||||
this.#recordExit(launch.process.exitCode, launch.process.signalCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recorded process exit without concatenating retained stream diagnostics.
|
||||
* Undefined until exit or close is observed.
|
||||
*/
|
||||
observedExit(): ProviderProcessExitObservation | undefined {
|
||||
const exit = this.#exitObservation;
|
||||
if (exit === undefined) return undefined;
|
||||
return { code: exit.code, signal: exit.signal };
|
||||
}
|
||||
|
||||
/** Latest retained output and exit observation, with explicit configured truncation. */
|
||||
snapshot(): ProviderProcessSnapshot {
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import { expect, it } from "vitest";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { ProviderProcessSupervisor } from "./ProviderProcess.js";
|
||||
|
||||
it("exit does not establish complete output when a producer closes its streams later", async () => {
|
||||
@@ -34,6 +34,57 @@ it("exit does not establish complete output when a producer closes its streams l
|
||||
}
|
||||
});
|
||||
|
||||
it("reads an observed exit without materializing stream diagnostics", () => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor({
|
||||
process: producer,
|
||||
ownsProcessLifetime: false,
|
||||
});
|
||||
try {
|
||||
producer.stdout.write("retained-diagnostic");
|
||||
const snapshot = vi.spyOn(supervisor, "snapshot");
|
||||
expect(supervisor.observedExit()).toBeUndefined();
|
||||
producer.emit("exit", null, "SIGKILL");
|
||||
expect(supervisor.observedExit()).toEqual({
|
||||
code: null,
|
||||
signal: "SIGKILL",
|
||||
});
|
||||
expect(snapshot).not.toHaveBeenCalled();
|
||||
expect(supervisor.snapshot()).toMatchObject({
|
||||
stdout: { text: "retained-diagnostic" },
|
||||
exitCode: null,
|
||||
signal: "SIGKILL",
|
||||
});
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("observes an exit that completed before supervision", () => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: 2,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor({
|
||||
process: producer,
|
||||
ownsProcessLifetime: false,
|
||||
});
|
||||
try {
|
||||
expect(supervisor.observedExit()).toEqual({ code: 2, signal: null });
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("reports a reached process memory limit only when the handle observed one", () => {
|
||||
let reached = false;
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
|
||||
Reference in New Issue
Block a user