Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Problem

Part of the webview memory mitigation effort. The frontend was requesting all router models regardless of which provider was selected. This caused unnecessary memory allocation and cache reconciliation for models that would never be used.

Solution

Implement intelligent provider filtering in the frontend:

  1. Identify which providers require router models (dynamic providers)
  2. Disable useRouterModels entirely for static providers
  3. For dynamic providers, request only the specific provider's models

Changes

useSelectedModel.ts

  • Added DYNAMIC_ROUTER_PROVIDERS set defining providers that need router models
  • Static providers (anthropic, openai-native, etc.): enabled: false
  • Dynamic providers: providers: [selectedProvider]

useRouterModels.ts

  • Added enabled option support
  • Added console.debug logging for observability
  • Enhanced provider filtering with request/response counters

Tests

  • Updated useSelectedModel.spec.ts for new static provider behavior

Impact

Before:

  • Fetched all router models (openrouter, roo, litellm, vercel, deepinfra, etc.) regardless of selected provider
  • Static providers like anthropic triggered unnecessary fetches

After:

  • Static providers: no router model fetches at all
  • Dynamic providers: only fetch the selected provider's models
  • Roo provider: only fetches Roo models

Memory savings:

  • Static provider users: ~8+ provider catalogs eliminated
  • Dynamic provider users: 7-8 provider catalogs eliminated (fetch only 1)

Files Changed

  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/components/ui/hooks/useRouterModels.ts
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts

Testing

  • ✅ Updated tests for static provider behavior
  • ✅ All webview UI tests passing
  • Console logs show reduced request frequency and narrower payloads

Part of

This is the third PR in a series to reduce webview memory usage:

  1. ✅ PR fix: Gate auth-driven Roo model refresh to active provider only #8915 - Gate auth-driven Roo model refresh
  2. ✅ PR feat: Add provider filtering support to router models backend #8916 - Backend provider filtering
  3. This PR - Frontend provider-scoped fetches

Dependencies

Requires PR #8916 to be merged first for backend filtering support. This PR sends provider filters that the backend must honor.

Manual Testing

  1. Select static provider (e.g., anthropic) → No router model requests in console
  2. Select Roo provider → Console shows [useRouterModels] request providers=["roo"]
  3. Switch providers → Verify only relevant provider models requested

Important

Optimizes router model fetching by introducing provider-specific logic, reducing unnecessary memory usage for static providers.

  • Behavior:
    • useSelectedModel.ts: Introduces DYNAMIC_ROUTER_PROVIDERS set to identify providers needing router models.
    • Disables useRouterModels for static providers and fetches only specific provider models for dynamic ones.
    • Updates loading and error state logic to consider only necessary data.
  • Functions:
    • useRouterModels.ts: Adds enabled option and provider filtering to getRouterModels().
    • Adds request/response logging for observability.
  • Tests:
    • Updates useSelectedModel.spec.ts to test new static provider behavior and ensure correct loading/error states.

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

Implements intelligent provider filtering in the frontend to request
only the models needed for the currently selected provider. This
dramatically reduces memory usage by avoiding unnecessary fetches
and smaller cache footprints.

- Add DYNAMIC_ROUTER_PROVIDERS set to identify providers needing models
- Disable useRouterModels for static providers (anthropic, openai-native, etc.)
- Pass provider-specific filters for dynamic providers
- Add observability logging to track request/response patterns
- Update tests for new behavior

Works with backend filtering (PR #8916) to achieve end-to-end
payload reduction.
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners October 29, 2025 20:20
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 29, 2025
@dosubot dosubot bot added the enhancement New feature or request label Oct 29, 2025
@roomote
Copy link

roomote bot commented Oct 29, 2025

Review Complete

No issues found. The implementation correctly:

  • Identifies static vs dynamic providers that need router model fetches
  • Gates useRouterModels entirely for static providers using the enabled option
  • Requests only provider-specific models for dynamic providers
  • Handles loading and error states properly by only considering relevant data sources
  • Updates tests to verify the new gating behavior
  • Guards against race conditions when multiple concurrent router model requests are in flight

Follow Along on Roo Code Cloud

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 29, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Oct 29, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Oct 29, 2025
…er filter to avoid race with active-only payload (pairs with #8916 backend filtering)
import { useLmStudioModels } from "./useLmStudioModels"
import { useOllamaModels } from "./useOllamaModels"

const DYNAMIC_ROUTER_PROVIDERS = new Set<ProviderName>([
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we’re going to forget to update this - isn’t this already in the types somewhere?


if (message.routerModels) {
const keys = Object.keys(message.routerModels || {})
console.debug(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this debug logging?

daniel-lxs added a commit that referenced this pull request Oct 31, 2025
- 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
Copy link
Member Author

Closing in favor of combined PR #8956 which addresses all feedback and uses a simpler single-provider API

@daniel-lxs daniel-lxs closed this Oct 31, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 31, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants