Skip to content

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

TypeScript

fix(gfs): review zach M1/M2 — make gfsc failure codes observable at the desktop

Alfredo Lopezd4cd83ec5ffb
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index d256d6322..11690589e 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.429",
+ "version": "0.1.430",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.429",
+ "version": "0.1.430",
"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.json
index f636c9e51..a02359ddd 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.429",
+ "version": "0.1.430",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/external/gfs.ts b/control-api/src/routes/external/gfs.ts
index bc254df4b..95c5263e0 100644
--- a/control-api/src/routes/external/gfs.ts
+++ b/control-api/src/routes/external/gfs.ts
@@ -614,17 +614,21 @@ async function proxyMutationToGfsc(
const headers: Record<string, string> = { 'content-type': 'application/json' }
headers['author' + 'ization'] = ['Bearer', token].join(' ')
let upstream: Response
+ // A TOTAL deadline (not the header-only one the streaming read proxies use):
+ // a mutation response is a small JSON body, so bounding the whole fetch+read
+ // exchange is correct — the read proxies stream large bodies and must clear the
+ // timer after headers, but here we want the whole exchange bounded. Without a
+ // timeout a hung gfsc pinned the desktop upload indefinitely (#281/H1).
+ const deadline = AbortSignal.timeout(config.gfscProxyTimeoutMs)
try {
upstream = await fetch(target, {
method,
headers,
body: JSON.stringify(req.body ?? {}),
- // Homologous with the operator proxy (routes/gfs/proxy.ts): without this the
- // fetch had NO timeout — a hung gfsc pinned the desktop upload indefinitely.
- signal: AbortSignal.timeout(config.gfscProxyTimeoutMs),
+ signal: deadline,
})
} catch (err) {
- const timedOut = err instanceof Error && err.name === 'TimeoutError'
+ const timedOut = deadline.aborted || (err instanceof Error && err.name === 'TimeoutError')
rootLogger.error(
{ err, gfscPath, method, timeoutMs: config.gfscProxyTimeoutMs },
timedOut
@@ -634,10 +638,27 @@ async function proxyMutationToGfsc(
res.status(timedOut ? 504 : 502).json({ error: timedOut ? 'gfsc_timeout' : 'gfsc_unreachable' })
return
}
+ // The same deadline also bounds this response-body read. If gfsc sent headers
+ // and then stalled the body, text() rejects — classify it (504/502) instead of
+ // letting it reject uncaught into a generic 500. Read BEFORE committing status,
+ // so a read failure can still set the right code.
+ let text: string
+ try {
+ text = await upstream.text()
+ } catch (err) {
+ const timedOut =
+ deadline.aborted ||
+ (err instanceof Error && (err.name === 'TimeoutError' || err.name === 'AbortError'))
+ rootLogger.error(
+ { err, gfscPath, method, status: upstream.status, timeoutMs: config.gfscProxyTimeoutMs },
+ 'gfs external mutation proxy: gfsc response body read failed'
+ )
+ res.status(timedOut ? 504 : 502).json({ error: timedOut ? 'gfsc_timeout' : 'gfsc_unreachable' })
+ return
+ }
res.status(upstream.status)
const contentType = upstream.headers.get('content-type')
if (contentType) res.setHeader('content-type', contentType)
- const text = await upstream.text()
// Never silent: surface a gfsc 4xx/5xx at this hop (the base64 RangeError 500 was
// invisible here before) while forwarding the body verbatim.
if (upstream.status >= 500) {
diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.json
index 4fb41b7a4..5afe5d859 100644
--- a/external-rest-api/package-lock.json
+++ b/external-rest-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-external-rest-api",
- "version": "0.1.61",
+ "version": "0.1.62",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-external-rest-api",
- "version": "0.1.61",
+ "version": "0.1.62",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/external-rest-api/package.json b/external-rest-api/package.json
index 39f50f425..bb6112c55 100644
--- a/external-rest-api/package.json
+++ b/external-rest-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-external-rest-api",
- "version": "0.1.61",
+ "version": "0.1.62",
"description": "External REST API for profile, team management, and RPC token brokerage",
"main": "dist/main.js",
"engines": {
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index ed521168d..140b1dcd1 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -8,7 +8,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.6.0',
- externalRestApiVersion: '0.1.61',
+ externalRestApiVersion: '0.1.62',
rpcProxyVersion: '0.1.62',
desktopVersion: '0.6.0',
minimumDesktopVersion: '0.1.252',
diff --git a/external-rest-api/src/routes/gfs.ts b/external-rest-api/src/routes/gfs.ts
index 77da58603..ee7c0a245 100644
--- a/external-rest-api/src/routes/gfs.ts
+++ b/external-rest-api/src/routes/gfs.ts
@@ -14,7 +14,12 @@ import { type AuthedRequest, extractAuthToken, requireAuth } from '../middleware
* `routes/contextSharedFilesystems.ts` + `routes/rpc.ts`.
*/
-const PROPAGATED = new Set([400, 401, 403, 404, 409, 410, 412, 422, 429, 503])
+// 5xx included so control-api's gfsc failure codes reach the desktop verbatim:
+// 504 gfsc_timeout, 502 gfsc_unreachable, plus 500/503 forwarded from gfsc. Without
+// them forwardControlApiError falls through to the global handler, which collapses
+// every 5xx to a generic 500 and the documented codes become unobservable at the
+// client (a wedged gfsc looks identical to an internal bug).
+const PROPAGATED = new Set([400, 401, 403, 404, 409, 410, 412, 422, 429, 500, 502, 503, 504])
const STREAM_HEADERS = ['content-type', 'content-length', 'content-disposition']
function forwardControlApiError(error: unknown, res: Response, next: NextFunction): void {