fix(llm): add HTTP-status and transport-level retry to Ollama backend#6531
Merged
Conversation
Ollama's chat/chat_stream/chat_with_tools sent every request through ollama-rs with no retry, so a single 429/503 or transient connection failure failed the whole turn immediately, unlike Claude/OpenAI/Gemini. ollama-rs discards HTTP status codes on non-2xx responses, so ollama.rs now posts chat requests directly via a dedicated reqwest client, reusing ChatMessageRequest/ChatMessageResponse only for serialization, letting retry::send_with_retry retry on real 429/503 with Retry-After support. A second layer, send_with_transport_retry, retries transient transport failures (timeout, mid-request connection reset) that never reach send_with_retry's status inspection. Connect-phase failures stay unretried and keep RouterProvider's fallback diagnostics intact. Also fixes a UTF-8 chunk-boundary data-loss bug in the streaming NDJSON parser this change introduces: it now buffers raw bytes across chunks and decodes only once a complete line is assembled, instead of decoding each chunk independently and silently dropping one that splits a multi-byte character. Closes #6491
bug-ops
enabled auto-merge (squash)
July 20, 2026 00:38
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.
Summary
chat/chat_stream/chat_with_toolssent every request throughollama-rswith no retry, so a single 429/503 or transient connection failure failed the whole turn immediately, unlike Claude/OpenAI/Gemini.ollama-rsdiscards HTTP status codes on non-2xx responses, soollama.rsnow posts chat requests directly via a dedicatedreqwestclient, reusingChatMessageRequest/ChatMessageResponseonly for serialization, lettingretry::send_with_retryretry on real HTTP 429/503 withRetry-Aftersupport — the same helper Claude/OpenAI/Gemini use.send_with_transport_retry, retries transient transport failures (timeout, mid-request connection reset) that never reachsend_with_retry's status inspection. Connect-phase failures stay unretried and keepRouterProvider's fallback diagnostics (RouterProvider::chat and chat_stream discard last provider error on fallback exhaustion #5821) intact.Closes #6491
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --binsRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"chat_with_toolsintegration test passchat_with_toolsretry