fix: stream historical session repair - #2084
Conversation
|
这次改动涉及 Provider Sync 流式重写、原子写入、回滚和真实进度,范围较大。当前 PR 没有 GitHub CI 结果,请先触发并跑完 Windows、macOS x64、macOS arm64 构建及相关 workspace 测试,重点确认锁冲突、外部修改保护、部分失败回滚和 session_index 流式清理语义。CI 全绿后再复审。 |
@BigPizzaV3 现在无法进行测试,此工作流程需要维护者批准 |
BigPizzaV3
left a comment
There was a problem hiding this comment.
当前分支已与 main 冲突,且改动范围较大(provider sync、SQLite、manager 进度和回滚)。请先 rebase 到最新 main,保留未提交用户数据兼容性,补跑三平台 CI,并重点说明删除/undo 索引修复(#2092)与历史 provider 同步的交互;通过后再复审。
aa2d5ca to
c9ed1d9
Compare
@BigPizzaV3 已按意见处理:
|
|
复审结论:本地 provider_sync 51/51 通过、改动本身没问题,但你 rebase 到的 base(48d4315)已过时。当前 main(48ac5f76)在你 rebase 后已合入 #2092(codex-plus-data 侧边栏索引清理)、#2093、#2098(launcher 平台重试预算)等。我实测把当前分支并入当前 main:tests/launcher.rs 与 crates/codex-plus-data/src/lib.rs 出现真冲突(launcher.rs 因 #2098 改了同名测试;lib.rs 因 #2092 改了 storage/sidebar)。请基于最新 main rebase,处理好这两处与 #2092/#2098 的交互后重跑三平台 CI;冲突解决后我立即复审通过。解决冲突即可,勿动其它逻辑。 |
|
提醒:之前已 approve,但当前 head 与最新 main 仍冲突(4 个文件未解决),state=DIRTY,无法合并。刚实测合并冲突在:\n\n- |
|
@liulinboyi 催一下:当前 head 与 main 仍冲突(provider_sync.rs / lib.rs / launcher.rs / App.tsx 四文件)。请基于含 #2097/#1712 的最新 main rebase 解决后 push。 |
|
我用当前 main(含新合并的 #2110/#2092/#2098)做了权威 merge 测试,4 处冲突仍在。其中 provider_sync.rs 那处是架构性分歧,不是普通 merge 能解的,需要重建。逐项说明: 1. 你的分支基于较老的 provider_sync.rs,引入了 bulk 批量架构( 修法:把你 fork 里那些 bulk 函数(
这些在 main 的 2. 冲突在 re-export 列表。你导入了 3. 导入列表冲突。你新增了 4. 冲突是一个测试:你命名为 重基建议: fork 那个 要不要我基于当前 main 帮你重建 provider_sync.rs 那些逻辑(把 bulk 意图移植进每会话循环),出一版补丁给你 review?你给我 |
问题
“修复历史会话”的批量 provider 同步在 Codex 历史会话较多时,会将多个 rollout JSONL 完整读入内存,同时保存原文、改写文本和回滚副本,内存占用会随全部历史会话正文规模增长。
同一流程后续的
session_index.jsonl清理也会同时保留完整字节、完整文本并构造完整的新文本,可能产生第二次内存峰值。另外,管理器此前使用定时器模拟进度,展示进度与后端实际处理情况不一致。改动
atomic_write_with流式原子写入 helper,支持分块写入临时文件、原子替换、保留原文件权限,并兼容现有atomic_write。session_meta中的model_provider,非 metadata 行、未知 JSON、无效 JSON、行结束符和其他正文内容原样保留。skipped_locked_rollout_files,其他错误会触发已应用文件的回滚。session_meta行、数量/顺序校验和 hash 校验,不再保存整份原始 rollout;同时恢复原始 mtime 和权限。session-meta-backup.json改为增量写入,保持原有 JSON schema 和兼容格式。session_index.jsonl的 preview/apply 清理改为流式读取和写入,保留未知记录、候选确认和快照变化保护语义。setInterval,改为监听后端真实计数并映射进度。run_provider_sync、run_provider_sync_with_target、ProviderSyncResult及 Remote Control 单会话恢复路径的兼容行为。vars_os()容错处理,避免 macOS 上存在非 UTF-8 环境变量时导致 manager 崩溃。测试
cargo test --workspace:通过cargo test -p codex-plus-data --test provider_sync:49 passedcargo test -p codex-plus-core settings::tests:46 passedcargo test -p codex-plus-core env_conflicts::tests:3 passednpm test:122 passednpm run check:通过npm run vite:build:通过cargo check -p codex-plus-manager:通过cargo build --release:通过git diff --check:通过hdiutil verify与 App 深度签名验证。cargo fmt --all -- --check仍会报告仓库现有格式差异,本次未做无关的格式化重排。涉及文件
crates/codex-plus-core/src/settings.rscrates/codex-plus-core/src/env_conflicts.rscrates/codex-plus-core/src/model_catalog.rscrates/codex-plus-core/src/relay_environment.rscrates/codex-plus-data/src/provider_sync.rscrates/codex-plus-data/src/lib.rscrates/codex-plus-data/tests/provider_sync.rsapps/codex-plus-manager/src-tauri/src/commands.rsapps/codex-plus-manager/src/App.tsxapps/codex-plus-manager/src/provider-sync-flow.tsapps/codex-plus-manager/src/provider-sync-flow.test.tsdocs/plans/2026-08-27-历史会话流式修复实施计划.mdProblem
The batch provider synchronization used by “Repair Historical Sessions” loaded multiple rollout JSONL files fully into memory and retained original text, rewritten text, and rollback copies. When a Codex installation contained many historical sessions, memory usage grew with the total size of all stored session content.
The subsequent
session_index.jsonlcleanup also retained the full file and constructed a complete rewritten copy, creating a second memory peak. In addition, the manager previously displayed simulated timer-based progress instead of progress based on actual backend work.Changes
atomic_write_withfor streamed atomic file writes with chunked output, atomic replacement, and preservation of existing file permissions.model_providerin validsession_metarecords. Preserve all non-metadata lines, unknown or invalid JSON, line endings, and other rollout content byte-for-byte.skipped_locked_rollout_files; other failures trigger rollback of files already applied in the current operation.session_metalines, count/order validation, and hashes instead of retaining complete rollout files. Restore original mtimes and permissions as well.session-meta-backup.jsonincrementally while preserving the existing JSON schema and compatibility.session_index.jsonlpreview/apply cleanup to streamed reads and writes while preserving unknown records, candidate confirmation, and snapshot-change protection.scanning,planning,backing_up,rewriting,updating_indexes,rolling_back, andcompletephases.setIntervalprogress.run_provider_sync,run_provider_sync_with_target,ProviderSyncResult, and Remote Control single-session recovery behavior.vars_os()so non-UTF-8 macOS environment variables do not crash the manager.Tests
cargo test --workspace: passedcargo test -p codex-plus-data --test provider_sync: 49 passedcargo test -p codex-plus-core settings::tests: 46 passedcargo test -p codex-plus-core env_conflicts::tests: 3 passednpm test: 122 passednpm run check: passednpm run vite:build: passedcargo check -p codex-plus-manager: passedcargo build --release: passedgit diff --check: passedhdiutil verifyand deep App signature checks.cargo fmt --all -- --checkstill reports existing repository formatting differences; no unrelated formatting-only changes were introduced.Files
crates/codex-plus-core/src/settings.rscrates/codex-plus-core/src/env_conflicts.rscrates/codex-plus-core/src/model_catalog.rscrates/codex-plus-core/src/relay_environment.rscrates/codex-plus-data/src/provider_sync.rscrates/codex-plus-data/src/lib.rscrates/codex-plus-data/tests/provider_sync.rsapps/codex-plus-manager/src-tauri/src/commands.rsapps/codex-plus-manager/src/App.tsxapps/codex-plus-manager/src/provider-sync-flow.tsapps/codex-plus-manager/src/provider-sync-flow.test.tsdocs/plans/2026-08-27-历史会话流式修复实施计划.md