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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(agent): langer Werkzeugaufruf ist kein haengender Stream
purple5fa0fa5c24a3
diff --git a/src/lib/__tests__/provider-stream.test.ts b/src/lib/__tests__/provider-stream.test.tsindex 0bb65d27..dbd7ebdf 100644--- a/src/lib/__tests__/provider-stream.test.ts+++ b/src/lib/__tests__/provider-stream.test.ts@@ -1,4 +1,4 @@-import { describe, it, expect } from 'vitest'+import { describe, it, expect, vi, afterEach } from 'vitest'import { streamProviderTurn } from '../provider-stream'import type { ChatStreamChunk, ProviderClient } from '../../api/providers/types'@@ -79,3 +79,26 @@ describe('streamProviderTurn', () => {await expect(streamProviderTurn(provider, 'm', [], {})).rejects.toThrow('boom')})})++// Kundenfall swift_maple90, 30.09.2026: ein langer file_write auf einem nativen+// Modell. Die Argumente sammeln sich im Provider, der dabei nichts liefert,+// waehrend die Bytes weiter fliessen. Der alte Waechter hier brach nach 300 s+// ohne gelieferten Chunk ab, mitten im Schreiben.+describe('a long tool call is not a stalled stream', () => {+ afterEach(() => { vi.useRealTimers() })++ it('waits for a done chunk that takes longer than five minutes', async () => {+ vi.useFakeTimers()+ const calls = [{ id: '1', function: { name: 'file_write', arguments: { path: 'big.ts', content: 'x' } } }]+ const provider = {+ id: 'openai',+ async *chatStream() {+ await new Promise((r) => setTimeout(r, 420_000))+ yield { content: '', done: true, toolCalls: calls, finishReason: 'tool_calls' } as ChatStreamChunk+ },+ } as unknown as ProviderClient+ const turn = streamProviderTurn(provider, 'm', [], {})+ await vi.advanceTimersByTimeAsync(420_000)+ await expect(turn).resolves.toMatchObject({ toolCalls: calls, finishReason: 'tool_calls' })+ })+})diff --git a/src/lib/provider-stream.ts b/src/lib/provider-stream.tsindex 01d3d369..ce46a415 100644--- a/src/lib/provider-stream.ts+++ b/src/lib/provider-stream.ts@@ -31,41 +31,16 @@ export interface StreamedProviderTurn {}/**- * No-bytes watchdog (audit A7). A backend that wedges mid-stream (crashed- * runner behind a live proxy, half-dead connection) ends neither with data- * nor with an error — the loop just sat on read() forever with the typing- * dots on. Five minutes with not a single chunk is a dead stream, not a slow- * one: reasoners emit thinking deltas while they work, so even "silent"- * phases produce bytes.+ * No watchdog of its own here. Until 30.09.2026 this file wrapped chatStream+ * in a second one (audit A7, 05.08.) that aborted after 300 s without a+ * YIELDED chunk. A provider yields only content, reasoning and the done chunk;+ * tool-call arguments accumulate inside it without a yield. A long file_write+ * on a native model therefore looked stalled while its bytes were still+ * flowing, and the run died with "Stream stalled" in the middle of the write+ * (customer case swift_maple90: 43 aborted requests, the run ended, "continue"+ * repeated the step). Dead lines are caught where the bytes are: readChunks in+ * api/stream-idle.ts, which every provider reads through since 31.08.*/-const STREAM_IDLE_TIMEOUT_MS = 300_000--async function* withIdleGuard<T>(iter: AsyncIterable<T>, idleMs: number): AsyncGenerator<T> {- const it = iter[Symbol.asyncIterator]()- for (;;) {- let timer: ReturnType<typeof setTimeout> | undefined- let next: IteratorResult<T>- try {- next = await Promise.race([- it.next(),- new Promise<never>((_, reject) => {- timer = setTimeout(- () => reject(new Error(`Stream stalled: no data received for ${Math.round(idleMs / 1000)}s.`)),- idleMs,- )- }),- ])- } catch (err) {- try { await it.return?.(undefined as never) } catch { /* releasing the reader is best-effort */ }- throw err- } finally {- clearTimeout(timer)- }- if (next.done) return- yield next.value- }-}-export async function streamProviderTurn(provider: ProviderClient,model: string,@@ -77,7 +52,7 @@ export async function streamProviderTurn(let content = ''let thinking = ''const turn: StreamedProviderTurn = { content: '', toolCalls: [], thinking: '' }- for await (const chunk of withIdleGuard(provider.chatStream(model, messages, options), STREAM_IDLE_TIMEOUT_MS)) {+ for await (const chunk of provider.chatStream(model, messages, options)) {if (chunk.content) {content += chunk.contentonContent?.(content, chunk.content)