Skip to content

fix(providers): fall back to configured models when models endpoint fetch fails#7530

Merged
DOsinga merged 13 commits intoblock:mainfrom
octogonz:main
Mar 26, 2026
Merged

fix(providers): fall back to configured models when models endpoint fetch fails#7530
DOsinga merged 13 commits intoblock:mainfrom
octogonz:main

Conversation

@octogonz
Copy link
Copy Markdown
Contributor

@octogonz octogonz commented Feb 26, 2026

Summary

Custom providers with a predefined models list could fail in Desktop when Goose attempted to fetch models from the provider API and the endpoint was not implemented. This change falls back to the configured models list if the API request fails.

Changes

  • Store optional custom_models from custom provider config.
  • Attempt API fetch first.
  • On error, fall back to configured models (with debug log).
  • Preserve existing behavior when no configured models are provided.

Why

Supports OpenAI-/Anthropic-compatible proxies and gateways that do not expose a models endpoint.

Fixes #7427

CC @tltsaia

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d23ffce1f4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

octogonz added a commit to octogonz/goose that referenced this pull request Feb 26, 2026
…mented errors

Auth failures (401/403), rate limits (429), and server errors (5xx) now
propagate correctly instead of being hidden by fallback. Only 404 and connection
failures trigger fallback to preserve diagnostics.

Fixes P1 feedback from PR block#7530
Custom providers with models defined in JSON config would fail when
switching models in the Desktop UI because the code always tried to
fetch from the /v1/models API endpoint, which many proxies don't
implement.

Now, for custom providers that define a models list:
- Try to fetch models from /v1/models API first
- On any error, gracefully fallback to predefined models from config
- Log a debug message when falling back

Backwards compatible: providers without custom models must still
succeed with the API call (unchanged behavior).

Fixes GitHub issue block#7427.

Signed-off-by: Pete Gonzalez <[email protected]>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 664cc3f2cc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…mented errors

Auth failures (401/403), rate limits (429), and server errors (5xx) now
propagate correctly instead of being hidden by fallback. Only 404 and connection
failures trigger fallback to preserve diagnostics.

Fixes P1 feedback from PR block#7530

Signed-off-by: Pete Gonzalez <[email protected]>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e38b52c7f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Connection failures should not trigger fallback to custom models - they
indicate the provider host is down, not that the models endpoint is missing.
This preserves diagnostics for outages.

Addresses second P1 feedback from PR block#7530.

Signed-off-by: Pete Gonzalez <[email protected]>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3e88965ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Using contains("404") could incorrectly match port numbers like localhost:4040
in connection error messages. The 404 status code is always formatted as "(404)"
in error messages from map_http_error_to_provider_error.

Addresses third P1 feedback from PR block#7530.

Signed-off-by: Pete Gonzalez <[email protected]>
@octogonz
Copy link
Copy Markdown
Contributor Author

@katzdave issue #7427 was closed by your PR #7484, however it didn't seem to address the problem where the desktop app displays an error message when trying to connect to a proxy service that does not implement the /v1/models endpoint.

I think we still need my PR #7530 to fix that part. Thanks!

@DOsinga DOsinga self-assigned this Mar 9, 2026
@DOsinga
Copy link
Copy Markdown
Collaborator

DOsinga commented Mar 10, 2026

thanks for diving onto this and sorry for the late reply

two things:

  • I think we are also using the models endpoint to check if the provider works at all during config. if it errors out anyway, maybe there is no difference, but something to think about
  • should we maybe always return the custom models and just override what the provider gives you? I imagine a scenario where a company wants to say, just use any of these three models and they can just create a custom provider for that

Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

The fix is correct and tightly scoped — the fallback only activates when custom_models is explicitly configured, so normal OpenAI/Anthropic flows are completely unaffected. Codex comments were all addressed well. I cleaned up a few inline comments that restated what the code already said clearly, and rebased onto main.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 073cc65212

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


