Skip to content

fix(api): honor custom model IDs for OpenAI-compatible providers - #1846

Open
p12tic wants to merge 1 commit into
Zoo-Code-Org:mainfrom
p12tic:fix-openai-custom-model
Open

p12tic wants to merge 1 commit into
Zoo-Code-Org:mainfrom
p12tic:fix-openai-custom-model

Conversation

@p12tic

@p12tic p12tic commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes: #1845

Description

Previously, getModel() silently fell back to the provider default when the configured apiModelId wasn't found in the static providerModels list. This sent the wrong model to the API for user-supplied custom models (e.g. newly released Fireworks models), surfacing as confusing "model not found" errors.

Now getModel() honors the exact user-configured ID and supplies openAiModelInfoSaneDefaults so the rest of the pipeline works, only falling back to the provider default when no model is configured.

  • Return known model metadata when the ID is in providerModels
  • Return the custom ID with sane defaults when unknown but configured
  • Fall back to the default only when no model ID is set

Test Procedure

Select custom model on fireworks.ai and check if it works. Full fix depends on #1848 and #1847. This PR doesn't make things worse, just fails one step further. It should land first.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • [n/a] Visual Snapshot (UI changes only): If a user would notice this change at a glance (layout, theme tokens, brand elements, empty/error states), I've added or updated a *.visual.tsx snapshot in webview-ui/. See webview-ui/AGENTS.md → "When a UI change needs a snapshot".
  • [n/a] Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • [n/a] Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 7590a858-c391-4d6b-9574-fd5592dd8e9f

📥 Commits

Reviewing files that changed from the base of the PR and between 45825e9 and 46e9068.

📒 Files selected for processing (2)
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (4)
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.

⚙️ CodeRabbit configuration file

Files:

  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.

⚙️ CodeRabbit configuration file

Files:

  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
Check React state and effect dependencies, cleanup, accessibility, i18n, and light/dark theme behavior.

⚙️ CodeRabbit configuration file

Files:

  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
Act as an adversarial second-opinion reviewer.

⚙️ CodeRabbit configuration file

Files:

  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
🔇 Additional comments (2)
webview-ui/src/components/ui/hooks/useSelectedModel.ts (1)

329-333: LGTM!

webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts (1)

1416-1463: LGTM!


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Configured model IDs that aren’t in a provider’s predefined list are now preserved when selecting a model and sending requests, rather than being replaced by the provider default. This applies to OpenAI-compatible and Z.AI providers.
    • Requests using an unlisted model ID now use standard model metadata. When no model ID is configured, the provider continues to use its default model and associated metadata.

Walkthrough

The provider and Z.AI model selection now preserve configured model IDs that are absent from their predefined lists and use sane default metadata for those IDs. When no ID is configured, each uses its applicable default model. Tests cover model selection and custom IDs passed to API methods.

Changes

Custom model selection

Layer / File(s) Summary
Provider model resolution
src/api/providers/base-openai-compatible-provider.ts, src/api/providers/__tests__/base-openai-compatible-provider.spec.ts
getModel uses predefined metadata for known IDs, sane default metadata for unknown configured IDs, and the provider default when no ID is configured. Tests cover these cases and verify that custom IDs reach createMessage and completePrompt unchanged.
Z.AI model selection
webview-ui/src/components/ui/hooks/useSelectedModel.ts, webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
Z.AI selection preserves configured IDs missing from its catalogs and uses sane default metadata. Tests also cover omitted or empty IDs selecting the China API line’s default model and metadata.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 46e90

Configured custom model IDs now reach the Fireworks and Z.AI requests unchanged, while unset IDs continue to use defaults. No merge-blocking risk was identified; proceed with normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to 46e90

The change affects 2 systems.

