Skip to content

fix(tui): guard reasoning_content behind provider check to prevent TUI display corruption from third-party APIs#1680

Closed
LittleBlacky wants to merge 1 commit into
Hmbown:mainfrom
LittleBlacky:fix/third-party-reasoning-content-display
Closed

fix(tui): guard reasoning_content behind provider check to prevent TUI display corruption from third-party APIs#1680
LittleBlacky wants to merge 1 commit into
Hmbown:mainfrom
LittleBlacky:fix/third-party-reasoning-content-display

Conversation

@LittleBlacky

Copy link
Copy Markdown

Problem

When using a third-party OpenAI-compatible API provider that returns reasoning_content fields in streaming SSE chunks, deepseek-tui incorrectly treats every token as a separate "thinking" block instead of normal text output. This causes severe display corruption where each character/token is rendered with its own thinking done · 0.0s header.

Fixes #1673

Root Cause

  1. is_reasoning_model() checks only the model name (e.g., deepseek-v4-pro, deepseek-v4-flash) to decide whether reasoning_content deltas should be treated as thinking blocks — it does not consider whether the current provider actually supports reasoning content semantics.

  2. When a non-DeepSeek provider streams reasoning_content fields alongside normal response text, every chunk triggers the thinking UI path, corrupting the display.

Fix

  • Added requires_reasoning_content() helper that returns true only for the native DeepSeek provider (ProviderKind::Deepseek).
  • Updated handle_chat_completion_stream() to use requires_reasoning_content(api_provider) instead of is_reasoning_model(model) when deciding whether to emit StreamEvent::ReasoningDelta.
  • Updated parse_sse_chunk() to accept the provider kind and use the same gate.

This ensures third-party OpenAI-compatible providers that happen to serve DeepSeek models are not incorrectly treated as supporting DeepSeek's reasoning content protocol, while preserving full native DeepSeek reasoning display.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to differentiate how various API providers handle reasoning_content in streaming deltas, specifically addressing third-party proxies that use this field for standard response text. Feedback includes a request to add NvidiaNim to the list of supported reasoning providers to avoid regressions, a suggestion to refine the tool call detection by checking for non-empty arrays rather than just the presence of the field, and a recommendation to adjust the fallback logic to prevent potential data loss when both reasoning and tool calls are present in the same chunk.

Comment thread crates/tui/src/client/chat.rs
Comment thread crates/tui/src/client/chat.rs Outdated
Comment thread crates/tui/src/client/chat.rs
@LittleBlacky LittleBlacky force-pushed the fix/third-party-reasoning-content-display branch from 64084fe to 0316407 Compare May 15, 2026 09:16
@LittleBlacky LittleBlacky reopened this May 15, 2026
@LittleBlacky LittleBlacky force-pushed the fix/third-party-reasoning-content-display branch from 0316407 to b5bf0a5 Compare May 15, 2026 13:21
@LittleBlacky LittleBlacky changed the title fix: skip reasoning_content from non-DeepSeek providers to prevent TUI display corruption fix(tui): guard reasoning_content behind provider check to prevent TUI display corruption from third-party APIs May 15, 2026
@Hmbown Hmbown added this to the v0.8.39 milestone May 15, 2026
@Hmbown

Hmbown commented May 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the provider-gated reasoning_content fix. The scoped behavior was harvested into v0.8.39 via #1734 and credited in the changelog, so I am closing this PR to keep the queue clean. If a generic OpenAI-compatible provider still renders answer text as repeated thinking blocks on latest, please reopen with the provider/model and one raw SSE chunk.

@Hmbown Hmbown closed this May 17, 2026
@LittleBlacky LittleBlacky deleted the fix/third-party-reasoning-content-display branch May 17, 2026 15:26
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.

reasoning_content 字段导致第三方中转 OpenAI格式 兼容 API 显示严重错乱

2 participants