Skip to content

fix: Add array type checks for model, agent, and MCP hub data to prev…#20469

Merged
yuneng-jiang merged 2 commits intoBerriAI:mainfrom
swayambhu94:fix/ui/model-hub-table-crash
Feb 6, 2026
Merged

fix: Add array type checks for model, agent, and MCP hub data to prev…#20469
yuneng-jiang merged 2 commits intoBerriAI:mainfrom
swayambhu94:fix/ui/model-hub-table-crash

Conversation

@swayambhu94
Copy link
Contributor

@swayambhu94 swayambhu94 commented Feb 5, 2026

…ent crashes from non-array API responses and include a regression test.

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🧹 Refactoring
✅ Test

Changes

Fixes a frontend regression where the
PublicModelHub
page would crash with TypeError: e.filter is not a function when the API returned an error object (e.g. { "detail": "..." }) instead of the expected data array.
Changes:

Added defensive Array.isArray() checks in
src/components/public_model_hub.tsx
for:
modelHubData
agentHubData
mcpHubData
Updated useMemo hooks and helper functions to handle invalid data gracefully. Added a regression test in
src/components/public_model_hub.test.tsx
that mocks a non-array API response to ensure the component renders without crashing.

Screenshot 2026-02-05 at 12 25 21 PM

…ent crashes from non-array API responses and include a regression test.

This PR:Fixes a frontend regression where the
PublicModelHub
 page would crash with TypeError: e.filter is not a function when the API returned an error object (e.g. { "detail": "..." }) instead of the expected data array.
Changes:

Added defensive Array.isArray() checks in
src/components/public_model_hub.tsx
 for:
modelHubData
agentHubData
mcpHubData
Updated useMemo hooks and helper functions to handle invalid data gracefully.
Added a regression test in
src/components/public_model_hub.test.tsx
 that mocks a non-array API response to ensure the component renders without crashing.
@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 6, 2026 3:04am

Request Review

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

Fixed a frontend crash where the PublicModelHub component would fail with TypeError: e.filter is not a function when API endpoints returned error objects instead of expected data arrays.

Changes:

  • Added Array.isArray() checks in useMemo hooks for modelHubData, agentHubData, and mcpHubData to return empty arrays when data is not an array
  • Added Array.isArray() guards before calling helper functions (getUniqueProviders, getUniqueModes, getUniqueFeatures, getUniqueAgentSkills, getUniqueMcpTransports) that expect array parameters and use .forEach()
  • Added conditional rendering checks for agent and MCP tabs to verify data is an array before checking length
  • Included a regression test that mocks an error response object to verify the component renders gracefully without crashing

The fix is minimal, defensive, and follows best practices for handling potentially invalid API responses.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are purely defensive type checks that prevent crashes without changing any business logic. The fix is well-tested with a regression test, follows UI testing guidelines from AGENTS.md, and only adds safety guards without modifying existing functionality
  • No files require special attention

Important Files Changed

Filename Overview
ui/litellm-dashboard/src/components/public_model_hub.tsx Added defensive Array.isArray() checks in multiple locations to prevent crashes when API returns error objects instead of arrays
ui/litellm-dashboard/src/components/public_model_hub.test.tsx Added regression test that mocks non-array API response to ensure component renders without crashing

Sequence Diagram

sequenceDiagram
    participant User
    participant PublicModelHub
    participant API
    participant useMemo
    participant HelperFuncs as Helper Functions

    User->>PublicModelHub: Load page
    PublicModelHub->>API: modelHubPublicModelsCall()
    
    alt API returns valid array
        API-->>PublicModelHub: [model1, model2, ...]
        PublicModelHub->>useMemo: Process modelHubData
        useMemo->>useMemo: Check Array.isArray(modelHubData)
        useMemo-->>PublicModelHub: filteredData array
        PublicModelHub->>HelperFuncs: getUniqueProviders(modelHubData)
        Note over HelperFuncs: Array.isArray check passed
        HelperFuncs->>HelperFuncs: forEach() on array
        HelperFuncs-->>PublicModelHub: [provider1, provider2, ...]
        PublicModelHub->>User: Render model hub with data
    else API returns error object
        API-->>PublicModelHub: {detail: "error message"}
        PublicModelHub->>useMemo: Process modelHubData
        useMemo->>useMemo: Check Array.isArray(modelHubData)
        Note over useMemo: Not an array - return []
        useMemo-->>PublicModelHub: [] (empty array)
        PublicModelHub->>HelperFuncs: getUniqueProviders(modelHubData)
        Note over HelperFuncs: Array.isArray check fails
        Note over HelperFuncs: Returns [] without calling forEach
        HelperFuncs-->>PublicModelHub: []
        PublicModelHub->>User: Render empty model hub (no crash)
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Collaborator

@yuneng-jiang yuneng-jiang left a comment

Choose a reason for hiding this comment

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

Added a comment


const filteredData = useMemo(() => {
if (!modelHubData) return [];
if (!modelHubData || !Array.isArray(modelHubData)) return [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having a defensive check here is good, and it solves the problem. However, I believe a better way to solve this is checking for response.ok inside of modelHubPublicModelsCall. This is more standard, and it tells the downstream components that an error explicitly happened instead of pretending it did not and going down the happy route

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have addressed the comment . Please check

Copy link
Collaborator

@yuneng-jiang yuneng-jiang left a comment

Choose a reason for hiding this comment

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

lgtm

@yuneng-jiang yuneng-jiang merged commit 5ce5399 into BerriAI:main Feb 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants