Skip to content

fix: pass target_model to resolve_runtime_provider in _ensure_runtime_credentials (#54147) - #54365

Closed
Sahil-SS9 wants to merge 1 commit into
NousResearch:mainfrom
Sahil-SS9:fix/issue-54147-stale-api-mode-on-model-flag-rebased
Closed

Sahil-SS9 wants to merge 1 commit into
NousResearch:mainfrom
Sahil-SS9:fix/issue-54147-stale-api-mode-on-model-flag-rebased

Conversation

@Sahil-SS9

Copy link
Copy Markdown
Contributor

Fixes #54147

Description

hermes chat -m <model> -q "..." was resolving api_mode and base_url from model.default in config.yaml instead of the explicitly-requested model. On opencode-go (and any provider whose model.default differs in api_mode from the requested model), this sent non-MiniMax models to a wrong endpoint, producing HTTP 404.

Root Cause

_ensure_runtime_credentials() in hermes_cli/cli_agent_setup_mixin.py called resolve_runtime_provider(requested=..., explicit_api_key=..., explicit_base_url=...) without target_model. The resolver then fell back to model_cfg.get("default") to derive api_mode and base_url, picking the wrong mode for any model that differed from the config default.

resolve_runtime_provider already accepted a target_model kwarg (added in PR #16890 for the /model switch path) — it just wasn't being passed here. Same family as #16878 and #15319 (the delegate_tool.py fix used the same one-line pattern).

Fix

Pass target_model=self.model to resolve_runtime_provider() in both the primary and fallback paths of _ensure_runtime_credentials(). The resolver now correctly derives api_mode=chat_completions and base_url=https://opencode.ai/zen/go/v1 for qwen3.7-plus regardless of what model.default is.

 runtime = resolve_runtime_provider(
     requested=self.requested_provider,
     explicit_api_key=self._explicit_api_key,
     explicit_base_url=self._explicit_base_url,
+    target_model=self.model,
 )
-runtime = resolve_runtime_provider(requested=_fb_provider)
+runtime = resolve_runtime_provider(
+    requested=_fb_provider,
+    target_model=_fb_model,
+)

Verification

  • Targeted tests: tests/cli/test_cli_provider_resolution.py (23), test_cli_approval_ui.py (22), test_cli_goal_interrupt.py (7), test_cli_secret_capture.py (5), test_cli_active_agent_ref_wiring.py (2) — 59/59 pass in 8.6s.
  • Manual repro (issue): hermes chat -m qwen3.7-plus -q "ok" → previously 404; with this fix, api_mode=chat_completions + base_url=.../v1 resolved correctly.
  • curl evidence (from issue): the /v1/chat/completions endpoint returns 200, the /chat/completions endpoint returns 404 HTML — confirming the wrong-base_url root cause.

Diff

 hermes_cli/cli_agent_setup_mixin.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Notes

  • No new tests added — the change is one-line per call site and mirrors the proven pattern from fix(opencode): re-derive api_mode per target model on /model switch #16890. The 23 existing tests in test_cli_provider_resolution.py already exercise resolve_runtime_provider resolution across all 20 opencode-go models and would have caught a regression in either direction. A targeted unit test asserting target_model is forwarded is a reasonable follow-up but not required for correctness.
  • Original branch fix/issue-54147-stale-api-mode-on-model-flag was 11,899 commits behind origin/main (stale-fetch artifact from the gate cron). This PR is raised from a fresh branch fix/issue-54147-stale-api-mode-on-model-flag-rebased containing the same single cherry-picked commit on current origin/main. The original branch is preserved untouched.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists labels Jun 28, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Duplicate of #54148 (earliest, canonical) — both pass target_model to resolve_runtime_provider() in _ensure_runtime_credentials() to fix the opencode-go non-default-model 404. This PR additionally patches the fallback path (a small superset); a maintainer may prefer it for that reason, but the dedup anchor is the earlier #54148. Both target #54147.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for covering both the primary and fallback credential-resolution paths. The premise remains present on current main: hermes_cli/cli_agent_setup_mixin.py:41 and :60 omit target_model, while hermes_cli/runtime_provider.py:414 prefers that value over model_cfg.default when deriving OpenCode routing.

Problems

  • The PR has no regression test. Current main's tests/cli/test_cli_provider_resolution.py has no assertion that _ensure_runtime_credentials() forwards target_model; PR #54148 contains a focused primary-path test, but it is not part of this PR. The fallback-path addition at hermes_cli/cli_agent_setup_mixin.py:60 is also untested.

Suggested changes

  • Add a kwargs-capturing regression test for the primary -m path and an AuthError fallback test asserting the resolver receives _fb_model as target_model.

This is an automated hermes-sweeper review.

requested=self.requested_provider,
explicit_api_key=self._explicit_api_key,
explicit_base_url=self._explicit_base_url,
target_model=self.model,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a direct regression test for this forwarding contract. Current main has no target_model assertion for _ensure_runtime_credentials(); PR #54148 has a primary-path example, and this PR should also cover the fallback call below.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
asimons81 pushed a commit to asimons81/hermes-agent that referenced this pull request Jul 15, 2026
…nonical Zen Go URL

The opencode-go HermesOverlay in hermes_cli/providers.py was the only
URL-bearing overlay missing a base_url_override. Every sibling overlay
(openai-api, xai-oauth, qwen-oauth, nous, lmstudio, stepfun,
minimax-oauth) pins a canonical base URL; opencode-go fell through to
mdev_info.api and, depending on what models.dev returned, defaulted to
https://opencode.ai/zen/go with no /v1 suffix.

The /v1-stripped URL is then rounded by anthropic_messages transport
into the same wrong path, surfacing as 'HTTP 404 — Not Found |
opencode' for every non-MiniMax model on the provider. This is the
caller-agnostic half of the bug class tracked at NousResearch/hermes-
agent#54147 — NousResearch#54148 / NousResearch#54365 fix _ensure_runtime_credentials
forwarding target_model (the per-call-site half); this overlay pin
ensures the URL is right regardless of which caller resolves the
provider, covering cron resolution, delegation, kanban, model-picker
prewarm, TUI switcher, and auxiliary fallbacks.

The pinned URL is consistent with every other registration path for
opencode-go in the codebase:

  - hermes_cli/auth.py:385     ProviderConfig.inference_base_url
  - plugins/model-providers/
    opencode-zen/__init__.py:
    142                         OpenCodeGoProfile.base_url
  - ~/.hermes/.env template   OPENCODE_GO_BASE_URL example

Refs NousResearch#54147.
@Sahil-SS9

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #54148 (filed earlier, same fix passing target_model to resolve_runtime_provider). Thanks to @alt-glitch for flagging.

@Sahil-SS9

Copy link
Copy Markdown
Contributor Author

Closing in favour of #54148 (canonical, filed first).

@Sahil-SS9 Sahil-SS9 closed this Jul 31, 2026
@Sahil-SS9
Sahil-SS9 deleted the fix/issue-54147-stale-api-mode-on-model-flag-rebased branch August 2, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: hermes chat -m <model> uses stale api_mode from config default → 404 on opencode-go

3 participants