Repository navigation
fix(web): keep Ask model selection in sync with config changes - #1710
Conversation
The (app) layout captured the configured models once and never re-rendered on client navigation, so after a config change the provider reset new selections to its stale default. The provider now only stores the preference, and each consumer resolves it against its page's current list.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (1)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughThe language-model provider now stores the preference separately from the configured model list. The selection hook resolves that preference against the models available to each chat component. Chat entry points pass the available models to ChangesLanguage model selection
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant ChatBox
participant useSelectedLanguageModel
participant LanguageModelProvider
ChatBox->>useSelectedLanguageModel: available languageModels
useSelectedLanguageModel->>LanguageModelProvider: read storedLanguageModel
LanguageModelProvider-->>useSelectedLanguageModel: stored preference
useSelectedLanguageModel-->>ChatBox: matching model or first available model
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The supplied evidence shows no remaining issue that would prevent merging after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 9 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes SOU-2321
Problem
If the Ask model config changed while a browser session was open, the model dropdown showed the new models, but picking anything other than the first one didn't stick. Starting a new chat could also send the old default model, which the server then rejected because it was no longer configured.
Root cause
LanguageModelProviderwas mounted in the(app)layout with the model list loaded when the layout first rendered. In Next 16, layouts don't re-render on client-side navigation, so that list went stale. The chat pages load their own fresh list and pass it to the selector. A newly configured model therefore showed up in the dropdown but was missing from the provider's list. The provider's reset effect then replaced the user's choice with the first model from its stale list, and that stale model is whatChatThreadsent.This regressed in #1295, which moved selection ownership into the layout-level provider to stop a localStorage write loop.
Fix
LanguageModelProvidernow only owns the persisted preference (localStorage). It no longer takes a model list, and the layout no longer loads models.useSelectedLanguageModel(languageModels)resolves the preference against the caller's current page list. It returns that list's entry, so capabilities likeinputModalitiesreflect the current config. If the preference isn't configured, it falls back to the first model.ChatBoxToolbar), the chat box (ChatBox) and the request sender (ChatThread) all resolve against the same page list, so the displayed and submitted models always agree.ChatBoxtakeslanguageModelsagain for this.The server still checks the submitted model against the current config, unchanged.
Testing
useSelectedLanguageModel.test.tsx. It mounts the provider once and swaps the page's model list, the way the persistent layout behaves after a config change. It drives the realLanguageModelSelectorand covers keeping a newly configured selection, falling back when the selected model is removed, using current-config capabilities, restoring the stored preference, and the no-models case.src/features/chatandsrc/ee/features/chattests pass (636 tests). Lint is clean on changed files.🤖 Generated with Claude Code
Note
Medium Risk
Changes how Ask resolves and submits the selected LLM across chat UI paths; wrong resolution could send an invalid model until the server rejects it, but scope is client-side state only with existing server validation.
Overview
Fixes Ask model selection drifting after the configured model list changes mid-session. The app layout no longer loads models into
LanguageModelProvider; the provider only persists the user's choice in localStorage.useSelectedLanguageModel(languageModels)now resolves that preference against each page's current model list (so capabilities like image input stay accurate), falls back to the first configured model when the saved choice is gone, and does not write fallbacks back to storage—avoiding both stale layout data and the localStorage write loop from #1295.ChatBox, toolbar, andChatThreadall takelanguageModelsfrom the page and use the same hook, so the dropdown, submit guard, and API payload stay aligned. AddsuseSelectedLanguageModel.test.tsxfor config swaps and removal cases; changelog updated.Reviewed by Cursor Bugbot for commit b88a1dc. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit