Skip to content

OpenRouter-compatible streaming can crash on empty tool-call arguments #1150

Description

@bechovang

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:
Error:  is empty
  • 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions