BigPizzaV3/CodexPlusPlus · critical

切换供应商失败: ;同时回滚配置失败:settings.json= ,Codex 实时文件=

Error message

切换供应商失败:{error};同时回滚配置失败:settings.json={},Codex 实时文件={}

What it means

When switching provider profiles fails, switch_relay_profile_in_home attempts to roll back settings.json and the Codex live files (config.toml / auth.json) from snapshots taken before the switch. If either rollback itself errors, the original error is wrapped with the rollback failures so the user knows the system may be in a partially-restored state.

Solutions

  1. Read the {error} prefix first — fix the root switch failure (e.g. permissions, invalid config)
  2. Manually restore: check codex_app_state snapshot dirs (relay_switch.before) and settings backups
  3. Ensure ~/.codex and the settings store are writable and not locked by other processes
  4. Retry the switch after restoring a consistent state; free disk space if writes failed

Example fix

// before: no guard — rollback errors surface as this combined message
switch_relay_profile_in_home(home, settings, id)
// after: pre-check writability and validate config before switching
ensure_writable(home)?;
validate_profile(&settings)?;
switch_relay_profile_in_home(home, settings, id)
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await switchProfile(settings, prevId);
} catch (e) {
  if (String(e).includes('同时回滚配置失败')) {
    // partial state: inspect relay_switch.before snapshot and settings backup, restore manually
    await restoreFromSnapshot(home, 'relay_switch.before');
  } else { throw e; }
}

Prevention

When it happens

Trigger: Any failure inside switch_relay_profile_in_home (write failure, status-check failure, etc.) where store.save(&original_settings) or live_snapshot.restore(home) also returns Err — the combined error is raised with both messages.

Common situations: Disk full or permission problems preventing both the switch and the restore; config.toml/auth.json locked by another process during rollback; snapshot restore failing because live files were deleted mid-switch; underlying switch error like invalid TOML compounded by an unwritable settings.json.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/58d3ef34bea62a24. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/relay_switch.rs:55

    store
        .save(&selected_settings)
        .context("保存供应商设置失败")?;
    let selected_settings = store.load().context("读取供应商设置失败")?;

    match apply_selected_relay_profile(home, &selected_settings) {
        Ok(result) => {
            crate::codex_app_state::sync_app_state_after_provider_switch_nonfatal(
                home,
                "relay_switch.after",
            );
            Ok(result)
        }
        Err(error) => {
            let settings_restore_error = store.save(&original_settings).err();
            let live_restore_error = live_snapshot.restore(home).err();
            if settings_restore_error.is_some() || live_restore_error.is_some() {
                anyhow::bail!(
                    "切换供应商失败:{error};同时回滚配置失败:settings.json={},Codex 实时文件={}",
                    settings_restore_error
                        .map(|error| error.to_string())
                        .unwrap_or_else(|| "ok".to_string()),
                    live_restore_error
                        .map(|error| error.to_string())
                        .unwrap_or_else(|| "ok".to_string())
                );
            }
            Err(error)
        }
    }
}

#[derive(Debug, Clone)]
struct LiveFilesSnapshot {
    config: Option<Vec<u8>>,
    auth: Option<Vec<u8>>,

View on GitHub (pinned to b1ed92e5e4)