Skip to content

fix(agent-server): dedupe models by provider and id, not id alone - #1927

Open
Osamaali313 wants to merge 1 commit into
bytedance:mainfrom
Osamaali313:fix/model-dedup-by-provider-and-id
Open

fix(agent-server): dedupe models by provider and id, not id alone#1927
Osamaali313 wants to merge 1 commit into
bytedance:mainfrom
Osamaali313:fix/model-dedup-by-provider-and-id

Conversation

@Osamaali313

Copy link
Copy Markdown

Problem

getAvailableModels in multimodal/tarko/agent-server/src/utils/model-utils.ts deduplicates by model.id alone:

const uniqueModels = allModels.filter(
  (model, index, arr) => arr.findIndex((m) => m.id === model.id) === index,
);

But everywhere else in the same module, model identity is the (provider, id) pairisModelConfigValid matches on model.provider === provider && model.id === modelId. The dedup key and the validation key disagree.

So when the same model id is configured under two different providers — a common multi-provider setup, e.g. gpt-4o via both openai and azure-openai, or claude-3-5-sonnet via anthropic and bedrock — the second entry is silently dropped.

Impact (live server code)

  • GET /api/v1/models (src/api/routes/system.ts) → getPublicAvailableModels → the second provider's model is missing from the model picker served to the UI.
  • updateSessionModel (src/api/controllers/system.ts) → isModelConfigValid → switching to the shared-id model under the second provider returns HTTP 400 "Invalid model configuration" even though it is configured.
  • AgentSession uses it for model resolution.

Reproduction

const config = {
  model: { provider: 'openai', id: 'gpt-4o' },
  server: { models: [{ provider: 'azure-openai', id: 'gpt-4o' }] },
};
before after
getAvailableModels(config) ['openai/gpt-4o'] (azure dropped) ['openai/gpt-4o', 'azure-openai/gpt-4o']
isModelConfigValid(config, 'azure-openai', 'gpt-4o') false true

Genuine duplicates (same provider and id) still collapse to one entry.

Fix

Include provider in the dedup key:

const uniqueModels = allModels.filter(
  (model, index, arr) =>
    arr.findIndex((m) => m.id === model.id && m.provider === model.provider) === index,
);

Tests

Added to tests/utils/model-utils.test.ts:

  • getAvailableModels keeps the same id under different providers, and still collapses genuine duplicates.
  • isModelConfigValid validates a shared id for each provider.

Before the fix, the two new positive cases fail; after, the full model-utils suite passes (18 tests). Verified by running the suite against the real module (vitest run tests/utils/model-utils.test.ts).

getAvailableModels() deduplicated by model.id only, but model identity in
this module is the (provider, id) pair -- isModelConfigValid() matches on
model.provider === provider && model.id === modelId. So when the same model
id is configured under two providers (e.g. gpt-4o via both openai and
azure-openai), the second entry was silently dropped: it went missing from
GET /api/v1/models (the picker) and updateSessionModel rejected switching to
it with "Invalid model configuration" even though it was configured. Include
provider in the dedup key. Genuine duplicates (same provider + id) still
collapse. Add regression tests.
Copilot AI review requested due to automatic review settings July 10, 2026 20:58
@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for tarko ready!

Name Link
🔨 Latest commit 9309abe
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/6a515cffe913c4000814f770
😎 Deploy Preview https://deploy-preview-1927--tarko.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit 9309abe
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/6a515cffbc0d4c0008162339
😎 Deploy Preview https://deploy-preview-1927--agent-tars-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants