Skip to content

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

TypeScript

fix(gfs): review M2 — desktop GFS uploads and funnel honor the 300s budget

Alfredo Lopezf080b8331990
diff --git a/deploy/base/profiles/configmaps.yaml b/deploy/base/profiles/configmaps.yaml
index b604bd289..e0f872719 100644
--- a/deploy/base/profiles/configmaps.yaml
+++ b/deploy/base/profiles/configmaps.yaml
@@ -31,6 +31,14 @@ data:
# the authoritative size gate downstream.
client_max_body_size 25165824;
+ # Homologate the funnel's idle timers with the 300s deadline the rest of the
+ # me-path uses (nginx defaults each to 60s). Without these the funnel is the
+ # one hop that 504s a large upload/download that every downstream hop would
+ # still wait 300s for.
+ proxy_read_timeout 300s;
+ proxy_send_timeout 300s;
+ client_body_timeout 300s;
+
server {
listen 8080;
diff --git a/desktop-app/src/config.ts b/desktop-app/src/config.ts
index 78fc5385e..d1f89ba4d 100644
--- a/desktop-app/src/config.ts
+++ b/desktop-app/src/config.ts
@@ -16,6 +16,7 @@ type DesktopConfig = Omit<DesktopRuntimeConfig, 'appName' | 'rpcProxyBaseUrl'> &
desktopProfileUiBaseUrl: string
desktopProfileUiBaseUrlExplicit: boolean
requestTimeoutMs: number
+ gfsUploadTimeoutMs: number
appName: string
}
@@ -556,6 +557,11 @@ export const config: DesktopConfig = {
desktopProfileUiBaseUrl: deriveProfileUiBaseUrl(initialRuntimeConfig.externalRestApiBaseUrl),
desktopProfileUiBaseUrlExplicit: hasExplicitProfileUiBaseUrl(),
requestTimeoutMs: Number(requiredOrDefault('REQUEST_TIMEOUT_MS', '60000')),
+ // Generous per-call deadline for GFS uploads: a 16 MB file is a ~22.4 MB
+ // base64 body, ~60s alone on a slow uplink — the 60s REQUEST_TIMEOUT_MS would
+ // abort it while every downstream hop still waits 300s. Parity with control-ui
+ // GFS_UPLOAD_TIMEOUT_MS.
+ gfsUploadTimeoutMs: Number(requiredOrDefault('GFS_UPLOAD_TIMEOUT_MS', '300000')),
appName: initialRuntimeConfig.appName?.trim() || DEFAULT_APP_NAME,
}
diff --git a/desktop-app/src/gfs/uriHandler.ts b/desktop-app/src/gfs/uriHandler.ts
index d463f1d13..fa15e8a83 100644
--- a/desktop-app/src/gfs/uriHandler.ts
+++ b/desktop-app/src/gfs/uriHandler.ts
@@ -9,6 +9,7 @@
* form); a human path may carry a trailing -<32hex> rid; otherwise it resolves
* by path. Diverging from the server grammar would break deep links.
*/
+import { config } from '../config.js'
const RID_RE = /^[0-9a-f]{32}$/
const TRAILING_RID_RE = /-([0-9a-f]{32})$/
@@ -84,7 +85,7 @@ export interface GfsTransport {
requestJson<T>(
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
url: string,
- options?: { token?: string; body?: unknown }
+ options?: { token?: string; body?: unknown; timeoutMs?: number }
): Promise<T>
/** Binary fetch for downloads (resolves to the raw bytes). */
fetchBytes(url: string, token: string): Promise<ArrayBuffer>
@@ -245,7 +246,13 @@ async function createGfsResource(
}
if (input.kind === 'file') body.contentBase64 = input.encodedData ?? ''
const path = `/api/v1/me/gfs/resources/${encodeURIComponent(input.parentResourceId)}/children?${q.toString()}`
- const options = { body } as { token?: string; body?: unknown }
+ // Uploads carry a base64 body up to the 16 MB cap (~22.4 MB): use the generous
+ // GFS upload deadline, not the 60s app-wide default that would abort a slow link.
+ const options = { body, timeoutMs: config.gfsUploadTimeoutMs } as {
+ token?: string
+ body?: unknown
+ timeoutMs?: number
+ }
options[TRANSPORT_TOKEN_FIELD] = session
const payload = await transport.requestJson<GfsEnvelope<GfsResourceView>>(
'POST',
@@ -267,7 +274,13 @@ async function replaceGfsFile(
}
if (input.ifMatch !== undefined) body.ifMatch = input.ifMatch
const path = `/api/v1/me/gfs/resources/${encodeURIComponent(input.resourceId)}/content?${q.toString()}`
- const options = { body } as { token?: string; body?: unknown }
+ // Replace uploads carry the same base64 body as create: use the generous GFS
+ // upload deadline instead of the 60s app-wide default.
+ const options = { body, timeoutMs: config.gfsUploadTimeoutMs } as {
+ token?: string
+ body?: unknown
+ timeoutMs?: number
+ }
options[TRANSPORT_TOKEN_FIELD] = session
const payload = await transport.requestJson<GfsEnvelope<GfsResourceView>>(
'PUT',
diff --git a/desktop-app/src/httpClient.ts b/desktop-app/src/httpClient.ts
index 5d56de2a7..021fa12c9 100644
--- a/desktop-app/src/httpClient.ts
+++ b/desktop-app/src/httpClient.ts
@@ -27,8 +27,14 @@ const TRANSIENT_RETRY_DELAY_MS = 250
* through the FULL request lifecycle, covering a rpc-proxy that streams headers
* then stalls the response body (security review, M8 follow-up).
*/
-export function withTimeout(signal?: AbortSignal): AbortSignal {
- const timeout = AbortSignal.timeout(config.requestTimeoutMs)
+export function withTimeout(signal?: AbortSignal, timeoutMs?: number): AbortSignal {
+ // A caller may pass a longer per-call deadline (e.g. GFS uploads) than the
+ // app-wide default; fall back to config.requestTimeoutMs otherwise.
+ const effectiveTimeoutMs =
+ typeof timeoutMs === 'number' && Number.isFinite(timeoutMs) && timeoutMs > 0
+ ? timeoutMs
+ : config.requestTimeoutMs
+ const timeout = AbortSignal.timeout(effectiveTimeoutMs)
if (!signal) return timeout
// Abort on whichever fires first (caller cancellation OR timeout).
return AbortSignal.any([signal, timeout])
@@ -88,6 +94,8 @@ export async function requestJson<T>(
body?: unknown
headers?: Record<string, string>
signal?: AbortSignal
+ /** Per-call deadline override (ms); defaults to config.requestTimeoutMs. */
+ timeoutMs?: number
retryTransientOnce?: boolean
}
): Promise<T> {
@@ -104,7 +112,7 @@ export async function requestJson<T>(
method,
headers,
body: options?.body === undefined ? undefined : JSON.stringify(options.body),
- signal: withTimeout(options?.signal),
+ signal: withTimeout(options?.signal, options?.timeoutMs),
})
const raw = await response.text()
diff --git a/desktop-app/test/gfsUriHandler.test.ts b/desktop-app/test/gfsUriHandler.test.ts
index 18d9442a5..25aeaa5fe 100644
--- a/desktop-app/test/gfsUriHandler.test.ts
+++ b/desktop-app/test/gfsUriHandler.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
+import { config } from '../src/config.js'
import {
GfsClient,
type GfsTransport,
@@ -420,13 +421,22 @@ describe('GfsClient resource mutations', () => {
1,
'POST',
`https://api.example/api/v1/me/gfs/resources/${RID}/children?drive=main`,
- { token: 'tok', body: { name: 'docs', kind: 'directory' } }
+ {
+ token: 'tok',
+ body: { name: 'docs', kind: 'directory' },
+ // Uploads use the generous GFS upload deadline, not the 60s app default.
+ timeoutMs: config.gfsUploadTimeoutMs,
+ }
)
expect(requestJson).toHaveBeenNthCalledWith(
2,
'POST',
`https://api.example/api/v1/me/gfs/resources/${RID}/children?drive=main`,
- { token: 'tok', body: { name: 'report.md', kind: 'file', contentBase64: 'aGVsbG8=' } }
+ {
+ token: 'tok',
+ body: { name: 'report.md', kind: 'file', contentBase64: 'aGVsbG8=' },
+ timeoutMs: config.gfsUploadTimeoutMs,
+ }
)
})
@@ -443,7 +453,11 @@ describe('GfsClient resource mutations', () => {
1,
'PUT',
`https://api.example/api/v1/me/gfs/resources/${RID}/content?drive=main`,
- { token: 'tok', body: { contentBase64: 'aGVsbG8=', ifMatch: 1 } }
+ {
+ token: 'tok',
+ body: { contentBase64: 'aGVsbG8=', ifMatch: 1 },
+ timeoutMs: config.gfsUploadTimeoutMs,
+ }
)
expect(requestJson).toHaveBeenNthCalledWith(
2,