Skip to content

The agent that grows with you

fix(desktop): show one error card when the agent fails to start

Adolan6b512010ec4c
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/agent-init-error.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/agent-init-error.test.tsx
index ea018ed8d41..9bee5c5168e 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/agent-init-error.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/agent-init-error.test.tsx
@@ -78,4 +78,63 @@ describe('useMessageStream agent-init error surfacing (#63078)', () => {
expect(toast).toBeDefined()
expect(toast!.detail).toBeUndefined()
})
+ it('merges the terminal error frame into the card the agent-init error event already painted', async () => {
+ mountStream()
+ seedOptimisticFirstMessage()
+
+ act(() =>
+ stream.handleEvent({
+ payload: { message: 'Hermes could not start the assistant for this session. Details: no provider.' },
+ session_id: SID,
+ type: 'error'
+ })
+ )
+
+ act(() =>
+ stream.handleEvent({
+ payload: {
+ error: 'no provider',
+ error_surface: { code: 'agent_init_failed', layer: 'runtime', retryable: true },
+ status: 'error',
+ text: 'no provider'
+ },
+ session_id: SID,
+ type: 'message.complete'
+ })
+ )
+
+ const errorRows = stream.state().messages.filter(m => m.role === 'assistant' && m.error)
+ expect(errorRows).toHaveLength(1)
+ expect(errorRows[0]!.errorSurface?.code).toBe('agent_init_failed')
+ })
+ it('keeps one card when the terminal error frame arrives before the agent-init error event', async () => {
+ mountStream()
+ seedOptimisticFirstMessage()
+
+ act(() =>
+ stream.handleEvent({
+ payload: {
+ error: 'no provider',
+ error_surface: { code: 'agent_init_failed', layer: 'runtime', retryable: true },
+ status: 'error',
+ text: 'no provider'
+ },
+ session_id: SID,
+ type: 'message.complete'
+ })
+ )
+
+ act(() =>
+ stream.handleEvent({
+ payload: { message: 'Hermes could not start the assistant for this session. Details: no provider.' },
+ session_id: SID,
+ type: 'error'
+ })
+ )
+
+ const errorRows = stream.state().messages.filter(m => m.role === 'assistant' && m.error)
+ expect(errorRows).toHaveLength(1)
+ expect(errorRows[0]!.error).toContain('could not start the assistant')
+ expect(errorRows[0]!.errorSurface?.code).toBe('agent_init_failed')
+ })
})
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
index 0c0e71eae33..9d178f32ff6 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
@@ -807,7 +807,16 @@ export function useMessageStream({
(finalText === existingText || finalText.startsWith(existingText) || existingText.startsWith(finalText))
)
- if (existing.pending || (!interimBoundaryPending && finalText && existingText === finalText)) {
+ // A bare `error` event (e.g. the agent build failing) already
+ // painted this turn's error card; the turn's terminal error frame
+ // is the same failure, so it settles onto that card.
+ const failureRepeatsErrorCard = Boolean(completionError && existing.error && !existingText)
+
+ if (
+ existing.pending ||
+ failureRepeatsErrorCard ||
+ (!interimBoundaryPending && finalText && existingText === finalText)
+ ) {
nextMessages = settleAt(index)
} else if (
(interimBoundaryPending && (responsePreviewed || responseTransformed)) ||
@@ -978,9 +987,26 @@ export function useMessageStream({
? Math.max(1, Math.round((Date.now() - state.turnStartedAt) / 1000))
: undefined
- const nextMessages = prev.some(m => m.id === streamId)
+ const lastUserIndex = prev.findLastIndex(message => message.role === 'user')
+
+ // The turn's terminal error frame may already have painted this
+ // failure's card; a trailing bare `error` event updates that card.
+ const repeatedCard = state.streamId
+ ? undefined
+ : prev.findLast(
+ (message, index) =>
+ index > lastUserIndex &&
+ message.role === 'assistant' &&
+ !message.hidden &&
+ message.error &&
+ !chatMessageText(message).trim()
+ )
+
+ const targetId = repeatedCard?.id ?? streamId
+
+ const nextMessages = prev.some(m => m.id === targetId)
? prev.map(message =>
- message.id === streamId
+ message.id === targetId
? {
...message,
completedAt: occurredAt,