Skip to content

fix(agents): keep the provider you picked across an auth-method change - #715

Open
Adam-Dalloul wants to merge 1 commit into
xintaofei:mainfrom
Adam-Dalloul:fix/claude-provider-rebind-keeps-your-pick
Open

fix(agents): keep the provider you picked across an auth-method change#715
Adam-Dalloul wants to merge 1 commit into
xintaofei:mainfrom
Adam-Dalloul:fix/claude-provider-rebind-keeps-your-pick

Conversation

@Adam-Dalloul

Copy link
Copy Markdown
Contributor

Fixes #628: with two Claude Code providers pointing at different model names, switching to the second one shows and saves the first one's model name.

Reproduction, which is the "点击cc的认证方式切换供应商" in the issue:

  1. Create provider A, then provider B, each with its own ANTHROPIC_MODEL.
  2. Bind Claude Code to B through the auth-method dropdown.
  3. Move the auth method to 官网订阅 or 自定义 and back to 供应商.
  4. The panel now shows A's model, and a save writes A's model into agent_setting.env_json and ~/.claude/settings.json.

Cause: handleClaudeAuthModeChange sets modelProviderId: null whenever the mode leaves model_provider, which is right, because a save in another mode must not persist a binding. Coming back therefore arrives with no binding and falls into the auto-select effect, which called handleModelProviderSelect(selectedModelProviders[0].id). list_all orders by row id, so [0] is the oldest provider, A. The Claude branch of handleModelProviderSelect is provider-authoritative by design, so it rewrites claudeMainModel, envText and configText from A while the user believes they are on B.

The change: the panel remembers the provider each agent was last bound to and prefers it. The head of the list stays the fallback for a first-time pick, and for a remembered provider that no longer exists.

Test: providerToRebindTo covers the four cases, and the first one fails on the old available[0] behaviour.

Not touched here, but adjacent and worth a separate look: the official_subscription branch of the same handler builds allEnvKeys from the API url and key only, so the eight ANTHROPIC_*_MODEL keys survive an auth-mode change in the draft, the env text and config.env.

Leaving "model_provider" auth mode drops `draft.modelProviderId`, so a save
in another mode cannot persist a binding. Coming back to provider mode
therefore arrives with no binding and falls into the auto-select, which took
the head of the provider list. That list is ordered by row id, so the agent
was silently rebound to its OLDEST provider, and the rebind rewrites the
draft's model fields, its env text and its config text with that provider's
values. With two providers pointing at different models, switching to the
second one showed and saved the first one's model name.

The panel now remembers the provider each agent was last bound to and
prefers it, falling back to the head of the list only for a first-time pick
or when the remembered provider is gone.

Reported in xintaofei#628.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codeg内置的cluade code供应商配置如果不是默认模型model name不会随配置自切换而会相互污染

1 participant