Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): address review findings on GFS timeout knob
Alfredo Lopez7a16c826597e
diff --git a/control-ui/app/control-api/[...path]/route.ts b/control-ui/app/control-api/[...path]/route.tsindex 21b5c0e16..f2c4267c5 100644--- a/control-ui/app/control-api/[...path]/route.ts+++ b/control-ui/app/control-api/[...path]/route.ts@@ -6,15 +6,28 @@ export const dynamic = 'force-dynamic'const CONTROL_API_INTERNAL_URL = process.env.CONTROL_API_INTERNAL_URL || 'http://127.0.0.1:8090'const DEFAULT_CONTROL_API_PROXY_TIMEOUT_MS = 30_000+// setTimeout / AbortSignal.timeout reject non-integers and values above the 32-bit+// signed ceiling (ERR_OUT_OF_RANGE), so an out-of-range env value must NOT reach them.+const MAX_PROXY_TIMEOUT_MS = 2_147_483_647+// Runtime-configurable server-side timeout (NOT NEXT_PUBLIC: read at request time in// the control-ui pod, mirroring CONTROL_API_INTERNAL_URL above). GFS uploads send the// file base64-encoded, so a ~10 MB payload over the Cloudflare tunnel can exceed the// old fixed 30s. Set CONTROL_API_PROXY_TIMEOUT_MS (milliseconds) on the deployment to-// raise it; an absent, NaN, or non-positive value falls back to the default.+// 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.function resolveProxyTimeoutMs(): number {const raw = process.env.CONTROL_API_PROXY_TIMEOUT_MSconst parsed = raw ? Number(raw) : Number.NaN- return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_CONTROL_API_PROXY_TIMEOUT_MS+ return Number.isInteger(parsed) && parsed > 0 && parsed <= MAX_PROXY_TIMEOUT_MS+ ? parsed+ : DEFAULT_CONTROL_API_PROXY_TIMEOUT_MS}const HOP_BY_HOP_HEADERS = new Set([diff --git a/control-ui/lib/__tests__/apiSendTimeout.test.ts b/control-ui/lib/__tests__/apiSendTimeout.test.tsindex e03ada8d6..2a169a355 100644--- a/control-ui/lib/__tests__/apiSendTimeout.test.ts+++ b/control-ui/lib/__tests__/apiSendTimeout.test.ts@@ -53,6 +53,16 @@ describe('apiSend request timeout', () => {expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), GFS_UPLOAD_TIMEOUT_MS)})+ it('treats a non-positive timeoutMs override as the default, never abort-immediately', async () => {+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout')++ await apiSend('POST', '/api/v1/example', { a: 1 }, {}, {}, { timeoutMs: 0 })++ // 0 must NOT arm setTimeout(fn, 0) (which would abort on the next tick); it falls+ // back to the 30s default, matching the server proxy's resolveProxyTimeoutMs.+ expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 30000)+ })+it('exposes a GFS upload ceiling well above the 30s default', () => {expect(GFS_UPLOAD_TIMEOUT_MS).toBe(300000)expect(GFS_UPLOAD_TIMEOUT_MS).toBeGreaterThan(30000)diff --git a/control-ui/lib/__tests__/controlApiProxyRoute.test.ts b/control-ui/lib/__tests__/controlApiProxyRoute.test.tsindex 91d377cdd..7c5c8b478 100644--- a/control-ui/lib/__tests__/controlApiProxyRoute.test.ts+++ b/control-ui/lib/__tests__/controlApiProxyRoute.test.ts@@ -145,10 +145,13 @@ describe('control-ui control-api proxy route', () => {expect(timeoutSpy).toHaveBeenCalledWith(300000)})- it('falls back to 30000ms when the env value is absent, NaN, or non-positive', async () => {+ it('falls back to 30000ms when the env value is absent, NaN, non-positive, non-integer, or out-of-range', async () => {const timeoutSpy = vi.spyOn(AbortSignal, 'timeout')- for (const bad of [undefined, 'not-a-number', '0', '-5']) {+ // Includes non-integer and out-of-range values: AbortSignal.timeout throws+ // ERR_OUT_OF_RANGE for those, which would 500 every body-bearing request if they+ // reached it, so they MUST fall back to the default instead.+ for (const bad of [undefined, 'not-a-number', '0', '-5', '300000.5', '5000000000', '1e12']) {timeoutSpy.mockClear()if (bad === undefined) delete process.env[ENV_KEY]else process.env[ENV_KEY] = baddiff --git a/control-ui/lib/api.ts b/control-ui/lib/api.tsindex 432b7ddb4..cc61cf0da 100644--- a/control-ui/lib/api.ts+++ b/control-ui/lib/api.ts@@ -174,7 +174,11 @@ async function fetchWithTimeout(timeoutMs: number = API_REQUEST_TIMEOUT_MS): Promise<Response> {const controller = new AbortController()- const timeoutId = window.setTimeout(() => controller.abort(), timeoutMs)+ // A non-positive or non-finite override means "use the default", never "abort+ // immediately" — this matches the server proxy's resolveProxyTimeoutMs semantics.+ const effectiveTimeoutMs =+ Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : API_REQUEST_TIMEOUT_MS+ const timeoutId = window.setTimeout(() => controller.abort(), effectiveTimeoutMs)const signal = init.signal ? AbortSignal.any([init.signal, controller.signal]) : controller.signaltry {return await fetch(input, {diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex cd4eaedc4..9368cfbce 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.387",+ "version": "0.1.388","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.387",+ "version": "0.1.388","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.jsonindex d7bf8d57b..4397b10b0 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.387",+ "version": "0.1.388","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/deploy/base/control-plane/control-ui.yaml b/deploy/base/control-plane/control-ui.yamlindex 464e62cda..3493acea5 100644--- a/deploy/base/control-plane/control-ui.yaml+++ b/deploy/base/control-plane/control-ui.yaml@@ -31,9 +31,13 @@ spec:- 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). Raised above the 30s default so large- # GFS uploads (file sent base64-encoded, ~+33%) are not cut mid-body over the- # Cloudflare tunnel. Applies only to body-bearing methods; SSE streams unaffected.+ # 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.- name: CONTROL_API_PROXY_TIMEOUT_MSvalue: "300000"- name: CONTROL_UI_PUBLIC_TOKEN_CSRF_SECRET