mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 19:51:20 -05:00
01e00dae72
* fix(process): corroborate Linux exits after procfs environ read races A token read failing with ENOENT/ESRCH may race with process exit while native identity observation still sees a live PID. Recheck native lifetime and accept absence only when corroborated; keep unverifiable or reused PIDs fail closed. Refs #7790 * fix(process): recheck Linux exit after final token retry A process can exit after the final retry of a failed procfs environment read. Re-observe native identity before producing final cleanup failures, and keep PID replacement and uncertain identity fail-closed. Add five integration-facing sweep regression cases for absence, live, unavailable, replaced and zombie-replaced candidates. Refs #7790 * fix(process): bound native exit settlement for token-open races After a terminal ENOENT/ESRCH run-token read, allow a tightly bounded native-only settlement window to corroborate pending Linux process exit. Retain an explicit failure for live/unavailable or changed PID identities, without inferring exit from the token error itself. Cover delayed absence, delayed replacement and bounded live retries. Refs #7790 * fix(process): share native token exit settlement * fix(process): signal only groups with validated members * fix(process): retain lineage through exit settlement * fix(process): type mixed identity observations in exit checks Map inference collapsed a readable/absent union onto the absent overload after main tightened ProcessIdentityObservation. * fix(process): refresh groups whose members exit during revalidation A same-group child forked after the revalidation snapshot is not an empty group, so cleanup reads the table again before skipping the signal. * test(process): arm group-refresh exit from the revalidation snapshot The regression follows the table read after planning observed the launcher token, and requires a later refresh to see the forked child. * test(mcp): assert bundle path issues by field The compare_bundles rejection reports each relative path as an invalid_format issue instead of one joined diagnostic sentence. * test(mcp): assert field issues for bundle paths and Dart ABI Relative bundle paths and rejected ABI selectors are reported as input issues on those fields, not as one joined diagnostic sentence. --------- Co-authored-by: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import type {
|
|
ProcessOwnershipHost,
|
|
ProcessRunTokenObservation,
|
|
ProcessTableEntry,
|
|
} from "./ProcessOwnership.js";
|
|
|
|
/** Structured native token availability, distinct from failed reads and caller cancellation. */
|
|
export class ProcessRunTokenReadError extends Error {
|
|
readonly _tag = "ProcessRunTokenReadError";
|
|
constructor(
|
|
readonly pid: number,
|
|
readonly availability: "absent" | "unavailable",
|
|
readonly reason: string,
|
|
) {
|
|
super(`Run token for PID ${String(pid)}: ${reason}`);
|
|
this.name = "ProcessRunTokenReadError";
|
|
}
|
|
}
|
|
|
|
const errorMessage = (cause: unknown): string =>
|
|
cause instanceof Error ? cause.message : String(cause);
|
|
|
|
/** Only a variable observed on this process supplies its run token. */
|
|
export const processRunIdFromEnvironment = (
|
|
environment: Readonly<Record<string, string>>,
|
|
): string | undefined =>
|
|
Object.hasOwn(environment, "REA_PROCESS_RUN_ID")
|
|
? environment.REA_PROCESS_RUN_ID
|
|
: undefined;
|
|
|
|
/** Read only ownership tokens, using per-process fallback for missing batch rows. */
|
|
export async function* readProcessRunTokens(
|
|
host: ProcessOwnershipHost,
|
|
processes: readonly ProcessTableEntry[],
|
|
signal?: AbortSignal,
|
|
): AsyncGenerator<{
|
|
readonly process: ProcessTableEntry;
|
|
readonly observation: ProcessRunTokenObservation;
|
|
}> {
|
|
signal?.throwIfAborted();
|
|
if (processes.length === 0) return;
|
|
let batch: ReadonlyMap<number, ProcessRunTokenObservation> | undefined;
|
|
let batchFailure: string | undefined;
|
|
if (host.runTokens !== undefined) {
|
|
try {
|
|
batch =
|
|
signal === undefined
|
|
? await host.runTokens(processes)
|
|
: await host.runTokens(processes, signal);
|
|
} catch (cause: unknown) {
|
|
signal?.throwIfAborted();
|
|
batchFailure = errorMessage(cause);
|
|
}
|
|
}
|
|
for (const process of processes) {
|
|
signal?.throwIfAborted();
|
|
let observation = batch?.get(process.pid);
|
|
if (observation === undefined) {
|
|
try {
|
|
const environment =
|
|
signal === undefined
|
|
? await host.environment(process.pid)
|
|
: await host.environment(process.pid, signal);
|
|
observation = {
|
|
state: "readable",
|
|
runId: processRunIdFromEnvironment(environment),
|
|
};
|
|
} catch (cause: unknown) {
|
|
signal?.throwIfAborted();
|
|
const reason = errorMessage(cause);
|
|
const code =
|
|
cause instanceof Error &&
|
|
"code" in cause &&
|
|
typeof cause.code === "string"
|
|
? cause.code
|
|
: undefined;
|
|
observation = {
|
|
state: "unavailable",
|
|
...(code === undefined ? {} : { code }),
|
|
reason:
|
|
batchFailure === undefined
|
|
? reason
|
|
: `${reason}; run-token batch failed: ${batchFailure}`,
|
|
};
|
|
}
|
|
}
|
|
signal?.throwIfAborted();
|
|
yield { process, observation };
|
|
}
|
|
}
|