jlcodes99/cockpit-tools · warning

[Codex导入] 当前账号重新激活失败(导入已成功): id={}, error={}

Error message

[Codex导入] 当前账号重新激活失败(导入已成功): id={}, error={}

What it means

Post-import reactivation failure log in reactivate_if_imported_matches_current (src-tauri/src/modules/codex_account_runtime_switch.rs:702). After a successful import, if the imported account matches the currently active account id, the module re-runs switch_account_managed so running profiles use the fresh tokens. If that switch fails, this error is logged and None is returned — the import result itself is preserved and the failure is intentionally non-fatal by design.

Source

Thrown at src-tauri/src/modules/codex_account_runtime_switch.rs:702

) -> Option<CodexAccount> {
    let current_id = load_account_index().current_account_id?;
    if !imported
        .iter()
        .any(|account| account.id.as_str() == current_id.as_str())
    {
        return None;
    }

    match switch_account_managed(&current_id).await {
        Ok(account) => {
            logger::log_info(&format!(
                "[Codex导入] 当前账号已重新激活: id={}, email={}",
                account.id, account.email
            ));
            Some(account)
        }
        Err(error) => {
            logger::log_error(&format!(
                "[Codex导入] 当前账号重新激活失败(导入已成功): id={}, error={}",
                current_id, error
            ));
            None
        }
    }
}

enum PreparedCodexAccountSwitch {
    Account(CodexAccount),
    ApiKeyWithOauth {
        api_key_account: CodexAccount,
        oauth_account: CodexAccount,
    },
}

async fn prepare_account_switch_locked(
    account_id: &str,

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Close any running Codex CLI processes that may lock the profile auth files, then re-trigger the import or a manual account switch
  2. Read the logged `error={}` detail to identify whether it is a file write, lock, or gateway start failure
  3. Manually switch to the account in the UI (switch_account_managed) to complete the reactivation
  4. Verify the Codex profile base_dir is writable and has free space
  5. Retry the import after resolving — import succeeded, only the refresh of the running session failed

Example fix

// before: treat reactivation failure as fatal and lose the import result
let reactivated = reactivate_if_imported_matches_current(&imported).await
    .ok_or_else(|| "reactivation failed".to_string())?;
// after: accept None, inform the user tokens updated but a manual switch is needed
if let Some(account) = reactivate_if_imported_matches_current(&imported).await {
    emit_side_effects(&account);
} else {
    ui::warn("导入成功,但当前账号重新激活失败,请手动切换一次账号以应用新 token");
}
Defensive patterns

Strategy: try-catch

Validate before calling

fn profile_dir_writable(base_dir: &Path) -> bool {
    let probe = base_dir.join(".write_probe");
    match std::fs::write(&probe, b"ok") {
        Ok(_) => { let _ = std::fs::remove_file(&probe); true }
        Err(_) => false,
}
}

Type guard

fn is_reactivation_applicable(imported: &[CodexAccount], current_id: &Option<String>) -> bool {
    match current_id {
        Some(id) => imported.iter().any(|a| a.id.as_str() == id.as_str()),
        None => false,
    }
}

Try / catch

// reactivation is non-fatal by design; always handle the None branch
match reactivate_if_imported_matches_current(&imported).await {
    Some(account) => apply_switch_side_effects(&account).await,
    None => warn_user("导入成功;当前账号自动重新激活失败,请手动切换一次账号"),
}

Prevention

When it happens

Trigger: switch_account_managed(&current_id) returning Err during reactivation — e.g. failure writing auth files to the Codex profile directory, failure stopping/starting the local gateway, storage lock contention, or the target profile directory being unwritable — triggered after import/import_from_json operations that updated the currently active account.

Common situations: Codex CLI process holding locks on auth.json while the app rewrites it; read-only or full profile directory; a concurrently running account switch racing with the import; local gateway port conflicts during ensure_bound_oauth_local_gateway.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/eceef5e45903ba1f. Report an issue: GitHub.