Skip to content

fix: 在 reasoning_content 流式输出期间发送进度事件,防止 TUI 卡在 Thinking 状态#426

Merged
Nomikfk1215 merged 3 commits into
1024XEngineer:mainfrom
Nomikfk1215:codex/reasoning-progress-event
May 10, 2026
Merged

fix: 在 reasoning_content 流式输出期间发送进度事件,防止 TUI 卡在 Thinking 状态#426
Nomikfk1215 merged 3 commits into
1024XEngineer:mainfrom
Nomikfk1215:codex/reasoning-progress-event

Conversation

@Nomikfk1215

@Nomikfk1215 Nomikfk1215 commented May 10, 2026

Copy link
Copy Markdown
Collaborator

#424 #425

问题

DeepSeek 兼容模型在生成任何文本内容或工具调用之前,会先流式输出大量 reasoning_content 分片,可能持续数分钟。OpenAI-compatible provider 静默将其累积到 Message.Meta 中,未通知 TUI,导致界面一直卡在 "thinking..." 无任何进度反馈。

修改

  • llm/types.go: ChatRequest 新增 OnStreamProgress 回调字段
  • agent/events.go: 新增 EventThinkingProgress 事件类型及 ReasoningCharCount/ReasoningActive 字段
  • provider/openai.go: 收到 reasoning_content 分片时触发 OnStreamProgress,流结束后发送终止通知
  • agent/completion_runtime.go: 将 OnStreamProgress 桥接为 EventThinkingProgress 事件
  • tui: thinking card 显示 "receiving hidden reasoning..." 进度提示
  • tests: 验证 reasoning_content 触发进度事件且不泄漏到正文

测试计划

  • Provider 测试: reasoning_content 触发进度回调,active/charCount 正确
  • Provider 测试: reasoning_content 不出现在组装后的消息正文中
  • TUI 测试: EventThinkingProgress 创建带进度提示的 thinking card
  • TUI 测试: EventThinkingProgress inactive 移除进度提示
  • TUI 测试: EventAssistantDelta 清除 reasoning progress 状态
  • TUI 测试: EventToolCallStarted 清除 reasoning progress 状态
  • Agent loop 确认: 无硬编码工具调用等待逻辑

🤖 Generated with Claude Code
@

Nomikfk1215 and others added 2 commits May 10, 2026 15:40
…nt TUI stuck on thinking

DeepSeek-compatible models stream reasoning_content chunks before producing any text content or tool calls, which could last minutes. The OpenAI provider silently accumulated these into Message.Meta without notifying the TUI, leaving the UI stuck on thinking with no progress indication.

Add EventThinkingProgress agent/TUI event type that carries only non-sensitive metadata (charCount, active) - never the reasoning text.

- llm/types.go: add OnStreamProgress callback to ChatRequest
- agent/events.go: add EventThinkingProgress and fields
- provider/openai.go: fire OnStreamProgress on reasoning_content chunks
- agent/completion_runtime.go: wire callback to emit progress events
- tui: update thinking card with receiving hidden reasoning note
- tests: verify reasoning_content triggers progress, never leaks to text

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov

codecov Bot commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.35052% with 42 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/mention/index.go 75.18% 21 Missing and 12 partials ⚠️
tui/component_palettes.go 40.00% 6 Missing ⚠️
tui/component_chat_stream.go 78.57% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the changed mention-indexing and reasoning-progress streaming paths across code quality, performance, security, and documentation accuracy. One composability issue stood out.

return runner.client.CreateMessage(ctx, request)
}

request.OnStreamProgress = func(charCount int, active bool) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

completeTurn overwrites any ChatRequest.OnStreamProgress callback that the caller may already have set. That makes the new hook non-composable and can silently break future call sites that want to observe provider progress themselves. Please capture the existing callback and invoke it from this wrapper instead of replacing it outright.

@Nomikfk1215 Nomikfk1215 changed the title fix: emit progress events during reasoning_content streaming to prevent TUI stuck on thinking fix: 在 reasoning_content 流式输出期间发送进度事件,防止 TUI 卡在 Thinking 状态 May 10, 2026
Cover the remaining uncovered branches in completion_runtime.go (0% → covered), tui_adapter.go (EventThinkingProgress mapping), and component_chat_stream.go (updateThinkingCard reasoning note + applyReasoningProgress edge cases).

- agent: test that completeTurn wires OnStreamProgress and emits EventThinkingProgress
- app: test mapAgentEvent maps ReasoningCharCount/ReasoningActive and mapAgentEventType handles EventThinkingProgress
- tui: test updateThinkingCard preserves reasoning note; test applyReasoningProgress skips non-thinking items

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Nomikfk1215

Copy link
Copy Markdown
Collaborator Author

说明:首先先是合了最开始的fix #426 ,后面认为这个fix改得还不够充分想revert重新做,但是revert
之后发现github没有把pr恢复,而是相当于提了一个新的commit,于是此pr为revert前面的revert,补交另一个修复pr

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.

1 participant