[Feature]: Chat rollback should also restore the worktree files
Problem
In a Chat session, "Roll back to here" makes the agent forget the turn and everything after it. The files in the worktree stay exactly as they were, and the confirmation dialog says so.
So undo only covers half of a bad turn. Example: I ask a worker to refactor the auth module. It edits 14 files and breaks the build. I roll back to the turn before. The agent no longer remembers the refactor, but the 14 edited files are still on disk, and the next turn starts from code the agent doesn't know it wrote. I have to clean the worktree by hand with git, or kill the session and start over.
This affects anyone who uses Chat sessions. It costs more with many parallel workers, because every bad turn needs its own manual cleanup.
Current behavior on main (a7d8bcfca):
backend/internal/ports/chat.go:ChatRollbacker"discards history back to a turn, provider-side".frontend/src/renderer/components/chat/ChatWorkspaceRollback.test.tsxasserts that the dialog tells the user the files are "left exactly as they are".
Proposed direction
Snapshot the worktree after each settled Chat turn, and let rollback restore the files and the conversation together.
t3code (pingdotgg/t3code) already does this. After every turn it saves a git checkpoint as a hidden ref, so the user's branch gets no extra commits. Reverting a turn restores the files and rolls the provider conversation back together. If the provider can't roll back its conversation, t3code refuses before it touches any file. See apps/server/src/checkpointing/CheckpointStore.ts and the "Turn completion and checkpoints" section of docs/internals/overview.md.
A rough shape for AO:
- When a Chat turn settles, snapshot the worktree, including uncommitted and untracked (not ignored) files, into a hidden ref such as
refs/ao/snapshots/<session>/<turn>. Leave the branch, index and stash alone. - "Roll back to here" first checks that the provider can roll back. Then it restores the files to that turn's snapshot and calls
ChatRollbacker. If either step fails, nothing changes and the dialog says why. - Before the user confirms, the dialog lists the files that will change.
- Snapshot refs are deleted when the session ends.
Open questions:
- Turns that committed or pushed. Restoring files is easy, but moving the branch back rewrites history. One option is to refuse rollback past a push. Another is to restore files only and leave commits alone.
- Edits the user made in the same worktree after that turn would be lost. AO's rules say never force-delete dirty worktrees, so this needs a clear warning or a refusal.
- The refs live in the repo's
.git, not under~/.ao. Worktree git objects already live there, but this should be checked against the "all AO state under~/.ao" rule. - AO already uses "checkpoint" for native chat history (
native_checkpoint.go). A different word, such as "file snapshot", would avoid confusion. - Start with Chat. TUI sessions could follow for harnesses whose hooks report when a turn ends.
Alternatives considered
- Keep the current behavior and let users clean up with git. It works, but it's manual, and you have to know which files the turn changed.
- Ask the agent to undo its own changes. It's unreliable, and it costs a turn.
Before submitting
- [x] I searched existing issues / discussions for something similar
- [ ] I am willing to help implement this if maintainers agree on scope