Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): preserve upload error statuses through relay
Alfredo Lopez3b7082ac7af5
diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.jsonindex 9348ad2a8..c190ad8df 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.71",+ "version": "0.1.72","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-external-rest-api",- "version": "0.1.71",+ "version": "0.1.72","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/external-rest-api/package.json b/external-rest-api/package.jsonindex f9ca2d12f..74887d709 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.71",+ "version": "0.1.72","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.tsindex 07fbd9ecd..ccc4ae588 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.7.0',- externalRestApiVersion: '0.1.71',+ externalRestApiVersion: '0.1.72',rpcProxyVersion: '0.1.64',desktopVersion: '0.7.0',minimumDesktopVersion: '0.1.252',diff --git a/external-rest-api/src/routes/gfs.ts b/external-rest-api/src/routes/gfs.tsindex 08779f96e..04967eebb 100644--- a/external-rest-api/src/routes/gfs.ts+++ b/external-rest-api/src/routes/gfs.ts@@ -21,13 +21,13 @@ type GfsRouterOptions = {*/// 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, 411, 412, 413, 422, 429, 500, 502, 503, 504,-])+// Preserve the GFS transport contract at this boundary. The client retry policy+// distinguishes transient 408/425/5xx responses from terminal 507 storage+// exhaustion, so collapsing an unlisted status into the process-wide 500 handler+// would change the meaning of a writer response. The 4xx allowlist remains+// explicit; every 5xx is safe to forward because it is already a ControlApiError+// produced by the authenticated control-plane request.+const PROPAGATED = new Set([400, 401, 403, 404, 408, 409, 410, 411, 412, 413, 422, 425, 429, 507])const STREAM_HEADERS = ['content-type','content-length',@@ -51,7 +51,10 @@ const STREAM_HEADERS = []function forwardControlApiError(error: unknown, res: Response, next: NextFunction): void {- if (error instanceof ControlApiError && PROPAGATED.has(error.status)) {+ const shouldPropagate =+ error instanceof ControlApiError &&+ (PROPAGATED.has(error.status) || (error.status >= 500 && error.status <= 599))+ if (shouldPropagate) {const body =error.body && typeof error.body === 'object' ? error.body : { error: String(error.message) }for (const header of STREAM_HEADERS) {diff --git a/external-rest-api/test/routes.gfs.test.ts b/external-rest-api/test/routes.gfs.test.tsindex bdd46db58..936e8c9e2 100644--- a/external-rest-api/test/routes.gfs.test.ts+++ b/external-rest-api/test/routes.gfs.test.ts@@ -341,18 +341,28 @@ describe('routes/gfs /me/gfs/* (user session passthrough → /external/gfs/*)',expect(res.body).toEqual({ error: 'escalation_rejected' })})- it('propagates control-api gfsc 5xx codes (504/502) verbatim, not a generic 500', async () => {- // control-api emits 504 gfsc_timeout / 502 gfsc_unreachable on the me-path;- // without them in PROPAGATED, forwardControlApiError fell through to the global- // handler which collapses every 5xx to 500 — the documented codes became- // unobservable at the desktop (a wedged gfsc looked like an internal bug).+ it('propagates GFS transport statuses/body/headers without changing retry semantics', async () => {+ // 507 is terminal for Desktop/Control UI, while 408/425 and the transient+ // 5xx family are retryable. The public relay must not turn any of them into+ // a generic 500 before the client can apply that policy.for (const [status, error] of [- [504, 'gfsc_timeout'],+ [408, 'request_timeout'],+ [425, 'too_early'],+ [500, 'gfsc_internal'],[502, 'gfsc_unreachable'],+ [503, 'gfsc_unavailable'],+ [504, 'gfsc_timeout'],+ [507, 'insufficient_storage'],+ [599, 'upstream_unknown'],] as const) {clientMock.controlApiRequest.mockReset()clientMock.controlApiRequest.mockRejectedValue(- new ControlApiError('gfsc failure', status, { error })+ new ControlApiError(+ 'gfsc failure',+ status,+ { error },+ new Headers({ 'retry-after': '7', 'x-ratelimit-limit': '16' })+ ))const res = await request(buildApp()).put('/me/gfs/resources/abc/content?drive=main')@@ -360,6 +370,8 @@ describe('routes/gfs /me/gfs/* (user session passthrough → /external/gfs/*)',.send({ contentBase64: 'AAAA' })expect(res.status).toBe(status)expect(res.body).toEqual({ error })+ expect(res.headers['retry-after']).toBe('7')+ expect(res.headers['x-ratelimit-limit']).toBe('16')}})