pref(checkpoint):修复 Checkpoint 恢复与 Run 级 Diff 完整性#572
Merged
phantom5099 merged 4 commits into1024XEngineer:mainfrom May 8, 2026
Merged
pref(checkpoint):修复 Checkpoint 恢复与 Run 级 Diff 完整性#572phantom5099 merged 4 commits into1024XEngineer:mainfrom
phantom5099 merged 4 commits into1024XEngineer:mainfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
/review 检查一遍还有没有存在checkpoints创建出错、run级diff存在遗漏或是参杂外部修改、代码回退出现遗漏等问题 |
Collaborator
Author
|
/code 提高测试覆盖率,检查一遍还有没有存在checkpoints创建出错、run级diff存在遗漏或是参杂外部修改、代码回退出现遗漏等问题,过程中如果发现有不符合预期行为的地方就输出总结告诉我,不要硬给漏洞补测试掩盖错误 |
This comment was marked as resolved.
This comment was marked as resolved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Agent 在运行过程中创建了新文件,restore 到更早的 checkpoint时,新文件未被删除。根因三层:
旧 Restore 仅接受 targetID 单参数,用 v_next单快照推断目标状态。对于post-delete、删除后重建、目录操作等场景需要复杂的启发式推断。
filesystem_move_file执行后源文件未标记删除,filesystem_remove_dir执行后目录内嵌套文件未标记删除。restore时这些已删除路径会被错误地"复活"。
scope=run 聚合 diff 对每个文件取 run 内首次被触碰前的版本作为baseline,取 run 内最后版本号的下一版本作为 after侧(contentAfterLastVersionLocked)。但最初 ListCheckpointOpts缺失 RunID 过滤,且 restoreCheckpointCore 中的markRestoredIDs 未排除 guard checkpoint(导致 undo信息丢失)。
方案
Restore(targetID, guardID) 改为对比两个明确的状态快照:
Guard checkpoint 恢复走 RestoreExact 单独路径:直接按 guard记录的版本号精确写回,不做双向对比。
Restore 中 hasGuard=false 时,hashSet 额外并 pathToVersions中所有已知文件。后续创建的文件的 hash 不在 target FileVersions中 → contentAtCheckpointLocked(hash, targetCP, false) 返回toExists=false → 触发 os.RemoveAll。
对源路径、filesystem_remove_dir
对目录及其嵌套文件、filesystem_delete_file
对目标路径,均在执行成功后调用 CapturePostDelete。
新增 EventRunDiffSummary 事件 (events.go:435) 和RunDiffSummaryPayload 类型,在 run 结束时由 run.go 触发,携带FromCheckpointID、ToCheckpointID、Diff、ChangedFiles。
修改范围
文件: internal/checkpoint/per_edit_snapshot.go
变更: Finalize 全量快照;FinalizePending增量快照;Restore(targetID, guardID) 双快照对比;RestoreExactguard 专用恢复;CapturePostDelete post-delete标记;RunAggregateDiff +contentAfterLastVersionLocked;contentAtCheckpointLocked增加fallbackIfMissing 参数
文件: internal/checkpoint/per_edit_snapshot_test.go
变更: 16 处 Restore 调用更新为三参数签名;新增TestRestore_Directory*、TestRestoreExact、TestRunAggregateDi
ff*、TestCheckpointDiffAfterDeleteAndRecreate、TestCheckpointDiffWithPostDeleteGuards*等
文件: internal/checkpoint/checkpoint_manager.go
变更: ListCheckpointOpts 增加 RunID 字段及 SQL 过滤
文件: internal/runtime/checkpoint_restore.go
变更: 提取 restoreCheckpointCore 核心逻辑;guard 使用FinalizePending;Restore 双参数调用;runDiff实现;markRestoredIDs 排除 guard checkpoint
文件: internal/runtime/checkpoint_gate.go
变更: lastEndOfTurnCheckpointID记录;findPreviousEndOfTurnCheckpoint 辅助方法
文件: internal/runtime/toolexec.go
变更: CapturePostDelete:move 源路径、remove_dir目录+嵌套文件、delete_file 目标路径;bash side effect路径记录;removeDirNestedPaths 集合传递给 post-delete
文件: internal/runtime/events.go
变更: 新增 EventRunDiffSummary 事件和 RunDiffSummaryPayload
文件: internal/runtime/run.go
变更: run 结束时触发 EventRunDiffSummary
文件: internal/repository/fingerprint.go
变更: ScanWorkdir / DiffFingerprints 从 checkpoint 包迁入,供
bash 指纹扫描重用
文件: internal/gateway/contracts.go
变更: CheckpointDiffInput 增加 Scope / RunID 字段
TUI/GUI 接入状态
已接入
待接入