Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): address audit — control-api OOM at 256Mi in minikube overlay (blocker)
Alfredo Lopeza24e1fd813e4
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 7ca75bea1..8a0a20350 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.424",+ "version": "0.1.425","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.424",+ "version": "0.1.425","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex fa5d70b7b..d8cbb7670 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.424",+ "version": "0.1.425","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/config.ts b/control-api/src/config.tsindex ecb1fc3eb..033cb2afe 100644--- a/control-api/src/config.ts+++ b/control-api/src/config.ts@@ -185,9 +185,10 @@ type Config = {gfscBaseUrl: string// In-cluster base URL of the writer-only gfsc Service for mutations.gfscWriteBaseUrl: string- // Timeout (ms) for the control-api→gfsc proxied fetch. Homologous with the- // browser client (GFS_UPLOAD_TIMEOUT_MS) and the control-ui server proxy- // (CONTROL_API_PROXY_TIMEOUT_MS): all default 300000. Raise all three together.+ // Timeout (ms) for the control-api→gfsc proxied fetch. Homologous with the browser+ // client (GFS_UPLOAD_TIMEOUT_MS, 300s) and the control-ui server proxy+ // (CONTROL_API_PROXY_TIMEOUT_MS, set to 300s in the deployment; its route.ts code+ // fallback is 30s). This one defaults to 300s in code. Raise all three together.gfscProxyTimeoutMs: number// ClusterIP service URL template for the per-SFS wfc. {hash} is replaced// with the 10-char sfsHash that HCC's sharedFileSystemReconciler computes.diff --git a/deploy/base/control-plane/control-api.yaml b/deploy/base/control-plane/control-api.yamlindex 4016f2b50..8c5e32c20 100644--- a/deploy/base/control-plane/control-api.yaml+++ b/deploy/base/control-plane/control-api.yaml@@ -125,13 +125,15 @@ spec:resources:limits:cpu: 300m- # GFS uploads arrive base64-in-JSON and are fully buffered: one 10.7MB- # upload holds ~5 transient copies (express raw buffer, JSON.parse input,- # parsed contentBase64 string, JSON.stringify output, undici write buffer)- # ≈ +60MiB over the ~86MiB idle baseline. Measured live: 4 concurrent- # 10.7MB uploads OOMKilled (exit 137) the pod at 256Mi; 512Mi holds ≥4- # concurrent worst-case (16MiB, the gfsc write cap) uploads with margin.- memory: 512Mi+ # GFS uploads arrive base64-in-JSON and are fully buffered: one upload+ # holds ~5 transient copies (express raw buffer, JSON.parse input, parsed+ # contentBase64 string, JSON.stringify output, undici write buffer). The+ # gfsc write cap is 24MiB (GFS_MAX_WRITE_BODY_BYTES), i.e. a 16MB raw file+ # → ~22.4MB body → ~125MiB transient over the ~86MiB idle baseline. At 256Mi+ # 2 concurrent uploads OOMKilled (exit 137) the pod; 768Mi holds ~5 concurrent+ # worst-case uploads with margin. The minikube overlay must not reduce this+ # (see deploy/overlays/minikube/patches/resource-limits.yaml).+ memory: 768Mirequests:cpu: 50mmemory: 128Midiff --git a/deploy/base/control-plane/control-ui.yaml b/deploy/base/control-plane/control-ui.yamlindex 3493acea5..f61c57235 100644--- a/deploy/base/control-plane/control-ui.yaml+++ b/deploy/base/control-plane/control-ui.yaml@@ -30,14 +30,11 @@ spec:env:- name: CONTROL_API_INTERNAL_URLvalue: http://control-api.control-plane.svc.cluster.local:8090- # Server-side control-ui proxy timeout in milliseconds (see- # app/control-api/[...path]/route.ts). Intended to keep large GFS uploads (file- # sent base64-encoded, ~+33%) from being cut mid-body over the Cloudflare tunnel;- # applies only to body-bearing methods, so SSE streams are unaffected.- # NOTE: currently LATENT — /control-api/* is served by the next.config.js rewrite,- # not this route handler, so this value does not govern prod today. It takes- # effect once the proxy is consolidated onto the handler (tracked follow-up); the- # client-side upload timeout in control-ui/lib/api.ts is what unblocks prod now.+ # Server-side control-ui proxy timeout in milliseconds. The app-router handler+ # app/control-api/[...path]/route.ts OWNS /control-api/* (the next.config.js+ # rewrite was removed), so this value governs the proxied upstream fetch. It+ # keeps large GFS uploads (file sent base64-encoded, ~+33%) from being cut+ # mid-body, and applies only to body-bearing methods so SSE streams are unaffected.- name: CONTROL_API_PROXY_TIMEOUT_MSvalue: "300000"- name: CONTROL_UI_PUBLIC_TOKEN_CSRF_SECRET@@ -68,10 +65,14 @@ spec:resources:limits:cpu: 300m- memory: 256Mi+ # The /control-api proxy route handler buffers a full arrayBuffer copy of+ # the request body (~22.4MB for a 16MB GFS upload) before forwarding; 256Mi+ # is tight under concurrent uploads. 512Mi gives headroom over the Next.js+ # baseline. The minikube overlay must not reduce this.+ memory: 512Mirequests:cpu: 50m- memory: 64Mi+ memory: 128MisecurityContext:allowPrivilegeEscalation: falsecapabilities:diff --git a/deploy/overlays/minikube/patches/resource-limits.yaml b/deploy/overlays/minikube/patches/resource-limits.yamlindex b5c32489f..381e53136 100644--- a/deploy/overlays/minikube/patches/resource-limits.yaml+++ b/deploy/overlays/minikube/patches/resource-limits.yaml@@ -20,7 +20,9 @@ spec:cpu: 50mmemory: 64Mi----# control-api: base is 300m/256Mi — keep but explicitly confirm for minikube+# control-api: must match base (768Mi) — GFS uploads buffer ~5x the base64 body+# (a 16MB file = 22.4MB body). 256Mi OOMKilled the pod at 2 concurrent uploads;+# do NOT reduce below base here or the RC3 fix is inert in minikube.apiVersion: apps/v1kind: Deploymentmetadata:@@ -34,12 +36,13 @@ spec:resources:limits:cpu: 200m- memory: 256Mi+ memory: 768Mirequests:cpu: 25m- memory: 64Mi+ memory: 128Mi----# control-ui: base is 300m/256Mi — reduce for minikube+# control-ui: 512Mi — the /control-api proxy route handler buffers a full+# arrayBuffer copy (~22.4MB for a 16MB upload) per in-flight request.apiVersion: apps/v1kind: Deploymentmetadata:@@ -53,10 +56,10 @@ spec:resources:limits:cpu: 200m- memory: 256Mi+ memory: 512Mirequests:cpu: 25m- memory: 64Mi+ memory: 128Mi---# control-postgres: base is 200m/256Mi — acceptable, reduce request slightlyapiVersion: apps/v1diff --git a/gfs-controller/src/api/serve.ts b/gfs-controller/src/api/serve.tsindex c8f5e0ffd..ee1be41f5 100644--- a/gfs-controller/src/api/serve.ts+++ b/gfs-controller/src/api/serve.ts@@ -73,15 +73,21 @@ export interface ServingDeps {/*** Largest mutation body gfsc accepts before failing loud with payload_too_large.- * Configurable via GFS_MAX_WRITE_BODY_BYTES so ops can raise it beyond the 16MiB- * default (which already fits base64(10MB) ≈ 13.98MB). A non-integer or- * non-positive value falls back to the default (fail-safe; never NaN).- * NOTE: to take effect on the gfsc pod this env must be plumbed through the- * host-context-controller gfsc template (deferred — inert while the default holds).+ * Configurable via GFS_MAX_WRITE_BODY_BYTES, plumbed to the gfsc pod through the+ * host-context-controller gfsc template (deploy sets it to 24MiB for the 16MB upload+ * cap). A non-integer or non-positive value fails loud to stderr and falls back to the+ * 16MiB default — otherwise a config typo would silently 413 every large upload.*/+const DEFAULT_MAX_WRITE_BODY_BYTES = 16 * 1024 * 1024;const MAX_WRITE_BODY_BYTES = ((): number => {- const raw = Number(process.env.GFS_MAX_WRITE_BODY_BYTES);- return Number.isInteger(raw) && raw > 0 ? raw : 16 * 1024 * 1024;+ const rawEnv = process.env.GFS_MAX_WRITE_BODY_BYTES;+ if (rawEnv === undefined) return DEFAULT_MAX_WRITE_BODY_BYTES;+ const raw = Number(rawEnv);+ if (Number.isInteger(raw) && raw > 0) return raw;+ console.error(+ `[gfsc] ignoring invalid GFS_MAX_WRITE_BODY_BYTES="${rawEnv}" (must be a positive integer); using ${DEFAULT_MAX_WRITE_BODY_BYTES}`+ );+ return DEFAULT_MAX_WRITE_BODY_BYTES;})();const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647;const NANOSECONDS_PER_MILLISECOND = 1_000_000n;diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 21274e92f..7883837a0 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.161",+ "version": "0.1.162","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.161",+ "version": "0.1.162","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/image-policy": "file:../packages/image-policy",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex cdd4381c3..3816787d0 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.161",+ "version": "0.1.162","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/k8s/gfsFactory.ts b/host-context-controller/src/k8s/gfsFactory.tsindex 9a556c1ac..431f90594 100644--- a/host-context-controller/src/k8s/gfsFactory.ts+++ b/host-context-controller/src/k8s/gfsFactory.ts@@ -266,7 +266,7 @@ function gfscEnv(config: GfsFactoryConfig, role: GfscRole): k8s.V1EnvVar[] {['GFS_SYNC_COPY_TIMEOUT_MS', config.syncCopyTimeoutMs],['GFS_MAX_WRITE_BODY_BYTES', config.maxWriteBodyBytes],]- const copyEnv = passthroughEnvEntries.flatMap(([name, value]): k8s.V1EnvVar[] =>+ const passthroughEnv = passthroughEnvEntries.flatMap(([name, value]): k8s.V1EnvVar[] =>value === undefined ? [] : [{ name, value }])@@ -295,7 +295,7 @@ function gfscEnv(config: GfsFactoryConfig, role: GfscRole): k8s.V1EnvVar[] {},},},- ...copyEnv,+ ...passthroughEnv,]}