fix(web): disambiguate MCP language model selection for ask_codebase

Closed
HA
3mo ago
+174-10

Fixes #1137

Summary

  • match askCodebase requests by provider and model before considering displayName
  • require displayName only when multiple configured models share the same provider and model
  • add focused unit coverage for selection, disambiguation, and not-configured cases
  • extract selectConfiguredLanguageModel into a server-free module so vitest can run without server-only imports
  • refactor selectConfiguredLanguageModel to a discriminated union so askCodebase can 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 lint on touched files (0 errors)
  • yarn build:deps before test run
  • ReadLints clean 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.