Skip to content

恢复等长 provider 的原地替换,并增加快速同步模式 - #92

Open
cccat6 wants to merge 5 commits into
Dailin521:mainfrom
cccat6:codex/restore-transactional-in-place-provider
Open

恢复等长 provider 的原地替换,并增加快速同步模式#92
cccat6 wants to merge 5 commits into
Dailin521:mainfrom
cccat6:codex/restore-transactional-in-place-provider

Conversation

@cccat6

@cccat6 cccat6 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

目的

Provider 同步应当遵循最小必要写入原则。修改少量元数据,不应让整个会话历史承担全量重写的成本。这个 PR 在保留备份、事务和恢复保障的前提下补回 in-place,避免把不必要的等待和磁盘写入留给用户。

关联

延续 #51 的等长 provider 优化,修复 #71 事务重构后的路径缺失,并保留 #69 要求的逐目标恢复证据。

改动

  • 只需要修改 provider、且新旧 ID 等字节长度并满足校验条件时,直接修改对应字节,不重写整个 rollout,也不更换 inode。
  • 原地修改接入现有备份、逐文件 journal、失败回滚和崩溃恢复,Windows 也支持。
  • 完整模式合并重复的正文扫描,原有检查范围不变。
  • 新增 CLI 的 sync --fast / switch <provider-id> --fast:只读必要的首行元数据,保留模型,明确提示未执行的历史检查。不满足原地条件时直接报错,不自动回退到全量重写。

备份继续使用官方 v2 格式,并支持恢复 v1/v2。新增的字节记录是可选字段,原有恢复数据完整保留,没有另起一套备份格式。

建议 provider ID 统一用 6 个 ASCII 字符,比如把 provider_a 写成 prov_a,因为内置的 openai 就是 6 个字符,相对最通用。

影响范围

Node CLI/共享服务、Windows worker、备份恢复,以及相关测试和文档。没有加入账户管理、认证或进程重启功能,没有修改桌面 UI 和 .NET 业务实现。

数据写入仍限于既有操作涉及的配置、rollout 元数据、SQLite、workspace 状态和托管备份;不修改消息正文或 updated_at

验证

  • Node 16 全套测试文件通过;Node 24:286 通过,6 项平台专属跳过。
  • Windows 原生写入、前置变化跳过、部分写入恢复和 mtime 测试通过。
  • 使用未修改的官方 Node/.NET Core,验证双方备份互相恢复及部分写入后的接手恢复,共 8 组通过。
  • Web 构建、打包检查和 git diff --check 通过。所有测试均使用临时夹具。

32 MiB 的 ext4 临时文件测试中,原地路径的计账写入约 44 KiB,完整重写约 32 MiB;快速模式的逻辑读取约 341 KiB。这里包含备份和日志开销,不是对实际大库耗时的保证。

边界与未验证项

旧工具可以恢复数据,但仍使用它原来的恢复方式,不会自动获得 in-place 优化。完整 Windows Node、macOS 和 WSL 验证仍待 CI/对应环境补齐,不能将其标为已通过。

本分支基于 main@c7ff852#90 的新版架构还需要在合并前按最终主线对齐。

检查清单

  • 修改限于原地同步、读取优化及必要的恢复兼容。
  • 已补充回归测试和相关中英文文档。
  • 未包含真实凭据、会话、数据库、备份或日志。
  • 上游要求的跨平台 ci-gate 全部通过。

cccat6 added 5 commits August 28, 2026 10:56
Restore the equal-length provider optimization from cccat6 PR Dailin521#51 (7231881, cdcde35, 84a60d3) following the v0.4 transaction refactor in Dailin521#71. Persist v3 mutation evidence before applying; recover same-inode writes through the existing journal, including bounded partial writes and append-preserving rollback.

MOSS trial scope only. Windows retains the prior worker; .NET/Windows parity and formal PR review are deferred. References Dailin521#51, Dailin521#71, Dailin521#69 and the active-writer inode review finding.
Extend the PR Dailin521#51 optimization restored by 1e0f8b3 with Windows exclusive-handle writes and recovery, post-write guards, and explicit metadata-only sync. Keep backup-first per-target journal semantics from Dailin521#71/Dailin521#69 and reject unknown recovery bytes.

Fuse default body diagnostics, cover failures on Node 16/24 and native Windows, and document proposed mtime/schema compatibility boundaries. No production deployment or upstream publication.
Restore stable-file mtime without backdating concurrent appends, including interrupted timestamp repair. Skip stale Windows preconditions before mutation, compensate valid rollout targets despite other byte conflicts, and keep v2 for backups without byte descriptors.

Bound header verification, remove redundant state and duplicate review/worker scaffolding, and cover the audit findings with regression tests. No production deployment.
Write the official v2 metadata and manifest with optional byte-undo records while retaining all standard restore fields and v1/v2 support. Remove the unpublished v3 format branch. Verified both directions against unmodified upstream Node and .NET Core, including applying-only partial writes.
@cccat6
cccat6 marked this pull request as ready for review August 28, 2026 11:01
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.

1 participant