Repository navigation
Fix chat thinking & Figure issue in GO - #16558
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdates LLM request/response handling, reasoning-state streaming, reference chunk normalization, and SSE answer chunk fields to carry start/end reasoning signals. ChangesThink-tag cleanup and reasoning-state streaming
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Model as LLM Provider
participant ChatPipelineService
participant ThinkStreamState
participant ChatSession
participant Client
Model->>ChatPipelineService: streamed delta
ChatPipelineService->>ThinkStreamState: EnterReasoning() / ExitReasoning()
ChatPipelineService->>ChatSession: StartToThink / EndToThink
ChatPipelineService->>ChatSession: delta or final chunk
ChatSession->>Client: SSE data event
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/agent/component/llm.go (1)
537-550: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winParse
json_outputfrom the cleaned response.Line 539 normalizes fenced/think-prefixed JSON into
cleaned, but Line 550 still unmarshalsresp.Content, soout["json"]is omitted even when"content"now contains valid JSON.Proposed fix
- if err := json.Unmarshal([]byte(resp.Content), &parsed); err == nil { + if err := json.Unmarshal([]byte(cleaned), &parsed); err == nil {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/component/llm.go` around lines 537 - 550, The JSON parsing in the response assembly is still using resp.Content instead of the normalized cleaned value, so json_output can be dropped after formatting cleanup. Update the p.JSONOutput branch in the llm response handling to unmarshal the cleaned response content (the same value assigned to out["content"]) and keep the existing fallback behavior if parsing fails. Use the cleaned variable and the json_output logic in the llm.go response builder to locate the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/chat_pipeline.go`:
- Around line 1105-1117: Keep ThinkStreamState synchronized with inReasoning in
the chat pipeline: the reasoning branch currently streams deltas without
updating thinkState.fullText with the matching <think>/<think> markers, and the
stream can finish while inReasoning is still true so EndToThink is never
emitted. Add shared enter/exit helpers around the reasoning transitions in the
ChatPipeline flow (the blocks using NextThinkDelta, inReasoning, and thinkState)
to append the proper markers when reasoning starts/ends, and make sure the
post-driver final flush closes any still-open reasoning state before returning
the last result.
In `@internal/service/chat_session.go`:
- Around line 1951-1952: The think-marker flags in sseAnswerChunk are always
being serialized by sseMarshalChunk, which causes false values to appear in the
SSE payload instead of being omitted. Update the StartToThink and EndToThink
JSON tags to use omitempty so the SSE shape matches the existing async chat
fields, and verify the serialization path in sseMarshalChunk still emits only
set markers.
---
Outside diff comments:
In `@internal/agent/component/llm.go`:
- Around line 537-550: The JSON parsing in the response assembly is still using
resp.Content instead of the normalized cleaned value, so json_output can be
dropped after formatting cleanup. Update the p.JSONOutput branch in the llm
response handling to unmarshal the cleaned response content (the same value
assigned to out["content"]) and keep the existing fallback behavior if parsing
fails. Use the cleaned variable and the json_output logic in the llm.go response
builder to locate the fix.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a850d851-f10e-495e-a422-fc7415e047d6
📒 Files selected for processing (3)
internal/agent/component/llm.gointernal/service/chat_pipeline.gointernal/service/chat_session.go
5f0228a to
138bb85
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/service/chat_pipeline.go (2)
4093-4102: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winFormat SQL chunks after metadata enrichment.
buildSQLReferencenow converts backend keys likedoc_id/kb_idto frontend keys beforeAsyncChatre-readsreference["chunks"]for metadata enrichment. That caller checks backend-shaped fields such askb_id, so SQL references can lose metadata or multi-KB disambiguation. Return raw chunks here, then applychunksFormatimmediately before emitting the final SQL result after enrichment.🧩 Proposed direction
- ref["chunks"] = chunksFormat(chunks) + ref["chunks"] = chunks @@ - ref["chunks"] = chunksFormat(chunks) + ref["chunks"] = chunksThen format
ans["reference"]["chunks"]after the enrichment block and just before sending the SQLAsyncChatResult.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/service/chat_pipeline.go` around lines 4093 - 4102, `buildSQLReference` is formatting `chunks` too early, which prevents `AsyncChat` from finding backend-shaped metadata fields like `kb_id` and `doc_id` during enrichment. Change `buildSQLReference` to return raw chunks for SQL references, then apply `chunksFormat` later in the `AsyncChat` flow after the metadata enrichment block and immediately before emitting the final SQL `AsyncChatResult`, using the existing `buildSQLReference`, `AsyncChat`, and `chunksFormat` symbols to place the fix.
1117-1123: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winDo not synthesize TTS for reasoning deltas.
These branches are inside model reasoning, but they produce
AudioBinaryfrom reasoning text. With TTS enabled, clients can play reasoning audio; the tool-stream path already keeps reasoning audionil. Reserve TTS for answer deltas afterEndToThink.🔇 Proposed fix
- AudioBinary: s.synthesizeTTS(ttsModel, d.Value), + AudioBinary: nil,Apply the same change to the reasoning flushes before emitting
EndToThink.Also applies to: 1131-1139, 1434-1440, 1448-1456
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/service/chat_pipeline.go` around lines 1117 - 1123, Reasoning deltas in the ThinkDeltaText branches are still being passed to s.synthesizeTTS and emitted as AudioBinary. Update the reasoning paths in chat_pipeline.go, including the flushes before EndToThink, so AsyncChatResult for reasoning text keeps AudioBinary nil and only answer deltas after EndToThink invoke TTS. Use the existing ThinkDeltaText and EndToThink flow to locate and mirror the tool-stream behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/service/chat_pipeline.go`:
- Around line 4093-4102: `buildSQLReference` is formatting `chunks` too early,
which prevents `AsyncChat` from finding backend-shaped metadata fields like
`kb_id` and `doc_id` during enrichment. Change `buildSQLReference` to return raw
chunks for SQL references, then apply `chunksFormat` later in the `AsyncChat`
flow after the metadata enrichment block and immediately before emitting the
final SQL `AsyncChatResult`, using the existing `buildSQLReference`,
`AsyncChat`, and `chunksFormat` symbols to place the fix.
- Around line 1117-1123: Reasoning deltas in the ThinkDeltaText branches are
still being passed to s.synthesizeTTS and emitted as AudioBinary. Update the
reasoning paths in chat_pipeline.go, including the flushes before EndToThink, so
AsyncChatResult for reasoning text keeps AudioBinary nil and only answer deltas
after EndToThink invoke TTS. Use the existing ThinkDeltaText and EndToThink flow
to locate and mirror the tool-stream behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6a096c70-4cd9-4476-b252-691c159073b9
📒 Files selected for processing (4)
internal/agent/component/llm.gointernal/service/chat_pipeline.gointernal/service/chat_session.gointernal/service/think_tag.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/agent/component/llm.go
- internal/service/chat_session.go
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUpdates LLM thinking config and answer cleanup, adds reasoning-state streaming signals, normalizes reference chunks, and extends SSE answer chunks with start/end reasoning flags. ChangesThink-tag cleanup and reasoning-state streaming
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ChatPipelineService
participant ThinkStreamState
participant ChatCompletions
participant Client
ChatPipelineService->>ThinkStreamState: EnterReasoning() / ExitReasoning()
ChatPipelineService->>ChatCompletions: StartToThink / EndToThink / answer delta
ChatCompletions->>Client: SSE data event
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
42bf7f2 to
f0ab57f
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16558 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f0ab57f to
d9efb58
Compare
### Summary Fix chat thinking & Figure issue
### Summary Fix chat thinking & Figure issue
Summary
Fix chat thinking & Figure issue