Split from #12092 (review of #12236). Measured 2026-11-13: on a 0.5 CPU / 384 MiB pod the whole forge was OOM-killed at "open pull", twice, because a cell may take 75% of the pod's memory and the forge itself holds ~170 MiB at rest.
What should be true: a cell is given at most min(75% of the pod's memory.max, the pod less the forge's own room, ~192 MiB), so on a small pod the check is what dies, never the forge.
Done when: memoryCeiling in src/apps/contain.ts gives 192 MiB on a 384 MiB pod, 320 on 512, 64 on 256, 1536 on 2 GiB, with a test (test/memory-ceiling.test.ts).
A patch that did this on the #12092 branch (commit c99b2dc66):
diff --git a/src/apps/contain.ts b/src/apps/contain.tsindex 574709c95..32fc1b9e1 100644--- a/src/apps/contain.ts+++ b/src/apps/contain.ts@@ -122,6 +122,13 @@ export const POD_MEMORY_FILE = "/sys/fs/cgroup/memory.max";
/** The share of the pod's memory a single cell may be given. */
export const POD_MEMORY_SHARE = 0.75;
+/**+ * What the forge itself needs inside its pod, MiB, measured at about 170 at+ * rest and 200 under a first hour's work (#12092): a cell is never given the+ * pod's memory down to this, so on a small machine the check dies, not the forge.+ */+export const FORGE_OWN_MIB = 192;+
/**
* The most memory one cell gets, MiB: `FORGE_CELL_MEMORY_MAX_MIB` when set,
* else a share of the pod's own `memory.max`, else 4096 where the host
@@ -156,6 +163,12 @@ function ceiling(
return own < machine.mib ? { mib: own, from: "size" } : machine;
}
+/** A share of the pod's bytes for one cell, never more than the pod less the forge's own room. */+export function podShareMiB(bytes: number): number {+ const mib = bytes / 1048576;+ return Math.max(1, Math.floor(Math.min(mib * POD_MEMORY_SHARE, mib - FORGE_OWN_MIB)));+}+
function machineCeiling(
env: string | undefined,
podFile: string,
@@ -165,7 +178,7 @@ function machineCeiling(
try {
const bytes = Number(readFileSync(podFile, "utf8").trim());
if (Number.isFinite(bytes) && bytes > 0)
- return { mib: Math.max(1, Math.floor((bytes * POD_MEMORY_SHARE) / 1048576)), from: "pod" };+ return { mib: podShareMiB(bytes), from: "pod" };
} catch {
// no cgroup v2 here, or "max" (unlimited): the fixed default below
}
diff --git a/test/memory-ceiling.test.ts b/test/memory-ceiling.test.tsindex c5cc6f13b..6a244a778 100644--- a/test/memory-ceiling.test.ts+++ b/test/memory-ceiling.test.ts@@ -19,6 +19,13 @@ describe("the memory ceiling is never a silent clamp (#3128)", () => {
expect(memoryCeiling(undefined, "/nonexistent/memory.max")).toBe(4096);
});
+ test("a small pod leaves the forge its own room: the check dies, not the forge (#12092)", () => {+ expect(memoryCeiling(undefined, pod(String(384 * 1048576)))).toBe(192);+ expect(memoryCeiling(undefined, pod(String(512 * 1048576)))).toBe(320);+ expect(memoryCeiling(undefined, pod(String(256 * 1048576)))).toBe(64);+ expect(memoryCeiling(undefined, pod(String(2048 * 1048576)))).toBe(1536);+ });+
test("a declared memory above the ceiling produces a warning; within it, none", () => {
const saved = process.env["FORGE_CELL_MEMORY_MAX_MIB"];
process.env["FORGE_CELL_MEMORY_MAX_MIB"] = "4096";
Split from #12092 (review of #12236). Measured 2026-11-13: on a 0.5 CPU / 384 MiB pod the whole forge was OOM-killed at "open pull", twice, because a cell may take 75% of the pod's memory and the forge itself holds ~170 MiB at rest.
What should be true: a cell is given at most min(75% of the pod's
memory.max, the pod less the forge's own room, ~192 MiB), so on a small pod the check is what dies, never the forge.Done when:
memoryCeilinginsrc/apps/contain.tsgives 192 MiB on a 384 MiB pod, 320 on 512, 64 on 256, 1536 on 2 GiB, with a test (test/memory-ceiling.test.ts).A patch that did this on the #12092 branch (commit c99b2dc66):