#21998: fix(models): prioritize exact model-id match over fuzzy scoring (#21942)
docs
size: XS
experienced-contributor
Cluster:
Model Configuration Fixes
## Summary
- **Bug**: Model resolver fuzzy-matches `gemini-3.1-pro-preview` to wrong model (`gemini-3-flash-preview` or `gemini-3.1-pro`)
- **Root cause**: `resolveFuzzy` in `model-selection.ts` runs fuzzy scoring without first checking for exact model ID matches
- **Fix**: Add exact model-id match check before fuzzy scoring in `resolveFuzzy`
Fixes #21942
## Problem
The `resolveFuzzy` function in `src/auto-reply/reply/model-selection.ts` scores all candidate models using weighted fuzzy matching (Levenshtein distance, substring matching, variant token penalties). When model names are similar (e.g. `gemini-3.1-pro-preview` vs `gemini-3-flash-preview` vs `gemini-3.1-pro`), the scoring can pick the wrong candidate because:
1. The `FUZZY_VARIANT_TOKENS` list includes "preview", and variant token penalties can reduce the score of the correct model
2. Levenshtein distance between similar model names may favor a shorter/different model
**Before fix:**
Input: `"gemini-3.1-pro-preview"`
Output: resolves to `gemini-3-flash-preview` or `gemini-3.1-pro` (wrong)
## Changes
- `src/auto-reply/reply/model-selection.ts` — add exact model-id match check at the top of `resolveFuzzy`, before fuzzy scoring
- `src/auto-reply/reply/model-selection.test.ts` — add regression test for exact match priority
**After fix:**
Input: `"gemini-3.1-pro-preview"`
Output: resolves to `gemini-3.1-pro-preview` (correct exact match)
## Test plan
- [x] New test: exact model ID resolves correctly over fuzzy candidates
- [x] All existing model-selection tests pass
- [x] Lint passes
## Effect on User Experience
**Before:** Using `/model gemini-3.1-pro-preview` could switch to the wrong model (e.g. `gemini-3-flash-preview`), causing unexpected behavior and confusion.
**After:** Exact model ID matches always take priority, so `/model gemini-3.1-pro-preview` correctly selects that exact model.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a model resolution bug where similar model names like `gemini-3.1-pro-preview` would incorrectly resolve to wrong candidates (`gemini-3-flash-preview` or `gemini-3.1-pro`) due to fuzzy scoring with variant token penalties.
**Key changes:**
- Added exact model-id match check before fuzzy scoring in `resolveFuzzy` function (src/auto-reply/reply/model-selection.ts:488-492)
- Added regression test to verify exact matches take priority over fuzzy matches
- Fixed telegram model-buttons parser to allow colons in provider names (e.g. `ollama:cloud`)
**How it works:**
The fix adds a simple exact match check that runs before the complex fuzzy scoring logic. When a user specifies a model like `gemini-3.1-pro-preview`, the resolver now checks if any candidate's model ID exactly matches the input (case-insensitive) before attempting fuzzy matching with Levenshtein distance and variant token penalties.
The telegram fix updates the regex pattern for parsing `mdl_list_{provider}_{page}` callback data to allow colon characters in provider names, preventing spurious LLM runs when using providers like `ollama:cloud`.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are minimal, well-tested, and directly address the reported bug. The exact match check is a simple, defensive addition that runs before fuzzy scoring, so it cannot break existing behavior - it only prevents incorrect fuzzy matches. The test coverage verifies the fix works as intended. The telegram regex change is also straightforward and properly tested.
- No files require special attention
<sub>Last reviewed commit: 611829d</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23136: fix: lookupContextTokens should handle provider/model refs
by patchguardio · 2026-02-22
79.1%
#21181: fix(models): add gemini-3.1-pro-preview forward-compat for google-g...
by Mellowambience · 2026-02-19
78.4%
#11198: fix(models): strip @profile suffix from model selection
by mcaxtr · 2026-02-07
78.2%
#20136: Telegram: fix cross-provider model checkmark in /models keyboard
by powerdot · 2026-02-18
78.1%
#9905: fix: require provider prefix for models set without alias (#5790)
by petter-b · 2026-02-05
77.9%
#13626: fix(model): propagate provider model properties in fallback resolution
by mcaxtr · 2026-02-10
77.7%
#23542: fix/hf inference
by Josephrp · 2026-02-22
76.9%
#21992: fix(telegram): allow colon in provider name for model callback pars...
by lailoo · 2026-02-20
76.1%
#19576: fix: tighten isSilentReplyText to match whole-text only
by aldoeliacim · 2026-02-18
75.7%
#21263: fix: add google-vertex support for Gemini 3.1 models
by pdd-cli · 2026-02-19
75.6%