fix(process): protect unrelated Hopper during cleanup

This commit is contained in:
morluto
2026-07-22 14:04:00 +00:00
parent 513fa294a4
commit e4ee4c9635
38 changed files with 499 additions and 88 deletions
+38
View File
@@ -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",
});