Skip to content

fix(setup): defer config.yaml write until after model selection#1188

Closed
ygd58 wants to merge 1 commit intoNousResearch:mainfrom
ygd58:fix/setup-race-condition
Closed

fix(setup): defer config.yaml write until after model selection#1188
ygd58 wants to merge 1 commit intoNousResearch:mainfrom
ygd58:fix/setup-race-condition

Conversation

@ygd58
Copy link
Contributor

@ygd58 ygd58 commented Mar 13, 2026

Problem

Closes #1182

_update_config_for_provider() was called immediately after provider selection for zai, kimi-coding, minimax, minimax-cn, and anthropic — before model selection happened. Since the gateway re-reads config.yaml per-message, this created a race condition where the gateway would pick up the new provider but still use the old (incompatible) model name.

Example: switching from OpenRouter (anthropic/claude-opus-4.6) to MiniMax would briefly write provider: minimax + base_url: https://api.minimax.io/v1 to disk while model.default was still anthropic/claude-opus-4.6. Any gateway message sent during setup would fail.

Even without a race: selecting "Keep current" at model selection would leave an OpenRouter-formatted model name permanently on a non-OpenRouter provider.

Fix

Capture selected_base_url in each affected provider block, then call _update_config_for_provider() once, after model selection completes, just before save_config(). The in-memory _set_model_provider() calls are kept in place so the config object stays consistent throughout the setup flow.

Affected providers

  • zai
  • kimi-coding
  • minimax
  • minimax-cn
  • anthropic

@ygd58
Copy link
Contributor Author

ygd58 commented Mar 13, 2026

Closing — upstream has landed a partial mitigation in main (adding default_model parameter to _update_config_for_provider). This addresses the "Keep current" edge case but the race condition window still exists since config.yaml is written before model selection completes.

The full Option A fix (deferring the write until after model selection) remains the correct solution if the race condition is a priority. Happy to reopen if needed.

@ygd58 ygd58 closed this Mar 13, 2026
@ygd58 ygd58 reopened this Mar 13, 2026
_update_config_for_provider() was called immediately after provider
selection for zai, kimi-coding, minimax, minimax-cn, and anthropic —
before model selection happened. Since the gateway re-reads config.yaml
per-message, this created a race condition where the gateway would pick
up the new provider but still use the old (incompatible) model name.

Fix: capture selected_base_url in each provider block, then call
_update_config_for_provider() once after model selection completes,
just before save_config(). The in-memory _set_model_provider() calls
are kept in place so the config object stays consistent throughout.

Fixes NousResearch#1182
@teknium1
Copy link
Contributor

Cherry-picked into PR #1499 with authorship preserved. Clean apply onto current main — the race condition was still present. Thanks for the fix, @ygd58!

@teknium1 teknium1 closed this Mar 16, 2026
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.

bug: setup flow writes provider to config.yaml before model selection, causing gateway race condition

2 participants