Skip to content

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

TypeScript

fix(rpc-proxy,desktop): log an unreadable Host ack and do not read an empty ack as dropped files

Alfredo Lopez1eeb6380457c
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx
index 36f96ecd2..70f9bee06 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.fileReferences.test.tsx
@@ -193,6 +193,17 @@ describe('sendAgentMessage — references the Host did not receive (#666 M1)', (
}
)
+ it('does not read an empty ack (the proxy answer to an unreadable Host body) as a drop', async () => {
+ const { result, spies } = await sendWithReferences({}, [planFile])
+
+ // Witness: the send went out with the reference and was not marked failed.
+ expect(sentReferenceIds()).toEqual([PLAN_ID])
+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)
+ expect(result.current.failedAgentSend).toBeNull()
+ expect(result.current.agentError).toBeNull()
+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')
+ })
+
it.each(ACK_SHAPES)('%s ack that echoes every sent id shows no error', async (shape, ack) => {
const { result, spies } = await sendWithReferences(
{ ...ack, acceptedFileReferenceIds: [PLAN_ID, NOTES_ID] },
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 4e8ac35da..2f97a56eb 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -2789,8 +2789,16 @@ export function useAgentChatController({
// and still accepts the message. The ack lists the reference ids the
// Host admitted; a sent id missing from it never reached the Host. The
// send itself stands and is not retried.
+ const taskId =
+ (typeof responseRecord.taskId === 'string' ? responseRecord.taskId : undefined) ||
+ (typeof responseRecord.id === 'string' ? responseRecord.id : undefined)
+ // An ack with no fields at all is not a Host ack: rpc-proxy answers `{}`
+ // when the Host's 2xx body is not JSON. It says nothing about which
+ // references the Host received, so it is not read as a drop. An older
+ // Host's ack still carries `success`, a `taskId` or a reply.
+ const ackIsEmpty = Object.keys(responseRecord).length === 0
let fileReferencesDropped = false
- if (ackOk && fileReferences.length > 0) {
+ if (ackOk && !ackIsEmpty && fileReferences.length > 0) {
const acceptedFileReferenceIds = new Set<string>(
Array.isArray(response.acceptedFileReferenceIds)
? response.acceptedFileReferenceIds
@@ -2809,9 +2817,6 @@ export function useAgentChatController({
pushToast(droppedMessage, 'error')
}
}
- const taskId =
- (typeof responseRecord.taskId === 'string' ? responseRecord.taskId : undefined) ||
- (typeof responseRecord.id === 'string' ? responseRecord.id : undefined)
if (!taskId) {
// Synchronous (non-async) response — a direct reply or a structured error.
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index b859c1158..338f898a4 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.85',
- rpcProxyVersion: '0.1.93',
+ rpcProxyVersion: '0.1.94',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index 0ea81ec4f..fa235616b 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 6c24211c3..cbaa8cf89 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.93",
+ "version": "0.1.94",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/services/__tests__/forwardHostMessageToHost.test.ts b/rpc-proxy/src/services/__tests__/forwardHostMessageToHost.test.ts
new file mode 100644
index 000000000..bc2cebce3
--- /dev/null
+++ b/rpc-proxy/src/services/__tests__/forwardHostMessageToHost.test.ts
@@ -0,0 +1,98 @@
+/**
+ * #666 D-6 — the ack rpc-proxy hands to Desktop when the Host's 2xx body is
+ * not a JSON object. The ack stays empty (the message may already be admitted,
+ * so an error would invite a resend) and the unreadable body is logged.
+ */
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { forwardHostMessageToHost } from '../mcpHostRestService.js'
+
+const host = { name: 'agent-x', url: 'http://host.test', headers: {} }
+const message = { content: 'hi', messageId: 'message-1' } as Parameters<
+ typeof forwardHostMessageToHost
+>[1]
+
+function upstream(body: string, init: { status?: number; contentType?: string } = {}) {
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(
+ async () =>
+ new Response(body, {
+ status: init.status ?? 200,
+ headers: { 'content-type': init.contentType ?? 'application/json' },
+ })
+ )
+ )
+}
+
+let warn: ReturnType<typeof vi.spyOn>
+beforeEach(() => {
+ warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
+})
+afterEach(() => {
+ vi.unstubAllGlobals()
+ vi.restoreAllMocks()
+})
+
+describe('forwardHostMessageToHost — Host ack body (#666 D-6)', () => {
+ it('returns a JSON object ack verbatim and logs nothing', async () => {
+ upstream(JSON.stringify({ success: true, taskId: 'task-1', acceptedFileReferenceIds: ['a'] }))
+
+ const ack = await forwardHostMessageToHost(host, message, { async: true })
+
+ // Witness: the body was read and returned, not replaced.
+ expect(ack).toEqual({ success: true, taskId: 'task-1', acceptedFileReferenceIds: ['a'] })
+ expect(warn).not.toHaveBeenCalled()
+ })
+
+ it('returns an empty ack for an empty body without logging', async () => {
+ upstream('')
+
+ expect(await forwardHostMessageToHost(host, message)).toEqual({})
+ expect(warn).not.toHaveBeenCalled()
+ })
+
+ it.each([
+ ['a non-JSON body', '<html>gateway</html>', 'text/html', 'SyntaxError'],
+ ['a JSON array', '[1,2]', 'application/json', 'not_an_object'],
+ ['a JSON string', '"ok"', 'application/json', 'not_an_object'],
+ ])(
+ 'answers {} and logs the unreadable body for %s',
+ async (_label, body, contentType, reason) => {
+ upstream(body, { contentType })
+
+ const ack = await forwardHostMessageToHost(host, message, { async: true })
+
+ expect(ack).toEqual({})
+ expect(warn).toHaveBeenCalledTimes(1)
+ expect(JSON.parse(String(warn.mock.calls[0]?.[0]))).toEqual({
+ event: 'host_message_ack_unreadable',
+ hostRef: 'agent-x',
+ messageId: 'message-1',
+ status: 200,
+ contentType,
+ reason,
+ bodyLength: body.length,
+ bodySnippet: body,
+ })
+ }
+ )
+
+ it('bounds the logged snippet to 300 characters', async () => {
+ upstream('x'.repeat(1000), { contentType: 'text/plain' })
+
+ await forwardHostMessageToHost(host, message)
+
+ const logged = JSON.parse(String(warn.mock.calls[0]?.[0]))
+ expect(logged.bodyLength).toBe(1000)
+ expect(logged.bodySnippet).toHaveLength(300)
+ })
+
+ it('still throws UpstreamHostError for a non-2xx answer', async () => {
+ upstream('boom', { status: 502, contentType: 'text/plain' })
+
+ await expect(forwardHostMessageToHost(host, message)).rejects.toMatchObject({
+ name: 'UpstreamHostError',
+ })
+ expect(warn).not.toHaveBeenCalled()
+ })
+})
diff --git a/rpc-proxy/src/services/mcpHostRestService.ts b/rpc-proxy/src/services/mcpHostRestService.ts
index 29694c481..0f6885655 100644
--- a/rpc-proxy/src/services/mcpHostRestService.ts
+++ b/rpc-proxy/src/services/mcpHostRestService.ts
@@ -163,14 +163,32 @@ export async function forwardHostMessageToHost(
let body: Record<string, unknown> = {}
if (rawBody.trim()) {
+ let parsed: unknown
+ let parseError: string | undefined
try {
- const parsed = JSON.parse(rawBody) as unknown
- body =
- parsed && typeof parsed === 'object' && !Array.isArray(parsed)
- ? (parsed as Record<string, unknown>)
- : {}
- } catch {
- body = {}
+ parsed = JSON.parse(rawBody) as unknown
+ } catch (error) {
+ parseError = error instanceof Error ? error.name : 'unknown'
+ }
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
+ body = parsed as Record<string, unknown>
+ } else {
+ // mcp-host answers every accepted message with a JSON object, so this is
+ // a broken or foreign upstream. The message may already be admitted, so
+ // the answer stays an empty ack instead of an error that would invite a
+ // resend; the log is the trace of what was received.
+ console.warn(
+ JSON.stringify({
+ event: 'host_message_ack_unreadable',
+ hostRef: payload.hostRef,
+ messageId: payload.messageId,
+ status: response.status,
+ contentType: response.headers.get('content-type'),
+ reason: parseError ?? 'not_an_object',
+ bodyLength: rawBody.length,
+ bodySnippet: rawBody.slice(0, 300),
+ })
+ )
}
}
return body