Skip to content

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

TypeScript

fix(desktop-app): detect references the Host did not receive and drop gfs URIs from the prompt

Alfredo Lopez28005b5ccd85
diff --git a/desktop-app/src/__tests__/ipc.fileReferences.test.ts b/desktop-app/src/__tests__/ipc.fileReferences.test.ts
index 136e47eba..cc844bca6 100644
--- a/desktop-app/src/__tests__/ipc.fileReferences.test.ts
+++ b/desktop-app/src/__tests__/ipc.fileReferences.test.ts
@@ -108,4 +108,19 @@ describe('rpc:invokeHostMessage fileReferences', () => {
await send({ fileReferences: [reference()] })
expect(service.invokeHostMessage).toHaveBeenCalledTimes(1)
})
+
+ it('names the index, code and parser message of the rejected entry', async () => {
+ await expect(
+ send({ fileReferences: [reference('plan.md'), { ...reference('notes.md'), name: 'a/b.md' }] })
+ ).rejects.toThrow(
+ 'Invalid host message request: fileReferences[1] FILE_REFERENCE_INVALID: name must not contain "/" or control characters'
+ )
+ await expect(send({ fileReferences: [{ ...reference(), schemaVersion: 2 }] })).rejects.toThrow(
+ 'Invalid host message request: fileReferences[0] FILE_REFERENCE_SCHEMA_VERSION_UNSUPPORTED: unsupported file reference schemaVersion 2; expected 1'
+ )
+ expect(service.invokeHostMessage).toHaveBeenCalledTimes(0)
+ // Control: the first entry alone is valid and goes through.
+ await send({ fileReferences: [reference('plan.md')] })
+ expect(service.invokeHostMessage).toHaveBeenCalledTimes(1)
+ })
})
diff --git a/desktop-app/src/ipc.ts b/desktop-app/src/ipc.ts
index f9858b9ea..e5540b7c3 100644
--- a/desktop-app/src/ipc.ts
+++ b/desktop-app/src/ipc.ts
@@ -176,9 +176,13 @@ function parseHostMessageRequest(raw: unknown): HostMessageRequest {
if (!Array.isArray(parsed.fileReferences)) {
throw new Error('Invalid host message request: fileReferences')
}
- const fileReferences = parsed.fileReferences.map(entry => {
+ const fileReferences = parsed.fileReferences.map((entry, index) => {
const result = parseFileReferenceV1(entry)
- if (!result.ok) throw new Error('Invalid host message request: fileReferences')
+ if (!result.ok) {
+ throw new Error(
+ `Invalid host message request: fileReferences[${index}] ${result.code}: ${result.message}`
+ )
+ }
return result.value
})
return { ...parsed, fileReferences }
diff --git a/desktop-app/src/types.ts b/desktop-app/src/types.ts
index 206a51359..bfcf48cf4 100644
--- a/desktop-app/src/types.ts
+++ b/desktop-app/src/types.ts
@@ -584,6 +584,17 @@ export type HostMessageResponse = {
* ignored the selection.
*/
modelSelectionRevision?: number
+ /**
+ * #666 — the attachment ids the Host admitted with this message. Absent when
+ * the Host predates the field or the send carried no attachments.
+ */
+ acceptedAttachmentIds?: readonly string[]
+ /**
+ * #666 — the FileReference ids the Host admitted with this message. A sent
+ * reference whose id is missing here did not reach the Host; the message was
+ * delivered without it.
+ */
+ acceptedFileReferenceIds?: readonly string[]
approval?: {
taskId: string
requestId: string
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 526b7b809..2e37b03cf 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
@@ -81,9 +81,11 @@ describe('sendAgentMessage — structured Global Files references (#666)', () =>
}),
])
expect(request.content).toContain(
- `Global Files: plan.md (gfs://main/${RID}). These files were explicitly selected by the user.`
+ 'Global Files: plan.md. These files were explicitly selected by the user.'
)
expect(request.content).not.toContain('clerum__gfs_read')
+ // The URI travels only in the structured reference above.
+ expect(request.content).not.toContain('gfs://')
})
it('sends no fileReferences field without a Global Files selection', async () => {
@@ -101,3 +103,132 @@ describe('sendAgentMessage — structured Global Files references (#666)', () =>
expect(request).not.toHaveProperty('fileReferences')
})
})
+
+const NOT_RECEIVED =
+ 'The Host did not receive the selected Global Files; the message was sent without them.'
+
+const notesFile: ComposerGlobalFileReference = {
+ ...planFile,
+ id: `global-file:${RID.replace('0', 'f')}`,
+ resourceId: RID.replace('0', 'f'),
+ gfsUri: `gfs://main/${RID.replace('0', 'f')}`,
+ label: 'notes.md',
+ version: 1,
+}
+
+const PLAN_ID = `gfs:main:${RID}@v4`
+const NOTES_ID = `gfs:main:${RID.replace('0', 'f')}@v1`
+
+/** The synchronous ack is a direct reply; the async ack carries a task id. */
+const ACK_SHAPES = [
+ ['synchronous', { response: 'done' }],
+ ['async', { taskId: 'task-refs' }],
+] as const
+
+async function sendWithReferences(
+ ack: Record<string, unknown>,
+ references: ComposerGlobalFileReference[]
+) {
+ clerum.rpc.invokeHostMessage.mockResolvedValue(ack)
+ const rendered = renderController()
+ await settleMount()
+ act(() => {
+ rendered.result.current.handleAddComposerReferenceAttachments(references)
+ })
+ await act(async () => {
+ await rendered.result.current.handleSendAgentMessage('Summarize the files')
+ })
+ return rendered
+}
+
+function sentReferenceIds(): string[] {
+ const request = sentRequest()
+ return (request.fileReferences as Array<{ id: string }>).map(reference => reference.id)
+}
+
+/** Proves the accepted-ack branch ran, whatever the ack shape. */
+function expectAcceptedAck(shape: string, pushToast: ReturnType<typeof vi.fn>) {
+ if (shape === 'synchronous') {
+ expect(pushToast).toHaveBeenCalledWith('Message sent to agent-x.', 'success')
+ return
+ }
+ expect(clerum.chat.appendMessages).toHaveBeenCalledWith(
+ 'agent-x',
+ expect.any(String),
+ expect.arrayContaining([expect.objectContaining({ role: 'user', task_id: 'task-refs' })])
+ )
+}
+
+describe('sendAgentMessage — references the Host did not receive (#666 M1)', () => {
+ it.each(ACK_SHAPES)(
+ '%s ack without acceptedFileReferenceIds shows the error once, without a retry',
+ async (shape, ack) => {
+ const { result, spies } = await sendWithReferences({ ...ack }, [planFile])
+
+ expect(sentReferenceIds()).toEqual([PLAN_ID])
+ expect(result.current.agentError).toBe(NOT_RECEIVED)
+ expect(spies.pushToast).toHaveBeenCalledWith(NOT_RECEIVED, 'error')
+ // The send stands: accepted, not failed, and not resent.
+ expectAcceptedAck(shape, spies.pushToast)
+ expect(result.current.failedAgentSend).toBeNull()
+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)
+ }
+ )
+
+ 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] },
+ [planFile, notesFile]
+ )
+
+ // Witness: the ack reached the accepted branch and echoed exactly the
+ // ids that were sent.
+ expectAcceptedAck(shape, spies.pushToast)
+ expect(sentReferenceIds()).toEqual([PLAN_ID, NOTES_ID])
+ expect(result.current.agentError).toBeNull()
+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')
+ })
+
+ it.each(ACK_SHAPES)(
+ '%s ack that echoes only some sent ids shows the error',
+ async (shape, ack) => {
+ const { result, spies } = await sendWithReferences(
+ { ...ack, acceptedFileReferenceIds: [PLAN_ID] },
+ [planFile, notesFile]
+ )
+
+ expect(sentReferenceIds()).toEqual([PLAN_ID, NOTES_ID])
+ expect(result.current.agentError).toBe(NOT_RECEIVED)
+ expect(spies.pushToast).toHaveBeenCalledWith(NOT_RECEIVED, 'error')
+ expectAcceptedAck(shape, spies.pushToast)
+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)
+ }
+ )
+
+ it('does not check the ack of a send without references', async () => {
+ const { result, spies } = await sendWithReferences({ response: 'done' }, [])
+
+ // Witness: the send was accepted; the ack carries no ids and needs none.
+ expectAcceptedAck('synchronous', spies.pushToast)
+ expect(sentRequest()).not.toHaveProperty('fileReferences')
+ expect(result.current.agentError).toBeNull()
+ expect(spies.pushToast).not.toHaveBeenCalledWith(NOT_RECEIVED, 'error')
+ })
+})
+
+describe('sendAgentMessage — payload too large (#666 L12)', () => {
+ it('names images and attached files in the 413 message', async () => {
+ clerum.rpc.invokeHostMessage.mockRejectedValue(new Error('Request Entity Too Large'))
+ const { result } = renderController()
+ await settleMount()
+
+ await act(async () => {
+ await result.current.handleSendAgentMessage('large send')
+ })
+
+ expect(result.current.agentError).toContain(
+ 'The message is larger than the deployed runtime accepts (images or attached files).'
+ )
+ expect(result.current.agentError).not.toContain('Image payload')
+ })
+})
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 7cc458608..3c757fb29 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -121,6 +121,8 @@ const MAX_MESSAGES_WITH_ACTIVITY_PER_AGENT = 50
const LOCAL_MESSAGE_PAGE_SIZE = 80
const SERVER_TURN_PAGE_SIZE = 40
const MAX_RECONCILE_DELTA_PAGES = 5
+const FILE_REFERENCES_NOT_RECEIVED_MESSAGE =
+ 'The Host did not receive the selected Global Files; the message was sent without them.'
const LATEST_PAGE_FALLBACK_WINDOW = Symbol('latest-page-fallback-window')
const DELTA_RECONCILIATION_WINDOW = Symbol('delta-reconciliation-window')
type ReconciliationMessagesResult = SessionMessagesResult & {
@@ -2769,6 +2771,21 @@ export function useAgentChatController({
{ force: true }
)
}
+ // #666 M1 — a Host or rpc-proxy that predates fileReferences drops them
+ // 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.
+ if (ackOk && fileReferences.length > 0) {
+ const acceptedFileReferenceIds = new Set<string>(
+ Array.isArray(response.acceptedFileReferenceIds)
+ ? response.acceptedFileReferenceIds
+ : []
+ )
+ if (fileReferences.some(reference => !acceptedFileReferenceIds.has(reference.id))) {
+ setAgentError(FILE_REFERENCES_NOT_RECEIVED_MESSAGE)
+ pushToast(FILE_REFERENCES_NOT_RECEIVED_MESSAGE, 'error')
+ }
+ }
const taskId =
(typeof responseRecord.taskId === 'string' ? responseRecord.taskId : undefined) ||
(typeof responseRecord.id === 'string' ? responseRecord.id : undefined)
@@ -2909,10 +2926,10 @@ export function useAgentChatController({
normalized.includes('payload too large')
const kind = classifyErrorKind(message)
const fallback = isRequestEntityTooLarge
- ? 'Runtime payload limit hit. This environment still needs updated rpc-proxy and mcp-host deployments for image uploads.'
+ ? 'Send fewer or smaller attachments. If small attachments are refused too, the rpc-proxy and mcp-host deployments may predate the current payload limits.'
: errorRecoveryHint(kind)
const friendlyMessage = isRequestEntityTooLarge
- ? 'Image payload is larger than the currently deployed runtime limit.'
+ ? 'The message is larger than the deployed runtime accepts (images or attached files).'
: kind === 'waking'
? 'Agent is waking up.'
: kind === 'network'
diff --git a/desktop-app/ui/src/lib/__tests__/composerReferencesPrompt.test.ts b/desktop-app/ui/src/lib/__tests__/composerReferencesPrompt.test.ts
index 4bde2663e..e29b81a84 100644
--- a/desktop-app/ui/src/lib/__tests__/composerReferencesPrompt.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/composerReferencesPrompt.test.ts
@@ -53,10 +53,40 @@ describe('composer references prompt helpers', () => {
// The Global Files line names the selection; the read instruction now comes
// from the Host's turn context for the structured fileReferences (#666).
expect(prompt).toContain(
- 'Global Files: quarterly-report.pdf (gfs://main/0123456789abcdef). These files were explicitly selected by the user.'
+ 'Global Files: quarterly-report.pdf. These files were explicitly selected by the user.'
)
expect(prompt).not.toContain('clerum__gfs_resolve')
expect(prompt).not.toContain('clerum__gfs_read')
+ // The URI travels only in the structured fileReferences; the line above is
+ // the witness that the Global Files entry was formatted.
+ expect(prompt).not.toContain('gfs://')
+ })
+
+ it('leaves a Global Files entry without a label out of the prompt', () => {
+ const unlabeled: ComposerReferenceAttachment = {
+ id: 'global-file:unlabeled',
+ type: 'global_file',
+ resourceId: 'resource-2',
+ drive: 'main',
+ gfsUri: 'gfs://main/fedcba9876543210',
+ label: ' ',
+ version: 1,
+ bytes: 10,
+ }
+ const labeled: ComposerReferenceAttachment = {
+ ...unlabeled,
+ id: 'global-file:notes',
+ label: 'notes.md',
+ }
+
+ const prompt = buildComposerReferencesPromptSection([unlabeled, labeled])
+
+ // Witness: the labeled entry is the only one on the line.
+ expect(prompt).toContain(
+ 'Global Files: notes.md. These files were explicitly selected by the user.'
+ )
+ expect(prompt).not.toContain('gfs://')
+ expect(buildComposerReferencesPromptSection([unlabeled])).toBeNull()
})
it('leaves request content unchanged when no references are attached', () => {
diff --git a/desktop-app/ui/src/lib/composerReferencesPrompt.ts b/desktop-app/ui/src/lib/composerReferencesPrompt.ts
index bcf8acad0..4aee24274 100644
--- a/desktop-app/ui/src/lib/composerReferencesPrompt.ts
+++ b/desktop-app/ui/src/lib/composerReferencesPrompt.ts
@@ -13,13 +13,15 @@ function formatAgentFileReference(
return `${filesystemName}${path.startsWith('/') ? path : `/${path}`}`
}
+/**
+ * Only the label: the gfs:// URI reaches the model through the structured
+ * fileReferences in the Host's turn context, never through message content.
+ * An entry without a label is left out of this line.
+ */
function formatGlobalFileReference(
reference: Extract<ComposerReferenceAttachment, { type: 'global_file' }>
): string {
- const label = normalizeComposerReferenceName(reference.label)
- const gfsUri = normalizeComposerReferenceName(reference.gfsUri)
- if (!gfsUri) return ''
- return label ? `${label} (${gfsUri})` : gfsUri
+ return normalizeComposerReferenceName(reference.label)
}
export function buildComposerReferencesPromptSection(