fix(claude): preserve live common config on provider switch & fix auto-inference default#3728
fix(claude): preserve live common config on provider switch & fix auto-inference default#3728wait4xx wants to merge 3 commits into
Conversation
|
wish it can fix as soon as possable🙏 |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 908ffc8744
ℹ️ 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".
When the live settings have no extractable common fields, the previous code would silently skip the update, leaving stale entries in the DB. With the new default in provider_uses_common_config, those stale fields would be written back on the next provider switch. Now we explicitly clear the snippet and set the cleared marker so that provider_uses_common_config correctly returns false. Addresses Codex review feedback on PR farion1231#3728. Co-authored-by: GLM 5.1
…o-inference default
Three overlapping bugs cause statusLine, enabledPlugins, model, and other
common fields to be lost or overwritten with stale values when switching
Claude Code providers.
1. Fix provider_uses_common_config() default for exclusive-mode apps:
- The json_is_subset heuristic was fundamentally broken because
provider settings_config only contains vendor-specific fields,
so the subset check always fails for providers without explicit
commonConfigEnabled.
- For exclusive-mode apps (Claude/Codex/Gemini), default to applying
common config when a non-empty snippet exists.
- Additive-mode apps keep the existing subset heuristic.
2. Add sync_common_config_from_live() to re-extract common config from
the current live settings.json and persist it to the database on each
provider switch. This ensures the common config snippet stays up-to-date
(e.g. when plugins like claude-hud update their cache paths).
3. Call sync_common_config_from_live() in switch_normal() after backfill
and before writing the target provider.
Co-authored-by: GLM 5.1
Closes farion1231#3631
When the live settings have no extractable common fields, the previous code would silently skip the update, leaving stale entries in the DB. With the new default in provider_uses_common_config, those stale fields would be written back on the next provider switch. Now we explicitly clear the snippet and set the cleared marker so that provider_uses_common_config correctly returns false. Addresses Codex review feedback on PR farion1231#3728. Co-authored-by: GLM 5.1
25fbcc4 to
2ce6805
Compare
CI UpdateFormatting issues have been fixed and all CI checks now pass on the fork:
Verified on fork CI run: https://github.com/wait4xx/cc-switch/actions/runs/26994322690 Also addressed the Codex review feedback: when live extraction returns empty, the stale snippet is now explicitly cleared (with the Co-authored-by: GLM 5.1 |
When the live settings have no extractable common fields, the previous code would silently skip the update, leaving stale entries in the DB. With the new default in provider_uses_common_config, those stale fields would be written back on the next provider switch. Now we explicitly clear the snippet and set the cleared marker so that provider_uses_common_config correctly returns false. Addresses Codex review feedback on PR farion1231#3728. Co-authored-by: GLM 5.1
f434f0b to
0060472
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00604723bd
ℹ️ 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".
Skip sync_common_config_from_live when the user has explicitly cleared the common config snippet. This prevents re-enabling common config from stale live fields after the user opted out. Addresses Codex review feedback on PR farion1231#3728. Co-authored-by: GLM 5.1
Closes #3631
Summary / 概述
Three overlapping bugs cause
statusLine,enabledPlugins,model, and other common fields to be lost or overwritten with stale values when switching Claude Code providers.本 PR 修复了三个叠加的 Bug,这些 Bug 会导致切换 Claude Code Provider 时
statusLine(claude-hud 状态栏)、enabledPlugins(插件列表)、model等通用配置字段丢失或被旧值覆盖。Bug 1:
provider_uses_common_config()自动推断逻辑失效(live.rs:354)对于未显式设置
meta.commonConfigEnabled的 provider(如内置的claude-official),None分支使用json_is_subset检查 provider 的settings_config是否包含 common config 的所有 key。但 provider 的settings_config只存储供应商专属字段(ANTHROPIC_AUTH_TOKEN、ANTHROPIC_BASE_URL等),永远不包含statusLine、enabledPlugins、model这些通用字段。子集检查始终失败,common config 永远不会被合并。结果:切换到
claude-official时,settings.json只写入了{"env": {}},所有通用配置丢失。Bug 2: Common config 永远不会重新同步(
lib.rs:1626)initialize_common_config_snippets()仅在首次启动时自动抽取 common config。一旦common_config_claude写入数据库,should_auto_extract_config_snippet()返回false,snippet 永远不会更新。当插件(如 claude-hud)更新导致缓存路径变化(如claude-hud/dist/→claude-hud/0.1.0/dist/),数据库中的旧路径在每次切换时都会被写回settings.json。Bug 3: 切换流程不回写 common config(
mod.rs:1660)switch_normal()从数据库读取 common config 合并到settings.json,但不会将最新的 live settings 同步回数据库。回填步骤(backfill)从 live settings 中剥离了 common config 后直接丢弃——只有供应商专属部分被存回了数据库。修复内容
修复
provider_uses_common_config默认推断(live.rs):排他模式应用(Claude/Codex/Gemini)只要存在非空 snippet 就默认合并 common config;additive 模式应用(Hermes/OpenClaw)保留原有json_is_subset推断逻辑。新增
sync_common_config_from_live()(live.rs):从当前 livesettings.json重新抽取 common config 并持久化到数据库,确保 snippet 始终是最新的。在
switch_normal()中调用sync_common_config_from_live()(mod.rs):回填完成后、写入目标 provider 之前,同步最新的 common config 到数据库。Related Issue / 关联 Issue
Fixes #3631
Related: #3700, #3697 (Codex 同类问题及修复 PR)
Screenshots / 截图
不适用(Rust 后端逻辑修复,无 UI 变化)
Checklist / 检查清单
pnpm typecheck不适用pnpm format:check不适用cargo clippypasses(本地无 Rust 工具链,已通过静态分析验证类型、import 和函数签名)Note on Tests / 测试说明
This PR does not include regression tests due to the lack of a local Rust toolchain. Below are the intended test cases for a contributor with a Rust environment to implement:
本 PR 因本地缺少 Rust 工具链未能附带回归测试。以下为设计的测试用例,供有 Rust 环境的 contributor 实现:
Test 1:
provider_service_switch_claude_preserves_common_config_fieldssettings.jsonwithstatusLine,enabledPlugins,modelcommonConfigEnabledset (relying on auto-inference)ANTHROPIC_API_KEY,ANTHROPIC_BASE_URL) are updatedstatusLine,enabledPlugins,model) are preservedTest 2:
provider_service_switch_claude_syncs_common_config_snippetsettings.jsonwith an updated claude-hud path (with version directory)common_config_claudewith a stale path (without version directory)common_config_claudein DB is updated to reflect the live pathThese tests should follow the existing patterns in
src-tauri/tests/provider_service.rs(seeprovider_service_switch_claude_updates_live_and_stateat line 1592 for reference).Reproduction Verification / 复现验证
Before fix / 修复前:
After fix / 修复后: common config is always merged for exclusive-mode apps, and the snippet is re-synced from live settings on every switch.
Co-authored-by: GLM 5.1
代码 Diff(供参考,已提交到分支)
改动文件清单
src-tauri/src/services/provider/live.rsprovider_uses_common_config推断默认值 + 新增sync_common_config_from_livesrc-tauri/src/services/provider/mod.rsswitch_normal中调用sync_common_config_from_livesrc-tauri/tests/provider_service.rs总计: 2 files changed, 55 insertions(+), 4 deletions(-)