Skip to content

Go: porting #18663 - #18726

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/porting-18663-to-go
Aug 25, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/porting-18663-to-go

Conversation

@wangq8

@wangq8 wangq8 commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 25, 2026
@wangq8 wangq8 added the ci Continue Integration label Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba99ab08-70df-4e50-81ce-78f857366ddd

📥 Commits

Reviewing files that changed from the base of the PR and between 8968750 and dfc0e9a.

📒 Files selected for processing (3)
  • internal/entity/models/base_model.go
  • internal/entity/models/types.go
  • internal/service/chat_pipeline.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The chat pipeline now normalizes messages to the chat-completions schema and preserves name, function-call, refusal, audio, and tool-call fields. Message assembly no longer drops messages solely because content is nil.

Changes

Chat message schema preservation

Layer / File(s) Summary
Extended message contract
internal/entity/models/types.go, internal/entity/models/base_model.go
The Message model and API payload builder now support name, function_call, refusal, and audio fields.
History normalization
internal/service/chat_pipeline.go
AsyncChat and AsyncChatSolo filter history messages to supported schema fields before citation cleanup.
Message map conversion
internal/service/chat_pipeline.go
Message conversion preserves supported metadata and tool calls. buildChatMessages skips only messages with an empty role.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to dfc0e

This change updates chat pipeline handling and related model types; no actionable merge-blocking risk remains in the supplied evidence.

Sequence Diagram(s)

sequenceDiagram
  participant AsyncChat
  participant normalizeLLMMessage
  participant LLMDriver
  AsyncChat->>normalizeLLMMessage: Normalize history message
  normalizeLLMMessage-->>AsyncChat: Return supported schema fields
  AsyncChat->>LLMDriver: Send normalized messages
Loading

Suggested reviewers: jinhai-cn, haruko386

Poem

A rabbit checked each message line

And kept the fields in proper design
Names and audio joined the call
Tool calls crossed the schema wall
Clean messages now hop fine!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description, but the repository template requires a Summary section with the purpose and background of the change. Add a Summary section that explains the chat-completions message normalization changes, the provider compatibility problem, and how this Go port addresses it.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies this as a Go port of issue #18663, which matches the pull request objective and changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is an AI review comment.

Thanks for porting #18663 to Go. The allowlist approach correctly stops bookkeeping keys (id, created_at, conversationId, doc_ids) from reaching strict providers, and threading name / tool_calls / tool_call_id / function_call / refusal / audio through Message is consistent with the Python LLM_MESSAGE_FIELDS set. A few things to address before merge:

  1. Missing tests. The Python PR ships 4 regression tests; this port adds none. normalizeLLMMessage and modelMessageFromMap (especially the tool_calls type-switch between []map[string]interface{} and []interface{}) are exactly the kind of code that silently regresses. Please add Go unit tests covering: bookkeeping keys dropped, tool_calls / tool_call_id preserved, caller map not mutated, and multimodal content-part arrays forwarded unchanged.

  2. content == nil guard dropped in buildChatMessages (chat_pipeline.go). The old code skipped messages with content == nil; the new code only skips role == "". A stored message with a role but nil content and no tool_calls will now be serialized by base_model.go as "content": null, which a strict provider (Groq is the very provider this targets) may reject. Suggest keeping the guard but allowing tool-call messages, e.g. skip only when role == "" || (content == nil && no tool_calls && no tool_call_id).

  3. Scope is broader than the Python original. In Python, async_chat / async_chat_solo still rebuild messages as role/content only; the allowlist was applied to rag_agent alone. Here AsyncChat / AsyncChatSolo now forward name / tool_calls / function_call / refusal / audio on all paths, not just the reasoning path. That is arguably a correctness improvement (tool history is no longer dropped), but it is a behavior change beyond the port — please confirm it is intended.

  4. Message.Name is typed interface{}. OpenAI's name field is a string, and the other scalar field (ToolCallID) uses string. Using interface{} loses type safety and forces the msg.Name != nil check in base_model.go to rely on interface nil-ness. Prefer string (with omitempty) or *string.

Minor: modelMessageFromMap reuses stringFromMap from bot.go, which is documented for entity.JSONMap (prompt_config) reads. It works because map[string]interface{} is assignable to entity.JSONMap, but a dedicated helper in this file would be clearer.

This is an AI review comment.

@wangq8
wangq8 merged commit 40326f1 into infiniflow:main Aug 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant