Skip to content

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

TypeScript

fix(sfs): preserve head stream semantics

Alfredo Lopeze1c72a18ca08
diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.json
index d149cfba2..c43c7c19e 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.73",
+ "version": "0.1.74",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-external-rest-api",
- "version": "0.1.73",
+ "version": "0.1.74",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/external-rest-api/package.json b/external-rest-api/package.json
index 2012fd655..5acf68823 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.73",
+ "version": "0.1.74",
"description": "External REST API for profile, team management, and RPC token brokerage",
"main": "dist/main.js",
"engines": {
diff --git a/external-rest-api/src/controlApiClient.ts b/external-rest-api/src/controlApiClient.ts
index 03798aec2..04bee12c8 100644
--- a/external-rest-api/src/controlApiClient.ts
+++ b/external-rest-api/src/controlApiClient.ts
@@ -215,7 +215,7 @@ export async function controlApiBinaryRequestWithStatus(
}
export async function controlApiStreamRequest(
- method: 'GET',
+ method: 'GET' | 'HEAD',
path: string,
options?: {
query?: Record<string, string | undefined>
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 4677676c6..2fb0956e3 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.73',
+ externalRestApiVersion: '0.1.74',
rpcProxyVersion: '0.1.64',
desktopVersion: '0.7.0',
minimumDesktopVersion: '0.1.252',
diff --git a/external-rest-api/src/routes/contextSharedFilesystems.ts b/external-rest-api/src/routes/contextSharedFilesystems.ts
index d5b6f25cd..4788a7a11 100644
--- a/external-rest-api/src/routes/contextSharedFilesystems.ts
+++ b/external-rest-api/src/routes/contextSharedFilesystems.ts
@@ -86,7 +86,7 @@ export function createContextSharedFilesystemsRouter(): Router {
return idx === -1 ? '' : req.originalUrl.slice(idx)
})()
const upstreamRes = await controlApiStreamRequest(
- 'GET',
+ req.method === 'HEAD' ? 'HEAD' : 'GET',
`/external/contexts/${encodeURIComponent(req.params.contextId)}` +
`/shared-filesystems/${encodeURIComponent(req.params.sfsName)}/proxy${subPath}${queryString}`,
{
@@ -107,6 +107,14 @@ export function createContextSharedFilesystemsRouter(): Router {
const cl = upstreamRes.headers.get('content-length')
if (cl) res.setHeader('content-length', cl)
+ // HEAD is metadata-only. Do not consume the upstream stream: a large
+ // shared filesystem object must never be downloaded just to suppress
+ // its body at the public Express boundary.
+ if (req.method === 'HEAD') {
+ res.end()
+ return
+ }
+
if (!upstreamRes.body) {
res.end()
return
diff --git a/external-rest-api/test/routes.contextSharedFilesystems.test.ts b/external-rest-api/test/routes.contextSharedFilesystems.test.ts
index 65cff7471..ded516b37 100644
--- a/external-rest-api/test/routes.contextSharedFilesystems.test.ts
+++ b/external-rest-api/test/routes.contextSharedFilesystems.test.ts
@@ -144,4 +144,32 @@ describe('Method gating', () => {
expect(res.body).toEqual({ error: 'forbidden' })
expect(res.headers['retry-after']).toBe('7')
})
+
+ it('forwards HEAD without draining an upstream response body', async () => {
+ authTokenMock.verifyToken.mockReturnValue(claims)
+ const getReader = vi.fn(() => {
+ throw new Error('HEAD body must not be read')
+ })
+ controlApiClientMock.controlApiStreamRequest.mockResolvedValue({
+ status: 200,
+ headers: new Headers({
+ 'content-type': 'application/octet-stream',
+ 'content-length': '1234',
+ }),
+ body: { getReader },
+ } as unknown as Response)
+
+ const res = await request(buildApp())
+ .head('/me/contexts/ctx-a/shared-filesystems/team-mission/proxy/files?download=1')
+ .set('authorization', 'Bearer good-token')
+
+ expect(res.status).toBe(200)
+ expect(res.headers['content-length']).toBe('1234')
+ expect(getReader).not.toHaveBeenCalled()
+ expect(controlApiClientMock.controlApiStreamRequest).toHaveBeenCalledWith(
+ 'HEAD',
+ '/external/contexts/ctx-a/shared-filesystems/team-mission/proxy/files?download=1',
+ { userSessionToken: 'good-token', throwOnHttpError: false }
+ )
+ })
})