Skip to content

fix: preserve DB auth when disk auth.json is absent during Codex provider switch#88

Merged
SaladDay merged 1 commit intoSaladDay:mainfrom
BFlameSwift:fix/codex-switch-preserve-db-auth
Apr 5, 2026
Merged

fix: preserve DB auth when disk auth.json is absent during Codex provider switch#88
SaladDay merged 1 commit intoSaladDay:mainfrom
BFlameSwift:fix/codex-switch-preserve-db-auth

Conversation

@BFlameSwift
Copy link
Copy Markdown
Contributor

Summary

Fixes #87 — provider switch overwrites synced DB auth with empty disk state.

When switching Codex providers, backfill_codex_current() and refresh_provider_snapshot() read auth from ~/.codex/auth.json. If the file is missing (e.g. after a WebDAV sync that only populated the DB), the code previously used None, which overwrote valid DB-synced OAuth tokens with empty data.

Changes

  • codex.rs / backfill_codex_current(): When auth.json doesn't exist on disk, fall back to current_provider.settings_config["auth"] (the DB snapshot) instead of None
  • mod.rs / refresh_provider_snapshot(): Same fix — when auth.json doesn't exist on disk, fall back to provider.settings_config["auth"] (the DB snapshot) instead of None

Root Cause

The provider switch followed a flawed execution order:

  1. Read ~/.codex/auth.json from disk (empty/missing after fresh WebDAV sync)
  2. Write that empty disk state back into the DB, destroying valid synced auth
  3. Write config files from the DB, which now contains empty auth

Fix

Both functions now check if auth.json exists on disk first (preferred, as it may be fresher). If absent, they fall back to the existing DB auth rather than using None. This ensures WebDAV-synced credentials survive a provider switch.

Backward Compatibility

The existing test switch_codex_succeeds_without_auth_json remains valid — when a provider has no auth in either disk or DB, the result is still None.

Test plan

  • Verify existing test switch_codex_succeeds_without_auth_json still passes
  • Verify codex_switch_removes_existing_auth_json_for_openai_official_provider still passes
  • Reproduce the WebDAV sync scenario: sync OAuth tokens via WebDAV, delete auth.json, run provider switch, verify DB auth is preserved

🤖 Generated with Claude Code

…ider switch

When switching Codex providers, backfill_codex_current() and
refresh_provider_snapshot() read auth from ~/.codex/auth.json. If the
file is missing (e.g. after a WebDAV sync that only populated the DB),
the code previously used None, which overwrote valid DB-synced OAuth
tokens with empty data.

Now both functions fall back to the existing DB snapshot's auth when
the disk file is absent, so WebDAV-synced credentials survive a
provider switch.

Closes SaladDay#87

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SaladDay
Copy link
Copy Markdown
Owner

SaladDay commented Apr 5, 2026

thanks!🙂

@SaladDay SaladDay merged commit 1d719a7 into SaladDay:main Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: provider switch overwrites synced DB auth with empty disk state

2 participants