fix(web): disambiguate MCP language model selection for ask_codebase
Fixes #1137
Summary
- match
askCodebaserequests byproviderandmodelbefore consideringdisplayName - require
displayNameonly when multiple configured models share the sameproviderandmodel - add focused unit coverage for selection, disambiguation, and not-configured cases
- extract
selectConfiguredLanguageModelinto a server-free module so vitest can run withoutserver-onlyimports - refactor
selectConfiguredLanguageModelto a discriminated union soaskCodebasecan drop the impossible fallback branch
Test plan
-
yarn workspace @sourcebot/web test --run src/ee/features/mcp/askCodebase.test.ts(5 passed: match by provider+model, displayName disambiguation, multi-match error, displayName-mismatch error, not-configured error) -
yarn workspace @sourcebot/web linton touched files (0 errors) -
yarn build:depsbefore test run -
ReadLintsclean for the touched files
Summary by CodeRabbit
- Bug Fixes
- Improved language model selection so the app now picks the correct configured model using provider and model, only asking for a display name when needed.
- Added clearer validation messages when no matching model is found or when multiple matches need disambiguation.
- Expanded automated tests to cover matching, ambiguity, and error cases.
[!NOTE]
Low Risk
Scoped to MCP/blocking ask model resolution and validation messages; no auth or data-path changes.
Overview
Fixes ask_codebase (and the blocking ask path that uses the same helper) so callers can pick a configured model with provider + model alone; displayName is only required when several configs share that pair.
Selection logic moves into selectConfiguredLanguageModel, which returns clearer 400 errors for no match, ambiguous duplicates, or a wrong displayName. askCodebase delegates to that helper instead of comparing via getLanguageModelKey. Vitest coverage exercises match, disambiguation, and error cases.
Reviewed by Cursor Bugbot for commit 57e7cef153e60a134e0c9e3fbedf2c678c672576. Bugbot is set up for automated code reviews on this repo. Configure here.