Skip to content

fix(model-selector): improve model selection logic for regional models - #2412

Merged
steebchen merged 1 commit into
theopenco:mainfrom
amelitoalcuitas:fix/model-selector-issue
May 26, 2026
Merged

steebchen merged 1 commit into
theopenco:mainfrom
amelitoalcuitas:fix/model-selector-issue

Conversation

@amelitoalcuitas

@amelitoalcuitas amelitoalcuitas commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced model selection parsing to correctly handle regional model URL variants
    • Improved fallback logic when resolving selected models with regional variant mappings
    • Fixed selection behavior to prevent accidental selection of unintended regional model variants, ensuring accurate region-aware selection preferences

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

ModelSelector selection parsing adds region-aware fallback logic to resolve the selected model more robustly from regional model URLs. When direct model ID matching fails, it searches by provider ID and raw model name, and applies region-aware preference for the selected mapping based on whether the input contains a region suffix.

Changes

Region-aware Model Selection

Layer / File(s) Summary
Region-aware selected model and mapping resolution
apps/playground/src/components/model-selector.tsx
Selection parsing for selectedModel introduces a fallback from root model.id lookup to provider + raw modelName matching. Selection of selectedMapping applies region preference: exact modelName matching when region suffix is present in input, otherwise preferring non-regional (!p.region) mappings to avoid unintended regional variant selection.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • theopenco/llmgateway#2224: Updates model-selector parsing to resolve correct provider mappings for region-encoded model IDs, directly related to this PR's regional model URL handling.

Suggested reviewers

  • steebchen
  • smakosh
🚥 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%. 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 and specifically describes the main change: improving model selection logic for regional models in the ModelSelector component.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/playground/src/components/model-selector.tsx`:
- Around line 868-870: selectedModelId currently uses
selectedModelIdRaw.split(":")[0], which removes everything after the first colon
and can mis-parse IDs that contain additional colons; change the logic to locate
the last colon (use lastIndexOf(":")) and strip only the trailing region suffix
so you preserve any internal colons in the ID when computing selectedModelId,
and apply the same trailing-suffix parsing fix to the other similar spots that
handle selectedModelIdRaw/selectedModel resolution in the same block (the code
around selectedModelId, selectedModelIdRaw and selectedModel resolution).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b04f9e7e-c2b9-4fdb-9088-8fdc4c1fcb30

📥 Commits

Reviewing files that changed from the base of the PR and between 7efd3b9 and e22f9de.

📒 Files selected for processing (1)
  • apps/playground/src/components/model-selector.tsx

Comment on lines 868 to 870
const selectedModelId = selectedModelIdRaw.includes(":")
? selectedModelIdRaw.split(":")[0]
: selectedModelIdRaw;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use trailing-suffix parsing instead of first-colon split

Line 868 currently uses split(":")[0], which strips at the first colon. This can mis-parse model IDs containing additional colons and break selectedModel resolution. Use lastIndexOf(":") (same pattern as downstream parsing) to only remove the trailing region suffix.

Suggested fix
-	const selectedModelId = selectedModelIdRaw.includes(":")
-		? selectedModelIdRaw.split(":")[0]
-		: selectedModelIdRaw;
+	const colonIndex = selectedModelIdRaw.lastIndexOf(":");
+	const selectedModelId =
+		colonIndex === -1
+			? selectedModelIdRaw
+			: selectedModelIdRaw.slice(0, colonIndex);

Also applies to: 871-884

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/playground/src/components/model-selector.tsx` around lines 868 - 870,
selectedModelId currently uses selectedModelIdRaw.split(":")[0], which removes
everything after the first colon and can mis-parse IDs that contain additional
colons; change the logic to locate the last colon (use lastIndexOf(":")) and
strip only the trailing region suffix so you preserve any internal colons in the
ID when computing selectedModelId, and apply the same trailing-suffix parsing
fix to the other similar spots that handle selectedModelIdRaw/selectedModel
resolution in the same block (the code around selectedModelId,
selectedModelIdRaw and selectedModel resolution).

@steebchen
steebchen merged commit 00283fa into theopenco:main May 26, 2026
9 checks passed
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