Summary
When using OpenRouter-compatible chat providers, the streaming tool-call parser in src/lib/models/providers/openai/openaiLLM.ts can throw on empty or partial function.arguments chunks.
This leaves the UI stuck on Brainstorming... because the research request dies before the client receives a clean end/error state.
Symptoms
- UI stays on
Brainstorming... for a long time
- Server logs show an error similar to:
- Research never transitions into
Research Progress or a proper error state
Root Cause
Some OpenAI-compatible providers stream tool-call arguments incrementally and may emit an empty or incomplete arguments chunk before the final JSON is complete. The current implementation parses each chunk immediately and throws.
Proposed Fix
- Treat empty
arguments chunks as {}
- Gracefully ignore parse failures for partial chunks until the JSON stream is complete
- Continue streaming instead of crashing the request
Additional Context
The generic Brainstorming... state gives little feedback when research has not started yet, so a small UI improvement to show elapsed time and likely wait reasons can help debugging.
Summary
When using OpenRouter-compatible chat providers, the streaming tool-call parser in
src/lib/models/providers/openai/openaiLLM.tscan throw on empty or partialfunction.argumentschunks.This leaves the UI stuck on
Brainstorming...because the research request dies before the client receives a clean end/error state.Symptoms
Brainstorming...for a long timeResearch Progressor a proper error stateRoot Cause
Some OpenAI-compatible providers stream tool-call arguments incrementally and may emit an empty or incomplete
argumentschunk before the final JSON is complete. The current implementation parses each chunk immediately and throws.Proposed Fix
argumentschunks as{}Additional Context
The generic
Brainstorming...state gives little feedback when research has not started yet, so a small UI improvement to show elapsed time and likely wait reasons can help debugging.