mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 19:45:34 +08:00
feat(codex): add opt-in migration and ledger-based restore for unified session history
- Enable dialog gains a checkbox (default off) to migrate existing official sessions from the built-in "openai" bucket into the shared "custom" bucket, with per-generation backups; failed migrations retry at startup - Disable dialog offers a precise restore driven by the backup ledger: only sessions recorded as "openai" in backups are flipped back, and sessions created while the toggle was on are never touched - Completion marker and backup generations are bound to the canonical Codex config dir; migrate/restore serialize on an op lock and the marker is written conditionally inside the settings write lock - save_settings rolls back the toggle and fails the save when the live rewrite fails; migration additionally requires the live config to actually route to the shared bucket (skips with live_not_unified so refused injection or proxy takeover can't split history) - Restore refuses to run while the toggle is (re-)enabled and reports nothing_to_restore instead of a zero-count success; local migration markers are now backend-owned in merge_settings_for_save so stale frontend payloads can't resurrect them - Settings autosave reverts optimistic form state on failure so a failed toggle change can't be replayed by an unrelated save - ConfirmDialog supports an optional checkbox; all four locales updated
This commit is contained in:
@@ -600,6 +600,25 @@ pub fn run() {
|
||||
log::warn!("✗ Codex provider template bucket migration failed: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
// 统一会话开关的官方历史迁移:开关开启但上次未完成(如文件被占用
|
||||
// 中途失败)时在启动期重试;函数内部自门控,开关关闭时直接跳过。
|
||||
match crate::codex_history_migration::maybe_migrate_codex_official_history_to_unified_bucket() {
|
||||
Ok(outcome) => {
|
||||
if let Some(reason) = outcome.skipped_reason {
|
||||
log::debug!("○ Codex official history unify migration skipped: {reason}");
|
||||
} else {
|
||||
log::info!(
|
||||
"✓ Codex official history unify migration completed: jsonl_files={}, state_rows={}",
|
||||
outcome.migrated_jsonl_files,
|
||||
outcome.migrated_state_rows
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("✗ Codex official history unify migration failed: {e}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1156,6 +1175,8 @@ pub fn run() {
|
||||
commands::read_live_provider_settings,
|
||||
commands::get_settings,
|
||||
commands::save_settings,
|
||||
commands::has_codex_unify_history_backup,
|
||||
commands::restore_codex_unified_history,
|
||||
commands::get_rectifier_config,
|
||||
commands::set_rectifier_config,
|
||||
commands::get_optimizer_config,
|
||||
|
||||
Reference in New Issue
Block a user