Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(proxy): pin the 512 MiB heap cap and the 1536Mi limit for the worst-structure load
Alfredo Lopez25c703c9b725
diff --git a/codex-llm-proxy/test/deployManifest.test.ts b/codex-llm-proxy/test/deployManifest.test.tsindex 6c5565088..968cffafc 100644--- a/codex-llm-proxy/test/deployManifest.test.ts+++ b/codex-llm-proxy/test/deployManifest.test.ts@@ -19,14 +19,31 @@ const CONTROL_PLANE_CONFIG = readFileSync(/** Headroom between the last in-flight request finishing and SIGKILL. */const SHUTDOWN_MARGIN_SECONDS = 20/**- * D5 (#739): peak RSS with eight 8 MiB streams, two 24 MiB visual streams and- * three queued 8 MiB bodies, heap capped at 384 MiB (tsc build, one process).+ * Heap cap the peak below was measured with. At 384 MiB the process aborts+ * while it parses the three admitted ordinary bodies when each one carries the+ * worst structure the contract admits (262144 containers, 262144 members,+ * 1048576 elements), before any stream reaches the upstream. 512 MiB is the+ * smallest cap that survives that load.*/-const D5_CAPPED_PEAK_RSS_MIB = 790.3+const HEAP_CAP_MIB = 512+/**+ * The largest measured peak, heap capped at HEAP_CAP_MIB (tsc build, one+ * process, upstream request through undici, macOS, Node v24.18.0):+ * - D5 (#739): eight 8 MiB streams, two 24 MiB visual streams and three+ * queued 8 MiB bodies with a text tool description: 790.3 MiB at a+ * 384 MiB cap;+ * - the same load with every ordinary body carrying the worst structure the+ * contract admits (#806 Q1): 1094.9 and 1129.2 MiB in two runs at 512.+ * That is the recorded peak.+ * Measured by hand, not by this suite (harness: 8 held streams, 3 queued+ * bodies, 2 visual bodies). Re-measure before changing it.+ */+const D5_CAPPED_PEAK_RSS_MIB = 1129.2const MEMORY_HEADROOM = 1.25/**- * Owner decision on review M4 (#739): the request sits near the D5 peak, so a- * busy node does not schedule the pod on memory it cannot give it under load.+ * Owner decision on review M4 (#739): the request stays at 768Mi. It sits+ * below the limit, so the scheduler reserves what the ordinary load uses and+ * the worst-structure burst is covered by the limit alone.*/const MEMORY_REQUEST_MIB = 768@@ -85,6 +102,7 @@ describe('codex-llm-proxy base manifest', () => {const heap = /--max-old-space-size=(\d+)/.exec(activeLines(MANIFEST)[nodeOptions + 1] ?? '')expect(heap, 'NODE_OPTIONS must cap the heap').not.toBeNull()const limit = resourceMemory('limits')+ expect(Number(heap![1])).toBe(HEAP_CAP_MIB)expect(Number(heap![1])).toBeLessThan(limit)expect(resourceMemory('requests')).toBeLessThanOrEqual(limit)expect(resourceMemory('requests')).toBe(MEMORY_REQUEST_MIB)diff --git a/grok-llm-proxy/test/deployManifest.test.ts b/grok-llm-proxy/test/deployManifest.test.tsindex c0f4e83f1..3e2277025 100644--- a/grok-llm-proxy/test/deployManifest.test.ts+++ b/grok-llm-proxy/test/deployManifest.test.ts@@ -24,24 +24,31 @@ const WORKFLOW_RECIPES = readFileSync(/** Headroom between the last in-flight request finishing and SIGKILL. */const SHUTDOWN_MARGIN_SECONDS = 20/**- * The larger of the two measured peaks, both with the heap capped at 384 MiB- * (tsc build, one process, upstream request through undici):- * - D5 (#739): eight 8 MiB streams and three queued 8 MiB bodies, 511 MiB- * (#739 measured 509.8);- * - D5 plus the visual slot (#784): the same load and one ~36 MB V2 stream- * (a 20 MiB PNG and 8 MiB of text), 775.4 MiB.- * Both were measured by hand, not by this suite. The 775.4 is the largest of- * three runs (771.3, 775.4, 765 MiB), taken on 2026-09-24 on macOS with- * Node v24.18.0 and recorded in the message of the commit that introduced- * this constant (`git log -S775.4 -- grok-llm-proxy/test/deployManifest.test.ts`).- * Re-measure before changing it.+ * Heap cap the peak below was measured with. At 384 MiB the process aborts+ * while it parses the three admitted ordinary bodies when each one carries the+ * worst structure the contract admits (262144 containers, 262144 members,+ * 1048576 elements), before any stream reaches the upstream. 512 MiB is the+ * smallest cap that survives that load.*/-const CAPPED_PEAK_RSS_MIB = 775.4+const HEAP_CAP_MIB = 512+/**+ * The largest measured peak, heap capped at HEAP_CAP_MIB (tsc build, one+ * process, upstream request through undici, macOS, Node v24.18.0):+ * - D5 (#739): eight 8 MiB streams and three queued 8 MiB bodies with a+ * text tool description: 511 MiB at a 384 MiB cap;+ * - D5 plus the visual slot (#784), same text load: 775.4 MiB at 384;+ * - the same load with every ordinary body carrying the worst structure the+ * contract admits (#806 Q1), plus one ~36 MB V2 stream: 1096.8 and 1110.7+ * MiB in two runs at 512. That is the recorded peak.+ * Measured by hand, not by this suite (harness: 8 held streams, 3 queued+ * bodies, 1 visual body). Re-measure before changing it.+ */+const CAPPED_PEAK_RSS_MIB = 1110.7const MEMORY_HEADROOM = 1.25/**- * Owner decision on review M4 (#739): the request sits just below- * CAPPED_PEAK_RSS_MIB (D5 plus one visual stream), so a busy node does not- * schedule the pod on memory it cannot give it under load.+ * Owner decision on review M4 (#739): the request stays at 768Mi. It sits+ * below the limit, so the scheduler reserves what the ordinary load uses and+ * the worst-structure burst is covered by the limit alone.*/const MEMORY_REQUEST_MIB = 768@@ -94,12 +101,13 @@ describe('grok-llm-proxy base manifest', () => {expect(grace).toBe(Math.ceil(worstCaseMs / 1000) + SHUTDOWN_MARGIN_SECONDS)})- it('T-DEP-2 caps the heap below the memory limit, keeps the limit 25% above the D5-plus-visual peak and requests 768Mi', () => {+ it('T-DEP-2 caps the heap below the memory limit, keeps the limit 25% above the worst-structure-plus-visual peak and requests 768Mi', () => {const nodeOptions = activeLines(MANIFEST).findIndex((line) => /name:\s*NODE_OPTIONS\s*$/.test(line))expect(nodeOptions, 'the container must set NODE_OPTIONS').toBeGreaterThanOrEqual(0)const heap = /--max-old-space-size=(\d+)/.exec(activeLines(MANIFEST)[nodeOptions + 1] ?? '')expect(heap, 'NODE_OPTIONS must cap the heap').not.toBeNull()const limit = resourceMemory('limits')+ expect(Number(heap![1])).toBe(HEAP_CAP_MIB)expect(Number(heap![1])).toBeLessThan(limit)expect(resourceMemory('requests')).toBeLessThanOrEqual(limit)expect(resourceMemory('requests')).toBe(MEMORY_REQUEST_MIB)diff --git a/scripts/tests/test-codex-llm-proxy-deploy-contract.sh b/scripts/tests/test-codex-llm-proxy-deploy-contract.shindex 6e46fc4f6..1ac340c54 100755--- a/scripts/tests/test-codex-llm-proxy-deploy-contract.sh+++ b/scripts/tests/test-codex-llm-proxy-deploy-contract.sh@@ -99,21 +99,24 @@ if named_containers != ["codex-llm-proxy"]:# Measured on the shipping design (#739 D5): eight 8 MiB streams, two 24 MiB# visual streams and three queued 8 MiB bodies peaked at 790 MiB of RSS with a-# 384 MiB old space and at 886-1009 MiB without it. The capped peak does not fit-# 768Mi; the limit is that peak plus 25 %, rounded up to 1Gi. The request is-# 768Mi (owner decision on review M4), near the peak, so a busy node does not-# schedule the pod on memory it cannot give it under load.+# 384 MiB old space and at 886-1009 MiB without it. When the three ordinary+# bodies carry the worst structure the contract admits (#806 Q1), a 384 MiB old+# space aborts while parsing them, and a 512 MiB one is the smallest that+# survives; that load peaked at 1095-1129 MiB of RSS. The limit is that peak+# plus 25 %, rounded up to 1536Mi. The request stays at 768Mi (owner decision on+# review M4), so the scheduler reserves what the ordinary load uses and the+# worst-structure burst is covered by the limit alone.memory_limit = re.search(r"limits:\n\s+cpu: \S+\n\s+memory: (\S+)", text)memory_request = re.search(r"requests:\n\s+cpu: \S+\n\s+memory: (\S+)", text)heap_cap = re.search(r"- name: NODE_OPTIONS\n\s+value: \"--max-old-space-size=(\d+)\"", text)-if not memory_limit or memory_limit.group(1) != "1Gi":- errors.append("proxy memory limit must be 1Gi")+if not memory_limit or memory_limit.group(1) != "1536Mi":+ errors.append("proxy memory limit must be 1536Mi")if not memory_request or memory_request.group(1) != "768Mi":errors.append("proxy memory request must be 768Mi")-if not heap_cap or heap_cap.group(1) != "384":- errors.append("proxy must cap the V8 old space at 384 MiB through NODE_OPTIONS")+if not heap_cap or heap_cap.group(1) != "512":+ errors.append("proxy must cap the V8 old space at 512 MiB through NODE_OPTIONS")# #739 D6: on SIGTERM the proxy stops accepting and waits for its open streams# (main.ts awaits servers.close()), so the grace period must outlast thediff --git a/scripts/tests/test-grok-llm-proxy-deploy-contract.sh b/scripts/tests/test-grok-llm-proxy-deploy-contract.shindex 90b0bd680..099114419 100755--- a/scripts/tests/test-grok-llm-proxy-deploy-contract.sh+++ b/scripts/tests/test-grok-llm-proxy-deploy-contract.sh@@ -86,22 +86,25 @@ if "CONTROL_API_INTERNAL_SERVICE_TOKENS" in text:errors.append("proxy must not receive the full token map")# Eight 8 MiB streams and three queued 8 MiB bodies (#739 D5) peaked at 511 MiB-# of RSS with a 384 MiB old space (#739 measured 509.8). One ~36 MB V2 stream in the visual slot-# (#784) on top of that load peaked at 775 MiB, past 768Mi; the limit is that-# peak plus 25 %, rounded up to 1Gi, as on codex-llm-proxy. The request is-# 768Mi (owner decision on review M4), near the peak, so a busy node does not-# schedule the pod on memory it cannot give it under load.+# of RSS with a 384 MiB old space (#739 measured 509.8); one ~36 MB V2 stream in+# the visual slot (#784) raised that to 775 MiB. When the three ordinary bodies+# carry the worst structure the contract admits (#806 Q1), a 384 MiB old space+# aborts while parsing them, and a 512 MiB one is the smallest that survives;+# with one visual stream that load peaked at 1097-1111 MiB of RSS. The limit is+# that peak plus 25 %, rounded up to 1536Mi. The request stays at 768Mi (owner+# decision on review M4), so the scheduler reserves what the ordinary load uses+# and the worst-structure burst is covered by the limit alone.memory_limit = re.search(r"limits:\n\s+cpu: \S+\n\s+memory: (\S+)", text)memory_request = re.search(r"requests:\n\s+cpu: \S+\n\s+memory: (\S+)", text)heap_cap = re.search(r"- name: NODE_OPTIONS\n\s+value: \"--max-old-space-size=(\d+)\"", text)-if not memory_limit or memory_limit.group(1) != "1Gi":- errors.append("proxy memory limit must be 1Gi")+if not memory_limit or memory_limit.group(1) != "1536Mi":+ errors.append("proxy memory limit must be 1536Mi")if not memory_request or memory_request.group(1) != "768Mi":errors.append("proxy memory request must be 768Mi")-if not heap_cap or heap_cap.group(1) != "384":- errors.append("proxy must cap the V8 old space at 384 MiB through NODE_OPTIONS")+if not heap_cap or heap_cap.group(1) != "512":+ errors.append("proxy must cap the V8 old space at 512 MiB through NODE_OPTIONS")# #739 D6: on SIGTERM the proxy stops accepting and waits for its open streams# (main.ts awaits servers.close()), so the grace period must outlast the