Skip to content

fix: surface Cohere model fetch errors - #285

Open
Pranavb1830 wants to merge 2 commits into
404-PF:mainfrom
Pranavb1830:fix/cohere-fetch-models-error
Open

fix: surface Cohere model fetch errors#285
Pranavb1830 wants to merge 2 commits into
404-PF:mainfrom
Pranavb1830:fix/cohere-fetch-models-error

Conversation

@Pranavb1830

@Pranavb1830 Pranavb1830 commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • Throw an error when the Cohere models endpoint returns a non-OK response.
  • Prevent failed API requests from being reported as successful model fetches with stale hardcoded models.
  • Allow the existing error-handling flow to fall back to manual model selection.

Closes #284

Testing

  • npm test — 356 passed, 0 failed
  • npm run format:check — passed

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling when retrieving Cohere models, ensuring failed requests are reported instead of silently using a default list.
    • Retained the default model list when requests succeed but provide no usable model data.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Cohere model discovery now throws an error for unsuccessful HTTP responses. Successful responses without usable model data still use the default model list.

Changes

Cohere model discovery

Layer / File(s) Summary
Surface Cohere request failures
src/providers/cohere.ts
fetchModels now throws an error containing the HTTP status and status text when the Cohere request fails. It no longer returns default models for unsuccessful responses.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: 404-page-found

Poem

A rabbit saw the error rise,
No stale models in disguise.
The status speaks, the failure shows,
And fallback data waits where it belongs.
Hop, hop, reliable flows! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: exposing errors from Cohere model fetching.
Linked Issues check ✅ Passed The change makes Cohere fetchModels throw on non-OK responses, which satisfies issue #284 and enables manual model selection fallback.
Out of Scope Changes check ✅ Passed The pull request contains one focused change that directly addresses issue #284 without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/providers/cohere.ts">

<violation number="1" location="src/providers/cohere.ts:79">
P3: The new throw-on-non-OK path in CohereProvider.fetchModels has no test coverage, even though it is the exact behavior this fix introduces (previous tests in tests/providers/provider-adapters.test.mjs only cover `complete`). Add a test that mocks a non-OK `/models` response (e.g. status 401) and asserts `fetchModels` rejects, mirroring how `complete` surfaces API errors at lines 234-249, so the stale-model regression this PR fixes stays guarded.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/providers/cohere.ts

if (!response.ok) {
return ['command-r-plus', 'command-r', 'command-xlarge', 'command-large'];
throw new Error(`Failed to fetch models (${response.status}): ${response.statusText}`);

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.

P3: The new throw-on-non-OK path in CohereProvider.fetchModels has no test coverage, even though it is the exact behavior this fix introduces (previous tests in tests/providers/provider-adapters.test.mjs only cover complete). Add a test that mocks a non-OK /models response (e.g. status 401) and asserts fetchModels rejects, mirroring how complete surfaces API errors at lines 234-249, so the stale-model regression this PR fixes stays guarded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/providers/cohere.ts, line 79:

<comment>The new throw-on-non-OK path in CohereProvider.fetchModels has no test coverage, even though it is the exact behavior this fix introduces (previous tests in tests/providers/provider-adapters.test.mjs only cover `complete`). Add a test that mocks a non-OK `/models` response (e.g. status 401) and asserts `fetchModels` rejects, mirroring how `complete` surfaces API errors at lines 234-249, so the stale-model regression this PR fixes stays guarded.</comment>

<file context>
@@ -76,7 +76,7 @@ export class CohereProvider implements Provider {
 
     if (!response.ok) {
-      return ['command-r-plus', 'command-r', 'command-xlarge', 'command-large'];
+      throw new Error(`Failed to fetch models (${response.status}): ${response.statusText}`);
     }
 
</file context>

@sonarqubecloud

Copy link
Copy Markdown

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] Cohere fetchModels silently returns a stale hardcoded model list on API errors

1 participant