Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): treat a bare pm2 memory ceiling as bytes so it still gets a heap cap
[._.]/ Adam Eivy6f35db39097d
diff --git a/ecosystem.config.cjs b/ecosystem.config.cjsindex 004c4b8aa2..7849301a16 100644--- a/ecosystem.config.cjs+++ b/ecosystem.config.cjs@@ -55,15 +55,22 @@ const COS_MAX_MEMORY = '2G';const MEMORY_UNIT_MB = { K: 1 / 1024, M: 1, G: 1024 };/**- * Parse a pm2 memory spec ('512M', '4G', '1024') to megabytes.- * pm2 itself defaults a bare number to bytes, but every spec here carries a unit- * and an unrecognized one returns null so `memoryLimits` degrades to "no cap"- * rather than silently inventing a wrong one.+ * Parse a pm2 memory spec to megabytes: '512M', '4G', or a bare '4294967296'.+ *+ * The bare form is BYTES — that is pm2's own rule for an unsuffixed value, and+ * PORTOS_SERVER_MAX_MEMORY / PORTOS_UI_MAX_MEMORY are user-set, so a machine that+ * already spells its ceiling in bytes must still get a heap cap. Dropping to "no+ * cap" there would leave exactly the configuration this policy exists to fix: an+ * RSS ceiling with nothing making V8 collect beneath it.+ *+ * An unrecognized spec returns null so `memoryLimits` degrades to "no cap" rather+ * than silently inventing a wrong one.*/function memorySpecToMB(spec) {- const match = String(spec).trim().match(/^(\d+(?:\.\d+)?)\s*([KMG])B?$/i);+ const match = String(spec).trim().match(/^(\d+(?:\.\d+)?)\s*([KMG])?B?$/i);if (!match) return null;- return Math.round(Number(match[1]) * MEMORY_UNIT_MB[match[2].toUpperCase()]);+ const unitMB = match[2] ? MEMORY_UNIT_MB[match[2].toUpperCase()] : 1 / (1024 * 1024);+ return Math.round(Number(match[1]) * unitMB);}/**diff --git a/scripts/ecosystem-memory-bounds.test.js b/scripts/ecosystem-memory-bounds.test.jsindex dbe48a5908..27d0f3acdf 100644--- a/scripts/ecosystem-memory-bounds.test.js+++ b/scripts/ecosystem-memory-bounds.test.js@@ -18,12 +18,17 @@ import path from 'path';*/const require = createRequire(import.meta.url);const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');-const { apps } = require(path.join(repoRoot, 'ecosystem.config.cjs'));+const configPath = path.join(repoRoot, 'ecosystem.config.cjs');+const { apps } = require(configPath);+// Deliberately a SECOND implementation of the config's own parser, not an import+// of it: a guard that reuses the parser under test agrees with itself and can no+// longer fail. A bare number is bytes, per pm2.const UNIT_MB = { K: 1 / 1024, M: 1, G: 1024 };const toMB = (spec) => {- const match = String(spec).trim().match(/^(\d+(?:\.\d+)?)\s*([KMG])B?$/i);- return match ? Number(match[1]) * UNIT_MB[match[2].toUpperCase()] : null;+ const match = String(spec).trim().match(/^(\d+(?:\.\d+)?)\s*([KMG])?B?$/i);+ if (!match) return null;+ return Number(match[1]) * (match[2] ? UNIT_MB[match[2].toUpperCase()] : 1 / (1024 * 1024));};const heapCapMB = (app) => {@@ -58,6 +63,30 @@ describe('ecosystem.config.cjs memory bounds', () => {expect(cap).toBeLessThan(ceiling);});+ // The ceilings are user-overridable via env, and pm2 accepts a BARE NUMBER as+ // bytes — the form a machine that tuned this before the heap cap existed is+ // most likely to already have. A parser that only understood '4G' returned no+ // cap there, leaving precisely the un-collected-heap-under-an-RSS-ceiling setup+ // this policy exists to fix. Asserted through a real config load rather than+ // against the parser directly, so it observes what pm2 would actually receive.+ it('still caps V8 when the ceiling is spelled in pm2 bare bytes', () => {+ const previous = process.env.PORTOS_SERVER_MAX_MEMORY;+ process.env.PORTOS_SERVER_MAX_MEMORY = '4294967296'; // 4 GB, in bytes+ try {+ delete require.cache[require.resolve(configPath)];+ const server = require(configPath).apps.find((a) => a.name === 'portos-server');+ expect(server.max_memory_restart).toBe('4294967296');+ expect(heapCapMB(server)).toBeGreaterThan(0);+ expect(heapCapMB(server)).toBeLessThan(4096);+ } finally {+ if (previous === undefined) delete process.env.PORTOS_SERVER_MAX_MEMORY;+ else process.env.PORTOS_SERVER_MAX_MEMORY = previous;+ // Drop the env-poisoned module so the shared `apps` above stays authoritative+ // for any later require of the config in this process.+ delete require.cache[require.resolve(configPath)];+ }+ });+// A heap cap must never reach the child processes these apps spawn (agent CLIs,// builds, media tooling) — NODE_OPTIONS is inherited by children, node_args is// not. server/services/pm2.js additionally strips the `node_args` key pm2