fix(process): tolerate exit during ownership revalidation

This commit is contained in:
morluto
2026-07-24 15:34:09 +00:00
parent 095c75df23
commit a0f8b72b7a
2 changed files with 33 additions and 0 deletions
+4
View File
@@ -391,6 +391,10 @@ const processOwnershipFailures = async (
if ((await host.environment(member.pid)).REA_PROCESS_RUN_ID !== runId)
failures.push({ pid: member.pid, reason: "run-token-mismatch" });
} catch {
try {
const live = liveProcesses(await host.listProcesses());
if (!live.some(({ pid }) => pid === member.pid)) continue;
} catch {}
failures.push({ pid: member.pid, reason: "environment-unreadable" });
}
}
+29
View File
@@ -447,6 +447,35 @@ describe("owned process-group cleanup", () => {
expect(signalGroup).not.toHaveBeenCalled();
});
it("accepts a member that exits during ownership revalidation", async () => {
const liveLauncher = {
pid: 100,
parentPid: 1,
processGroupId: 100,
state: "S",
command: "fixture",
};
const listProcesses = vi
.fn<ProcessOwnershipHost["listProcesses"]>()
.mockResolvedValueOnce([liveLauncher])
.mockResolvedValue([]);
const signalGroup = vi.fn();
const adapter: ProcessOwnershipHost = {
listProcesses,
environment: () =>
Promise.reject(new Error("process exited before environment read")),
signalGroup,
};
await expect(cleanupOwnedProcessGroup(ownership, adapter)).resolves.toEqual(
{
cleaned: true,
signaled: false,
},
);
expect(signalGroup).not.toHaveBeenCalled();
});
it("ignores exited zombie members during live ownership checks", async () => {
const environment = vi.fn((pid: number) =>
Promise.resolve(pid === 101 ? {} : { REA_PROCESS_RUN_ID: "run-token" }),