Skip to content

Fix multiple model chat always use the chat model, not using the passing model - #18439

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-multiple-model-chat-model-not-used
Aug 18, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-multiple-model-chat-model-not-used

Conversation

@wangq8

@wangq8 wangq8 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Aug 18, 2026
@wangq8 wangq8 added ci Continue Integration and removed 🐞 bug Something isn't working, pull request that fix bug. size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 18, 2026
@coderabbitai

coderabbitai Bot commented Aug 18, 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: 919e0a49-13fa-415c-a5de-838475301cbc

📥 Commits

Reviewing files that changed from the base of the PR and between 15aad78 and 3a5c1d9.

📒 Files selected for processing (1)
  • api/apps/restful_apis/chat_api.py

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The chat completion flow now clears tenant_llm_id when a specific llm_id is supplied. This prevents both model identifiers from remaining set.

Changes

Chat model selection

Layer / File(s) Summary
Clear tenant model state
api/apps/restful_apis/chat_api.py
When the request supplies llm_id, the flow clears dia.tenant_llm_id before applying the selected model configuration.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 3a5c1

This is a narrowly scoped chat behavior fix, and no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: lynn-inf, buua436

Poem

A rabbit chose a model bright,
And cleared the old one out of sight.
One ID hops into the flow,
No stale tenant tags can show.
Clean chat paths now spring just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description, so the required Summary section and background context are missing. Add a Summary section that explains the model-selection bug, the cause, and how clearing tenant_llm_id fixes it.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the main fix: using the selected model for multiple-model chat instead of always using the chat model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 requested a review from Lynn-Inf August 18, 2026 09:12

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

Thanks for the fix! I reviewed the change and the root cause is correct.

Analysis

In session_completion, when a chat_model_id (llm_id) is passed, only dia.llm_id is overwritten while dia.tenant_llm_id keeps its persisted value. Downstream, every model-resolution path prefers the tenant model id when both fields are set:

  • get_models (used by rag_agent for reasoning paths): if dialog.tenant_llm_id: chat_model_config = get_model_config_by_id(... tenant_llm_id ...)
  • async_chat: if dialog.tenant_llm_id: ... get_model_config_by_id(... tenant_llm_id ...)
  • async_chat_solo: same tenant_llm_id-first branch

So for a "multiple model" chat whose tenant_llm_id is set, the passed model is silently ignored. Setting dia.tenant_llm_id = None here forces resolution to go through resolve_model_config(... dialog.llm_id ...), which is the intended behavior.

A couple of notes/requests:

  1. No persistence side effect — dia is the in-memory object returned by DialogService.get_by_id, and the assignment isn't saved, so this only affects the current request. Good. But worth a one-line comment in code explaining why tenant_llm_id must be cleared, otherwise a future refactor may drop it as "redundant".

  2. Same bug exists in the OpenAI-compatible endpoint — openai_chat_completions in api/apps/restful_apis/openai_api.py also does dia.llm_id = requested_model without clearing dia.tenant_llm_id. A chat configured with a tenant model will likewise ignore model in the request body. Consider applying the same fix there for consistency (or confirm it's intentionally out of scope).

  3. Passing a tenant-model id still works after the fix — since resolve_model_config first tries get_model_config_by_id (id lookup), passing a tenant_llm UUID as chat_model_id still resolves correctly, so no regression there.

  4. Tests — this is a small, low-risk fix, but a regression test covering "chat with tenant_llm_id + explicit llm_id in request uses the requested model" would prevent it from silently coming back.

LGTM otherwise.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (c3153ba) to head (3a5c1d9).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #18439   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ 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.

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

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant