Skip to content

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

TypeScript

test(rpc-proxy): prove wake timeout producers

Alfredo Lopezacf817dce16d
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 6e8d28411..aea5c7c54 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -9,7 +9,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.10.0',
externalRestApiVersion: '0.1.84',
- rpcProxyVersion: '0.1.99',
+ rpcProxyVersion: '0.1.100',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index 86f4f3b84..e5797758c 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.99",
+ "version": "0.1.100",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.99",
+ "version": "0.1.100",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 9d0c0b0f7..92b7b6b07 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.99",
+ "version": "0.1.100",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts b/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
index 120425472..3a2280d7b 100644
--- a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
+++ b/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts
@@ -67,6 +67,7 @@ const HOST_CONNECTION = {
headers: {},
}
const originalUpstreamTimeoutMs = config.upstreamTimeoutMs
+const originalFetch = globalThis.fetch
function makeApp() {
const app = express()
@@ -104,6 +105,7 @@ beforeEach(() => {
afterEach(() => {
vi.useRealTimers()
config.upstreamTimeoutMs = originalUpstreamTimeoutMs
+ globalThis.fetch = originalFetch
})
describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
@@ -406,6 +408,37 @@ describe('POST /rpc/hosts/:hostRef/messages wake-and-hold triggers', () => {
})
})
+ it('the real REST forwarder aborts a hanging wake retry and returns 504', async () => {
+ config.upstreamTimeoutMs = 30
+ let retrySignal: AbortSignal | undefined
+ const fetchMock = vi
+ .fn()
+ .mockRejectedValueOnce(hostDownError())
+ .mockImplementationOnce((_url: string, init: RequestInit) => {
+ retrySignal = init.signal as AbortSignal
+ return new Promise((_resolve, reject) => {
+ retrySignal!.addEventListener('abort', () => reject(retrySignal!.reason), {
+ once: true,
+ })
+ })
+ })
+ globalThis.fetch = fetchMock as unknown as typeof fetch
+ serviceMock.forwardHostMessageToHost.mockImplementation(
+ forwardHostMessageToHost as typeof serviceMock.forwardHostMessageToHost
+ )
+ controlApiMock.requestHostWakeFromControlApi.mockResolvedValue({
+ kind: 'active',
+ wakeGeneration: null,
+ })
+
+ const response = await postMessage(makeApp()).expect(504)
+
+ expect(response.body).toEqual({ error: 'Gateway Timeout' })
+ expect(fetchMock).toHaveBeenCalledTimes(2)
+ expect(retrySignal?.aborted).toBe(true)
+ expect(controlApiMock.requestHostWakeFromControlApi).toHaveBeenCalledTimes(1)
+ })
+
it('a token without wake scope keeps the original full upstream timeout', async () => {
authTokenMock.verifyRpcToken.mockReturnValue({
...VALID_CLAIMS,
diff --git a/rpc-proxy/src/__tests__/wake-route-coverage.test.ts b/rpc-proxy/src/__tests__/wake-route-coverage.test.ts
index b7289c749..5cee76bd8 100644
--- a/rpc-proxy/src/__tests__/wake-route-coverage.test.ts
+++ b/rpc-proxy/src/__tests__/wake-route-coverage.test.ts
@@ -2,11 +2,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { Response as ExpressResponse } from 'express'
import express from 'express'
import request from 'supertest'
+import { config } from '../config.js'
import {
createRpcRouter,
respondControlApiHostAccessRejection,
respondUpstreamUnavailable,
} from '../routes/rpc.js'
+import { isUpstreamTimeoutError } from '../services/wakeAndHold.js'
// ── Issue #791 §11.4/§11.5 — extend wake-and-hold to the remaining finite
// Desktop routes, and prove terminal-response (duplicate-write) safety in the
@@ -72,6 +74,10 @@ function makeApp() {
app.use(createRpcRouter())
app.use(
(err: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
+ if (isUpstreamTimeoutError(err)) {
+ res.status(504).json({ error: 'Gateway Timeout' })
+ return
+ }
res.status(500).json({ error: err instanceof Error ? err.message : 'Internal error' })
}
)
@@ -103,6 +109,7 @@ function drainingResponse(): Response {
}
const originalFetch = globalThis.fetch
+const originalUpstreamTimeoutMs = config.upstreamTimeoutMs
beforeEach(() => {
vi.clearAllMocks()
@@ -115,6 +122,54 @@ beforeEach(() => {
afterEach(() => {
globalThis.fetch = originalFetch
+ config.upstreamTimeoutMs = originalUpstreamTimeoutMs
+})
+
+describe('finite route upstream deadlines', () => {
+ it.each([
+ {
+ label: 'deny approval',
+ scope: 'host:approval:write',
+ path: '/rpc/hosts/chatllm/approvals/deny',
+ body: { toolCallId: 'tc-timeout' },
+ },
+ {
+ label: 'set model',
+ scope: 'host:model:write',
+ path: '/rpc/hosts/chatllm/model',
+ body: { chatId: 'c1', model: 'claude-haiku-4-5' },
+ },
+ {
+ label: 'list artifacts',
+ scope: 'host:task:read',
+ path: '/rpc/hosts/chatllm/artifacts',
+ body: null,
+ },
+ ])('$label returns 504 when the actual upstream deadline aborts a hung fetch', async row => {
+ config.upstreamTimeoutMs = 30
+ authTokenMock.verifyRpcToken.mockReturnValue(claims([row.scope, 'host:wake:write']))
+ let upstreamSignal: AbortSignal | undefined
+ const fetchMock = vi.fn().mockImplementation((_url: string, init: RequestInit) => {
+ upstreamSignal = init.signal as AbortSignal
+ return new Promise((_resolve, reject) => {
+ upstreamSignal!.addEventListener('abort', () => reject(upstreamSignal!.reason), {
+ once: true,
+ })
+ })
+ })
+ globalThis.fetch = fetchMock as unknown as typeof fetch
+
+ const app = makeApp()
+ const outgoing = row.body
+ ? request(app).post(row.path).send(row.body)
+ : request(app).get(row.path)
+ const res = await outgoing.set('authorization', 'Bearer tok').expect(504)
+
+ expect(res.body).toEqual({ error: 'Gateway Timeout' })
+ expect(upstreamSignal?.aborted).toBe(true)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(controlApiMock.requestHostWakeFromControlApi).not.toHaveBeenCalled()
+ })
})
describe('§11.4 wake coverage — GET /rpc/hosts/:hostRef/models', () => {