Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Problem

Users reported increased webview memory usage starting in v3.29.0, causing crashes. Investigation identified that router model fetches were triggering excessive memory allocation and reconciliation in the webview.

Root Causes Identified

  1. Auth-driven model refresh (PR feat: add dynamic model loading for Roo Code Cloud provider #8728): Auth state changes triggered for all providers regardless of which provider was active
  2. Unbounded router model fetches: All dynamic providers fetched models even when not needed
  3. Large aggregate payloads: Full router model catalogs cached and reconciled repeatedly in React Query

Solution

Implemented a surgical, focused fix that gates Roo Code Cloud router model traffic:

Changes Made

  1. Gate auth-driven Roo refresh (ExtensionStateContext.tsx)

    • Only posts requestRooModels when auth transitions to true AND current provider === "roo"
    • Prevents unnecessary fetches when using other providers
  2. Provider-filtered router model fetches (useSelectedModel.ts)

    • Introduced DYNAMIC_ROUTER_PROVIDERS set to identify which providers need router models
    • Disables useRouterModels for static providers (anthropic, openai-native, etc.)
    • For dynamic providers, passes providers: [selectedProvider] to fetch only needed models
    • When provider === "roo", fetches only Roo models
  3. Backend provider filter support (webviewMessageHandler.ts)

    • Honors message.values.providers filter when present
    • Fetches only specified subset of router models
    • Maintains existing default behavior when no filter provided
  4. Observability (useRouterModels.ts)

    • Added console.debug logging with request/response counters
    • Shows which providers are requested and returned

Test Coverage

  • Auth gating test: Verifies auth transitions only trigger requestRooModels when provider === "roo"
  • Provider filtering test: Verifies backend correctly filters models based on providers list
  • Updated hook tests: Adjusted for new static-provider gating behavior
  • All tests passing: 94 webview UI tests + backend tests

Impact

Before:

  • Auth changes triggered full router model fetches for all providers
  • All contexts fetched aggregated models from all dynamic providers
  • Large payloads repeatedly cached and reconciled

After:

  • Router models only fetched when explicitly needed
  • Roo models only fetched when Roo is active provider
  • Significantly smaller payloads (single provider vs. aggregate)
  • Reduced reconciliation overhead in React Query cache

Safety

  • No global state shape changes
  • No removal of existing features
  • Narrow blast radius: auth effect, selected model hook, one handler
  • Preserves all existing functionality

Files Changed

  • webview-ui/src/context/ExtensionStateContext.tsx
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/components/ui/hooks/useRouterModels.ts
  • src/core/webview/webviewMessageHandler.ts
  • webview-ui/src/context/__tests__/ExtensionStateContext.roo-auth-gate.spec.tsx (new)
  • src/core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts (new)
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts (updated)

Manual Testing

  1. Switch to non-Roo provider → Verify no requestRooModels on auth changes
  2. Switch to Roo provider → Verify routerModels payload contains only "roo" key
  3. Navigate Settings and Chat → Confirm no regressions
  4. Monitor console logs → Verify reduced request frequency and narrower payloads

Important

Optimizes Roo provider model fetches by gating requests to reduce memory usage, with tests added for new behavior.

  • Behavior:
    • Gated auth-driven Roo refresh in ExtensionStateContext.tsx to only trigger requestRooModels when provider is "roo".
    • Filtered router model fetches in useSelectedModel.ts to only fetch models for dynamic providers.
    • Updated webviewMessageHandler.ts to honor message.values.providers filter for router model fetches.
  • Tests:
    • Added ExtensionStateContext.roo-auth-gate.spec.tsx to test auth-driven Roo model requests.
    • Added webviewMessageHandler.routerModels.spec.ts to test provider filtering in model fetches.
    • Updated useSelectedModel.spec.ts for static provider gating behavior.
  • Misc:
    • Added logging in useRouterModels.ts for request/response tracking.

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

- Only fetch Roo models when Roo is the active provider
- Gate auth-driven requestRooModels by current provider
- Add provider filtering support in backend handler
- Disable router model fetches for static providers
- Add tests for auth gating and provider filtering

Resolves memory growth issue by minimizing unnecessary router model traffic
@daniel-lxs daniel-lxs requested a review from jr as a code owner October 29, 2025 18:11
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Oct 29, 2025
@roomote
Copy link

roomote bot commented Oct 29, 2025

PR Review Summary

Review Complete - No Issues Found

I've thoroughly reviewed all changes in this PR and found no issues that require attention. The implementation is solid:

What Was Reviewed

  • Backend filtering logic (webviewMessageHandler.ts): Correctly implements optional provider filtering
  • Frontend gating (useSelectedModel.ts, useRouterModels.ts): Properly gates router model fetches for static providers
  • Auth-driven refresh (ExtensionStateContext.tsx): Correctly gates Roo model refreshes to only fire when Roo is the active provider
  • Test coverage: Comprehensive tests validate the key functionality
  • Type safety: All TypeScript contracts are maintained correctly
  • Backward compatibility: No filter defaults to existing aggregate behavior

Key Strengths

✅ Clean, focused implementation
✅ No breaking changes
✅ Comprehensive test coverage (both frontend and backend)
✅ Follows established codebase patterns
✅ Proper error handling and fallbacks
✅ Type-safe implementation

The PR successfully achieves its goal of reducing webview memory usage through targeted, surgical changes.


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
Copy link
Member Author

This PR has been split into three smaller, more focused PRs for easier review:

  1. PR fix: Gate auth-driven Roo model refresh to active provider only #8915 - Gate auth-driven Roo model refresh to active provider only

    • Focuses solely on the ExtensionStateContext auth gating
    • Independent change, can be reviewed and merged first
  2. PR feat: Add provider filtering support to router models backend #8916 - Add provider filtering support to router models backend

    • Backend-only changes to honor provider filters
    • Independent, can be merged in any order
  3. PR feat: Add provider-scoped router model fetches in frontend #8917 - Add provider-scoped router model fetches in frontend

Each PR is now focused on a single concern, making review faster and reducing merge conflicts. All three PRs together provide the same functionality as this original PR.

@daniel-lxs daniel-lxs closed this Oct 29, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 29, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 29, 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:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants