Skip to content

fix(model): preserve custom endpoint credentials during /model switch#15826

Merged
teknium1 merged 1 commit into
mainfrom
salvage/model-switch-custom-endpoint
Apr 26, 2026
Merged

fix(model): preserve custom endpoint credentials during /model switch#15826
teknium1 merged 1 commit into
mainfrom
salvage/model-switch-custom-endpoint

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #15088 by @kshitijk4poor onto current main.

Summary

/model <name> on custom/local endpoints (ollama-launch, lmstudio, vllm, LAN servers, etc.) no longer silently probes OpenRouter and fails. Named custom providers keep their known-good credentials during switch, and cloud/aliased models absent from /v1/models are accepted instead of rejected.

Changes

  • hermes_cli/model_switch.py: when re-resolution returns bare custom, preserve existing api_key/base_url/api_mode from the live agent. Add user_providers override for models absent from /v1/models but present in saved provider config.
  • hermes_cli/models.py: custom endpoints where /v1/models doesn't list the requested model now return accepted: True with a note instead of rejecting — matches real-world server behavior where cloud/aliased models are supported but not enumerated (glm-5:cloud, :latest variants).
  • tui_gateway/server.py: wires user_providers/custom_providers into switch_model() so TUI gets the same named-custom resolution as CLI.
  • cli.py: pull user_provs/custom_provs load out of the picker-only branch so switch_model() always gets them.

Root cause

Named custom providers (config providers: { ollama-launch: { ... } }) resolve through _resolve_named_custom_runtime() returning provider: "custom". When switch_model() re-resolves credentials with requested="custom", resolve_runtime_provider can't find the original endpoint and falls through to OpenRouter. Validation then probes OpenRouter's /v1/models instead of the local server.

Validation

  • Targeted tests: 131/131 model_switch + validation tests pass. 1 pre-existing failure on main (test_saved_model_still_probes_endpoint) unrelated to this PR.
  • E2E (this salvage): custom endpoint with model not in /v1/models now returns accepted: True; credential preservation guard wired correctly in switch_model().

Credit: @kshitijk4poor (authorship preserved via cherry-pick). Closes #15088. Complements #15823 which fixed the hermes doctor false-positive on the same report.

…els not in /v1/models

When switching models on a custom endpoint (ollama-launch):
- Same-provider switches no longer re-resolve credentials (fixes base_url
  being lost for 'custom' provider on subsequent switches)
- Named providers (ollama-launch) are resolved via user_providers so
  switch_model can find their base_url from config
- Models not in the /v1/models probe but present in the user's saved
  provider config are accepted with a warning instead of rejected
- CLI /model and TUI /model both pass user_providers/custom_providers
  to switch_model so the config model list is available for validation

Closes #15088
@teknium1 teknium1 merged commit 2c56dce into main Apr 26, 2026
9 of 11 checks passed
@teknium1 teknium1 deleted the salvage/model-switch-custom-endpoint branch April 26, 2026 01:03
@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 comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 26, 2026
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 comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants