From 72598322d14992004c8ede446ef919573ebf41c7 Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Fri, 6 Feb 2026 19:35:39 +0800 Subject: [PATCH] feat(desktop): handle agent_error events and clearLastRoute in IPC Forward agent_error as passthrough event to renderer. Add clearLastRoute() calls in hub:sendMessage and localChat:send handlers so channel replies stop when desktop sends a message. Handle agent_error in use-local-chat to show error UI. Co-Authored-By: Claude Opus 4.6 --- apps/desktop/electron/ipc/hub.ts | 12 +++++++----- apps/desktop/src/hooks/use-local-chat.ts | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/desktop/electron/ipc/hub.ts b/apps/desktop/electron/ipc/hub.ts index b038efe8..288c4ef0 100644 --- a/apps/desktop/electron/ipc/hub.ts +++ b/apps/desktop/electron/ipc/hub.ts @@ -236,6 +236,7 @@ export function registerHubIpcHandlers(): void { if (agent.closed) { return { error: `Agent is closed: ${agentId}` } } + h.channelManager.clearLastRoute() agent.write(content) return { ok: true } }) @@ -268,11 +269,11 @@ export function registerHubIpcHandlers(): void { return } - // Compaction events: forward with no stream tracking - const isCompactionEvent = - event.type === 'compaction_start' || event.type === 'compaction_end' - if (isCompactionEvent) { - safeLog(`[IPC] Sending compaction event to renderer: ${event.type}`) + // Compaction and error events: forward with no stream tracking + const isPassthroughEvent = + event.type === 'compaction_start' || event.type === 'compaction_end' || event.type === 'agent_error' + if (isPassthroughEvent) { + safeLog(`[IPC] Sending ${event.type} event to renderer`) mainWindowRef.webContents.send('localChat:event', { agentId, streamId: null, @@ -384,6 +385,7 @@ export function registerHubIpcHandlers(): void { return { error: 'Not subscribed to agent events. Call subscribe first.' } } + h.channelManager.clearLastRoute() agent.write(content) safeLog(`[IPC] Local chat message sent to agent: ${agentId}`) return { ok: true } diff --git a/apps/desktop/src/hooks/use-local-chat.ts b/apps/desktop/src/hooks/use-local-chat.ts index cf637f25..ec7e9677 100644 --- a/apps/desktop/src/hooks/use-local-chat.ts +++ b/apps/desktop/src/hooks/use-local-chat.ts @@ -56,6 +56,14 @@ export function useLocalChat() { const payload = data as unknown as StreamPayload if (!payload.event) return + // Handle agent errors as transient UI feedback (not persisted to history) + if (payload.event.type === 'agent_error') { + const errorMsg = (payload.event as { error?: string }).error ?? 'Unknown error' + chatRef.current.setError({ code: 'AGENT_ERROR', message: errorMsg }) + setIsLoading(false) + return + } + chatRef.current.handleStream(payload) if (payload.event.type === 'message_start') setIsLoading(true) if (payload.event.type === 'message_end') setIsLoading(false)