Skip to content

Conversation

@deon-sanchez
Copy link
Collaborator

@deon-sanchez deon-sanchez commented Jan 27, 2026

The Bug

Screen.Recording.2026-01-27.at.3.33.35.PM.mov

The Fix

Screen.Recording.2026-01-27.at.3.32.42.PM.mov

Testing Strategy

select language model component and add a provider with api key and select models.

Description

This pull request introduces optimistic UI updates for toggling model enablement in the model provider modal. Now, when users toggle models, the UI immediately reflects their changes before the server responds, and multiple toggles are batched and sent together. The changes also ensure pending updates are flushed when switching providers or closing the modal, and add comprehensive tests for this new behavior.

Optimistic UI and batching for model toggles:

  • Added a pendingUpdates state to ModelProvidersContent.tsx to accumulate model enable/disable changes locally and batch them before sending to the server. Pending updates are flushed when the provider changes or the modal closes. (src/frontend/src/modals/modelProviderModal/components/ModelProvidersContent.tsx) [1] [2] [3]
  • Updated ModelSelection.tsx to accept a pendingUpdates prop and prioritize pending updates for UI state, enabling immediate feedback when toggling models. (src/frontend/src/modals/modelProviderModal/components/ModelSelection.tsx) [1] [2]

Testing improvements:

  • Added a new test suite to verify optimistic UI behavior with pendingUpdates, including cases for enabled/disabled states, server fallback, and prioritization. (src/frontend/src/modals/modelProviderModal/__tests__/ModelSelection.test.tsx)

Type and error handling enhancements:

  • Updated error handling to use the more specific ResponseErrorDetailAPI type for provider activation and validation errors. (src/frontend/src/modals/modelProviderModal/components/ModelProvidersContent.tsx) [1] [2]

Imports and type usage:

  • Added imports for ModelStatusUpdate and improved usage of types in affected files for clarity and maintainability. (src/frontend/src/modals/modelProviderModal/components/ModelProvidersContent.tsx, src/frontend/src/modals/modelProviderModal/components/ModelSelection.tsx, src/frontend/src/modals/modelProviderModal/__tests__/ModelSelection.test.tsx) [1] [2] [3]

Summary by CodeRabbit

  • New Features

    • Added optimistic UI feedback for model selections - enable/disable changes now display immediately in the interface.
  • Improvements

    • Batched model status updates for improved performance and efficiency.
    • Enhanced error handling and type safety in provider activation and API key management flows.

✏️ Tip: You can customize this high-level summary in your review settings.

@deon-sanchez deon-sanchez self-assigned this Jan 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

The changes introduce batching functionality for model enable/disable updates and optimistic UI support. A parent component accumulates model toggle changes in a pendingUpdates map and flushes them as a batch upon provider switch or unmount. A child component checks pending updates to display optimistic UI states before server confirmation.

Changes

Cohort / File(s) Summary
Model Update Batching and Optimistic UI
src/frontend/src/modals/modelProviderModal/components/ModelProvidersContent.tsx
Introduces pendingUpdates state (Map) to accumulate model toggles; adds flushPendingUpdates() to send batched updates; modifies handleModelToggle to record changes instead of immediate dispatch; adds effects to flush updates on provider change and component unmount; refines error handling with ResponseErrorDetailAPI types; passes pendingUpdates down to ModelSelection component.
Optimistic UI Support
src/frontend/src/modals/modelProviderModal/components/ModelSelection.tsx
Extends ModelProviderSelectionProps with optional pendingUpdates prop; updates model enablement check to prioritize pending updates over server-provided status for optimistic UI display; adds ModelStatusUpdate import.

Sequence Diagram

