Skip to content

fix: guard http.DefaultTransport type assertion in xiaomi for Go 1.25 - #15787

Merged
yingfeng merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/xiaomi-go125-transport
Jun 8, 2026
Merged

yingfeng merged 3 commits into
infiniflow:mainfrom
xugangqiang:fix/xiaomi-go125-transport

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Problem

TestXiaomiNewModelWithCustomDefaultTransport panics on Go 1.25:

panic: interface conversion: http.RoundTripper is models.roundTripperFunc, not *http.Transport

In Go 1.25, http.DefaultTransport is no longer *http.Transport, so the unchecked type assertion in NewXiaomiModel panics when the test replaces it with a roundTripperFunc.

Fix

Use a safe type assertion with fallback to a new http.Transport, matching the pattern already used in modelscope.go.

Verification

go test -run TestXiaomiNewModelWithCustomDefaultTransport ./internal/entity/models/...
# PASS

Internal contributors only.

🤖 Generated with Claude Code

http.DefaultTransport is no longer *http.Transport in Go 1.25,
causing a panic in NewXiaomiModel. Use a safe type assertion with
fallback to a new Transport, matching the pattern already used in
other models (e.g. modelscope.go).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 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

Run ID: 226e854b-c2a0-4480-ae8b-1ed4c08f5c08

📥 Commits

Reviewing files that changed from the base of the PR and between 180adcc and 8b57166.

📒 Files selected for processing (1)
  • internal/entity/models/xiaomi.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/xiaomi.go

📝 Walkthrough

Walkthrough

Defensive transport initialization in NewXiaomiModel; ChatWithMessages and ChatStreamlyWithSender validate inputs and replace max_tokens with max_completion_tokens; reasoning extraction is refactored; unit tests updated for base-URL selection, SSE behavior, and method guards.

Changes

Xiaomi model updates

Layer / File(s) Summary
Defensive transport cloning with fallback
internal/entity/models/xiaomi.go
NewXiaomiModel type-checks http.DefaultTransport before cloning; if not a *http.Transport, it creates a new http.Transport with ProxyFromEnvironment and applies existing connection/timeouts/compression tuning.
Chat input validation and token param rename
internal/entity/models/xiaomi.go
ChatWithMessages and ChatStreamlyWithSender return an error for empty modelName. When MaxTokens is set, requests use max_completion_tokens instead of max_tokens.
Reasoning and answer extraction refactor
internal/entity/models/xiaomi.go
ChatWithMessages always reads reasoning_content from the response, falls back to GetThinkingAndAnswer if empty and thinking is enabled, and trims leading newlines after derivation.
Unit test adjustments
internal/entity/models/xiaomi_test.go
Tests updated: base-URL override uses "default" region key; malformed SSE frames are skipped without error; CheckConnection succeeds, TranscribeAudio and AudioSpeech return input-validation errors for nil inputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#15350: Both PRs update model constructors to defensively clone http.DefaultTransport only when it’s an *http.Transport, otherwise falling back to a new http.Transport with ProxyFromEnvironment.
  • infiniflow/ragflow#15339: Hardened New*Model transport initialization with the same fallback approach.
  • infiniflow/ragflow#15765: Modifies Xiaomi chat driver request parsing/config and reasoning/content extraction similar to these changes.

Suggested labels

size:S

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped through code with careful paws,
I checked each transport for its cause,
Tokens renamed, reasoning trimmed,
Tests now skip the frames that limped,
A rabbit's patch — no panic, just laws.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description thoroughly explains the problem, provides the fix with context, and includes verification; however, it lacks the required template structure with explicit 'What problem does this PR solve?' and 'Type of change' sections. Reformat the description to match the repository template by adding 'What problem does this PR solve?' and 'Type of change' sections, and check the appropriate change type checkbox (Bug Fix).
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 clearly and specifically summarizes the main fix: guarding an http.DefaultTransport type assertion in the Xiaomi model for Go 1.25 compatibility.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@xugangqiang xugangqiang added the ci Continue Integration label Jun 8, 2026
@xugangqiang
xugangqiang marked this pull request as draft June 8, 2026 12:44
@xugangqiang
xugangqiang marked this pull request as ready for review June 8, 2026 12:44
- Use max_completion_tokens instead of max_tokens (Xiaomi API convention)
- Extract reasoning_content regardless of Thinking setting
- Add model name validation before HTTP call
- Update test: use "default" key for empty-region override
- Update test: malformed SSE frames are silently skipped, not errored
- Update test: TranscribeAudio/AudioSpeech are implemented methods
- Update test: CheckConnection is implemented (checks base URL reachable)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 8, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/entity/models/xiaomi_test.go (1)

131-155: 💤 Low value

Consider renaming test to match the "default" key.

The test name TestXiaomiUsesEmptyRegionBaseURLOverride suggests it uses an empty string key, but line 145 now uses "default" as the map key. Consider renaming to TestXiaomiUsesDefaultRegionBaseURL or similar to match the actual behavior.

🤖 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/entity/models/xiaomi_test.go` around lines 131 - 155, The test
function name TestXiaomiUsesEmptyRegionBaseURLOverride is misleading because the
NewXiaomiModel call uses map key "default"; rename the test to reflect that
(e.g., TestXiaomiUsesDefaultRegionBaseURL) so the test name matches the
behavior; update the test function identifier and any references to
TestXiaomiUsesEmptyRegionBaseURL, keeping the body (NewXiaomiModel, URLSuffix,
ChatWithMessages) unchanged.
🤖 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/entity/models/xiaomi.go`:
- Around line 79-81: Add the same modelName non-empty validation that's in
ChatWithMessages to ChatStreamlyWithSender: detect if modelName == "" at the
start of ChatStreamlyWithSender and return an immediate error (e.g.,
fmt.Errorf("model name is required")) so streaming calls fail fast instead of
later during HTTP construction; update the function ChatStreamlyWithSender to
mirror the validation logic used by ChatWithMessages.

---

Nitpick comments:
In `@internal/entity/models/xiaomi_test.go`:
- Around line 131-155: The test function name
TestXiaomiUsesEmptyRegionBaseURLOverride is misleading because the
NewXiaomiModel call uses map key "default"; rename the test to reflect that
(e.g., TestXiaomiUsesDefaultRegionBaseURL) so the test name matches the
behavior; update the test function identifier and any references to
TestXiaomiUsesEmptyRegionBaseURL, keeping the body (NewXiaomiModel, URLSuffix,
ChatWithMessages) unchanged.
🪄 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: c015ad56-9ba9-4358-915b-198bfcf866c7

📥 Commits

Reviewing files that changed from the base of the PR and between 4030e27 and 180adcc.

📒 Files selected for processing (2)
  • internal/entity/models/xiaomi.go
  • internal/entity/models/xiaomi_test.go

Comment thread internal/entity/models/xiaomi.go Resolved
Match the same guard already present in ChatWithMessages for
consistent error reporting before HTTP request construction.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@yingfeng
yingfeng merged commit 35527f6 into infiniflow:main Jun 8, 2026
1 check passed
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (e81bca7) to head (8b57166).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15787   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xugangqiang
xugangqiang deleted the fix/xiaomi-go125-transport branch July 1, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. 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.

2 participants