fix(model): only strip /v1 from OpenCode URLs on fresh provider resolution - #14919
fix(model): only strip /v1 from OpenCode URLs on fresh provider resolution#14919aniruddhaadak80 wants to merge 1 commit into
Conversation
…ution The /v1 suffix stripping for OpenCode anthropic_messages endpoints was applied unconditionally, including when switching models on the same provider where the base_url was already correct from a prior resolution. This caused models that legitimately need /v1 in the URL to break when switching between them. Add a guard so /v1 is only stripped when the URL was freshly resolved (provider_changed or explicit_provider). When the user stays on the same provider and just switches models, the base_url is already in the correct form and must not be modified. Closes NousResearch#14879
|
Thanks for the investigation @aniruddhaadak80 — but I have to close this without merging. Current main already handles this scenario correctly (fixed by PR #4508 on April 2, 22 days before #14879 was filed). E2E-verified with the exact repro from the issue: The The proposed change regresses 4 existing tests in
These guard the same-provider anthropic_messages switch case (e.g. The underlying issue #14879 will be closed too — the user was on a version predating PR #4508. Appreciate the detailed PR body with the three-case analysis — just happened to land against a scenario already covered. |
Summary
Fixes #14879
The
/modelcommand unconditionally strips/v1from OpenCode base URLs whenapi_mode == "anthropic_messages", but this breaks models that need/v1in the URL when the user switches models on the same provider (where the URL was already correct from a prior resolution).Root Cause
In
switch_model(), the/v1stripping regex runs whenever:api_mode == "anthropic_messages"opencode-zenoropencode-goBut it didn't check whether the URL was freshly resolved or was carried over from the current session. When a user on
opencode-goswitches from one model to another (same provider), thebase_urlis already in the correct form and stripping/v1corrupts it.Changes
hermes_cli/model_switch.py —
switch_model():(provider_changed or explicit_provider)to the/v1strip condition/v1is now only stripped when the URL was freshly resolved viaresolve_runtime_provider()(i.e., the provider changed or was explicitly specified)base_urlis left as-isTesting
openrouter→opencode-go):provider_changed=True→/v1stripped as beforeopencode-go):provider_changed=False, explicit_provider=""→/v1preserved (bug fixed)/model sonnet --provider opencode-go):explicit_provider="opencode-go"→/v1stripped correctlytarget_providercheck → no changeChecklist