Skip to content

fix(codex): always update model catalog JSON on provider switch#3360

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
Postroggy:worktree-bugfix-codex-catalog-stale
Jun 1, 2026
Merged

fix(codex): always update model catalog JSON on provider switch#3360
farion1231 merged 2 commits into
farion1231:mainfrom
Postroggy:worktree-bugfix-codex-catalog-stale

Conversation

@Postroggy

Copy link
Copy Markdown
Contributor

Summary

  • Codex cc-switch-model-catalog.json and model_catalog_json in config.toml were only regenerated when the proxy was active (takeover) or a live backup existed. Switching providers while the proxy was idle left the catalog stale — requiring a full CC Switch restart to pick up the new provider's models.
  • Root cause: the catalog update was gated inside the should_sync_backup block in hot_switch_provider.
  • Fix: after the should_sync_backup block, unconditionally call write_codex_provider_live_with_catalog for Codex provider switches when the proxy is not currently active (!live_taken_over). This mirrors what live.rs already does during a normal provider apply.

Test plan

  • New test hot_switch_codex_provider_updates_model_catalog_json_without_proxy_takeover: seeds two providers (each with modelCatalog), switches without proxy takeover, asserts catalog JSON file is created and contains the new provider's model, and that config.toml now includes model_catalog_json.
  • All existing hot_switch_codex_* tests still pass.
  • Full test suite: 1369 passed, 0 new failures (2 pre-existing port-binding flaky tests unaffected).

🤖 Generated with Claude Code

Without this fix, the cc-switch-model-catalog.json file and the
model_catalog_json field in config.toml were only regenerated when
should_sync_backup was true (proxy active or backup exists). Switching
providers while the proxy was idle left the catalog pointing at the
previous provider's models, requiring a full restart to take effect.

After the existing should_sync_backup block, unconditionally call
write_codex_provider_live_with_catalog when switching a Codex provider
and the proxy is not currently active (live_taken_over == false). This
mirrors what live.rs already does during a normal provider apply.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@AideYu

AideYu commented May 30, 2026

Copy link
Copy Markdown

I can reproduce a related Codex model catalog issue on CC Switch 3.16.0 on macOS.

The PR description matches one part of the behavior: switching Codex providers while the proxy is idle can leave the live cc-switch-model-catalog.json / model_catalog_json stale.

There seems to be an additional persistence case worth covering:

  1. Create or edit a Codex provider, for example DeepSeek Direct, with settings_config.modelCatalog.models containing:
    • deepseek-v4-flash
    • deepseek-v4-pro
  2. Save the provider and verify the model mapping appears in the UI.
  3. Switch from that provider back to an imported OpenAI/Gmail Codex account.
  4. Re-open the DeepSeek provider editor.

Observed result:

  • The model mapping rows disappear from the provider editor.
  • The provider row in SQLite loses settings_config.modelCatalog.
  • The provider's settings_config.config can also lose the model_catalog_json = ... line.

Expected result:

  • Switching away from a Codex provider should not mutate or drop that provider's saved modelCatalog.
  • The live catalog/config should be refreshed for the active provider, but inactive provider snapshots should keep their model mappings.

Local workaround that confirms the failure mode:

  • I added a SQLite trigger that restores settings_config.modelCatalog and model_catalog_json for that specific provider if CC Switch writes an update without them.
  • After that, a DeepSeek Direct -> Gmail switch no longer deletes the saved model mapping, and the Gmail/OpenAI live model list no longer includes the DeepSeek models.

So #3360 looks directionally correct for the live catalog refresh path, but it may also need a test/assertion that provider switching does not rewrite an inactive Codex provider's saved modelCatalog to null/missing.

@farion1231

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80c010e91a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/services/proxy.rs Outdated
@chofuhoyu

Copy link
Copy Markdown
Contributor

This is important and should solve my problem in #3356 (comment)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b0a32ccde

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/services/proxy.rs

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@farion1231
farion1231 merged commit 8bf1660 into farion1231:main Jun 1, 2026
4 checks passed
AnXiYiZhi pushed a commit to AnXiYiZhi/DevCLaw-old that referenced this pull request Jun 9, 2026
…on1231#3360)

* fix(codex): always update model catalog JSON on provider switch

Without this fix, the cc-switch-model-catalog.json file and the
model_catalog_json field in config.toml were only regenerated when
should_sync_backup was true (proxy active or backup exists). Switching
providers while the proxy was idle left the catalog pointing at the
previous provider's models, requiring a full restart to take effect.

After the existing should_sync_backup block, unconditionally call
write_codex_provider_live_with_catalog when switching a Codex provider
and the proxy is not currently active (live_taken_over == false). This
mirrors what live.rs already does during a normal provider apply.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(codex): refresh catalog on restored hot switch

---------

Co-authored-by: yueqi.guo <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Jason <[email protected]>
gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
…on1231#3360)

* fix(codex): always update model catalog JSON on provider switch

Without this fix, the cc-switch-model-catalog.json file and the
model_catalog_json field in config.toml were only regenerated when
should_sync_backup was true (proxy active or backup exists). Switching
providers while the proxy was idle left the catalog pointing at the
previous provider's models, requiring a full restart to take effect.

After the existing should_sync_backup block, unconditionally call
write_codex_provider_live_with_catalog when switching a Codex provider
and the proxy is not currently active (live_taken_over == false). This
mirrors what live.rs already does during a normal provider apply.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* fix(codex): refresh catalog on restored hot switch

---------

Co-authored-by: yueqi.guo <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Jason <[email protected]>
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.

4 participants