Changed systems: webview-ui, src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — webview-ui (ui) was modified; 2 changed files map to changed impact.
  • observed — src (api) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/api/providers/tests/base-openai-compatible-provider.spec.ts: The type import now also brings in openAiModelInfoSaneDefaults for the new model-metadata test.
  • observed — Modified behavior in src/api/providers/tests/base-openai-compatible-provider.spec.ts: A shared TEST_MODEL_INFO constant now holds the test model’s metadata, previously declared inline in the constructor’s model map.
  • observed — Modified behavior in src/api/providers/tests/base-openai-compatible-provider.spec.ts: The test provider constructor now accepts optional apiModelId and modelMaxTokens options, and its model map references the shared metadata constant.
  • observed — Modified behavior in src/api/providers/tests/base-openai-compatible-provider.spec.ts: The constructor forwards the optional settings to the base provider.
🚥 Pre-merge checks | ✅ 8
✅ Passed checks (8 passed)
Check name Status Explanation
Linked Issues check ✅ Passed For [#1845], BaseOpenAiCompatibleProvider.getModel() now returns a configured unknown apiModelId unchanged and supplies openAiModelInfoSaneDefaults. createStream() and completePrompt() use t…
Out of Scope Changes check ✅ Passed The changed provider logic and tests implement the custom-model selection objective in [#1845]. The Z.AI changes apply the same configured-ID preservation rule and add matching tests. No unrelated pro…
Regression Evidence ✅ Passed PASS. The changed behavior has focused coverage at the lowest valid layers. base-openai-compatible-provider.spec.ts covers the OpenAI-compatible provider default, known IDs, unknown configured IDs w…
Security Boundaries ✅ Passed No changed path meets the security failure conditions. BaseOpenAiCompatibleProvider.getModel() preserves the configured ID and places it only in the OpenAI request's JSON model field. The endpoint…
Persistence Integrity ✅ Passed No changed persistence path exists. The production changes only read apiModelId/apiConfiguration and return model IDs and metadata. BaseOpenAiCompatibleProvider.getModel() and the Z.AI branch of…
Lifecycle Resource Cleanup ✅ Passed No changed lifecycle path exists. The provider change only alters getModel() metadata and model ID selection, and the Z.AI hook change only returns a configured ID with fallback metadata. The change…
Title check ✅ Passed The title clearly and concisely describes the main change: preserving custom model IDs for OpenAI-compatible providers.
Description check ✅ Passed The description includes the linked issue, implementation details, test procedure, checklist, and documentation impact. It omits optional sections such as Visual Snapshots, Videos, Additional Notes, a…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Awaiting fresh human maintainer or CODEOWNER approval.

Automated review is complete for the latest commit but does not replace human approval.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Sep 28, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 28, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Sep 28, 2026
@p12tic
p12tic marked this pull request as draft September 28, 2026 22:57
@p12tic
p12tic marked this pull request as ready for review September 28, 2026 23:07
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed awaiting-maintainer CodeRabbit approved; waiting for a human maintainer labels Sep 28, 2026
Comment thread src/api/providers/base-openai-compatible-provider.ts
Comment thread src/api/providers/base-openai-compatible-provider.ts
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-maintainer CodeRabbit approved; waiting for a human maintainer labels Oct 1, 2026
Previously, getModel() silently fell back to the provider default
when the configured apiModelId wasn't found in the static
providerModels list. This sent the wrong model to the API for
user-supplied custom models (e.g. newly released Fireworks models),
surfacing as confusing "model not found" errors.

Now getModel() honors the exact user-configured ID and supplies
openAiModelInfoSaneDefaults so the rest of the pipeline works, only
falling back to the provider default when no model is configured.

- Return known model metadata when the ID is in providerModels
- Return the custom ID with sane defaults when unknown but configured
- Fall back to the default only when no model ID is set
@p12tic
p12tic force-pushed the fix-openai-custom-model branch from 45825e9 to 46e9068 Compare October 1, 2026 09:32
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-author PR is waiting for the author to address requested changes labels Oct 1, 2026
@p12tic
p12tic requested a review from taltas October 1, 2026 09:54
@github-actions github-actions Bot added the coderabbit-review-active Required CI passed; CodeRabbit review is active label Oct 1, 2026
@github-actions github-actions Bot added awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit and removed awaiting-author PR is waiting for the author to address requested changes labels Oct 1, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer CodeRabbit approved; waiting for a human maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Broken custom model on fireworks.ai

2 participants