Skip to content

fix(codex): 修复 Codex provider 同步功能#1900

Open
Fldicoahkiin wants to merge 1 commit intofarion1231:mainfrom
Fldicoahkiin:fix/codex-model-provider-sync
Open

fix(codex): 修复 Codex provider 同步功能#1900
Fldicoahkiin wants to merge 1 commit intofarion1231:mainfrom
Fldicoahkiin:fix/codex-model-provider-sync

Conversation

@Fldicoahkiin
Copy link
Copy Markdown

根据审查意见修复 Codex provider 同步功能:

修复内容

  1. sync_codex_rollout_model_provider: 只修复缺失值(空字符串),不覆盖已有值
  2. sync_codex_threads_model_provider: 只修复 NULL 值,不覆盖已有 provider 记录
  3. 删除 rebuild_codex_session_index: 基于错误前提(threads 表不是 session_index 的全量来源)
  4. 执行路径优化: 只在 switch_normal 中执行,不在热切换路径执行(避免重 I/O 操作增加切换耗时)
  5. 添加警告注释: 明确竞态条件风险

变更统计

  • src-tauri/src/codex_config.rs: 修改同步策略,删除重建函数
  • src-tauri/src/services/provider/mod.rs: 删除重建函数调用,优化注释

Closes #1694

@Fldicoahkiin Fldicoahkiin force-pushed the fix/codex-model-provider-sync branch from 1d6714d to 25b3836 Compare April 5, 2026 05:11
@Fldicoahkiin
Copy link
Copy Markdown
Author

已根据审查意见修复:

  1. sync_codex_rollout_model_provider: 只修复缺失值(空字符串),不覆盖已有 provider 记录
  2. sync_codex_threads_model_provider: 只修复 NULL 值,不覆盖已有值
  3. 删除 rebuild_codex_session_index: 基于错误前提(threads 表不是 session_index 全量来源)
  4. 执行路径优化: 只在 switch_normal 执行,不在热切换路径执行

请 review。

@farion1231
Copy link
Copy Markdown
Owner

@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: 25b38368d8

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

// 避免 thread/list 因历史元数据与当前 provider 不一致而过滤空历史。
// 注意:此操作只在正常切换时执行,不在热切换时执行(避免重 I/O 操作增加切换耗时)
if matches!(app_type, AppType::Codex) {
if let Err(e) = sync_codex_rollout_model_provider(id) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use Codex model_provider key for metadata sync

The id passed here is the cc-switch provider record ID, but Codex session metadata is keyed by TOML model_provider values (for example custom/openai), not by internal UUIDs. In this repo, non-additive providers are created with generated UUID IDs, so using id causes both sync helpers to write a value that does not match Codex’s active provider key, which means thread/list filtering can still miss or misclassify history after switching. Please parse the target provider’s settings_config.config and pass its model_provider value to these sync functions instead of the internal provider ID.

Useful? React with 👍 / 👎.

Comment on lines +333 to +335
lines[0] =
serde_json::to_string(&first).map_err(|e| AppError::JsonSerialize { source: e })?;
write_text_file(&path, &(lines.join("\n") + "\n"))?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid full-file rewrite during rollout metadata patch

This path rewrites the entire JSONL file from an in-memory snapshot after reading it, so if Codex is concurrently appending events to the same rollout file during a switch, any lines appended between the read and the atomic replace are lost. The severity depends on concurrent writes, but that scenario is realistic for active sessions and leads to irreversible history truncation. The sync should avoid replacing whole files (or use locking/active-session exclusion) when only the first line needs patching.

Useful? React with 👍 / 👎.

@Fldicoahkiin Fldicoahkiin force-pushed the fix/codex-model-provider-sync branch from 25b3836 to da9b909 Compare April 5, 2026 07:53
@Fldicoahkiin Fldicoahkiin changed the title fix(codex): 修复同步策略,解决审查意见 fix(codex): 修复 Codex provider 同步功能 Apr 5, 2026
@Fldicoahkiin Fldicoahkiin force-pushed the fix/codex-model-provider-sync branch 3 times, most recently from 7bfb0db to 1906053 Compare April 5, 2026 19:24
根据审查意见实现 Codex provider 同步功能:

sync_codex_rollout_model_provider: 只修复缺失值(空字符串),不覆盖已有值

sync_codex_threads_model_provider: 只修复 NULL 值,不覆盖已有 provider 记录

不添加 rebuild_codex_session_index: 基于错误前提(threads 表不是全量来源)

只在 switch_normal 中执行,不在热切换路径执行(避免重 I/O 操作增加切换耗时)

fixes farion1231#1694
@Fldicoahkiin Fldicoahkiin force-pushed the fix/codex-model-provider-sync branch from 1906053 to 06b0fcb Compare April 5, 2026 19:32
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.

2 participants