Skip to content

fix(model): return clear error instead of silent openai default for unrecognized models#2492

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.2from
herjarsa:fix/model-not-found-error
May 21, 2026
Merged

fix(model): return clear error instead of silent openai default for unrecognized models#2492
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.2from
herjarsa:fix/model-not-found-error

Conversation

@herjarsa
Copy link
Copy Markdown
Contributor

Description

When a model name cannot be resolved to any known provider, resolveModelByProviderInference() was silently defaulting to { provider: "openai" }, producing a misleading "No credentials for provider: openai" error.

Changes

open-sse/services/model.ts:

  • Changed the last-resort return in resolveModelByProviderInference() from { provider: "openai" } to { provider: null, errorType: "model_not_found", errorMessage: "..." }
  • This prevents the confusing OpenAI credential error for unrecognised models

src/sse/handlers/chatHelpers.ts:

  • Added handler for errorType === "model_not_found" in resolveModelOrError()
  • Returns a clear 400 error with model resolution guidance

Related Issue

Closes #2491

@herjarsa herjarsa requested a review from diegosouzapw as a code owner May 21, 2026 13:50
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves model resolution by replacing the silent 'openai' default with a specific 'model_not_found' error when a provider cannot be inferred. The chat handler was updated to catch this error and return a descriptive bad request response. Feedback includes a requirement to add unit tests for these changes as per the repository style guide and a recommendation to replace 'any' type casting with a shared interface to improve maintainability.

Comment on lines +471 to 482
// Last resort: no provider could be inferred — return a clear error instead
// of silently defaulting to "openai", which would produce a misleading
// "No credentials for provider: openai" response when the model name
// is unrecognised (e.g. a missing combo, a typo, or a bare model id
// that doesn't exist in any provider's catalog).
return {
provider: "openai",
provider: null,
model: modelId,
extendedContext,
errorType: "model_not_found",
errorMessage: `Unable to determine provider for model '${modelId}'. Use a provider/model prefix (e.g. openai/${modelId}) or ensure the model is added as a combo entry.`,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The repository style guide (Rule 9) requires that all changes to production code in open-sse/ include tests. Please add unit tests (e.g., in tests/unit/services/model.test.ts) to verify that resolveModelByProviderInference correctly returns the model_not_found error object when no provider can be inferred, ensuring this new logic is covered and preventing regressions.

References
  1. Always include tests when changing production code (src/, open-sse/, electron/, bin/). (link)

// model_not_found: raised by resolveModelByProviderInference when no
// provider could be inferred — return a clear error instead of the
// misleading "openai" default that the old code silently fell back to.
if ((modelInfo as any).errorType === "model_not_found") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The use of any casting for modelInfo is a maintainability issue as it bypasses TypeScript's type checking. While this pattern exists elsewhere in the file, it would be better to define a shared interface for the model resolution result (including errorType and errorMessage) in open-sse/services/model.ts and use it here to avoid unsafe casts.

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented May 21, 2026

Code Review Summary

Status: 2 Issues Found (Already Reported) | Recommendation: Address existing comments before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0

Overview of Changes

This PR fixes a misleading error behavior where resolveModelByProviderInference() silently defaulted to { provider: "openai" } for unrecognized model names, producing confusing "No credentials for provider: openai" errors.

Changes:

  • open-sse/services/model.ts: Returns { provider: null, errorType: "model_not_found", errorMessage: "..." } instead of defaulting to OpenAI
  • src/sse/handlers/chatHelpers.ts: Handles model_not_found error type with a clear 400 response
  • Tests updated in both chat-helpers.test.ts and services-branch-hardening.test.ts

Existing Inline Comments

File Line Issue
open-sse/services/model.ts 482 WARNING: Missing unit tests for the new model_not_found error path
src/sse/handlers/chatHelpers.ts 181 WARNING: as any casting bypasses type checking — consider defining a shared interface for model resolution results

Positive Observations

  • The model_not_found pattern is consistent with the existing ambiguous_model error handling (model.ts:449-453)
  • Error message is clear and actionable, guiding users to use provider/model prefix syntax
  • Tests properly cover the new behavior in both test files
  • The change improves user experience by replacing a misleading error with explicit guidance
Files Reviewed (4 files)
  • open-sse/services/model.ts — Core change: last-resort return now returns error object instead of OpenAI default
  • src/sse/handlers/chatHelpers.ts — Handler for model_not_found error type follows existing ambiguous_model pattern
  • tests/unit/chat-helpers.test.ts — New test for unrecognized bare model names
  • tests/unit/services-branch-hardening.test.ts — Updated test expectations for unknown model resolution

Reviewed by qwen3.6-plus · 303,940 tokens

- Updated existing 'made-up-model' test in services-branch-hardening
  to expect model_not_found instead of silent openai default
- Added new resolveModelOrError test in chat-helpers for unrecognised
  bare model names returning model_not_found error
@diegosouzapw diegosouzapw changed the base branch from main to release/v3.8.2 May 21, 2026 18:46
@diegosouzapw diegosouzapw merged commit 8d43cbd into diegosouzapw:release/v3.8.2 May 21, 2026
56 of 72 checks passed
@diegosouzapw
Copy link
Copy Markdown
Owner

Thank you for this contribution! 🎉 Your fix has been integrated into the upcoming v3.8.2 release. Great work!

@diegosouzapw diegosouzapw mentioned this pull request May 21, 2026
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.

BUG: Unrecognised model names silently fall back to OpenAI, causing misleading credential errors

2 participants