Repository navigation
fix(codex): keep the user's API-key login when switching to a third-party provider - #577
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
jayhemnani9910
force-pushed
the
fix/codex-api-key-login-not-residue
branch
from
November 25, 2026 05:51
ee2e309 to
762dd0a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Codex user who logged in with
codex login --with-api-keyloses that login the first time they switch to a third-party provider:The same thing happens with "Preserve Codex official login" turned on. A ChatGPT OAuth login in the same steps is stashed and restored as expected.
The imported
defaultrow has categorycustom, soprepareputs its key into the list of third-party keys.is_residuethen sees the liveauth.jsonas a key that an older version wrote for a relay. It is left out of the stash and deleted, even with preserve on. The comment onis_residuealready says a key the user logged in with themselves must not count.This change only counts a row's key when the row's config sends traffic somewhere other than built-in OpenAI: a
model_providerother thanopenai,openai_base_urlorbase_url, a[model_providers.openai]override, a profile that sets one of those, or a config that does not parse. A login with no config.toml, with only settings likemodel = ...and[profiles.*], withmodel_provider = "openai", or with an unused[model_providers.*]table is now stashed and restored like an OAuth login. Keys that older versions wrote for real relay rows are still cleaned up.Not changed: switching back to the
defaultcard itself (not an official card) still leavesauth.jsonempty, as before, because a non-official target never restores from the stash. Upstream cc-switch builds the residue list the same way (codex_direct.rs).Testing
provider_service_switch_codex_stashes_user_api_key_login_from_imported_default: default, relay, official for five config shapes;auth.jsonis back with the user's key. Fails on main.provider_service_switch_codex_preserve_keeps_user_api_key_login_from_imported_default: with preserve on,auth.jsonis untouched after the relay switch. Fails on main.provider_service_switch_codex_official_clears_legacy_relay_key: a relay key left inauth.jsonby an older version is still removed on the switch to official, for five relay config shapes. Passes before and after.cargo fmt --checkandcargo clippy --all-targetsshow nothing new. The fullcargo testrun has the same failures with and without the change (permission checks on this machine's temp dirs, e.g. database init and managed config dir tests).