Refresh Codex provider label on proxy takeover hot-switch

During proxy takeover, switching third-party Codex providers left the
client-visible provider name stale: sync_codex_live_from_provider_while_proxy_active
based the live config on the existing live file and only patched
base_url/wire_api/model, never refreshing model_provider or
model_providers.<id>.name. The Codex app kept showing the previous
provider in its bottom-right label.

Rebuild the effective settings from the DB for the selected provider so
the live config carries the correct provider key and display name, then
merge MCP servers back from the existing live config. base_url stays
pointed at the local proxy, and official OAuth in auth.json is untouched
(takeover writes config.toml only when auth preservation is enabled).

Generalize preserve_codex_mcp_servers_in_backup ->
preserve_codex_mcp_servers_from_existing_config since it now serves both
the backup and live-sync paths.
This commit is contained in:
Jason
2026-06-01 15:16:13 +08:00
parent aeaa016cae
commit b7499fc871
3 changed files with 78 additions and 21 deletions
+6 -4
View File
@@ -1563,7 +1563,7 @@ impl ProviderService {
/// Switch flow:
/// 1. Validate target provider exists
/// 2. Check if proxy takeover mode is active AND proxy server is running
/// 3. If takeover mode active: hot-switch proxy target only (no Live config write)
/// 3. If takeover mode active: hot-switch proxy target and refresh proxy-safe Live labels
/// 4. If normal mode:
/// a. **Backfill mechanism**: Backfill current live config to current provider
/// b. Update local settings current_provider_xxx (device-level)
@@ -1631,7 +1631,9 @@ impl ProviderService {
}
if should_hot_switch {
// Proxy takeover mode: hot-switch only, don't write Live config
// Proxy takeover mode: hot-switch without restoring upstream Live config.
// The proxy layer may still refresh proxy-safe Live fields so client labels
// follow the selected provider while endpoints remain local.
log::info!(
"代理接管模式:热切换 {} 的目标供应商为 {}",
app_type.as_str(),
@@ -1645,8 +1647,8 @@ impl ProviderService {
)
.map_err(|e| AppError::Message(format!("热切换失败: {e}")))?;
// Note: No Live config write, no MCP sync
// The proxy server will route requests to the new provider via is_current
// The proxy server will route requests to the new provider via is_current.
// MCP sync is intentionally skipped while Live config is owned by takeover.
return Ok(SwitchResult::default());
}