@@ -451,6 +451,47 @@ describe("createOllamaStreamFn thinking events", () => {
451451 expect ( yieldedBeforeDone ) . toBe ( true ) ;
452452 } ) ;
453453
454+ it ( "refreshes the guarded-fetch idle timeout for each streamed chunk" , async ( ) => {
455+ const chunks = [
456+ {
457+ model : "qwen3.5" ,
458+ created_at : "2026-01-01T00:00:00Z" ,
459+ message : { role : "assistant" as const , content : "Hello" } ,
460+ done : false ,
461+ } ,
462+ {
463+ model : "qwen3.5" ,
464+ created_at : "2026-01-01T00:00:01Z" ,
465+ message : { role : "assistant" as const , content : " world" } ,
466+ done : false ,
467+ } ,
468+ makeOllamaResponse ( { content : "" } ) ,
469+ ] ;
470+ const body = makeNdjsonBody ( chunks ) ;
471+ const refreshTimeout = vi . fn ( ) ;
472+ fetchWithSsrFGuardMock . mockResolvedValue ( {
473+ response : new Response ( body , { status : 200 } ) ,
474+ release : vi . fn ( async ( ) => undefined ) ,
475+ refreshTimeout,
476+ } ) ;
477+
478+ const streamFn = createOllamaStreamFn ( "http://localhost:11434" ) ;
479+ const stream = streamFn (
480+ { api : "ollama" , provider : "ollama" , id : "qwen3.5" , contextWindow : 65536 } as never ,
481+ { messages : [ { role : "user" , content : "test" } ] } as never ,
482+ { } ,
483+ ) ;
484+
485+ const events : Array < { type : string } > = [ ] ;
486+ for await ( const event of stream as AsyncIterable < { type : string } > ) {
487+ events . push ( event ) ;
488+ }
489+
490+ // One refresh per consumed NDJSON chunk keeps the deadline a no-progress
491+ // timeout instead of a wall-clock cap on slow remote Ollama hosts.
492+ expect ( refreshTimeout ) . toHaveBeenCalledTimes ( chunks . length ) ;
493+ } ) ;
494+
454495 it ( "reports caller aborts during dense native stream processing as aborted" , async ( ) => {
455496 const chunks = [
456497 ...Array . from ( { length : 65 } , ( _value , index ) => ( {
0 commit comments