perf(process): batch ownership tokens during rooted cleanup
Use the host bulk token reader for each cleanup validation while preserving identity checks before and after token reads. Fall back for unsupported readers or omitted rows, retain explicit unavailable observations, and preserve batch and individual failures. Source ownership regressions and real owned-process boundary tests pass; a warm Darwin validation probe reduced median time from 90 ms to 52 ms.
This commit is contained in:
@@ -641,29 +641,7 @@ const processOwnershipFailures = async (
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const member of members) {
|
||||
try {
|
||||
if ((await host.environment(member.pid)).REA_PROCESS_RUN_ID !== runId)
|
||||
failures.push({ pid: member.pid, reason: "run-token-mismatch" });
|
||||
} catch (cause: unknown) {
|
||||
try {
|
||||
const live = liveProcesses(await host.listProcesses());
|
||||
if (!live.some(({ pid }) => pid === member.pid)) continue;
|
||||
} catch (recheckCause: unknown) {
|
||||
failures.push({
|
||||
pid: member.pid,
|
||||
reason: "environment-unreadable",
|
||||
diagnostic: `${errorMessage(cause)}; process liveness recheck failed: ${errorMessage(recheckCause)}`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
failures.push({
|
||||
pid: member.pid,
|
||||
reason: "environment-unreadable",
|
||||
diagnostic: errorMessage(cause),
|
||||
});
|
||||
}
|
||||
}
|
||||
failures.push(...(await processRunTokenFailures(members, runId, host)));
|
||||
if (
|
||||
failures.length === 0 &&
|
||||
expectedIdentities.size > 0 &&
|
||||
@@ -694,6 +672,60 @@ const processOwnershipFailures = async (
|
||||
return failures;
|
||||
};
|
||||
|
||||
const processRunTokenFailures = async (
|
||||
members: readonly ProcessTableEntry[],
|
||||
runId: string,
|
||||
host: ProcessOwnershipHost,
|
||||
): Promise<readonly ProcessOwnershipValidationFailure[]> => {
|
||||
const failures: ProcessOwnershipValidationFailure[] = [];
|
||||
let runTokenObservations:
|
||||
| ReadonlyMap<number, ProcessRunTokenObservation>
|
||||
| undefined;
|
||||
let runTokenReadFailure: string | undefined;
|
||||
if (host.runTokens !== undefined) {
|
||||
try {
|
||||
runTokenObservations = await host.runTokens(members);
|
||||
} catch (cause: unknown) {
|
||||
runTokenReadFailure = errorMessage(cause);
|
||||
}
|
||||
}
|
||||
for (const member of members) {
|
||||
const batchObservation = runTokenObservations?.get(member.pid);
|
||||
let observation =
|
||||
batchObservation ?? (await readEnvironmentRunToken(host, member.pid));
|
||||
if (
|
||||
runTokenReadFailure !== undefined &&
|
||||
observation.state === "unavailable"
|
||||
)
|
||||
observation = {
|
||||
state: "unavailable",
|
||||
reason: `${observation.reason}; run-token batch failed: ${runTokenReadFailure}`,
|
||||
};
|
||||
if (observation.state === "readable") {
|
||||
if (observation.runId !== runId)
|
||||
failures.push({ pid: member.pid, reason: "run-token-mismatch" });
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const live = liveProcesses(await host.listProcesses());
|
||||
if (!live.some(({ pid }) => pid === member.pid)) continue;
|
||||
} catch (recheckCause: unknown) {
|
||||
failures.push({
|
||||
pid: member.pid,
|
||||
reason: "environment-unreadable",
|
||||
diagnostic: `${observation.reason}; process liveness recheck failed: ${errorMessage(recheckCause)}`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
failures.push({
|
||||
pid: member.pid,
|
||||
reason: "environment-unreadable",
|
||||
diagnostic: observation.reason,
|
||||
});
|
||||
}
|
||||
return failures;
|
||||
};
|
||||
|
||||
interface TokenOwnedProcessScan {
|
||||
readonly owned: readonly ProcessTableEntry[];
|
||||
readonly failures: readonly ProcessOwnershipValidationFailure[];
|
||||
|
||||
Reference in New Issue
Block a user