Skip to content

Commit 6d8f8c6

Browse files
committed
fix(producer): render inside an agent's macOS sandbox no longer dies on uptime
The render work dir's owner stamp falls back to os.uptime() for a boot time when /proc is missing. The seatbelt refuses uptime (uv_uptime EPERM), so every render died with that error before Chrome started. The fallback is now optional like the /proc read, and render reaches the existing message that says to rerun outside the sandbox.
1 parent dc0e80e commit 6d8f8c6

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
import { describe, expect, it, vi } from "vitest";
5+
6+
// An agent's macOS seatbelt refuses uptime: "uv_uptime returned EPERM (operation not permitted)".
7+
vi.mock("node:os", async (actual) => ({
8+
...(await actual<typeof import("node:os")>()),
9+
uptime: () => {
10+
throw Object.assign(new Error("A system error occurred: uv_uptime returned EPERM"), {
11+
code: "ERR_SYSTEM_ERROR",
12+
});
13+
},
14+
}));
15+
16+
// Without /proc, as on macOS, so Linux CI takes the uptime path too.
17+
vi.mock("node:fs", async (actual) => {
18+
const fs = await actual<typeof import("node:fs")>();
19+
return {
20+
...fs,
21+
readFileSync: ((path: string, ...rest: unknown[]) => {
22+
if (path === "/proc/sys/kernel/random/boot_id")
23+
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
24+
return (fs.readFileSync as (...args: unknown[]) => unknown)(path, ...rest);
25+
}) as typeof fs.readFileSync,
26+
};
27+
});
28+
29+
const { createRenderWorkDir } = await import("./renderDirOwner.js");
30+
31+
describe("a render work dir where the system refuses uptime", () => {
32+
it("is still created and stamped with its owner", () => {
33+
const parent = mkdtempSync(join(tmpdir(), "hf-render-dir-sandbox-"));
34+
try {
35+
const dir = createRenderWorkDir(join(parent, "work-"), parent);
36+
const owner = JSON.parse(readFileSync(join(dir, "owner.json"), "utf-8"));
37+
expect(owner.pid).toBe(process.pid);
38+
} finally {
39+
rmSync(parent, { recursive: true, force: true });
40+
}
41+
});
42+
});

‎packages/producer/src/services/render/renderDirOwner.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function pidScope(): { host: string; boot?: string; pidns?: string } {
3737
// Without /proc (macOS, Windows) the boot time, to the minute, stands in for the boot id.
3838
boot:
3939
attempt(() => readFileSync("/proc/sys/kernel/random/boot_id", "utf-8").trim()) ??
40-
String(Math.round(Date.now() / 60_000 - uptime() / 60)),
40+
attempt(() => String(Math.round(Date.now() / 60_000 - uptime() / 60))),
4141
pidns: attempt(() => readlinkSync("/proc/self/ns/pid")),
4242
};
4343
}

0 commit comments

Comments
 (0)