Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Oct 31, 2025

Problem

The existing PRs #8916 and #8917 implemented provider filtering but used an array-based approach. Per mrubens' feedback, this should be simplified to use a single provider filter instead.

Solution

This PR combines and improves upon #8916 and #8917 by:

  1. Simplified API: Uses single provider: string instead of providers: string[]
  2. Type Reuse: Leverages existing isDynamicProvider from @roo-code/types instead of duplicating provider lists
  3. Cleaner Code: Removes backward compatibility complexity and debug logging
  4. Better Performance: Reduces payload sizes and eliminates unnecessary fetches

Changes

Backend (src/core/webview/webviewMessageHandler.ts)

  • Changed from providers array to single provider string filter
  • Simplified filtering logic using providerFilter instead of requestedSet
  • Maintained backward compatibility (no filter = fetch all)

Frontend (webview-ui/src/components/ui/hooks/)

  • useRouterModels: Updated to accept single provider option
  • useSelectedModel: Uses isDynamicProvider from types to determine when to fetch
  • Removed all console.debug logging
  • Gates router model fetches entirely for static providers

Tests

  • Updated backend test to verify single-provider filtering
  • Updated frontend tests to reflect gated behavior for static providers

Impact

Before:

  • Frontend could request all providers or a filtered array
  • Custom DYNAMIC_ROUTER_PROVIDERS constant duplicated type info
  • Debug logging cluttered console

After:

  • Cleaner single-provider API
  • Reuses existing type definitions
  • No debug logging
  • Static providers (anthropic, openai-native, etc.) skip router fetches entirely
  • Dynamic providers fetch only their own models

Addresses mrubens' Comments

✅ PR #8916: "Is there a reason for this filter to be an array?" - Now uses single provider
✅ PR #8916: "...make a function that only fetches one...Or just do it all in one PR" - Combined in one PR with simplified API
✅ PR #8917: "isn't this already in the types somewhere?" - Now uses isDynamicProvider from types
✅ PR #8917: "Can we remove this debug logging?" - All debug logging removed

Testing

  • ✅ Backend tests pass (3/3)
  • ✅ Frontend tests pass (14/14)
  • ✅ Type checking passes

Closes #8916
Closes #8917


Important

Optimize router model fetching by switching to single-provider filtering, improving performance and simplifying code.

  • Behavior:
    • Switch from providers: string[] to provider: string in webviewMessageHandler.ts for filtering router models.
    • Simplifies logic by using providerFilter instead of requestedSet.
    • Maintains backward compatibility by fetching all if no filter is provided.
  • Frontend:
    • useRouterModels in useRouterModels.ts now accepts a single provider and an enabled flag.
    • useSelectedModel in useSelectedModel.ts updated to use isDynamicProvider and gate fetches for static providers.
  • Tests:
    • Add tests in webviewMessageHandler.routerModels.spec.ts to verify single-provider filtering.
    • Update useSelectedModel.spec.ts to reflect changes in loading and error states for static providers.

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

- Simplify backend to use single provider filter instead of array
- Use existing isDynamicProvider from @roo-code/types instead of duplicating
- Update frontend to request only the needed provider
- Gate router model fetches entirely for static providers
- Remove unnecessary debug logging
- Update tests to reflect new behavior

This combines and improves upon PRs #8916 and #8917 by:
1. Using a simpler single-provider API (provider: string instead of providers: string[])
2. Leveraging existing type definitions from packages/types
3. Eliminating race conditions through simpler request/response matching
4. Reducing payload sizes and network usage

Closes #8916
Closes #8917
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners October 31, 2025 16:34
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Oct 31, 2025
@roomote
Copy link
Contributor

roomote bot commented Oct 31, 2025

Review Summary

I've reviewed the latest changes to this PR. The critical issue from the previous review has been resolved.

Issues Found

  • Critical: Response matching bug in useRouterModels - Fixed in commit 9dac237. The backend now correctly includes the provider in the response values.

Status

All issues have been addressed. The PR is ready for merge.


Follow Along on Roo Code Cloud

Previous Reviews

Comment on lines +28 to +34
const msgProvider = message?.values?.provider as string | undefined

// Verify response matches request
if (provider !== msgProvider) {
// Not our response; ignore and wait for the matching one
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical bug: The backend never includes the provider in the response values, so msgProvider will always be undefined. When a provider filter is used (e.g., provider="roo"), the check provider !== msgProvider evaluates to "roo" !== undefined, which is always true, causing the response to be ignored indefinitely. The promise will timeout after 10 seconds, breaking router model fetching for all dynamic providers. The backend needs to include the provider in the response: provider.postMessageToWebview({ type: "routerModels", routerModels, values: { provider: requestedProvider } })

Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Cannot approve due to critical issue found. The response matching bug must be fixed before this PR can be merged.

The frontend needs the provider in message.values.provider to match
requests with responses. Without this, all filtered requests would
timeout after 10 seconds.
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 31, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Oct 31, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Oct 31, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 2, 2025
@mrubens mrubens merged commit 31de103 into main Nov 2, 2025
17 checks passed
@mrubens mrubens deleted the feat/combined-provider-filtering branch November 2, 2025 05:04
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 2, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 2, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 2, 2025
* Correct tool use suggestion to improve model adherence to suggestion (RooCodeInc#8315)

* Correct tool use suggestion to improve model adherence to suggestion

* tweak

* removing user hint when refreshing models (RooCodeInc#7710)

* feat(zgsm): add quota info display and periodic updates

* Show the Roo provider on the welcome screen (RooCodeInc#8317)

* wip: Website Improvements (RooCodeInc#8303)

Co-authored-by: Matt Rubens <[email protected]>

* refactor: remove pr-reviewer mode (RooCodeInc#8222)

* feat: add animated quota display with staggered transitions

* Merge remote-tracking branch 'upstream/main' into roo-to-main

* web: More website copy tweaks (RooCodeInc#8326)

Co-authored-by: Matt Rubens <[email protected]>

* fix: remove <thinking> tags from prompts for cleaner output and fewer tokens (RooCodeInc#8319)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>

* Upgrade Supernova (RooCodeInc#8330)

* chore: add changeset for v3.28.9 (RooCodeInc#8336)

* Changeset ver