Skip to content

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

Closed
kshitijk4poor wants to merge 1 commit into
mainfrom
fix/model-switch-custom-endpoint
Closed

fix(model): preserve custom endpoint credentials during /model switch#15088
kshitijk4poor wants to merge 1 commit into
mainfrom
fix/model-switch-custom-endpoint

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

/model <name> on custom/local endpoints (ollama-launch, lmstudio, vllm, LAN servers, Docker hostnames, etc.) silently probes OpenRouter instead of the local server, causing model switches to fail.

Before: User on Ollama types /model glm-5:cloud → error says model not found on https://openrouter.ai/api/v1/models

After: /model glm-5:cloud → validates against the local endpoint → model switch succeeds

Root Cause

Named custom providers (config providers: { ollama-launch: { ... } }) resolve through _resolve_named_custom_runtime() which returns provider: "custom". When switch_model() later re-resolves credentials for the same provider, resolve_runtime_provider(requested="custom") can't find the original endpoint and falls through to OpenRouter. Validation then probes OpenRouter's model list instead of the local server.

Fix

When switching models on the same provider (no --provider flag), the existing api_key and base_url from the live agent are already correct. Re-resolution is still attempted for credential rotation and provider-specific URL adjustments (e.g. OpenCode strips /v1 for Anthropic models). But if re-resolution returns a different base_url for a "custom"/"local" provider, that signals a fallthrough — the caller's known-good credentials are preserved instead.

Not hardcoded to Ollama/localhost. The guard uses behavioral detection (base_url mismatch on re-resolution for custom providers), not URL pattern matching. Works for:

  • Local Ollama (127.0.0.1:11434)
  • LAN servers (192.168.x.x:8080)
  • Docker hostnames (http://ollama:11434)
  • Custom domains (https://my-gpu-server:8080)
  • IPv6 localhost ([::1]:11434)

Known providers (OpenRouter, OpenCode, Copilot, etc.) still re-resolve normally.

Verified

  • Live: ollama launch hermes/model gemma3:4b"✓ Model switched: gemma3:4b, Provider: ollama-launch"
  • E2E: 6 endpoint types tested (localhost, LAN IP, custom domain, Docker, IPv6, OpenRouter)
  • 207 existing model-switch + TUI tests pass

@kshitijk4poor kshitijk4poor force-pushed the fix/model-switch-custom-endpoint branch from 48e798e to 5aad06c Compare April 24, 2026 11:18
@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 labels Apr 24, 2026
@kshitijk4poor kshitijk4poor force-pushed the fix/model-switch-custom-endpoint branch 2 times, most recently from 9e32855 to ca8df75 Compare April 24, 2026 11:46
@kshitijk4poor kshitijk4poor force-pushed the fix/model-switch-custom-endpoint branch from ca8df75 to 3d0171a Compare April 25, 2026 07:27
…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
@kshitijk4poor kshitijk4poor force-pushed the fix/model-switch-custom-endpoint branch from 3d0171a to 0d3d2a2 Compare April 25, 2026 08:40
teknium1 pushed a commit that referenced this pull request Apr 26, 2026
…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

Copy link
Copy Markdown
Contributor

Merged via #15826 with your authorship preserved via cherry-pick. Thanks @kshitijk4poor — solid diagnosis and fix. Complements #15823 (Gille's hermes doctor fix) for the full DrWayne report.

ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…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 NousResearch#15088
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
…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 NousResearch#15088
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…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 NousResearch#15088
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
…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 NousResearch#15088
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…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 NousResearch#15088
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…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 NousResearch#15088
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 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