fix(model-availability): prefer exact model ID match in fuzzyMatchModel (#1460)

* fix(model-availability): prefer exact model ID match in fuzzyMatchModel

* fix(model-availability): use filter+shortest for multi-provider tie-break

- Change Priority 2 from find() to filter()+reduce()
- Preserves shortest-match tie-break when multiple providers share model ID
- Add test for multi-provider same model ID case
- Addresses Oracle review feedback
This commit is contained in:
YeonGyu-Kim
2026-02-04 11:25:59 +09:00
committed by GitHub
parent c57c0a6bcb
commit faae3d0f32
2 changed files with 53 additions and 2 deletions
+17 -2
View File
@@ -72,14 +72,29 @@ export function fuzzyMatchModel(
return null
}
// Priority 1: Exact match (normalized)
// Priority 1: Exact match (normalized full model string)
const exactMatch = matches.find((model) => normalizeModelName(model) === targetNormalized)
if (exactMatch) {
log("[fuzzyMatchModel] exact match found", { exactMatch })
return exactMatch
}
// Priority 2: Shorter model name (more specific)
// Priority 2: Exact model ID match (part after provider/)
// This ensures "glm-4.7-free" matches "zai-coding-plan/glm-4.7-free" over "zai-coding-plan/glm-4.7"
// Use filter + shortest to handle multi-provider cases (e.g., openai/gpt-5.2 + opencode/gpt-5.2)
const exactModelIdMatches = matches.filter((model) => {
const modelId = model.split("/").slice(1).join("/")
return normalizeModelName(modelId) === targetNormalized
})
if (exactModelIdMatches.length > 0) {
const result = exactModelIdMatches.reduce((shortest, current) =>
current.length < shortest.length ? current : shortest,
)
log("[fuzzyMatchModel] exact model ID match found", { result, candidateCount: exactModelIdMatches.length })
return result
}
// Priority 3: Shorter model name (more specific, fallback for partial matches)
const result = matches.reduce((shortest, current) =>
current.length < shortest.length ? current : shortest,
)