Skip to content

Commit 73bc218

Browse files
dpageclaude
andcommitted
Strictly guard Ollama stream: raise if no terminal done frame received.
Truncated content from a dropped connection should not be treated as a complete response, even if partial text was streamed. Always raise when final_data is None, matching CodeRabbit's recommendation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 933a69e commit 73bc218

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

web/pgadmin/llm/providers/ollama.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,17 @@ def _read_ollama_stream(
434434
input_tokens = data.get('prompt_eval_count', 0)
435435
output_tokens = data.get('eval_count', 0)
436436

437-
# Build final response — only if the stream completed normally
438-
content = ''.join(content_parts)
439-
if final_data is None and not content and not tool_calls:
437+
# Ensure the stream completed with a terminal done frame;
438+
# truncated content from a dropped connection is unreliable.
439+
if final_data is None:
440440
raise LLMClientError(LLMError(
441-
message="Stream ended without a complete response",
441+
message="Ollama stream ended before terminal done frame",
442442
provider=self.provider_name,
443443
retryable=True
444444
))
445445

446+
content = ''.join(content_parts)
447+
446448
if tool_calls:
447449
stop_reason = StopReason.TOOL_USE
448450
elif done_reason == 'stop':

0 commit comments

Comments
 (0)