Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(compare): show why a side failed instead of an empty answer with 0-stats

purpled7ba47cc2d11
diff --git a/src/components/chat/ABCompare.tsx b/src/components/chat/ABCompare.tsx
index d14219a4..ad812a61 100644
--- a/src/components/chat/ABCompare.tsx
+++ b/src/components/chat/ABCompare.tsx
@@ -6,6 +6,7 @@ import { MarkdownRenderer } from './MarkdownRenderer'
import { StatusChip } from '../status/StatusChip'
import { deriveRunStatus } from '../status/run-status'
import { stripModelNoise } from '../../lib/strip-model-noise'
+import { compareFailureText } from '../../lib/compare-failure'
import { ArrowLeft, Send, Square, Zap, Clock, Hash } from 'lucide-react'
import { displayModelName } from '../../api/providers/registry'
@@ -120,9 +121,14 @@ export function ABCompare() {
{messagesA.map(msg => (
<div key={msg.id} className={`text-[0.7rem] ${msg.role === 'user' ? 'text-gray-400 italic' : 'text-gray-200'}`}>
{msg.role === 'assistant' ? (
- cleanA.get(msg.id) || !isStreamingA
- ? <MarkdownRenderer content={cleanA.get(msg.id) || ''} />
- : <div role="status" data-testid="compare-status-a"><StatusChip {...deriveRunStatus({ message: { content: '' } })} /></div>
+ <>
+ {cleanA.get(msg.id) || (!isStreamingA && !msg.error)
+ ? <MarkdownRenderer content={cleanA.get(msg.id) || ''} />
+ : !msg.error && <div role="status" data-testid="compare-status-a"><StatusChip {...deriveRunStatus({ message: { content: '' } })} /></div>}
+ {msg.error && (
+ <p role="alert" data-testid="compare-error-a" className="mt-1 whitespace-pre-wrap text-red-300/90">{compareFailureText(msg.error)}</p>
+ )}
+ </>
) : (
<p>{msg.content}</p>
)}
@@ -147,9 +153,14 @@ export function ABCompare() {
{messagesB.map(msg => (
<div key={msg.id} className={`text-[0.7rem] ${msg.role === 'user' ? 'text-gray-400 italic' : 'text-gray-200'}`}>
{msg.role === 'assistant' ? (
- cleanB.get(msg.id) || !isStreamingB
- ? <MarkdownRenderer content={cleanB.get(msg.id) || ''} />
- : <div role="status" data-testid="compare-status-b"><StatusChip {...deriveRunStatus({ message: { content: '' } })} /></div>
+ <>
+ {cleanB.get(msg.id) || (!isStreamingB && !msg.error)
+ ? <MarkdownRenderer content={cleanB.get(msg.id) || ''} />
+ : !msg.error && <div role="status" data-testid="compare-status-b"><StatusChip {...deriveRunStatus({ message: { content: '' } })} /></div>}
+ {msg.error && (
+ <p role="alert" data-testid="compare-error-b" className="mt-1 whitespace-pre-wrap text-red-300/90">{compareFailureText(msg.error)}</p>
+ )}
+ </>
) : (
<p>{msg.content}</p>
)}
diff --git a/src/hooks/__tests__/ab-compare-shows-a-failed-side.test.ts b/src/hooks/__tests__/ab-compare-shows-a-failed-side.test.ts
new file mode 100644
index 00000000..b8164232
--- /dev/null
+++ b/src/hooks/__tests__/ab-compare-shows-a-failed-side.test.ts
@@ -0,0 +1,100 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * C5 (funde-C.md): in Compare, a side whose request failed (engine 500,
+ * model gone, Ollama down) kept an empty answer under "0.0 t/s · 0" with no
+ * word of why. `useABCompare` swallowed abort and failure in one bare catch.
+ *
+ * Now a failure lands on the side's message as `error`, the stats stay null
+ * (no fake result), and the column text says why. A stop by the user is
+ * still no failure.
+ *
+ * Run: npx vitest run src/hooks/__tests__/ab-compare-shows-a-failed-side.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { renderHook, act } from '@testing-library/react'
+
+vi.mock('../../lib/run-lane-of-model', () => ({
+ laneOf: () => 'cloud',
+ currentLaneFacts: () => ({ openaiSlotIsLocal: false, ollamaBaseIsLocal: false }),
+}))
+
+const OK = 'openai::qwen2.5-7b'
+const BAD = 'openai::llama-3.2-3b'
+const ENGINE_500 = 'HTTP 500: llama-server could not load the model (out of memory)'
+
+vi.mock('../../api/providers', () => ({
+ getProviderForModel: (model: string) => ({
+ provider: {
+ chatStream: (_m: string, _msgs: unknown, opts: { signal?: AbortSignal }) => (async function* () {
+ if (model === BAD) throw new Error(ENGINE_500)
+ if (model === 'openai::stopped') {
+ await new Promise<void>((_res, rej) => opts.signal?.addEventListener('abort', () => {
+ const e = new Error('aborted'); e.name = 'AbortError'; rej(e)
+ }))
+ }
+ yield { content: 'hi', done: false }
+ yield { content: '', done: true }
+ })(),
+ },
+ modelId: model,
+ }),
+ getProviderIdFromModel: () => 'openai',
+}))
+
+import { useABCompare } from '../useABCompare'
+import { useCompareStore } from '../../stores/compareStore'
+import { useSettingsStore } from '../../stores/settingsStore'
+import { __resetRunLanesForTests } from '../../lib/run-lanes'
+import { DEFAULT_SETTINGS } from '../../lib/constants'
+import { compareFailureText } from '../../lib/compare-failure'
+
+beforeEach(() => {
+ __resetRunLanesForTests()
+ useCompareStore.setState({
+ isComparing: true, modelA: '', modelB: '',
+ messagesA: [], messagesB: [], statsA: null, statsB: null,
+ isStreamingA: false, isStreamingB: false,
+ })
+ useSettingsStore.setState({ settings: { ...DEFAULT_SETTINGS, contextDecay: false } })
+})
+
+describe('Compare: a side that failed says so', () => {
+ it('B fails with an engine 500: B carries the error, no 0-stats; A is a normal result', async () => {
+ useCompareStore.setState({ modelA: OK, modelB: BAD })
+ const { result } = renderHook(() => useABCompare())
+ await act(async () => { await result.current.sendCompare('Say hi') })
+
+ const s = useCompareStore.getState()
+ const lastA = s.messagesA[s.messagesA.length - 1]
+ const lastB = s.messagesB[s.messagesB.length - 1]
+
+ expect(lastA.content).toBe('hi')
+ expect(lastA.error).toBeUndefined()
+ expect(s.statsA?.tokens).toBe(1)
+
+ expect(s.statsB).toBeNull()
+ expect(s.isStreamingB).toBe(false)
+ expect(lastB.content).toBe('')
+ expect(lastB.error?.kind).toBe('engine')
+ expect(lastB.error?.detail).toContain('out of memory')
+
+ const text = compareFailureText(lastB.error!)
+ expect(text).toMatch(/did not answer/)
+ expect(text).toContain(ENGINE_500)
+ })
+
+ it('a stop by the user is no failure: no error on the message', async () => {
+ useCompareStore.setState({ modelA: OK, modelB: 'openai::stopped' })
+ const { result } = renderHook(() => useABCompare())
+ let round: Promise<void> = Promise.resolve()
+ await act(async () => {
+ round = result.current.sendCompare('Say hi')
+ for (let i = 0; i < 10; i++) await Promise.resolve()
+ })
+ await act(async () => { result.current.stopCompare(); await round })
+
+ const s = useCompareStore.getState()
+ expect(s.messagesB[s.messagesB.length - 1].error).toBeUndefined()
+ })
+})
diff --git a/src/hooks/useABCompare.ts b/src/hooks/useABCompare.ts
index 2b78e18b..d462ff2c 100644
--- a/src/hooks/useABCompare.ts
+++ b/src/hooks/useABCompare.ts
@@ -21,6 +21,9 @@ import { buildSamplingRequest } from '../lib/sampling'
import { runInLane } from '../lib/run-slot'
import { laneOf, currentLaneFacts } from '../lib/run-lane-of-model'
import { useGenerationStore } from '../stores/generationStore'
+import { messageErrorFor } from '../lib/message-error'
+import { syncOllamaHealthFromError } from '../lib/sync-ollama-health'
+import type { MessageError } from '../types/chat'
/**
* Booking identity for the local lane, standing in for a `conversationId`.
@@ -41,6 +44,18 @@ import { useGenerationStore } from '../stores/generationStore'
*/
export const COMPARE_LANE_ID = 'lib:ab-compare'
+/**
+ * What a side's catch makes of what was thrown (C5). A stop by the user is no
+ * failure: the side keeps what arrived and its stats. Anything else is: the
+ * side gets the error as a field, the same `messageErrorFor` the chat hook
+ * writes, so the column can say why this model did not answer.
+ */
+export function compareFailureOf(err: unknown, signal: AbortSignal, model: string, answerSoFar: string): MessageError | null {
+ if (signal.aborted || (err instanceof Error && err.name === 'AbortError')) return null
+ syncOllamaHealthFromError(err)
+ return messageErrorFor(err, { cloud: getProviderIdFromModel(model) === 'lu-cloud' }, answerSoFar)
+}
+
export function useABCompare() {
const store = useCompareStore()
const settings = useSettingsStore((s) => s.settings)
@@ -149,10 +164,12 @@ export function useABCompare() {
fullContent += part.prose
useCompareStore.getState().addContentA(part.prose)
}
+ const signal = abortA.current!.signal
+ let failure: MessageError | null = null
try {
const { provider, modelId } = getProviderForModel(modelA)
const stream = provider.chatStream(modelId, sendMessages, {
- ...opts, thinking: thinkOptFor(modelA), signal: abortA.current!.signal,
+ ...opts, thinking: thinkOptFor(modelA), signal,
})
for await (const chunk of stream) {
if (chunk.content) {
@@ -161,9 +178,15 @@ export function useABCompare() {
}
}
show(splitter.flush())
- } catch { /* aborted or error */ }
+ } catch (err) {
+ failure = compareFailureOf(err, signal, modelA, fullContent)
+ }
fullContent = settleThinking(fullContent, '', false).content
const elapsed = Date.now() - startTime
+ if (failure) {
+ useCompareStore.getState().finishA(fullContent, null, { ...failure, at: Math.min(failure.at, fullContent.length) })
+ return
+ }
useCompareStore.getState().finishA(fullContent, {
tokens: tokenCount,
timeMs: elapsed,
@@ -187,10 +210,12 @@ export function useABCompare() {
fullContent += part.prose
useCompareStore.getState().addContentB(part.prose)
}
+ const signal = abortB.current!.signal
+ let failure: MessageError | null = null
try {
const { provider, modelId } = getProviderForModel(modelB)
const stream = provider.chatStream(modelId, sendMessages, {
- ...opts, thinking: thinkOptFor(modelB), signal: abortB.current!.signal,
+ ...opts, thinking: thinkOptFor(modelB), signal,
})
for await (const chunk of stream) {
if (chunk.content) {
@@ -199,9 +224,15 @@ export function useABCompare() {
}
}
show(splitter.flush())
- } catch { /* aborted or error */ }
+ } catch (err) {
+ failure = compareFailureOf(err, signal, modelB, fullContent)
+ }
fullContent = settleThinking(fullContent, '', false).content
const elapsed = Date.now() - startTime
+ if (failure) {
+ useCompareStore.getState().finishB(fullContent, null, { ...failure, at: Math.min(failure.at, fullContent.length) })
+ return
+ }
useCompareStore.getState().finishB(fullContent, {
tokens: tokenCount,
timeMs: elapsed,
diff --git a/src/lib/compare-failure.ts b/src/lib/compare-failure.ts
new file mode 100644
index 00000000..4246d637
--- /dev/null
+++ b/src/lib/compare-failure.ts
@@ -0,0 +1,26 @@
+/**
+ * The sentence a Compare column shows when its model did not answer (C5).
+ *
+ * The chat says a failure in a short sentence of ours with the raw reason
+ * kept underneath (lib/error-text.ts withDetail). A Compare side that failed
+ * used to show nothing at all, an empty answer under "0.0 t/s", which read as
+ * "the model had nothing to say" and skewed the comparison.
+ */
+import type { MessageError } from '../types/chat'
+import { withDetail } from './error-text'
+
+const SENTENCE: Record<MessageError['kind'], string> = {
+ engine: 'The engine could not run this model, so it did not answer.',
+ network: 'This model could not be reached, so it did not answer.',
+ credits: "You're out of credits, so this model did not answer.",
+ session: 'Sign in to LU Cloud again, then send the comparison once more.',
+ limit: 'This model hit a request limit and did not answer.',
+ interrupted: 'This answer was interrupted.',
+ generic: 'This model did not answer.',
+}
+
+export function compareFailureText(error: MessageError): string {
+ // A request limit's reason is already the full sentence (lib/request-limit.ts).
+ if (error.kind === 'limit' && error.detail) return error.detail
+ return withDetail(SENTENCE[error.kind] ?? SENTENCE.generic, error.detail)
+}
diff --git a/src/mobile/screens/agent/ComparePage.tsx b/src/mobile/screens/agent/ComparePage.tsx
index 29739c49..7ffabdda 100644
--- a/src/mobile/screens/agent/ComparePage.tsx
+++ b/src/mobile/screens/agent/ComparePage.tsx
@@ -20,6 +20,7 @@ import { AGENT_STRINGS as T } from '../../strings/agent'
import { Button, Composer, EmptyState, IconButton, ModelChip, Notice, Page, Segmented, Spinner, toast } from '../../ui'
import './parts/agent.css'
import { NEW_CHAT } from './parts/chat-ref'
+import { compareFailureText } from '../../../lib/compare-failure'
import { compareBlock, formatRate, keptPair, rateIsMeaningful, type Side } from './parts/compare-logic'
import { localCount, modelLabel, whereOf } from './parts/model-names'
import { consentFor, isCloudModel, reportAnswer } from './parts/policy'
@@ -131,8 +132,8 @@ export default function ComparePage() {
{queued ? S.waitingTurn : S.waiting}
</span>
) : empty ? (
- <span className="m-ag-error" role="alert" data-testid={`m-compare-noanswer-${side}`}>
- {S.noAnswer}
+ <span className="m-ag-error" role="alert" style={{ whiteSpace: 'pre-wrap' }} data-testid={`m-compare-noanswer-${side}`}>
+ {message.error ? compareFailureText(message.error) : S.noAnswer}
</span>
) : (
<div className="m-ag-answer-text">{message.content}</div>
diff --git a/src/stores/compareStore.ts b/src/stores/compareStore.ts
index a6499f67..a2e45876 100644
--- a/src/stores/compareStore.ts
+++ b/src/stores/compareStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand'
-import type { Message } from '../types/chat'
+import type { Message, MessageError } from '../types/chat'
import { useUIStore } from './uiStore'
interface ModelStats {
@@ -24,8 +24,13 @@ interface CompareState {
addContentA: (content: string) => void
addContentB: (content: string) => void
startRound: (userMessage: Message) => void
- finishA: (content: string, stats: ModelStats) => void
- finishB: (content: string, stats: ModelStats) => void
+ /**
+ * End a side's turn. A side whose request failed passes `stats: null` and
+ * its `error`: the column then shows why it did not answer instead of an
+ * empty answer under "0.0 t/s", which read like a result (C5).
+ */
+ finishA: (content: string, stats: ModelStats | null, error?: MessageError) => void
+ finishB: (content: string, stats: ModelStats | null, error?: MessageError) => void
setStreamingA: (on: boolean) => void
setStreamingB: (on: boolean) => void
reset: () => void
@@ -73,20 +78,20 @@ export const useCompareStore = create<CompareState>()((set) => ({
isStreamingB: true,
})),
- finishA: (content, stats) => set((s) => {
+ finishA: (content, stats, error) => set((s) => {
const msgs = [...s.messagesA]
const last = msgs[msgs.length - 1]
if (last && last.role === 'assistant') {
- msgs[msgs.length - 1] = { ...last, content }
+ msgs[msgs.length - 1] = error ? { ...last, content, error } : { ...last, content }
}
return { messagesA: msgs, statsA: stats, isStreamingA: false }
}),
- finishB: (content, stats) => set((s) => {
+ finishB: (content, stats, error) => set((s) => {
const msgs = [...s.messagesB]
const last = msgs[msgs.length - 1]
if (last && last.role === 'assistant') {
- msgs[msgs.length - 1] = { ...last, content }
+ msgs[msgs.length - 1] = error ? { ...last, content, error } : { ...last, content }
}
return { messagesB: msgs, statsB: stats, isStreamingB: false }
}),