pub fn is_endpoint_not_implemented(&self) -> bool {
match self {
ProviderError::RequestFailed(msg) => msg.contains("(404)"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match endpoint-not-implemented on status, not message text

ProviderError::is_endpoint_not_implemented() currently checks RequestFailed text with msg.contains("(404)"), which can misclassify non-404 failures whenever the upstream error payload happens to include that substring (for example, a 400/405 response message mentioning 404). In that case fetch_supported_models() in the OpenAI/Anthropic providers will incorrectly return custom_models and hide the real API error. Because RequestFailed embeds arbitrary server text, this detection should use structured status information instead of substring matching.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and for addressing all the codex comments thoroughly — the fallback logic is tightly scoped and correct.

I've pushed two small follow-up commits to your branch:

  1. Removed inline comments that restated what the code already said clearly, and collapsed the nested match/if into a cleaner guard pattern.
  2. Addressed the copilot P2: replaced the msg.contains("(404)") substring check with a dedicated ProviderError::EndpointNotFound variant, emitted structurally from map_http_error_to_provider_error when the HTTP status is exactly 404. This means a 400/405 response whose body happens to contain (404) will no longer be mistaken for a missing endpoint. Added two test cases covering 404 with and without a payload that itself contains a 404 substring.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39181a57b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

StatusCode::NOT_FOUND => {
ProviderError::RequestFailed(format!("Resource not found (404): {}", extract_message()))
}
StatusCode::NOT_FOUND => ProviderError::EndpointNotFound(extract_message()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep inference 404s as RequestFailed for model hints

Mapping every 404 to EndpointNotFound here regresses the model-recommendation flow for failed inference calls. Agent::enhance_model_error in agents/reply_parts.rs only augments ProviderError::RequestFailed with “available models” suggestions, so a /chat/completions response like “model ... not found” now skips that path and surfaces a less actionable generic error. This is a user-visible regression from the previous RequestFailed mapping for 404 responses.

Useful? React with 👍 / 👎.

…stFailed for inference 404s

The shared map_http_error_to_provider_error was changed to emit
EndpointNotFound for all 404 responses, but enhance_model_error in
reply_parts.rs only augments RequestFailed errors with available-model
suggestions. A /chat/completions 404 (e.g. 'model X not found') would
skip that path and surface a less actionable error.

Fix: emit EndpointNotFound only from fetch_models_from_api (where we
actually want the custom-models fallback), and keep the shared 404
mapper returning RequestFailed so inference errors still get the
model-recommendation enhancement.

Signed-off-by: Douwe Osinga <[email protected]>
Copy link
Copy Markdown
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

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

Addressed the remaining Codex P2 about EndpointNotFound regressing the model-recommendation flow.

The fix in 6c756b50: instead of emitting EndpointNotFound from the shared map_http_error_to_provider_error (which is used for all HTTP calls including inference), the 404→EndpointNotFound conversion now only happens inside fetch_models_from_api on both OpenAI and Anthropic providers. The shared mapper keeps returning RequestFailed for 404s, so enhance_model_error in reply_parts.rs continues to match inference 404s and append the helpful "Available models" suggestion.

@DOsinga DOsinga added this pull request to the merge queue Mar 26, 2026
Merged via the queue into block:main with commit 27e197e Mar 26, 2026
22 checks passed
michaelneale added a commit that referenced this pull request Mar 26, 2026
* main: (337 commits)
  fix: replace panics with user-friendly errors in CLI session builder (#7901)
  fix: read GOOSE_CONTEXT_LIMIT from config.yaml, not just env vars (#7900)
  fix: deliver truncation notice as separate content block (#7899)
  fix: use platform-appropriate commands in developer extension instructions (#7898)
  fix: replace any with proper SVG types in icon components (#7873)
  chore: remove debug console.log statements, stale comments, and dead code (#8142)
  feat: Gemini OAuth provider (#8129)
  chore(deps): bump picomatch from 2.3.1 to 2.3.2 in /documentation (#8123)
  feat: show installed skills in UI (#7910)
  fix(deps): gate keyring platform features behind target-specific deps (#8039)
  chore(deps): bump yaml from 2.8.2 to 2.8.3 in /evals/open-model-gym/suite (#8124)
  fix: strip message wrapper in CLI session title generation (#7996)
  fix(providers): fall back to configured models when models endpoint fetch fails (#7530)
  chore(deps): bump brace-expansion from 5.0.3 to 5.0.5 in /evals/open-model-gym/suite (#8139)
  fix: prevent Ollama provider from hanging on tool-calling requests (#7723)
  fix: VMware Tanzu Platform provider - bug fixes, streaming, UI improvements (#8126)
  feat: allow GOOSE_CLI_SHOW_THINKING to be set in config.yaml (#8097)
  fix: GitHub Copilot auth fails to open browser in Desktop app (#6957) (#8019)
  fix(ci): produce .tar.gz archives for Zed ACP registry compatibility (#8054)
  feat: add GOOSE_SHOW_FULL_OUTPUT config to disable tool output truncation (#7919)
  ...

# Conflicts:
#	crates/goose/src/providers/formats/openai.rs
hydrosquall pushed a commit to hydrosquall/goose that referenced this pull request Mar 31, 2026
…etch fails (block#7530)

Signed-off-by: Pete Gonzalez <[email protected]>
Signed-off-by: Douwe Osinga <[email protected]>
Co-authored-by: Pete Gonzalez <[email protected]>
Co-authored-by: Douwe Osinga <[email protected]>
Signed-off-by: Cameron Yick <[email protected]>
@octogonz
Copy link
Copy Markdown
Contributor Author

octogonz commented Apr 2, 2026

Thanks very much! 🚀

blackgirlbytes pushed a commit that referenced this pull request Apr 2, 2026
* main: (337 commits)
  fix: replace panics with user-friendly errors in CLI session builder (#7901)
  fix: read GOOSE_CONTEXT_LIMIT from config.yaml, not just env vars (#7900)
  fix: deliver truncation notice as separate content block (#7899)
  fix: use platform-appropriate commands in developer extension instructions (#7898)
  fix: replace any with proper SVG types in icon components (#7873)
  chore: remove debug console.log statements, stale comments, and dead code (#8142)
  feat: Gemini OAuth provider (#8129)
  chore(deps): bump picomatch from 2.3.1 to 2.3.2 in /documentation (#8123)
  feat: show installed skills in UI (#7910)
  fix(deps): gate keyring platform features behind target-specific deps (#8039)
  chore(deps): bump yaml from 2.8.2 to 2.8.3 in /evals/open-model-gym/suite (#8124)
  fix: strip message wrapper in CLI session title generation (#7996)
  fix(providers): fall back to configured models when models endpoint fetch fails (#7530)
  chore(deps): bump brace-expansion from 5.0.3 to 5.0.5 in /evals/open-model-gym/suite (#8139)
  fix: prevent Ollama provider from hanging on tool-calling requests (#7723)
  fix: VMware Tanzu Platform provider - bug fixes, streaming, UI improvements (#8126)
  feat: allow GOOSE_CLI_SHOW_THINKING to be set in config.yaml (#8097)
  fix: GitHub Copilot auth fails to open browser in Desktop app (#6957) (#8019)
  fix(ci): produce .tar.gz archives for Zed ACP registry compatibility (#8054)
  feat: add GOOSE_SHOW_FULL_OUTPUT config to disable tool output truncation (#7919)
  ...

# Conflicts:
#	crates/goose/src/providers/formats/openai.rs
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.

Cannot use Azure OpenAI deployment endpoints (no /models endpoint)

2 participants