Skip to content

fix(deeplink): keep a Codex link's provider config instead of rebuilding a fixed template - #567

Open
RGB-loop wants to merge 1 commit into
SaladDay:mainfrom
RGB-loop:fix/codex-deeplink-keep-config
Open

RGB-loop wants to merge 1 commit into
SaladDay:mainfrom
RGB-loop:fix/codex-deeplink-keep-config

Conversation

@RGB-loop

Copy link
Copy Markdown
Contributor

Problem

Importing a Codex provider from a ccswitch://v1/import?resource=provider&app=codex&config=… link keeps only the API key, base_url and model from the link's config.toml. build_codex_settings() always rebuilds a fixed template, so:

  • query_params (e.g. api-version for Azure-style endpoints), http_headers, supports_websockets, request_max_retries, stream_idle_timeout_ms, model_catalog_url … are silently dropped;
  • model_reasoning_effort is overwritten with "high" and the stored requires_openai_auth with true.

The desktop app had the same bug (farion1231/cc-switch #3751, #5510, #7438, #7942) and fixed it in farion1231/cc-switch@11e1326b. This PR ports that fix for parity, per AGENTS.md.

Change

New src/deeplink/codex_link.rs (ported from upstream 11e1326b), wired into merge_codex_config / build_codex_settings:

  • keep the provider-owned keys of the selected [model_providers.*] table (always renamed to custom) and the top-level provider fields the live projection writes (ROW_TOP_FIELDS, CODEX_EXCLUSIVE_TOP, nested subagent/memory model names); user-global settings ([features], [tools], MCP, notify, …) are not imported;
  • reject tables that make Codex run a command or read local credentials (auth, aws, gateway_oauth, env_http_headers);
  • drop env_key in favour of the link's key; reject a link that only has env_key;
  • keep model_catalog_url only when it is on the endpoint's origin;
  • URL params still win over the config; experimental_bearer_token is rewritten to the link's key;
  • links without a config still produce the existing template byte for byte (new test asserts the exact text).

ROW_TOP_FIELDS becomes pub(crate) (same as upstream).

Before / after (real binary, isolated HOME, dummy key)

Link config: model_reasoning_effort = "low", query_params = { "api-version" = … }, request_max_retries = 7, stream_idle_timeout_ms = 600000, same-origin model_catalog_url.

Before (9a2bdf5), stored row:

model_reasoning_effort = "high"
[model_providers.custom]
name = "Relay"
base_url = "https://relay.example.com/v1"
wire_api = "responses"
requires_openai_auth = true

After:

model_reasoning_effort = "low"
[model_providers.custom]
name = "Relay"
base_url = "https://relay.example.com/v1"
wire_api = "responses"
requires_openai_auth = true
model_catalog_url = "https://relay.example.com/v1/models"
query_params = { "api-version" = "2025-04-01-preview" }
request_max_retries = 7
stream_idle_timeout_ms = 600000

A second link with requires_openai_auth = false, http_headers and supports_websockets now keeps all three, and they reach the live ~/.codex/config.toml after switching.

Tests

  • cargo fmt --check
  • cargo test --lib deeplink — 18 passed (11 new Codex link tests: field retention, URL override, catalog origin, rejected tables, env_key, whole-config.toml links, no-config template bytes)
  • cargo test --test deeplink_import — 19 passed

Not covered: no run against a real Codex relay.

🤖 Generated with Claude Code

…ing a fixed template

A Codex provider link that carries a config.toml lost everything except the
key, base_url and model: query_params, http_headers, request_max_retries,
stream_idle_timeout_ms, model_catalog_url and others were dropped, and
model_reasoning_effort / requires_openai_auth were overwritten by the
fixed template.

Port the upstream desktop fix (farion1231/cc-switch 11e1326b): keep the
provider-owned keys of the selected [model_providers.*] table (renamed to
custom) plus the top-level provider fields the projection writes; reject
tables that make Codex run a command or read local credentials (auth, aws,
gateway_oauth, env_http_headers); drop env_key in favour of the link's key
and reject env_key-only links; keep model_catalog_url only on the
endpoint's origin. URL params still win, and links without a config keep
the existing template byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RGB-loop
RGB-loop marked this pull request as ready for review November 17, 2026 15:02
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.

1 participant