Skip to content

fix: preserve takeover live state during provider refresh#1912

Open
congmucc wants to merge 4 commits intofarion1231:mainfrom
congmucc:main
Open

fix: preserve takeover live state during provider refresh#1912
congmucc wants to merge 4 commits intofarion1231:mainfrom
congmucc:main

Conversation

@congmucc
Copy link
Copy Markdown

@congmucc congmucc commented Apr 5, 2026

Summary / 概述

This PR fixes the original stale takeover config issue in switch-mode apps: after provider changes, Claude takeover could keep provider-owned live fields stale even though the current provider had already changed.

The follow-up update narrows the implementation so takeover refresh works from the existing live/backup state, refreshes provider-owned fields, and then reapplies takeover-owned overlay fields instead of rebuilding unrelated live config from scratch.

  • Refresh taken-over live config after hot switch or current-provider update so displayed/effective provider settings stay aligned
  • Preserve live-only settings while updating provider-owned fields under takeover
  • Keep proxy-down restore-safe refresh consistent for taken-over live state, including the no-backup case
  • Treat malformed backup, malformed previous common-config snippets, or Codex live parse failures as warnings in takeover refresh paths instead of failing provider updates
  • Skip best-effort takeover refresh when the live config is missing
  • Add regression coverage for takeover live refresh, common-config updates, and proxy-down fallback behavior
  • OpenCode and OpenClaw remain unchanged because they do not use takeover in the current architecture
  • Verification run:
    • cargo fmt --manifest-path src-tauri/Cargo.toml --check
    • git diff --check
    • cargo test sync_current_provider_for_app_skips_proxy_refresh_when_proxy_server_is_not_running --manifest-path src-tauri/Cargo.toml
    • cargo test sync_current_provider_for_app_preserves_taken_over_live_when_proxy_server_is_not_running_without_backup --manifest-path src-tauri/Cargo.toml
    • cargo test sync_current_common_config_for_app_tolerates_malformed_backup --manifest-path src-tauri/Cargo.toml
    • cargo test sync_current_common_config_for_app_tolerates_malformed_previous_snippet --manifest-path src-tauri/Cargo.toml
    • cargo test refresh_takeover_state_from_provider_reapplies_current_common_config_to_live --manifest-path src-tauri/Cargo.toml

Related Issue / 关联 Issue

Fixes #1850

Follow-up to #1828 (which closed #1827)

Screenshots / 截图

N/A (backend / service-layer change)

Before / 修改前 After / 修改后
Under Claude takeover, hot switch or current-provider update could leave provider-owned live fields stale, so displayed/effective settings drifted from the current provider Takeover refresh now reapplies provider-owned fields onto existing live/backup state and then reapplies takeover overlay fields, keeping displayed/effective settings aligned without dropping live-only config
Proxy-down or best-effort takeover refresh could lose existing takeover state in edge cases introduced by the earlier rebuild-based path Restore-safe and best-effort refresh paths now preserve existing takeover state, skip missing-live cases, and tolerate malformed best-effort inputs

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查 [not applicable]
  • pnpm format:check passes / 通过代码格式检查 [not applicable]
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • No i18n update needed (no user-facing text change) / 无用户可见文案变更,无需更新国际化

Generalize proxy takeover refresh for switch-mode apps and keep the takeover state updates consistent under concurrency.

- Rebuild Claude, Codex, and Gemini takeover live configs from the current provider before applying proxy-safe overlays
- Make proxy-active backup and live refresh atomic under the per-app switch lock to avoid inconsistent takeover state during concurrent updates
@congmucc
Copy link
Copy Markdown
Author

congmucc commented Apr 6, 2026

@codex review 审查

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@yovinchen
Copy link
Copy Markdown
Collaborator

@codex review

@congmucc
Copy link
Copy Markdown
Author

congmucc commented Apr 6, 2026

@codex review 审查

Copy link
Copy Markdown

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

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: 1469e5d2d7

ℹ️ 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".

@farion1231
Copy link
Copy Markdown
Owner

Hi, I owe you an apology for the long silence. As the sole maintainer of this project, I've been overwhelmed and fell behind on reviews — but that's on me, not on you. Your contribution matters and I will review this PR. If it needs a rebase, just let me know or I can handle it. Thank you for your time and patience.

- refresh takeover updates from existing live and backup snapshots so Claude display fields stay aligned without dropping live-only settings
- keep proxy-down restore and common-config transition paths consistent, including backup recreation and malformed backup tolerance
- add regression coverage for takeover live refresh, common-config updates, and proxy-down fallback behavior
@congmucc congmucc changed the title fix: rebuild takeover live configs from current provider fix: preserve takeover live state during provider refresh Apr 7, 2026
@congmucc
Copy link
Copy Markdown
Author

congmucc commented Apr 7, 2026

@farion1231 I pushed a focused follow-up update for this PR.

The current revision keeps takeover live and backup state aligned during provider refresh without rebuilding unrelated live-only config, and it also addresses the earlier review findings from the previous rebuild-based path.

A rebase should not be needed at the moment. This branch is currently based on upstream/main, so the PR should now be ready for review against the updated diff.

@congmucc
Copy link
Copy Markdown
Author

congmucc commented Apr 7, 2026

@codex review

- remove explicit auto-deref usage in Codex takeover merge logic so cargo clippy is clean again
- keep the change scoped to warning-only cleanup without altering takeover refresh behavior
Copy link
Copy Markdown

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

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: 863aef8f41

ℹ️ 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".

- downgrade previous common-config removal failures to a warning during takeover transition refresh
- add regression coverage for malformed stored snippets so live and backup refresh continue
@congmucc
Copy link
Copy Markdown
Author

congmucc commented Apr 7, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants