Skip to content

fix(web): keep Ask model selection in sync with config changes - #1710

Merged
brendan-kellam merged 3 commits into
mainfrom
jminnetian/fix-SOU-2321
Oct 8, 2026
Merged

brendan-kellam merged 3 commits into
mainfrom
jminnetian/fix-SOU-2321

Conversation

@jsourcebot

@jsourcebot jsourcebot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

LanguageModelProvider was 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 what ChatThread sent.

This regressed in #1295, which moved selection ownership into the layout-level provider to stop a localStorage write loop.

Fix

  • LanguageModelProvider now 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 like inputModalities reflect the current config. If the preference isn't configured, it falls back to the first model.
  • The dropdown (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. ChatBox takes languageModels again for this.
  • The fallback is derived, not written back to storage. Only an explicit user selection writes, so the fix(web): stop rapid localStorage flip when removing a language model #1295 write loop can't come back. The provider stays in the layout so the preference is already loaded when a chat page mounts.

The server still checks the submitted model against the current config, unchanged.

Testing

  • Added 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 real LanguageModelSelector and 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.
  • Three of these tests fail against the previous implementation, including the "selection won't stick" case.
  • src/features/chat and src/ee/features/chat tests 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, and ChatThread all take languageModels from the page and use the same hook, so the dropdown, submit guard, and API payload stay aligned. Adds useSelectedLanguageModel.test.tsx for 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

  • Bug Fixes
    • Ask model selections no longer revert to a stale default when model configuration changes during a browser session. When a saved model is unavailable, chat uses the first available model without overwriting the saved preference.

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

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 4b023277-330f-49a2-92ce-22f9c33245ea
📥 Commits

Reviewing files that changed from the base of the PR and between d7a2e22 and b88a1dc.

📒 Files selected for processing (1)
  • CHANGELOG.md

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: b1c9222c-640f-4446-b921-7719096a37eb
📥 Commits

Reviewing files that changed from the base of the PR and between b4d1a02 and d7a2e22.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • packages/web/src/app/(app)/askgh/[owner]/[repo]/components/landingPage.tsx
  • packages/web/src/app/(app)/chat/components/landingPageChatBox.tsx
  • packages/web/src/app/(app)/layout.tsx
  • packages/web/src/ee/features/chat/components/chatThread/chatThread.tsx
  • packages/web/src/features/chat/components/chatBox/chatBox.tsx
  • packages/web/src/features/chat/components/chatBox/chatBoxToolbar.tsx
  • packages/web/src/features/chat/languageModelContext.tsx
  • packages/web/src/features/chat/useSelectedLanguageModel.test.tsx
  • packages/web/src/features/chat/useSelectedLanguageModel.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The 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 ChatBox.

Changes

Language model selection

Layer / File(s) Summary
Store preference and resolve selection
packages/web/src/features/chat/languageModelContext.tsx, packages/web/src/features/chat/useSelectedLanguageModel.ts, packages/web/src/features/chat/useSelectedLanguageModel.test.tsx, packages/web/src/app/(app)/layout.tsx, CHANGELOG.md
The provider stores the preference without replacing it when a model is unavailable. The hook selects the matching available model, or the first available model, and returns no model when the list is empty. Tests cover preference restoration, configuration changes, fallback behavior, updated capabilities, and an empty model list. The layout no longer loads model configuration for the provider.
Pass available models to chat controls
packages/web/src/features/chat/components/chatBox/chatBox.tsx, packages/web/src/features/chat/components/chatBox/chatBoxToolbar.tsx, packages/web/src/app/(app)/askgh/[owner]/[repo]/components/landingPage.tsx, packages/web/src/app/(app)/chat/components/landingPageChatBox.tsx, packages/web/src/ee/features/chat/components/chatThread/chatThread.tsx
ChatBox requires the available model list. Chat pages, threads, and the toolbar pass that list to ChatBox or the selection hook.

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
Loading

Suggested reviewers: brendan-kellam

Merge Risk: ⚪ Minimal · up to d7a2e

The supplied evidence shows no remaining issue that would prevent merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: keeping the Ask model selection aligned with configuration 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.
Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@brendan-kellam
brendan-kellam merged commit 89cae31 into main Oct 8, 2026
12 of 13 checks passed
@brendan-kellam
brendan-kellam deleted the jminnetian/fix-SOU-2321 branch October 8, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants