{"record":{"id":"ff4d4d10503cda61","repo":"BigPizzaV3/CodexPlusPlus","slug":"config-toml-auth-json","errorCode":null,"errorMessage":"供应商配置总开关已关闭，未写入 config.toml / auth.json。","messagePattern":"供应商配置总开关已关闭，未写入 config\\.toml / auth\\.json。","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/relay_switch.rs","lineNumber":26,"sourceCode":"};\nuse crate::settings::{BackendSettings, RelayMode, SettingsStore};\n\n#[derive(Debug, Clone, PartialEq, Eq)]\npub struct RelaySwitchResult {\n    pub settings: BackendSettings,\n    pub configured: bool,\n    pub backup_path: Option<String>,\n}\n\npub fn switch_relay_profile_in_home(\n    store: &SettingsStore,\n    home: &Path,\n    next_settings: BackendSettings,\n    previous_active_relay_id: &str,\n) -> anyhow::Result<RelaySwitchResult> {\n    let mut selected_settings = next_settings;\n    if !selected_settings.relay_profiles_enabled {\n        anyhow::bail!(\"供应商配置总开关已关闭，未写入 config.toml / auth.json。\");\n    }\n    crate::codex_app_state::capture_app_state_snapshot_nonfatal(home, \"relay_switch.before\");\n\n    let original_settings = store.load().unwrap_or_default();\n    let live_snapshot = LiveFilesSnapshot::capture(home).context(\"读取当前 Codex 实时配置失败\")?;\n    if !previous_active_relay_id.trim().is_empty()\n        && previous_active_relay_id != selected_settings.active_relay_id\n    {\n        backfill_profile_before_switch(home, &mut selected_settings, previous_active_relay_id)?;\n    }\n\n    store\n        .save(&selected_settings)\n        .context(\"保存供应商设置失败\")?;\n    let selected_settings = store.load().context(\"读取供应商设置失败\")?;\n\n    match apply_selected_relay_profile(home, &selected_settings) {\n        Ok(result) => {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/relay_switch.rs#L8-L44","documentation":"switch_relay_profile_in_home refuses to switch provider profiles when the backend settings have relay_profiles_enabled = false. The master switch for multi-provider configuration is off, so no config.toml / auth.json writes are performed and the switch aborts.","triggerScenarios":"Calling switch_relay_profile_in_home (via the manager's switch command) with next_settings.relay_profiles_enabled == false — i.e. the user toggled off the provider-profiles feature (or loaded settings where it defaulted off) and then attempted a profile switch.","commonSituations":"User disabled the provider-config master toggle in the manager UI and an automation/script still tried to switch; settings.json synced/reset from another machine lost the enabled flag; a fresh install defaults the flag off.","solutions":["Enable the relay-profiles master switch in settings (set relay_profiles_enabled = true) and retry","Update the caller to check relay_profiles_enabled before invoking the switch","Re-save settings in the manager UI so the flag persists","Inspect settings.json to confirm the flag state before automating switches"],"exampleFix":"// before\nawait invoke(\"switch_relay_profile\", { settings: { relay_profiles_enabled: false, ... } })\n// after\nif (!settings.relay_profiles_enabled) throw new Error(\"enable relay profiles first\");\nawait invoke(\"switch_relay_profile\", { settings });","handlingStrategy":"validation","validationCode":"if (!settings.relay_profiles_enabled) {\n  throw new Error('relay profiles are disabled; enable the master switch before switching providers');\n}\nawait invoke('switch_relay_profile', { settings });","typeGuard":"const canSwitch = (s) => s.relay_profiles_enabled === true;","tryCatchPattern":"try { await switchProfile(settings); } catch (e) { if (String(e).includes('总开关已关闭')) { showEnableRelayProfilesPrompt(); } else throw e; }","preventionTips":["Gate switch UI/actions on the relay_profiles_enabled flag","Persist the flag explicitly when saving settings","Sync-check settings across machines before automated switches"],"tags":["config","feature-flag","rust"],"backgroundTag":"feature-not-enabled","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}