feat(llm): SSE streaming fallback for OpenAI & Anthropic chat#35
Merged
Conversation
added 2 commits
May 17, 2026 02:11
When the non-streaming POST returns a 5xx or fails with a transport timeout/connect error, retry the same request with `stream: true` and parse the SSE stream into the same String the trait already returns. Non-retryable errors (4xx including 429) bubble up unchanged. Adds shared `drain_sse_events` helper plus provider-specific parsers for OpenAI Chat Completions (`choices[0].delta.content`, stops on `[DONE]`) and Anthropic Messages (`content_block_delta.delta.text`, stops on `message_stop`, surfaces `error` events). Enables the `stream` feature on reqwest.
Wiremock-driven integration tests covering both branches added in the previous commit: - 5xx on the non-stream POST → retry with stream:true and parse SSE - 4xx (400 / 401) → bubble up unchanged, no fallback Each test asserts the parsed text matches the streamed deltas and that the mock observed exactly one non-stream and zero or one stream call, so a regression that skips or duplicates the fallback path is caught. Adds a sanity factory check that create_llm_provider_raw still wires OpenAIProvider and AnthropicProvider.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9ddfbf969
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
added 2 commits
May 17, 2026 02:22
reqwest::bytes_stream() can split a multi-byte UTF-8 codepoint across chunks. The previous parser called from_utf8 on each raw chunk and silently dropped any chunk that ended mid-codepoint, which truncated streamed completions containing accents, emoji, or CJK text. Buffer the stream as Vec<u8> and only decode once a complete \n\n event has been collected, so partial codepoints stay in the buffer until their continuation bytes arrive. Adds a regression test that splits the 4-byte 🌏 mid-codepoint and a wiremock test streaming Vietnamese + emoji + CJK end-to-end through OpenAIProvider::chat.
Some OpenAI-compatible proxies (e.g. nip.io routers fronting Claude) ignore stream:false and always reply with Content-Type: text/event-stream + HTTP 200. The previous code only checked status, then ran .json() on the response and failed every call with "JSON parse error". Inspect Content-Type on success: when it is text/event-stream, route the response through the existing SSE parser instead of decoding JSON. Adds two regression tests using set_body_raw so the mock advertises the SSE content type.
0bd7826 to
e037f91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Type
feat– New featurefix– Bug fixrefactor– Code restructuringdocs– Documentationtest– Testsperf– Performancechore– MaintenanceChanges
Architecture Area
core/middleware.py)analysis/analyzer.py,analysis/skills.py)agents/registry.py)tools/protocol.py)orchestrator/memory.py)pr/patrol.py)orchestrator/pipeline.py)Pre-submit Checklist
ruff check contribai/passes (lint)ruff format --check contribai/ tests/passes (format)pytest tests/ -vpasses (356+ tests)from __future__ import annotationsat top of new filesgit commit -s)Related Issues