Repository navigation
fix(providers): do not retry an Ollama stream after output was emitted - #1701
Open
pcbeingused33 wants to merge 1 commit into
Open
pcbeingused33 wants to merge 1 commit into
pcbeingused33 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
clark-cant
reviewed
Nov 26, 2026
clark-cant
left a comment
Contributor
There was a problem hiding this comment.
Review: fix(providers): do not retry an Ollama stream after output was emitted
Summary: OllamaProvider.ChatStream wraps the whole client.Chat call, including onChunk delivery, in RetryDo. A mid-stream failure after chunks were delivered replays the request and duplicates the already-delivered text, so a cut after Hel reaches the caller as HelHelHel. This PR tracks whether any content/thinking chunk reached onChunk and, if so, surfaces the stream error without retrying.
Risk level: Low
Mandatory gates:
- Duplicate / prior implementation: clear. No prior or open PR/issue implements this. The sibling CodexProvider.ChatStream already applies the same no-replay-after-emit rule at internal/providers/codex.go:152, and docs/02-providers.md:224 documents the intended streaming contract: once SSE events start flowing, no retry occurs mid-stream. This PR brings the Ollama streaming path in line with it.
- Project standards: docs found. AGENTS.md, CLAUDE.md, CONTRIBUTING.md and docs/02-providers.md cover provider retry conventions; the change touches no i18n, SQL or migration surfaces.
- Strategic necessity: clear value. Correctness bug fix for duplicated streamed output on a supported provider, small and well-scoped, from a repeat contributor.
Findings:
- Critical: none
- Important: none
- Suggestion: none blocking. The emitted flag covers content and thinking chunks only, which matches what is delivered through onChunk since tool calls are accumulated rather than streamed, so the retry guard is correct.
Verification:
- Diff is focused: 2 files, +47/-4 in internal/providers/ollama.go and internal/providers/ollama_test.go.
- New test TestOllamaChatStream_NoRetryAfterChunkEmitted asserts one request, Hel delivered once, and an error returned.
- mergeStateStatus CLEAN / MERGEABLE; CI green: go, web, release-versioning all pass.
Verdict: Approve
Merge note: merge-ready with CLEAN state and green CI, but carries 0 approvals, so this automation does not merge; a maintainer approval is required.
Posted by /ck:review-pr at 2026-11-26T13:09:00Z
6 tasks done
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
OllamaProvider.ChatStreamwraps the wholeclient.Chatcall, including theonChunkcallbacks, inRetryDo. If the connection drops mid-stream (e.g.unexpected EOF, which is retryable), the request is replayed and the caller receives the already delivered text again: a stream cut afterHelreaches the caller asHelHelHel. Once a content or thinking chunk has been passed toonChunk, a stream error is now returned without retrying, the same ruleCodexProvider.ChatStreamalready applies. Failures before any output are retried as before.Type
main)Target Branch
devChecklist
go build ./...passesgo build -tags sqliteonly ./...passes (if Go changes)go vet ./internal/providers/passesgo test -race ./internal/providers/cd ui/web && pnpm build(if UI changes) (no UI changes)$1, $2(no string concat) (no SQL changes)internal/upgrade/version.go(if new migration) (no migration)Test Plan
TestOllamaChatStream_NoRetryAfterChunkEmitteduses anhttptestserver that sends one chunk and aborts the connection. Without the fix it sees 3 requests andHelHelHel; with it, 1 request,Heland an error.This PR was prepared with AI assistance (Claude Code); the change and tests were generated and run by the assistant, and the submitter has not independently reviewed the code line by line.