Skip to content

Clear stale base_url on gateway model switches - #51488

Closed
ipriyaaanshu wants to merge 1 commit into
NousResearch:mainfrom
ipriyaaanshu:codex/clear-stale-base-url
Closed

Clear stale base_url on gateway model switches#51488
ipriyaaanshu wants to merge 1 commit into
NousResearch:mainfrom
ipriyaaanshu:codex/clear-stale-base-url

Conversation

@ipriyaaanshu

@ipriyaaanshu ipriyaaanshu commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Clears stale inline model.base_url values when gateway model switches persist non-custom providers.

This is a focused follow-up to merged PR #49380. That PR added shared stale endpoint cleanup and wired it into gateway model-switch persistence, but the shared helper clears api_key, legacy api, and api_mode only. It does not clear base_url, so a gateway /model switch can still re-save an old inline endpoint for a built-in provider.

In my local repro, switching models from Telegram rewrote config.yaml with:

model:
  default: minimax-m3
  provider: opencode-go
  base_url: https://opencode.ai/zen/go

The provider profile endpoint is https://opencode.ai/zen/go/v1, so later gateway-spawned agents inherited the stale inline endpoint and failed even though TUI/direct provider calls worked.

This PR keeps existing helper behavior backward-compatible by making base_url clearing opt-in, then enables it only in the gateway persistence paths for non-custom providers.

Relationship to existing work

Related Issue

Fixes #25107

Refs #47533 and #51486.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • hermes_cli/config.py: add optional clear_base_url support to clear_model_endpoint_credentials(...).
  • gateway/slash_commands.py: clear inline base_url when persisting gateway model switches for non-custom providers.
  • tests/gateway/test_model_picker_persist.py: assert picker-based built-in provider switches do not persist model.base_url.
  • tests/gateway/test_model_command_flat_string_config.py: assert typed /model built-in provider switches do not persist model.base_url.

How to Test

  1. Run the focused gateway regression tests:

    python -m pytest tests/gateway/test_model_picker_persist.py tests/gateway/test_model_command_flat_string_config.py -q
  2. Confirm the result:

    8 passed, 2 warnings
    
  3. Manual repro used before this patch: switch an opencode-go model from Telegram and inspect config.yaml; the stale root model.base_url was reintroduced before this fix.

Checklist

Code

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I have run pytest tests/ -q and all tests pass
  • I have added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I have tested on my platform: Ubuntu 24.04.4 LTS

Documentation & Housekeeping

  • I have updated relevant documentation (README, docs/, docstrings) - or N/A
  • I have updated cli-config.yaml.example if I added/changed config keys - or N/A
  • I have updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - or N/A
  • I have considered cross-platform impact (Windows, macOS) per the compatibility guide - or N/A
  • I have updated tool descriptions/schemas if I changed tool behavior - or N/A

For New Skills

N/A

Screenshots / Logs

Sanitized failing endpoint before the fix:

Provider: opencode-go
Endpoint: https://opencode.ai/zen/go
Error: APIConnectionError / HTTP 404 depending on attempt

@ipriyaaanshu
ipriyaaanshu force-pushed the codex/clear-stale-base-url branch from 75c8992 to bb3a90e Compare June 23, 2026 18:29
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jun 23, 2026
@ipriyaaanshu
ipriyaaanshu marked this pull request as ready for review June 23, 2026 18:38
@teknium1

Copy link
Copy Markdown
Contributor

Salvaged and merged via PR #53977 (#53977). Your commit was cherry-picked onto current main with your authorship preserved (commit f6deabc), bundled with the opencode-zen picker catalog fix from #49129 since both came from the same model-picker report. The base_url clear logic merged as-is. Thanks!

@teknium1 teknium1 closed this Jun 28, 2026
pai-scaffolde pushed a commit to pai-scaffolde/hermes-agent that referenced this pull request Jun 28, 2026
pai-scaffolde pushed a commit to pai-scaffolde/hermes-agent that referenced this pull request Jun 28, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway /model switch leaves stale base_url and does not persist api_mode

3 participants