Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): close RC3/RC4/RC5 so 10MB uploads work via the real UI path

Alfredo Lopez59f7243b59f5
diff --git a/control-ui/app/control-api/[...path]/route.ts b/control-ui/app/control-api/[...path]/route.ts
index f2c4267c5..c41201c3c 100644
--- a/control-ui/app/control-api/[...path]/route.ts
+++ b/control-ui/app/control-api/[...path]/route.ts
@@ -17,11 +17,9 @@ const MAX_PROXY_TIMEOUT_MS = 2_147_483_647
// raise it; an absent, non-integer, non-positive, or out-of-range value falls back to
// the default.
//
-// NOTE: currently LATENT — `/control-api/*` is served by the next.config.js rewrite
-// (afterFiles precedence shadows this catch-all route handler), so this timeout does
-// not govern prod today. It becomes effective once the proxy is consolidated onto this
-// handler (tracked follow-up); the client-side upload timeout in lib/api.ts is what
-// unblocks prod now.
+// This handler OWNS `/control-api/*`: the next.config.js rewrite for that path was
+// removed (it routed through Next's internal proxy, which silently truncates request
+// bodies at 10MiB and hard-caps at a 30s proxyTimeout). Do not reintroduce the rewrite.
function resolveProxyTimeoutMs(): number {
const raw = process.env.CONTROL_API_PROXY_TIMEOUT_MS
const parsed = raw ? Number(raw) : Number.NaN
@@ -30,13 +28,22 @@ function resolveProxyTimeoutMs(): number {
: DEFAULT_CONTROL_API_PROXY_TIMEOUT_MS
}
+// Headers this proxy must never forward upstream. Beyond the classic RFC 9110
+// hop-by-hop set, undici's fetch() refuses to send `Expect` at all — forwarding it
+// throws `NotSupportedError: expect header not supported` and turns any upload
+// > ~1MB from curl-like clients (which auto-add `Expect: 100-continue`) into a 502.
+// Browsers can never send `Expect` (it is a fetch/XHR forbidden request header), but
+// a correct proxy strips it regardless. `content-length` and `host` are recomputed
+// by undici for the upstream request.
const HOP_BY_HOP_HEADERS = new Set([
'connection',
'content-length',
+ 'expect',
'host',
'keep-alive',
'proxy-authenticate',
'proxy-authorization',
+ 'proxy-connection',
'te',
'trailer',
'transfer-encoding',
@@ -111,6 +118,19 @@ async function proxyControlApi(
: 'control-api proxy request failed'
const status =
err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError') ? 504 : 502
+ // Fail-loud: surface the underlying cause (undici wraps the real reason in
+ // err.cause) so a proxy failure is never undiagnosable from the pod logs.
+ console.error('[control-api proxy] request failed', {
+ url: upstreamUrl,
+ method: req.method,
+ status,
+ message,
+ name: err instanceof Error ? err.name : undefined,
+ cause:
+ err instanceof Error && 'cause' in err
+ ? String((err as { cause?: unknown }).cause)
+ : undefined,
+ })
return NextResponse.json({ error: message }, { status })
}
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index dcca8f277..4d312c178 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.389",
+ "version": "0.1.390",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.389",
+ "version": "0.1.390",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index d71b5a910..7467c2e7c 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.389",
+ "version": "0.1.390",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/deploy/base/control-plane/control-api.yaml b/deploy/base/control-plane/control-api.yaml
index cea8ae8b4..4016f2b50 100644
--- a/deploy/base/control-plane/control-api.yaml
+++ b/deploy/base/control-plane/control-api.yaml
@@ -125,10 +125,16 @@ spec:
resources:
limits:
cpu: 300m
- memory: 256Mi
+ # 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
requests:
cpu: 50m
- memory: 64Mi
+ memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
diff --git a/gfs-controller/src/api/serve.test.ts b/gfs-controller/src/api/serve.test.ts
index 59c4b50d9..9835db416 100644
--- a/gfs-controller/src/api/serve.test.ts
+++ b/gfs-controller/src/api/serve.test.ts
@@ -515,6 +515,46 @@ describe("GfsServingHandler — write routes (governed mutation)", () => {
expect(calls).toHaveLength(0);
});
+ it("413 payload_too_large advertises Connection: close (request body not fully received)", async () => {
+ // When readJsonBody aborts mid-stream (body over MAX_WRITE_BODY_BYTES), the
+ // client is still sending: the socket cannot be reused and Node will reset
+ // it. Without `Connection: close`, a pooling client (undici in control-api's
+ // gfs proxy) queues its NEXT request onto the poisoned socket and gets
+ // ECONNRESET -> 502 gfsc_unreachable (reproduced live: 413 then-immediate
+ // request failed deterministically). Real IncomingMessage semantics:
+ // `complete` is false while the body has not been fully received.
+ const res = new FakeRes();
+ const { d, calls } = writeDeps();
+ const oversized = "A".repeat(16 * 1024 * 1024 + 4);
+ const request = reqBody(`/v1/resources/${RID}/content`, {
+ method: "PUT",
+ auth: "Bearer t",
+ rawBody: `{"contentBase64":"${oversized}","ifMatch":2}`,
+ });
+ (request as unknown as { complete: boolean }).complete = false;
+ await run(d, request, res);
+ expect(res.statusCode).toBe(413);
+ expect((res.json as { error: { code: string } }).error.code).toBe("payload_too_large");
+ expect(res.headers["Connection"]).toBe("close");
+ expect(calls).toHaveLength(0);
+ });
+
+ it("does NOT close the connection on an error whose request body WAS fully received", async () => {
+ // A fully-consumed body (here: valid JSON, invalid base64) leaves the socket
+ // clean — keep-alive must survive, only the mid-stream abort case may close.
+ const res = new FakeRes();
+ const { d } = writeDeps();
+ const request = reqBody(`/v1/resources/${RID}/content`, {
+ method: "PUT",
+ auth: "Bearer t",
+ body: { contentBase64: "@@@not-base64@@@", ifMatch: 2 },
+ });
+ (request as unknown as { complete: boolean }).complete = true;
+ await run(d, request, res);
+ expect(res.statusCode).toBe(400);
+ expect(res.headers["Connection"]).toBeUndefined();
+ });
+
it("412 precondition_failed: an AGENT replace WITHOUT If-Match is rejected before the store", async () => {
const res = new FakeRes();
const { d, calls } = writeDeps();
diff --git a/gfs-controller/src/api/serve.ts b/gfs-controller/src/api/serve.ts
index 826fbd88c..c8f5e0ffd 100644
--- a/gfs-controller/src/api/serve.ts
+++ b/gfs-controller/src/api/serve.ts
@@ -156,11 +156,32 @@ function requireRid(raw: string): string {
}
}
-function sendJson(res: ServerResponse, status: number, body: unknown): void {
- res.writeHead(status, { "Content-Type": "application/json" });
+function sendJson(
+ res: ServerResponse,
+ status: number,
+ body: unknown,
+ headers?: Record<string, string>
+): void {
+ res.writeHead(status, { "Content-Type": "application/json", ...headers });
res.end(JSON.stringify(body));
}
+/**
+ * When a response is written BEFORE the request body was fully received (e.g.
+ * payload_too_large aborts the read mid-stream), the connection cannot be
+ * reused: unread bytes are still in flight and Node resets the socket after
+ * the response. Without advertising `Connection: close`, a pooling client
+ * (undici in control-api's gfs proxy) queues its next request onto the
+ * about-to-die socket and gets ECONNRESET → a spurious 502 gfsc_unreachable
+ * (reproduced live: 413 → immediately-following proxied request failed
+ * deterministically). `req.complete` is Node's own "entire message received"
+ * flag; `=== false` keeps plain-object test doubles (complete: undefined)
+ * and fully-consumed bodies on normal keep-alive.
+ */
+function abortConnectionHeader(req: IncomingMessage): Record<string, string> | undefined {
+ return req.complete === false ? { Connection: "close" } : undefined;
+}
+
export class GfsServingHandler {
constructor(private readonly deps: ServingDeps) {}
@@ -191,7 +212,10 @@ export class GfsServingHandler {
const resourceWrite = isWrite && this.deps.writeService && resourceMatch
&& (method === "DELETE" || Boolean(this.deps.audit));
if ((copyMatch && !copyWrite) || (method === "PATCH" && !renameWrite) || (method !== "GET" && !resourceWrite && !copyWrite)) {
- sendJson(res, 404, { ok: false, error: { code: "not_found", message: "not found" } });
+ // This 404 can be written before a request body was consumed (e.g. a
+ // POST with a body to an unsupported verb/route) — same socket-poisoning
+ // risk as the catch path below, so it carries the same close semantics.
+ sendJson(res, 404, { ok: false, error: { code: "not_found", message: "not found" } }, abortConnectionHeader(req));
return true;
}
@@ -230,7 +254,7 @@ export class GfsServingHandler {
}`
);
}
- if (!res.headersSent) sendJson(res, status, body);
+ if (!res.headersSent) sendJson(res, status, body, abortConnectionHeader(req));
else res.end(); // a content stream already started; just terminate
} finally {
cancelCopyTimer?.();