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(agent): a step LU Cloud ended as a runaway is not sent again

purpleb8346fdcb5cb
diff --git a/src/api/providers/__tests__/stream-error-keeps-its-code.test.ts b/src/api/providers/__tests__/stream-error-keeps-its-code.test.ts
new file mode 100644
index 00000000..e1440cce
--- /dev/null
+++ b/src/api/providers/__tests__/stream-error-keeps-its-code.test.ts
@@ -0,0 +1,66 @@
+/**
+ * LU Cloud ends a step it will not let run on with an SSE error chunk
+ * (lu-labs.ai inference route, 30.09.2026): `stalled_dead` after 90 s without
+ * a byte, `stalled_runaway` after 10 minutes without visible output. The
+ * provider used to throw a bare Error, the code was lost, and the agent's
+ * retry ladder read "no status" as transient and sent the runaway step again,
+ * twice, ten minutes each, on the customer's credits.
+ */
+import { describe, it, expect, vi } from 'vitest'
+import type { ProviderConfig } from '../types'
+import { isTerminalModelError } from '../../../lib/http-status'
+
+type CapturedInit = { method?: string; headers?: Record<string, string>; body?: string }
+
+const backendMock = (respond: (url: string) => Response) => ({
+ isTauri: () => false,
+ localFetch: vi.fn(async (url: string, _init: CapturedInit) => respond(url)),
+ localFetchStream: vi.fn(async (url: string, _init: CapturedInit) => respond(url)),
+ ollamaUrl: (path: string) => `http://localhost:11434/api${path}`,
+ backendCall: vi.fn(),
+ isPrivateOrLanHost: () => false,
+ isDirectFetchAllowed: () => false,
+ hostnameOf: (url: string) => new URL(url).hostname,
+ ensureProxyAllowsHost: vi.fn(),
+})
+
+async function streamError(code: string): Promise<unknown> {
+ vi.resetModules()
+ const body =
+ `data: ${JSON.stringify({ choices: [{ index: 0, delta: { content: 'Writing the page.' } }] })}\n\n` +
+ `data: ${JSON.stringify({ error: { message: `ended (${code})`, type: 'stalled', code } })}\n\n` +
+ 'data: [DONE]\n\n'
+ vi.doMock('../../backend', () =>
+ backendMock((url) =>
+ url.includes('/chat/completions')
+ ? new Response(body, { headers: { 'Content-Type': 'text/event-stream' } })
+ : new Response('{}', { status: 404 }),
+ ),
+ )
+ const { OpenAIProvider } = await import('../openai-provider')
+ const config: ProviderConfig = {
+ id: 'openai', name: 'LU Cloud', enabled: true, apiKey: 'x', baseUrl: 'https://lu-labs.test/api/inference/v1', isLocal: false,
+ }
+ const p = new OpenAIProvider(config)
+ try {
+ for await (const chunk of p.chatStream('google/gemma-4-26B-A4B-it', [{ role: 'user', content: 'go' }])) { void chunk }
+ } catch (e) {
+ return e
+ }
+ throw new Error('the stream did not throw')
+}
+
+describe('a stream error chunk keeps its code', () => {
+ it('a runaway step is thrown with its code and is not retried', async () => {
+ const err = await streamError('stalled_runaway')
+ expect((err as { code?: string }).code).toBe('stalled_runaway')
+ expect((err as Error).message).toContain('ended (stalled_runaway)')
+ expect(isTerminalModelError(err)).toBe(true)
+ })
+
+ it('a dead line keeps its code and stays retryable', async () => {
+ const err = await streamError('stalled_dead')
+ expect((err as { code?: string }).code).toBe('stalled_dead')
+ expect(isTerminalModelError(err)).toBe(false)
+ })
+})
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index 4f0999fd..db8938b6 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -910,10 +910,16 @@ export class OpenAIProvider implements ProviderClient {
// text-only model returns `event: error` with HTTP 200 (2026-06-21).
const streamErr = chunk.error
if (streamErr) {
- throw new Error(
+ // The server's code travels with the error, so the retry ladder can
+ // tell a step it must not repeat (LU Cloud `stalled_runaway`: ten
+ // minutes of output nobody saw) from a dropped line.
+ const serverCode = typeof streamErr === 'string' ? undefined : asString(prop(streamErr, 'code')) || undefined
+ throw new ProviderError(
typeof streamErr === 'string'
? streamErr
: withContextNumbers(asString(prop(streamErr, 'message')) || 'Streaming error', streamErr),
+ 'openai',
+ serverCode,
)
}
diff --git a/src/lib/http-status.ts b/src/lib/http-status.ts
index 87d936d5..4e4c7176 100644
--- a/src/lib/http-status.ts
+++ b/src/lib/http-status.ts
@@ -107,6 +107,10 @@ export function isTerminalModelError(err: unknown): boolean {
// twelve silent minutes before the run gave up, same shape as the
// `credits_exhausted` bug this line is modelled on.
if (e?.code === 'credits_exhausted' || e?.code === 'signed_out' || e?.code === 'flash_timeout') return true
+ // LU Cloud ended a step that produced no visible output for ten minutes
+ // (a model run away inside a tool call). Sending it again runs the same
+ // ten minutes again, twice, on the customer's credits.
+ if (e?.code === 'stalled_runaway') return true
const status = httpStatusOf(err)
if (status === 429 || status === 408) return false
if (status === 401 && e?.provider === 'lu-cloud') return false