sequenceDiagram
    participant User
    participant ModelProvidersContent
    participant ModelSelection
    participant API

    User->>ModelProvidersContent: Toggle model enabled/disabled
    ModelProvidersContent->>ModelProvidersContent: Add to pendingUpdates map
    ModelProvidersContent->>ModelSelection: Pass pendingUpdates prop
    ModelSelection->>ModelSelection: Check pendingUpdates for optimistic state
    ModelSelection->>User: Display optimistic UI state

    alt On Provider Switch or Unmount
        ModelProvidersContent->>ModelProvidersContent: flushPendingUpdates()
        ModelProvidersContent->>API: updateEnabledModels(batched updates)
        API->>ModelProvidersContent: Response confirmation
        ModelProvidersContent->>ModelProvidersContent: Clear pendingUpdates
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 2 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR introduces batching mechanism for model enable/disable updates with pendingUpdates state and flushPendingUpdates() function, but includes no test files for new batching logic, optimistic updates, or modified event handlers. Add ModelProvidersContent.test.tsx and ModelSelection.test.tsx with tests for pending updates accumulation, flushPendingUpdates() behavior, batched API calls, optimistic UI updates, and regression tests for existing functionality.
Test Quality And Coverage ⚠️ Warning Pull request introduces batching logic and optimistic UI without corresponding test coverage for new functionality. Add comprehensive tests for ModelProvidersContent batching logic, pendingUpdates behavior, and effect-based flushing, plus extend ModelSelection tests for optimistic UI.
Test File Naming And Structure ⚠️ Warning PR introduces batching functionality but test coverage lacks tests for ModelProvidersContent, pendingUpdates prop, and batching edge cases. Create ModelProvidersContent.test.tsx with batching tests and update ModelSelection.test.tsx to verify pendingUpdates behavior and edge cases.
✅ 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 'fix: batch Enabled Models for Model Provider' accurately reflects the main change: implementing batching for model enable/disable updates to improve performance and reduce redundant API calls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Excessive Mock Usage Warning ✅ Passed The PR adds a new test file ModelSelection.test.tsx with well-organized structure using 2 justified module mocks for external dependencies and proper test fixtures covering 11 test cases for rendering, interactions, and edge cases without obscuring core logic.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch le-187

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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 17%
17.53% (5054/28816) 10.97% (2438/22206) 11.62% (733/6304)

Unit Test Results

Tests Skipped Failures Errors Time
2041 0 💤 0 ❌ 0 🔥 27.079s ⏱️

@github-actions github-actions bot added the bug Something isn't working label Jan 27, 2026
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 12.12121% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.88%. Comparing base (4b056b4) to head (9a4397e).

Files with missing lines Patch % Lines
...ProviderModal/components/ModelProvidersContent.tsx 0.00% 29 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11472      +/-   ##
==========================================
- Coverage   34.89%   34.88%   -0.01%     
==========================================
  Files        1420     1420              
  Lines       68217    68244      +27     
  Branches     9984     9992       +8     
==========================================
+ Hits        23804    23808       +4     
- Misses      43179    43202      +23     
  Partials     1234     1234              
Flag Coverage Δ
frontend 16.05% <12.12%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...s/modelProviderModal/components/ModelSelection.tsx 85.00% <100.00%> (+1.66%) ⬆️
...ProviderModal/components/ModelProvidersContent.tsx 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/frontend/src/modals/modelProviderModal/components/ModelProvidersContent.tsx (1)

41-145: Don’t drop pendingUpdates on failed batch + keep invalidation consistent.

flushPendingUpdates clears state immediately; if the mutation fails, optimistic changes are lost and the UI silently falls back to stale server data. The unmount flush also bypasses invalidation/error handling, so downstream views can stay stale. Please clear only on success, surface errors, and invalidate consistently for the unmount path.

✅ Suggested fix
 const flushPendingUpdates = useCallback(() => {
   if (pendingUpdates.size === 0) return;

   const updates = Array.from(pendingUpdates.values());
   updateEnabledModels(
     { updates },
     {
       onSuccess: () => {
         queryClient.invalidateQueries({ queryKey: ["useGetEnabledModels"] });
+        setPendingUpdates(new Map());
       },
+      onError: () => {
+        setErrorData({
+          title: "Error updating models",
+          list: ["Please retry."],
+        });
+      },
     },
   );
-  setPendingUpdates(new Map());
-}, [pendingUpdates, updateEnabledModels, queryClient]);
+}, [pendingUpdates, updateEnabledModels, queryClient, setErrorData]);

 // Flush pending updates on unmount (modal close)
 useEffect(() => {
   return () => {
     if (pendingUpdates.size > 0) {
       const updates = Array.from(pendingUpdates.values());
-      updateEnabledModels({ updates });
+      updateEnabledModels(
+        { updates },
+        {
+          onSuccess: () => {
+            queryClient.invalidateQueries({ queryKey: ["useGetEnabledModels"] });
+          },
+        },
+      );
     }
   };
-}, [pendingUpdates, updateEnabledModels]);
+}, [pendingUpdates, updateEnabledModels, queryClient]);

@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 27, 2026
@github-actions github-actions bot added the lgtm This PR has been approved by a maintainer label Jan 27, 2026
@deon-sanchez deon-sanchez added this pull request to the merge queue Jan 27, 2026
@deon-sanchez deon-sanchez removed this pull request from the merge queue due to a manual request Jan 27, 2026
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants