Checkpoints and Rewind: File Snapshots, Conversation Rollback, and Why the Two Must Stay Independent
Make bad edits undoable: implement content-hash-based file snapshots, form two independent timelines with the session event log, support rolling back files only, the conversation only, or both together, and handle a repo that already had uncommitted changes — week two retrospective.
Today's Goals
- Implement a set of content-addressed file snapshots, and explain how it divides labor with a git commit
- Turn file rollback and conversation rollback into two independent, selectable recovery paths
- Handle three real problems: uncommitted changes, external changes, and snapshot size
Yesterday built the gate before acting; today builds the way back afterwards. When you finish, scroll back up and tick the three goals off.
Plain-Language Walkthrough
Save points and rollback: bad edits can go back to yesterday's version
Yesterday's gate blocked wrong directions; today handles the case where the direction was right, the plan was approved, they followed it, and the result is still wrong. What you want then is not an explanation but "put it back."
The rule is simple: save a version before acting, so that "try again" costs one keypress.
And the easiest misstep here is: do not use a git commit for that version. Running git commit on the user's behalf for "the state before changes" looks convenient, and the cost is a pile of commits in their history that they did not write and will spend time rebasing away. An Agent's save points are the Agent's own ledger and must not mix into the user's history. The division in one sentence:
| Whose ledger | Records | Who decides | |
|---|---|---|---|
| git commit | the user's | "this is a version I endorse" | the user |
| Snapshot | mca's own | "this is what it looked like before and after I acted" | the program, automatically |
So today has three parts: how to save (only what should be saved, and not twice), how to go back (files and conversation are two lines, and you must say which), and how not to lose the user's work (rollback is the only action that actively overwrites user files, so a check must precede it).
Interview questions
How would you design an agent's file snapshots, and why not just make git commits?Agent 的文件快照怎么设计?为什么不直接用 git 提交?
Common in ChinaCommon overseasBasic#snapshots#content-addressing🔒 Unlock this chapter to see the answer keys.
Why must file rollback and conversation rewind be separate? What happens when you rewind only one of them?文件回滚和对话回退为什么要分开?只回一边会发生什么?
Common in ChinaCommon overseasIntermediate#rewind#two-timelines🔒 Unlock this chapter to see the answer keys.
Before a rewind you find uncommitted changes in the workspace, or a file that was modified externally. How do you handle it?回滚前发现工作区有未提交改动,或者文件被外部改过,你怎么处理?
Common in ChinaCommon overseasDeep dive#workspace-safety#dirty-state🔒 Unlock this chapter to see the answer keys.
