Skip to content

fix(cli): auto-select Codex model when provider resolves to openai-codex - #696

Closed
teyrebaz33 wants to merge 2 commits into
NousResearch:mainfrom
teyrebaz33:fix/codex-model-default-resolution-v2
Closed

fix(cli): auto-select Codex model when provider resolves to openai-codex#696
teyrebaz33 wants to merge 2 commits into
NousResearch:mainfrom
teyrebaz33:fix/codex-model-default-resolution-v2

Conversation

@teyrebaz33

Copy link
Copy Markdown
Contributor

Problem

Fixes #651

When a user sets up Hermes with OpenAI Codex, any non-Codex model in LLM_MODEL, OPENAI_MODEL, or the config default (e.g. anthropic/claude-opus-4.6) causes an immediate 400 BadRequestError on every request:

Error code: 400 - {'detail': "The 'anthropic/claude-opus-4.6' model is not supported when using Codex with a ChatGPT account."}

Root Cause

HermesCLI.__init__ sets self.model from LLM_MODEL / OPENAI_MODEL env-vars or the config default before the provider is resolved. When _ensure_runtime_credentials() later resolves the provider to openai-codex, the incompatible model was never corrected.

PR #661 addressed only the config-default path and used a hardcoded fallback model (gpt-5.3-codex). This PR fixes the root cause for all model sources including env-vars, which is the exact scenario reported in #651.

Fix

In _ensure_runtime_credentials(), after the provider resolves to openai-codex, check whether the active model is Codex-compatible. If not, replace it with the first model returned by get_codex_model_ids() and warn the user if they had explicitly set the model.

Changes

  • cli.py: Add _model_is_default flag to track explicit vs default model selection
  • cli.py: In _ensure_runtime_credentials(), normalise incompatible models when provider is openai-codex — covers CLI arg, env-var, and config default paths
  • cli.py: Trigger agent rebuild when effective model changes
  • tests/test_cli_provider_resolution.py: Add 3 tests covering config-default path, env-var path (exact [Bug]: hi borked it? #651 scenario), and explicit Codex model preservation

Testing

pytest tests/test_cli_provider_resolution.py tests/test_codex_models.py -q
9 passed in 2.92s

Full suite: 2063 passed, 0 failed.

When the runtime provider resolves to openai-codex, the active model is
now validated against the Codex API regardless of how it was set (CLI
arg, LLM_MODEL env-var, or config default).  If the model is not
Codex-compatible, it is replaced with the first available Codex model
returned by get_codex_model_ids().

Root cause of NousResearch#651: LLM_MODEL=claude-opus-4-6 was set in the user's
.env, which caused a 400 BadRequestError on every Codex request.

Fixes NousResearch#651
The Codex Responses API rejects model IDs with a provider prefix
(e.g. openai/gpt-5.3-codex) — only the bare slug is accepted.

Reported by @yosun in NousResearch#651 after the initial fix.
@teyrebaz33 teyrebaz33 mentioned this pull request Mar 8, 2026
1 task
teknium1 added a commit that referenced this pull request Mar 8, 2026
When _ensure_runtime_credentials() resolves the provider to openai-codex,
check if the active model is Codex-compatible.  If not (e.g. the default
anthropic/claude-opus-4.6), swap it for the best available Codex model.
Also strips provider prefixes the Codex API rejects (openai/gpt-5.3-codex
→ gpt-5.3-codex).

Adds _model_is_default flag so warnings are only shown when the user
explicitly chose an incompatible model (not when it's the config default).

Fixes #651.

Co-inspired-by: stablegenius49 (PR #661)
Co-inspired-by: teyrebaz33 (PR #696)
@teknium1

teknium1 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the thorough fix @teyrebaz33! The _model_is_default flag and the comprehensive test coverage (4 scenarios) were both great ideas that we incorporated into the final implementation.

Unfortunately this PR couldn't be merged directly because the branch is 12 commits behind main and the diff includes unrelated regressions — it removes the /title command (session naming from PR #720), the /provider command, reverts image preprocessing back to raw base64 (undoing commit cf810c2), and removes session title display on resume.

We implemented the fix in commit 95b1130, combining the best of both this PR and #661:

Credit noted in the commit message. Closing this PR — thanks for the contribution!

@teknium1 teknium1 closed this Mar 8, 2026
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
When _ensure_runtime_credentials() resolves the provider to openai-codex,
check if the active model is Codex-compatible.  If not (e.g. the default
anthropic/claude-opus-4.6), swap it for the best available Codex model.
Also strips provider prefixes the Codex API rejects (openai/gpt-5.3-codex
→ gpt-5.3-codex).

Adds _model_is_default flag so warnings are only shown when the user
explicitly chose an incompatible model (not when it's the config default).

Fixes NousResearch#651.

Co-inspired-by: stablegenius49 (PR NousResearch#661)
Co-inspired-by: teyrebaz33 (PR NousResearch#696)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
When _ensure_runtime_credentials() resolves the provider to openai-codex,
check if the active model is Codex-compatible.  If not (e.g. the default
anthropic/claude-opus-4.6), swap it for the best available Codex model.
Also strips provider prefixes the Codex API rejects (openai/gpt-5.3-codex
→ gpt-5.3-codex).

Adds _model_is_default flag so warnings are only shown when the user
explicitly chose an incompatible model (not when it's the config default).

Fixes NousResearch#651.

Co-inspired-by: stablegenius49 (PR NousResearch#661)
Co-inspired-by: teyrebaz33 (PR NousResearch#696)
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
When _ensure_runtime_credentials() resolves the provider to openai-codex,
check if the active model is Codex-compatible.  If not (e.g. the default
anthropic/claude-opus-4.6), swap it for the best available Codex model.
Also strips provider prefixes the Codex API rejects (openai/gpt-5.3-codex
→ gpt-5.3-codex).

Adds _model_is_default flag so warnings are only shown when the user
explicitly chose an incompatible model (not when it's the config default).

Fixes NousResearch#651.

Co-inspired-by: stablegenius49 (PR NousResearch#661)
Co-inspired-by: teyrebaz33 (PR NousResearch#696)
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]: hi borked it?

2 participants