Skip to content

fix(inference): report provider errors and cut-off cloud chat streams - #355

Merged
ganisback merged 1 commit into
OpenCSGs:mainfrom
pcbeingused333:fix/c6417-cloud-stream-errors
Nov 28, 2026
Merged

ganisback merged 1 commit into
OpenCSGs:mainfrom
pcbeingused333:fix/c6417-cloud-stream-errors

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

When an OpenAI-compatible provider answers 200 and then fails mid-stream, Chat returns the partial text with a nil error, so a truncated answer looks complete.

Cause: openAIEngine.handleStreamWithCacheUsage skips data: {"error": ...} events (they have no choices) and does not check that the stream actually finished before returning scanner.Err().

Fix:

  • an in-stream error payload (object or string) is returned as an error carrying the provider's message;
  • a stream that emitted events but ended with neither [DONE] nor a finish_reason returns io.ErrUnexpectedEOF, as the llama engine already does for a missing [DONE];
  • finish_reason without [DONE] is still accepted, and an open <think> block is closed in that case too;
  • responses with no data: events behave as before.

This affects callers of Chat (for example /api/chat with a cloud or third-party model). The raw /v1/chat/completions proxy path does not go through this code.

Tests: new cases in internal/inference/openai_stream_error_test.go fail without the change and pass with it. go test ./internal/inference/ passes, as do the chat, provider and gateway related tests in internal/server.

This change was prepared with AI assistance.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ganisback
ganisback merged commit 9c1e90f into OpenCSGs:main Nov 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants