Repository navigation
Fix multiple model chat always use the chat model, not using the passing model - #18439
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe chat completion flow now clears ChangesChat model selection
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This is a narrowly scoped chat behavior fix, and no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ 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 |
wangq8
left a comment
There was a problem hiding this comment.
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 byrag_agentfor 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: sametenant_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:
-
No persistence side effect —
diais the in-memory object returned byDialogService.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 whytenant_llm_idmust be cleared, otherwise a future refactor may drop it as "redundant". -
Same bug exists in the OpenAI-compatible endpoint —
openai_chat_completionsinapi/apps/restful_apis/openai_api.pyalso doesdia.llm_id = requested_modelwithout clearingdia.tenant_llm_id. A chat configured with a tenant model will likewise ignoremodelin the request body. Consider applying the same fix there for consistency (or confirm it's intentionally out of scope). -
Passing a tenant-model id still works after the fix — since
resolve_model_configfirst triesget_model_config_by_id(id lookup), passing atenant_llmUUID aschat_model_idstill resolves correctly, so no regression there. -
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
No description provided.