-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(codex): 修复 Codex provider 同步功能 #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,12 +13,12 @@ use serde::Deserialize; | |
| use serde_json::Value; | ||
|
|
||
| use crate::app_config::AppType; | ||
| use crate::codex_config::{sync_codex_rollout_model_provider, sync_codex_threads_model_provider}; | ||
| use crate::error::AppError; | ||
| use crate::provider::{Provider, UsageResult}; | ||
| use crate::services::mcp::McpService; | ||
| use crate::settings::CustomEndpoint; | ||
| use crate::store::AppState; | ||
|
|
||
| // Re-export sub-module functions for external access | ||
| pub use live::{ | ||
| import_default_config, import_openclaw_providers_from_live, | ||
|
|
@@ -1542,13 +1542,30 @@ impl ProviderService { | |
| } | ||
| } | ||
|
|
||
| // Codex 特殊处理:切换 live 配置后,同步历史 rollout 首行中的 model_provider, | ||
| // 避免 thread/list 因历史元数据与当前 provider 不一致而过滤空历史。 | ||
| // 注意:此操作只在正常切换时执行,不在热切换时执行(避免重 I/O 操作增加切换耗时) | ||
| if matches!(app_type, AppType::Codex) { | ||
| if let Err(e) = sync_codex_rollout_model_provider(id) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
| log::warn!("同步 Codex rollout model_provider 失败: {e}"); | ||
| result | ||
| .warnings | ||
| .push("codex_rollout_sync_failed".to_string()); | ||
| } | ||
| if let Err(e) = sync_codex_threads_model_provider(id) { | ||
| log::warn!("同步 Codex threads.model_provider 失败: {e}"); | ||
| result | ||
| .warnings | ||
| .push("codex_threads_sync_failed".to_string()); | ||
| } | ||
| } | ||
|
|
||
| // Sync MCP | ||
| McpService::sync_all_enabled(state)?; | ||
|
|
||
| Ok(result) | ||
| } | ||
|
|
||
| /// Sync current provider to live configuration (re-export) | ||
| pub fn sync_current_to_live(state: &AppState) -> Result<(), AppError> { | ||
| sync_current_to_live(state) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.