Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Nov 5, 2025

This PR fixes issue #9047 where switching providers after selecting a model causes a TypeError.

Problem

When users switch providers after selecting a model, the router models for the new provider may not be loaded yet, causing a TypeError when the code tries to access properties on undefined objects.

Solution

Added optional chaining (?.) to all router model accesses in the useSelectedModel hook to safely handle cases where router models are undefined during provider transitions.

Changes

  • Added optional chaining to router model accesses for:
    • openrouter
    • requesty
    • glama
    • unbound
    • litellm
    • chutes
    • roo

Testing

  • All existing tests pass
  • Type checking passes
  • The fix prevents the TypeError and allows the UI to handle invalid selections gracefully

Fixes #9047


Important

Fixes TypeError when switching providers after model selection by adding optional chaining to router model accesses in useSelectedModel.

  • Behavior:
    • Fixes TypeError when switching providers after model selection by adding optional chaining (?.) to router model accesses in useSelectedModel.
    • Handles undefined router models during provider transitions for openrouter, requesty, glama, unbound, litellm, chutes, and roo.
  • Testing:
    • All existing tests pass.
    • Type checking passes.
    • UI now handles invalid selections gracefully, preventing TypeError.

This description was created by Ellipsis for fd6c987. You can customize this summary. It will automatically update as commits are pushed.

…ror when switching providers

Fixes #9047 - When switching providers after selecting a model, the router models
for the new provider may not be loaded yet, causing a TypeError when trying to
access properties on undefined. Added optional chaining to safely handle these cases.
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 5, 2025 09:36
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Nov 5, 2025
@roomote
Copy link
Author

roomote bot commented Nov 5, 2025

See this task on Roo Code Cloud

Review complete. The PR correctly addresses the TypeError issue by adding optional chaining to router model accesses. The fix is consistent with existing patterns in the codebase and handles the race condition appropriately when switching providers.

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 5, 2025
@daniel-lxs
Copy link
Member

Superseded by #9054, which includes both the model validation fixes and the optional chaining fixes from this PR to prevent TypeError during provider transitions.

@daniel-lxs daniel-lxs closed this Nov 5, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Switching providers after selecting a model causes a TypeError

4 participants