Skip to content

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

TypeScript

test(gfs): review zach M1-M7 — cover the real timeout/read/memory/passthrough paths

Alfredo Lopez2e0fcbd508ad
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 11690589e..b26325c9b 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.430",
+ "version": "0.1.431",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.430",
+ "version": "0.1.431",
"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 a02359ddd..818e6dd4c 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.430",
+ "version": "0.1.431",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/network.gateway.intent.test.ts b/control-api/test/network.gateway.intent.test.ts
index 237043aef..77ce3debc 100644
--- a/control-api/test/network.gateway.intent.test.ts
+++ b/control-api/test/network.gateway.intent.test.ts
@@ -380,6 +380,26 @@ describe('network/gateway intent (manifest-level)', () => {
expect(Math.ceil((webCap * 4) / 3)).toBeLessThan(GFSC_WRITE_CAP)
})
+ it('keeps control-api memory at >=768Mi in base AND the minikube overlay (RC3 OOM guard)', () => {
+ // RC3: a base64 GFS upload holds ~5 transient body copies; at 256Mi two
+ // concurrent uploads OOMKilled the pod (exit 137). The base fix was inert in
+ // minikube until the overlay was also raised — re-pinning any overlay below
+ // 768Mi silently reintroduces the 7.5MB-PDF OOM, so assert it executably.
+ const controlApiLimitMi = (yaml: string): number => {
+ const doc = yamlDocs(yaml).find(
+ d => /kind:\s*Deployment/.test(d) && /name:\s*control-api\b/.test(d)
+ )
+ expect(doc, 'control-api Deployment not found').toBeTruthy()
+ const m = doc!.match(/limits:[\s\S]*?memory:\s*(\d+)Mi/)
+ expect(m, 'control-api limits.memory (Mi) not found').not.toBeNull()
+ return Number(m![1])
+ }
+ const base = controlApiLimitMi(read(`${BASE}/control-plane/control-api.yaml`))
+ const minikube = controlApiLimitMi(read(`${OVERLAYS}/minikube/patches/resource-limits.yaml`))
+ expect(base).toBeGreaterThanOrEqual(768)
+ expect(minikube).toBeGreaterThanOrEqual(768)
+ })
+
it('keeps the Minikube control-api Marketplace on the shared registry', () => {
const controlApiConfig = read(`${OVERLAYS}/minikube/configmaps/control-api-config.yaml`)
diff --git a/control-api/test/routes.externalGfs.test.ts b/control-api/test/routes.externalGfs.test.ts
index 9b1a6153d..e861edb3c 100644
--- a/control-api/test/routes.externalGfs.test.ts
+++ b/control-api/test/routes.externalGfs.test.ts
@@ -1,6 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import express from 'express'
import request from 'supertest'
+// The MOCKED config object (defined below); mutating gfscProxyTimeoutMs drives a
+// real deadline abort in the read-proxy timeout test.
+import { config } from '../src/config.js'
/**
* Unit tests for the end-user gfs surface on the /external (Session-JWT) plane.
@@ -125,6 +128,7 @@ beforeEach(() => {
)
mockAppendPermissionEvents.mockResolvedValue(null)
mockSignGfsToken.mockReturnValue({ token: 'gfs-user-token', expiresInSeconds: 300 })
+ ;(config as { gfscProxyTimeoutMs: number }).gfscProxyTimeoutMs = 300_000
})
afterEach(() => vi.unstubAllGlobals())
@@ -1084,6 +1088,36 @@ describe('user resource mutations via gfsc proxy', () => {
expect(res.body).toEqual({ error: 'gfsc_timeout' })
})
+ it('returns 504 when gfsc sends mutation headers then stalls the response body', async () => {
+ // The response-body read is bounded by the same deadline; a stall after
+ // headers must classify as 504 (via the guarded text()), not reject uncaught
+ // into a generic 500. The mock wires the deadline signal to the body stream
+ // the way undici does, then never sends bytes.
+ auth()
+ ;(config as { gfscProxyTimeoutMs: number }).gfscProxyTimeoutMs = 20
+ const fetchMock = vi.fn((_url: string, init: { signal: AbortSignal }) =>
+ Promise.resolve(
+ new Response(
+ new ReadableStream({
+ pull(controller) {
+ init.signal.addEventListener('abort', () => controller.error(init.signal.reason))
+ },
+ }),
+ { status: 200, headers: { 'content-type': 'application/json' } }
+ )
+ )
+ )
+ vi.stubGlobal('fetch', fetchMock)
+ const app = await buildApp()
+ const res = await request(app)
+ .post(`/external/gfs/resources/${R}/children`)
+ .set('x-user-session-token', 'sess')
+ .send({ name: 'docs', kind: 'file', contentBase64: 'AAAA' })
+
+ expect(res.status).toBe(504)
+ expect(res.body).toEqual({ error: 'gfsc_timeout' })
+ })
+
it('forwards a gfsc 5xx on a user mutation verbatim (never a silent 500)', async () => {
auth()
const fetchMock = vi.fn(
@@ -1356,3 +1390,88 @@ describe('per-agent delegation surface (guard + list + rate limit)', () => {
).toEqual([1, 2])
})
})
+
+describe('user read proxy via gfsc (GET /external/gfs/proxy/:rid)', () => {
+ const readPath = `/external/gfs/proxy/${R}`
+
+ it('streams a 200 body and forwards content headers with a read gfs.read token', async () => {
+ auth()
+ const fetchMock = vi.fn(
+ async () =>
+ new Response('file-bytes-here', {
+ status: 200,
+ headers: {
+ 'content-type': 'text/plain',
+ 'content-length': '15',
+ 'content-disposition': 'attachment; filename="f.bin"',
+ },
+ })
+ )
+ vi.stubGlobal('fetch', fetchMock)
+ const app = await buildApp()
+ const res = await request(app).get(readPath).set('x-user-session-token', 'sess')
+
+ expect(res.status).toBe(200)
+ expect(res.headers['content-type']).toBe('text/plain')
+ expect(res.headers['content-length']).toBe('15')
+ expect(res.headers['content-disposition']).toBe('attachment; filename="f.bin"')
+ expect(res.text).toBe('file-bytes-here')
+ expect(mockSignGfsToken).toHaveBeenCalledWith({
+ subject: U1,
+ drive: 'main',
+ scopes: ['gfs.read'],
+ })
+ expect(fetchMock).toHaveBeenCalledWith(
+ `http://gfsc.gfs.svc:8087/v1/resources/${R}/content`,
+ expect.objectContaining({ method: 'GET', signal: expect.any(AbortSignal) })
+ )
+ })
+
+ it('returns 504 gfsc_timeout on a REAL header-deadline abort (AbortError, signal.aborted)', async () => {
+ auth()
+ ;(config as { gfscProxyTimeoutMs: number }).gfscProxyTimeoutMs = 20
+ const fetchMock = vi.fn(
+ (_url: string, init: { signal: AbortSignal }) =>
+ new Promise((_resolve, reject) => {
+ init.signal.addEventListener('abort', () => reject(init.signal.reason))
+ })
+ )
+ vi.stubGlobal('fetch', fetchMock)
+ const app = await buildApp()
+ const res = await request(app).get(readPath).set('x-user-session-token', 'sess')
+
+ expect(res.status).toBe(504)
+ expect(res.body).toEqual({ error: 'gfsc_timeout' })
+ expect(fetchMock.mock.calls[0][1].signal.aborted).toBe(true)
+ })
+
+ it('returns 502 gfsc_unreachable when the gfsc read fetch fails', async () => {
+ auth()
+ const fetchMock = vi.fn(async () => {
+ throw new Error('connect ECONNREFUSED')
+ })
+ vi.stubGlobal('fetch', fetchMock)
+ const app = await buildApp()
+ const res = await request(app).get(readPath).set('x-user-session-token', 'sess')
+
+ expect(res.status).toBe(502)
+ expect(res.body).toEqual({ error: 'gfsc_unreachable' })
+ })
+
+ it('forwards a gfsc 5xx error body verbatim (never a silent 500)', async () => {
+ auth()
+ const fetchMock = vi.fn(
+ async () =>
+ new Response(JSON.stringify({ ok: false, error: { code: 'internal', message: 'boom' } }), {
+ status: 500,
+ headers: { 'content-type': 'application/json' },
+ })
+ )
+ vi.stubGlobal('fetch', fetchMock)
+ const app = await buildApp()
+ const res = await request(app).get(readPath).set('x-user-session-token', 'sess')
+
+ expect(res.status).toBe(500)
+ expect(res.body).toEqual({ ok: false, error: { code: 'internal', message: 'boom' } })
+ })
+})
diff --git a/control-api/test/routes.gfsProxy.test.ts b/control-api/test/routes.gfsProxy.test.ts
index 404da5539..b4322630c 100644
--- a/control-api/test/routes.gfsProxy.test.ts
+++ b/control-api/test/routes.gfsProxy.test.ts
@@ -1,6 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import express from 'express'
import request from 'supertest'
+// Imports the MOCKED config object below; mutating gfscProxyTimeoutMs on it lets a
+// test drive a real deadline abort (see the 504 timeout test).
+import { config } from '../src/config.js'
const mockSignGfsToken = vi.hoisted(() => vi.fn())
@@ -43,6 +46,8 @@ async function buildApp() {
beforeEach(() => {
mockSignGfsToken.mockReset()
mockSignGfsToken.mockReturnValue({ token: 'x' })
+ // Reset the (mutable) mocked timeout so a test that shrinks it can't leak into others.
+ ;(config as { gfscProxyTimeoutMs: number }).gfscProxyTimeoutMs = 300_000
})
afterEach(() => vi.unstubAllGlobals())
@@ -93,12 +98,19 @@ describe('/api/v1/gfs/proxy', () => {
)
})
- it('returns 504 gfsc_timeout when the gfsc fetch times out', async () => {
- const fetchMock = vi.fn(async () => {
- const err = new Error('The operation was aborted due to timeout')
- err.name = 'TimeoutError'
- throw err
- })
+ it('returns 504 gfsc_timeout on a REAL deadline abort (AbortError, signal.aborted)', async () => {
+ // The proxy aborts its OWN AbortController via setTimeout, so a real timeout
+ // surfaces as AbortError with signal.aborted===true — NOT a TimeoutError. A
+ // fetch mock that respects the signal (rejects with signal.reason on abort)
+ // exercises the real `deadline.signal.aborted` branch; injecting a TimeoutError
+ // (as before) only hit the defensive fallback and left the real path untested.
+ ;(config as { gfscProxyTimeoutMs: number }).gfscProxyTimeoutMs = 20
+ const fetchMock = vi.fn(
+ (_url: string, init: { signal: AbortSignal }) =>
+ new Promise((_resolve, reject) => {
+ init.signal.addEventListener('abort', () => reject(init.signal.reason))
+ })
+ )
vi.stubGlobal('fetch', fetchMock)
const app = await buildApp()
@@ -108,6 +120,9 @@ describe('/api/v1/gfs/proxy', () => {
expect(res.status).toBe(504)
expect(res.body).toEqual({ error: 'gfsc_timeout' })
+ // Prove the mock actually saw an aborted signal (i.e. the real timeout path ran).
+ const init = fetchMock.mock.calls[0][1]
+ expect(init.signal.aborted).toBe(true)
})
it('returns 502 gfsc_unreachable when the gfsc fetch fails', async () => {
diff --git a/desktop-app/test/gfsUriHandler.test.ts b/desktop-app/test/gfsUriHandler.test.ts
index 25aeaa5fe..b9cb84ff4 100644
--- a/desktop-app/test/gfsUriHandler.test.ts
+++ b/desktop-app/test/gfsUriHandler.test.ts
@@ -1,5 +1,4 @@
import { describe, expect, it, vi } from 'vitest'
-import { config } from '../src/config.js'
import {
GfsClient,
type GfsTransport,
@@ -424,8 +423,10 @@ describe('GfsClient resource mutations', () => {
{
token: 'tok',
body: { name: 'docs', kind: 'directory' },
- // Uploads use the generous GFS upload deadline, not the 60s app default.
- timeoutMs: config.gfsUploadTimeoutMs,
+ // Assert the concrete 300000, not config.gfsUploadTimeoutMs: vitest treats
+ // {timeoutMs: undefined} as equal to a call without the key, so referencing
+ // config would make this pass vacuously if the field were ever dropped.
+ timeoutMs: 300000,
}
)
expect(requestJson).toHaveBeenNthCalledWith(
@@ -435,7 +436,7 @@ describe('GfsClient resource mutations', () => {
{
token: 'tok',
body: { name: 'report.md', kind: 'file', contentBase64: 'aGVsbG8=' },
- timeoutMs: config.gfsUploadTimeoutMs,
+ timeoutMs: 300000,
}
)
})
@@ -456,7 +457,7 @@ describe('GfsClient resource mutations', () => {
{
token: 'tok',
body: { contentBase64: 'aGVsbG8=', ifMatch: 1 },
- timeoutMs: config.gfsUploadTimeoutMs,
+ timeoutMs: 300000,
}
)
expect(requestJson).toHaveBeenNthCalledWith(
diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.json
index 5afe5d859..60b742151 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.62",
+ "version": "0.1.63",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-external-rest-api",
- "version": "0.1.62",
+ "version": "0.1.63",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/external-rest-api/package.json b/external-rest-api/package.json
index bb6112c55..c327c9059 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.62",
+ "version": "0.1.63",
"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 140b1dcd1..28b697415 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.62',
+ externalRestApiVersion: '0.1.63',
rpcProxyVersion: '0.1.62',
desktopVersion: '0.6.0',
minimumDesktopVersion: '0.1.252',
diff --git a/external-rest-api/test/routes.gfs.test.ts b/external-rest-api/test/routes.gfs.test.ts
index 5fd996d45..472104e5c 100644
--- a/external-rest-api/test/routes.gfs.test.ts
+++ b/external-rest-api/test/routes.gfs.test.ts
@@ -113,6 +113,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).
+ for (const [status, error] of [
+ [504, 'gfsc_timeout'],
+ [502, 'gfsc_unreachable'],
+ ] as const) {
+ clientMock.controlApiRequest.mockReset()
+ clientMock.controlApiRequest.mockRejectedValue(
+ new ControlApiError('gfsc failure', status, { error })
+ )
+ const res = await request(buildApp())
+ .put('/me/gfs/resources/abc/content?drive=main')
+ .set('authorization', 'Bearer sess-xyz')
+ .send({ contentBase64: 'AAAA' })
+ expect(res.status).toBe(status)
+ expect(res.body).toEqual({ error })
+ }
+ })
+
it('streams a content download (binary) from the proxy', async () => {
clientMock.controlApiStreamRequest.mockResolvedValue(
new Response('hello', {
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 7883837a0..c672234da 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.162",
+ "version": "0.1.163",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.162",
+ "version": "0.1.163",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 3816787d0..85b46b7c4 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.162",
+ "version": "0.1.163",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/gfsConfig.test.ts b/host-context-controller/src/gfsConfig.test.ts
index b532237c3..eece76ca0 100644
--- a/host-context-controller/src/gfsConfig.test.ts
+++ b/host-context-controller/src/gfsConfig.test.ts
@@ -8,6 +8,7 @@ afterEach(() => {
delete process.env.GFS_SYNC_COPY_MAX_OBJECTS
delete process.env.GFS_SYNC_COPY_MAX_BYTES
delete process.env.GFS_SYNC_COPY_TIMEOUT_MS
+ delete process.env.GFS_MAX_WRITE_BODY_BYTES
delete process.env.CONTEXT_MAPPER_GFSC_IMAGE_PULL_POLICY
delete process.env.CONTEXT_MAPPER_NODELOCAL_DNS_CIDR
})
@@ -28,17 +29,20 @@ describe('gfsDefaultFactoryConfig', () => {
expect(c.syncCopyMaxObjects).toBeUndefined()
expect(c.syncCopyMaxBytes).toBeUndefined()
expect(c.syncCopyTimeoutMs).toBeUndefined()
+ expect(c.maxWriteBodyBytes).toBeUndefined()
})
it('passes synchronous copy limits through verbatim, including explicit empty values', () => {
process.env.GFS_SYNC_COPY_MAX_OBJECTS = '2500'
process.env.GFS_SYNC_COPY_MAX_BYTES = ''
process.env.GFS_SYNC_COPY_TIMEOUT_MS = '45000'
+ process.env.GFS_MAX_WRITE_BODY_BYTES = '25165824'
const c = gfsDefaultFactoryConfig()
expect(c.syncCopyMaxObjects).toBe('2500')
expect(c.syncCopyMaxBytes).toBe('')
expect(c.syncCopyTimeoutMs).toBe('45000')
+ expect(c.maxWriteBodyBytes).toBe('25165824')
})
it('fails loud on an invalid image pull policy (no silent default)', () => {
diff --git a/host-context-controller/src/k8s/gfsFactory.test.ts b/host-context-controller/src/k8s/gfsFactory.test.ts
index fd147ab8a..f9d3306dd 100644
--- a/host-context-controller/src/k8s/gfsFactory.test.ts
+++ b/host-context-controller/src/k8s/gfsFactory.test.ts
@@ -150,6 +150,7 @@ describe('gfsFactory writer Deployment', () => {
expect(byName('GFS_SYNC_COPY_MAX_OBJECTS')).toBeUndefined()
expect(byName('GFS_SYNC_COPY_MAX_BYTES')).toBeUndefined()
expect(byName('GFS_SYNC_COPY_TIMEOUT_MS')).toBeUndefined()
+ expect(byName('GFS_MAX_WRITE_BODY_BYTES')).toBeUndefined()
})
it('passes configured synchronous copy limits verbatim to writer and reader', () => {
@@ -158,6 +159,7 @@ describe('gfsFactory writer Deployment', () => {
syncCopyMaxObjects: '2500',
syncCopyMaxBytes: '',
syncCopyTimeoutMs: '45000',
+ maxWriteBodyBytes: '25165824',
}
for (const role of ['writer', 'reader'] as const) {
@@ -167,6 +169,9 @@ describe('gfsFactory writer Deployment', () => {
expect(byName('GFS_SYNC_COPY_MAX_OBJECTS')?.value).toBe('2500')
expect(byName('GFS_SYNC_COPY_MAX_BYTES')?.value).toBe('')
expect(byName('GFS_SYNC_COPY_TIMEOUT_MS')?.value).toBe('45000')
+ // The 16MB upload cap depends on this reaching gfsc; a dropped passthrough
+ // leaves gfsc on its 16MiB default and 413s a 16MB file.
+ expect(byName('GFS_MAX_WRITE_BODY_BYTES')?.value).toBe('25165824')
}
})