fix(process): protect unrelated Hopper during cleanup
This commit is contained in:
+15
-12
@@ -27,6 +27,11 @@ import {
|
||||
ProviderProcessSupervisor,
|
||||
} from "../process/ProviderProcess.js";
|
||||
import type { BridgeLaunch, BridgeLauncher } from "./BridgeLauncher.js";
|
||||
import {
|
||||
createOwnedHopperShutdownDiagnostic,
|
||||
type HopperDiagnostic,
|
||||
providerCleanupFailure,
|
||||
} from "./HopperDiagnostics.js";
|
||||
import {
|
||||
isHopperCleanupRequired,
|
||||
isHopperShutdownAcknowledgement,
|
||||
@@ -54,10 +59,6 @@ export interface HopperClientOptions {
|
||||
}
|
||||
|
||||
/** Safe launcher telemetry; stderr content is intentionally never exposed. */
|
||||
type HopperDiagnostic =
|
||||
| { readonly type: "launcher-stderr"; readonly bytes: number }
|
||||
| { readonly type: "launcher-exit"; readonly code: number | null };
|
||||
|
||||
/**
|
||||
* Owns one authenticated NDJSON-over-Unix-socket bridge session.
|
||||
*
|
||||
@@ -327,6 +328,16 @@ export class HopperClient {
|
||||
const stopped = await this.#process.stop(
|
||||
cleanupResult === undefined ? {} : { cleanupResult },
|
||||
);
|
||||
const diagnostic = createOwnedHopperShutdownDiagnostic(
|
||||
this.#process.launch,
|
||||
stopped,
|
||||
cleanupResult,
|
||||
);
|
||||
this.#options.onDiagnostic?.(diagnostic);
|
||||
this.#logger.info(
|
||||
diagnostic,
|
||||
"Owned Hopper launcher shutdown completed",
|
||||
);
|
||||
if (stopped.status === "incomplete")
|
||||
this.#logger.warn(
|
||||
{ reason: stopped.reason },
|
||||
@@ -541,11 +552,3 @@ const startupInterruption = (
|
||||
deadline.cancelled
|
||||
? new HopperCancelledError()
|
||||
: new HopperTimeoutError(deadline.timeoutMs);
|
||||
|
||||
const providerCleanupFailure = (cause: unknown): ProcessCleanupResult => ({
|
||||
cleaned: false,
|
||||
reason:
|
||||
cause instanceof Error
|
||||
? `owned provider cleanup failed: ${cause.message}`
|
||||
: "owned provider cleanup failed",
|
||||
});
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { ProcessCleanupResult } from "../process/ProcessOwnership.js";
|
||||
import type { ProviderProcessStopResult } from "../process/ProviderProcess.js";
|
||||
import type { BridgeLaunch } from "./BridgeLauncher.js";
|
||||
|
||||
/** Sanitized Hopper launcher and owned-shutdown telemetry. */
|
||||
export type HopperDiagnostic =
|
||||
| { readonly type: "launcher-stderr"; readonly bytes: number }
|
||||
| { readonly type: "launcher-exit"; readonly code: number | null }
|
||||
| {
|
||||
readonly type: "owned-shutdown";
|
||||
readonly status: ProviderProcessStopResult["status"];
|
||||
readonly launcher_pid: number | null;
|
||||
readonly process_group_id: number | null;
|
||||
readonly cleanup_signaled: boolean | null;
|
||||
readonly reason: string | null;
|
||||
};
|
||||
|
||||
/** Retain actionable ownership coordinates without exposing the run token. */
|
||||
export const createOwnedHopperShutdownDiagnostic = (
|
||||
launch: BridgeLaunch,
|
||||
stopped: ProviderProcessStopResult,
|
||||
cleanup: ProcessCleanupResult | undefined,
|
||||
): Extract<HopperDiagnostic, { readonly type: "owned-shutdown" }> => ({
|
||||
type: "owned-shutdown",
|
||||
status: stopped.status,
|
||||
launcher_pid: launch.ownership?.leaderPid ?? launch.process.pid ?? null,
|
||||
process_group_id: launch.ownership?.processGroupId ?? null,
|
||||
cleanup_signaled: cleanup?.cleaned === true ? cleanup.signaled : null,
|
||||
reason: stopped.status === "incomplete" ? stopped.reason : null,
|
||||
});
|
||||
|
||||
/** Convert an unexpected cleanup rejection without exposing a stack or token. */
|
||||
export const providerCleanupFailure = (
|
||||
_cause: unknown,
|
||||
): ProcessCleanupResult => ({
|
||||
cleaned: false,
|
||||
reason: "owned provider cleanup failed",
|
||||
});
|
||||
Reference in New Issue
Block a user