fix(supervisor): treat blank computer limits as unset (#132)
.env.example ships RAKAZO_COMPUTER_MEMORY, _CPUS and _PIDS_LIMIT with no value. Loaded as empty strings, they bypassed the ?? defaults and the startup validation threw, so the supervisor crashed on a fresh setup. Claude-Session: https://claude.ai/code/session_012UBam2saiShpLy5o2cy3h8 Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
68b1e63c46
commit
f7b0cfb341
@ -669,6 +669,17 @@ describe("computer resource limits", () => {
|
|||||||
expect(HostConfig.PidsLimit).toBe(2048);
|
expect(HostConfig.PidsLimit).toBe(2048);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("falls back to the defaults when a limit is set but blank", () => {
|
||||||
|
// .env.example ships these keys with no value, which loads as "" rather than undefined.
|
||||||
|
for (const value of ["", " "]) {
|
||||||
|
for (const k of KEYS) process.env[k] = value;
|
||||||
|
const { HostConfig } = containerCreateOptions(createInput);
|
||||||
|
expect(HostConfig.Memory).toBe(2 * 1024 ** 3);
|
||||||
|
expect(HostConfig.NanoCpus).toBe(2 * 1e9);
|
||||||
|
expect(HostConfig.PidsLimit).toBe(2048);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("pins MemorySwap to Memory so the ceiling cannot be swapped past", () => {
|
it("pins MemorySwap to Memory so the ceiling cannot be swapped past", () => {
|
||||||
process.env.RAKAZO_COMPUTER_MEMORY = "1536m";
|
process.env.RAKAZO_COMPUTER_MEMORY = "1536m";
|
||||||
const { HostConfig } = containerCreateOptions(createInput);
|
const { HostConfig } = containerCreateOptions(createInput);
|
||||||
|
|||||||
@ -113,19 +113,25 @@ function parsePidsLimit(name: string, raw: string): number {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** An unset or blank variable (as .env.example ships these) means the default. */
|
||||||
|
function limitSetting(name: string, fallback: string): string {
|
||||||
|
const value = process.env[name];
|
||||||
|
return value?.trim() ? value : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
/** The host resource ceilings applied to every bot computer. */
|
/** The host resource ceilings applied to every bot computer. */
|
||||||
export function computerResourceLimits() {
|
export function computerResourceLimits() {
|
||||||
const memoryBytes = parseMemoryBytes(
|
const memoryBytes = parseMemoryBytes(
|
||||||
"RAKAZO_COMPUTER_MEMORY",
|
"RAKAZO_COMPUTER_MEMORY",
|
||||||
process.env.RAKAZO_COMPUTER_MEMORY ?? DEFAULT_COMPUTER_MEMORY,
|
limitSetting("RAKAZO_COMPUTER_MEMORY", DEFAULT_COMPUTER_MEMORY),
|
||||||
);
|
);
|
||||||
const nanoCpus = parseNanoCpus(
|
const nanoCpus = parseNanoCpus(
|
||||||
"RAKAZO_COMPUTER_CPUS",
|
"RAKAZO_COMPUTER_CPUS",
|
||||||
process.env.RAKAZO_COMPUTER_CPUS ?? DEFAULT_COMPUTER_CPUS,
|
limitSetting("RAKAZO_COMPUTER_CPUS", DEFAULT_COMPUTER_CPUS),
|
||||||
);
|
);
|
||||||
const pidsLimit = parsePidsLimit(
|
const pidsLimit = parsePidsLimit(
|
||||||
"RAKAZO_COMPUTER_PIDS_LIMIT",
|
"RAKAZO_COMPUTER_PIDS_LIMIT",
|
||||||
process.env.RAKAZO_COMPUTER_PIDS_LIMIT ?? DEFAULT_COMPUTER_PIDS_LIMIT,
|
limitSetting("RAKAZO_COMPUTER_PIDS_LIMIT", DEFAULT_COMPUTER_PIDS_LIMIT),
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
// Memory and MemorySwap are set together: leaving MemorySwap unset lets the
|
// Memory and MemorySwap are set together: leaving MemorySwap unset lets the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user