mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 03:02:56 +00:00
* fix(process): preserve producer-owned inspection cancellation Prototype the explicit inspection origin and retained file/batch owner protocol. Downstream adapter migration and lease binding remain required before integration. * fix(process): type inspection ownership handoffs precisely * fix(process): retain plain inspection preparation cancellation * fix(process): retain explicit inspection cleanup and cancellation facts * fix(process): require explicit inspection facts and cleanup scope * refactor(process): remove redundant cleanup forwarding wrapper * fix(firmware): retain inspection cancellation and cleanup ownership * fix(wakaru): retain typed inspection outcomes and caller scope * fix(ghidra): preserve inspection facts and launch cleanup scope * fix(providers): preserve typed process inspection outcomes * refactor(process): remove obsolete inspection cancellation re-export * fix(native): preserve inspection preparation cleanup and cancellation * fix(registration): retain typed inspection cleanup during Git discovery * fix(process): preserve inspection deadline origin in adapter handoff * fix(process): consume the canonical inspection selector in binding * fix(native): preserve inspection deadlines and cleanup retry completion * test(process): narrow the retained Darwin preparation owner * fix(providers): preserve preparation ownership and timeout policy Narrow preparation facts through their canonical owner, preserve actual cleanup capabilities and recorded cancellation, and keep enclosing command deadlines authoritative. Retain raw inspection records through Java refusal and configuration projections without changing availability fallback policy. * refactor(process): use one inspection failure type owner * fix(providers): retain recorded secondary failures when rebinding * fix(ghidra): preserve normalized inspection facts through public projection * fix(process): normalize native process listing cancellation * docs(development): clarify failure provenance and cleanup verification * fix(process): preserve direct inspection cancellation facts * fix(process): retain inspection owners through termination * fix(process): preserve command inspection cleanup provenance * fix(desktop): preserve inspection facts after cleanup retry * refactor(process)!: migrate desktop capture with inspection producers * fix(desktop)!: preserve capture failure origins and cleanup owners (#10115) * fix(desktop): preserve capture failure origins and cleanup * fix(desktop): type keyring cleanup cancellation * fix(kuna)!: retain copy cleanup before retiring workspaces (#10114) * fix(kuna): own copy cancellation and descriptor cleanup * fix(kuna): close copy descriptors before workspace removal * test(kuna): type copy lifecycle gates for project library * docs(kuna): explain retained copy-file cleanup and staging ownership * docs(kuna): separate cache publication, integrity and cleanup guidance * fix(desktop): retain sampling inspection owners before release * fix(process): preserve capture file read cancellation origin * fix(process): retain capture inspection cancellation and cleanup owners * fix(process): retain sampling inspection failures in capture scope * fix(process): retain inspection failures through mandatory cleanup * fix(process): distinguish sampler shutdown from capture cancellation * fix(browser): retain startup EOF before later cancellation * fix(process): bind capture inspection cleanup to the owning run * test(process): migrate cancellation fixtures to typed owners Record explicit preparation and command cancellation facts, retain exact opaque reasons and physical causes, and guard the mocked version probe from native preparation. Keep the live Wakaru command control while adding a recording equivalent for bounded source verification. * fix(process): own sampling reads and settle inspection peers * fix(errors): retain authored recovery through cleanup composition * fix(process): retain all sampling inspection leaves for final cleanup * test(browser): report recording cleanup signal outcome * fix(process): keep inspection error context out of implicit JSON * fix(desktop): retain normalized sampling cleanup ownership * test(process): assert tagged startup cancellation
216 lines
7.2 KiB
TypeScript
216 lines
7.2 KiB
TypeScript
import { processInspectionCancellations } from "../ProcessInspectionCleanup.js";
|
|
import {
|
|
ProcessOwnershipInspectionCancelled,
|
|
isProcessOwnershipInspectionCancellation,
|
|
} from "../ProcessInspectionCancellation.js";
|
|
import {
|
|
normalizeCaptureFailure,
|
|
ProcessCaptureInspectionFailure,
|
|
ProcessCaptureError,
|
|
} from "./ProcessCaptureError.js";
|
|
import { ProcessRunTokenReadError } from "../ProcessRunTokenObservations.js";
|
|
import { err, ok, type Result } from "../../domain/result.js";
|
|
|
|
/** All admitted sampling reads settled; exact fulfilled values and failures remain available. */
|
|
export class SamplingReadBatchFailure extends ProcessCaptureError {
|
|
readonly inspectionFailures: readonly ProcessCaptureInspectionFailure[];
|
|
constructor(readonly outcomes: readonly PromiseSettledResult<unknown>[]) {
|
|
const rejected = outcomes.flatMap((outcome) =>
|
|
outcome.status === "rejected" ? [outcome.reason as unknown] : [],
|
|
);
|
|
const inspections = [
|
|
...new Set(rejected.flatMap(samplingInspectionFailures)),
|
|
];
|
|
const untypedPhysical = rejected.some(
|
|
(failure) =>
|
|
samplingInspectionFailures(failure).length === 0 ||
|
|
(failure instanceof SamplingReadBatchFailure &&
|
|
failure.userCategory !== "cancelled" &&
|
|
failure.inspectionFailures.every(
|
|
(leaf) => leaf.userCategory === "cancelled",
|
|
)),
|
|
);
|
|
const primary =
|
|
inspections.find((failure) => failure.userCategory !== "cancelled") ??
|
|
(untypedPhysical ? undefined : inspections[0]);
|
|
const resources = [
|
|
...new Set(inspections.flatMap((failure) => failure.cleanupResources)),
|
|
];
|
|
super(primary?.message ?? "Process sampling reads failed", {
|
|
cause: new AggregateError(
|
|
rejected,
|
|
"Admitted process sampling reads failed",
|
|
),
|
|
...(primary === undefined ? {} : { cleanupPrimary: primary }),
|
|
...(primary?.userCategory === "cancelled"
|
|
? { userCategory: "cancelled" as const, reason: "cancelled" as const }
|
|
: {}),
|
|
...(resources.length === 0
|
|
? {}
|
|
: {
|
|
cleanup: {
|
|
reason: "Process sampling descriptors remain owned",
|
|
resources,
|
|
},
|
|
}),
|
|
});
|
|
this.inspectionFailures = inspections;
|
|
for (const failure of inspections)
|
|
if (failure !== primary) this.retainSecondaryFailure(failure);
|
|
this.bindCleanupDependencies(inspections);
|
|
}
|
|
}
|
|
|
|
/** Only the direct inspection fact or this owner's explicit settled vector transfers leases. */
|
|
export const samplingInspectionFailures = (
|
|
cause: unknown,
|
|
): readonly ProcessCaptureInspectionFailure[] =>
|
|
cause instanceof SamplingReadBatchFailure
|
|
? cause.inspectionFailures
|
|
: cause instanceof ProcessCaptureInspectionFailure
|
|
? [cause]
|
|
: [];
|
|
|
|
export function settleSamplingReads<T extends readonly Promise<unknown>[]>(
|
|
reads: readonly [...T],
|
|
): Promise<{ -readonly [K in keyof T]: Awaited<T[K]> }>;
|
|
export async function settleSamplingReads(
|
|
reads: readonly Promise<unknown>[],
|
|
): Promise<unknown[]> {
|
|
const outcomes = await Promise.allSettled(reads);
|
|
if (outcomes.some((outcome) => outcome.status === "rejected"))
|
|
throw new SamplingReadBatchFailure(outcomes);
|
|
return outcomes.flatMap((outcome) =>
|
|
outcome.status === "fulfilled" ? [outcome.value] : [],
|
|
);
|
|
}
|
|
|
|
/** Retain a count, first failure and interruption fact with their observations. */
|
|
export interface SamplingDiagnostics {
|
|
readonly count: number;
|
|
readonly first: string | null;
|
|
readonly interrupted: boolean;
|
|
}
|
|
|
|
export interface SamplingObservation<T> {
|
|
readonly value: T;
|
|
readonly diagnostics: SamplingDiagnostics;
|
|
}
|
|
|
|
export type SamplingReadFailure =
|
|
| { readonly kind: "process-exited" }
|
|
| { readonly kind: "cancelled"; readonly reason: unknown }
|
|
| {
|
|
readonly kind: "unavailable";
|
|
readonly systemCode: string | undefined;
|
|
readonly diagnostic: string;
|
|
};
|
|
|
|
export const mergeSamplingDiagnostics = (
|
|
...parts: readonly SamplingDiagnostics[]
|
|
): SamplingDiagnostics => ({
|
|
count: parts.reduce((count, part) => count + part.count, 0),
|
|
first: parts.find((part) => part.first !== null)?.first ?? null,
|
|
interrupted: parts.some((part) => part.interrupted),
|
|
});
|
|
|
|
export const samplingObservation = <T>(
|
|
value: T,
|
|
...diagnostics: readonly SamplingDiagnostics[]
|
|
): SamplingObservation<T> => ({
|
|
value,
|
|
diagnostics: mergeSamplingDiagnostics(...diagnostics),
|
|
});
|
|
|
|
export const samplingFailure = (diagnostic: string): SamplingDiagnostics => ({
|
|
count: 1,
|
|
first: diagnostic,
|
|
interrupted: false,
|
|
});
|
|
|
|
/** An interrupted attempt left an observation or declared traversal unfinished. */
|
|
export const samplingInterrupted = (): SamplingDiagnostics => ({
|
|
count: 0,
|
|
first: null,
|
|
interrupted: true,
|
|
});
|
|
|
|
/** Settle each issued read, including peers still completing after shutdown. */
|
|
export const readSamplingSource = async <T>(
|
|
source: string,
|
|
signal: AbortSignal,
|
|
read: () => Promise<T>,
|
|
): Promise<Result<T, SamplingReadFailure>> => {
|
|
if (signal.aborted) return err({ kind: "cancelled", reason: signal.reason });
|
|
try {
|
|
return ok(await read());
|
|
} catch (cause: unknown) {
|
|
const cancellation = ProcessOwnershipInspectionCancelled.from(cause);
|
|
if (
|
|
signal.aborted &&
|
|
isProcessOwnershipInspectionCancellation(cancellation) &&
|
|
processInspectionCancellations(cancellation).every(
|
|
(fact) => fact.reason === signal.reason,
|
|
)
|
|
)
|
|
return err({ kind: "cancelled", reason: signal.reason });
|
|
const inspection = normalizeCaptureFailure(cancellation ?? cause);
|
|
if (
|
|
inspection instanceof ProcessCaptureInspectionFailure ||
|
|
inspection instanceof SamplingReadBatchFailure
|
|
)
|
|
throw inspection;
|
|
if (
|
|
cause instanceof ProcessRunTokenReadError &&
|
|
cause.availability === "absent"
|
|
)
|
|
return err({ kind: "process-exited" });
|
|
const systemCode =
|
|
cause instanceof Error &&
|
|
"code" in cause &&
|
|
typeof cause.code === "string"
|
|
? cause.code
|
|
: undefined;
|
|
const reason =
|
|
cause instanceof Error
|
|
? `${cause.name}: ${cause.message}`
|
|
: String(cause);
|
|
return err({
|
|
kind: "unavailable",
|
|
systemCode,
|
|
diagnostic: `${source}: ${systemCode === undefined ? "" : `${systemCode}: `}${reason}`,
|
|
});
|
|
}
|
|
};
|
|
|
|
export const samplingReadObservation = <T>(
|
|
result: Result<T, SamplingReadFailure>,
|
|
): SamplingObservation<T | undefined> =>
|
|
result.ok
|
|
? samplingObservation(result.value)
|
|
: samplingObservation(
|
|
undefined,
|
|
result.error.kind === "cancelled"
|
|
? samplingInterrupted()
|
|
: result.error.kind === "process-exited"
|
|
? mergeSamplingDiagnostics()
|
|
: samplingFailure(result.error.diagnostic),
|
|
);
|
|
|
|
/** Missing procfs entries are expected exit races; denied reads stay unknown. */
|
|
export const readProcSamplingSource = async <T>(
|
|
path: string,
|
|
signal: AbortSignal,
|
|
read: () => Promise<T>,
|
|
): Promise<SamplingObservation<T | undefined>> => {
|
|
const result = await readSamplingSource(path, signal, read);
|
|
if (
|
|
!result.ok &&
|
|
result.error.kind === "unavailable" &&
|
|
(result.error.systemCode === "ENOENT" ||
|
|
result.error.systemCode === "ESRCH")
|
|
)
|
|
return samplingObservation(undefined);
|
|
return samplingReadObservation(result);
|
|
};
|