Mechanism: Rollback
One-sentence definition
Rollback is having a known-good restore point — commit, stash, branch tip, or snapshot — before agent edits land, so you can undo quickly when a pass violates scope, fails verify, or fails checkpoint.
The problem
The agent edits twelve files. Verify fails. You try to guide it back but the diff is tangled — partial fixes on top of partial refactors. You manually hunt for what changed. Twenty minutes later you wish you had a button that meant “pretend this session never happened.”
Without rollback, every agent session is high-stakes. Fear of breaking the tree makes you hesitate to use loops and agents at all — or you keep broken state and patch forward.
Symptoms:
- “Something broke but I don’t know when”
- Mixed good and bad edits in one working tree
- Avoiding agent mode on main because undo feels hard
- Long revert sessions instead of one command
How it works
Create a restore point before the first agent edit:
Clean tree / known commit
│
▼
Snapshot (commit · branch · stash)
│
▼
Agent work
│
├── success + checkpoint ──► keep; merge forward
│
└── fail ──► rollback to snapshot; re-prompt or narrow goalCommon snapshot patterns:
- Git commit on a branch —
git checkout -b agent/health-fixthen commit WIP before each risky pass - Stash — quick local experiments:
git stash push -m "pre-agent" - Branch per experiment — see branch-per-experiment
- File copy — last resort for non-git assets; not a substitute for version control
Rollback is not failure — it is part of the loop. A failed pass plus clean rollback is cheaper than a failed pass plus forward patching.
When to use it
- Before any agent or loop session on shared or main-adjacent branches
- When a pass violates constraints or scope fence
- When verify fails repeatedly and the diff grows
- Before trying a second model or radically different approach on the same task
When not to use it
- When you have already merged to main without a branch — rollback still exists (
git revert) but cost is higher; prevent with branches - Using rollback instead of small commits — commit good increments; rollback bad passes, do not rollback everything always
Failure modes
No snapshot — Agent runs on dirty uncommitted main. Fix: Branch + commit or stash first; non-negotiable habit.
Snapshot too late — After three agent passes. Fix: Snapshot before pass one; optional commit after each green verify.
Rollback without learning — Revert and repeat the same prompt. Fix: Tighten goal, constraints, or context budget before retry.
Mixed manual + agent edits — Cannot tell what to revert. Fix: Commit human work separately; agent on clean branch.
Afraid to rollback — Keep bad diff and patch. Fix: Treat revert as normal; time saved beats sunk-cost pride.
Minimal example
Context: Starting the health endpoint agent fix.
Steps:
git checkout -b agent/health-okgit commit --allow-empty -m "snapshot: before health agent session"or commit current clean state.- Run agent passes. If pass 4 violates constraints (touched
Dockerfile):
– git checkout -- . or git reset --hard HEAD to snapshot
– Re-send goal + constraints; do not patch forward from the bad diff.
- When verify passes and checkpoint approves, squash or merge the branch.
Done when: You executed at least one rollback drill — revert to snapshot in under a minute.
Tool instances (optional deep-dive)
Portable idea above; this section is tool-specific. Date: June 2026.
Cursor
- Agent on a git branch — default habit; main stays clean.
- Reject all / undo in diff view for partial rollback before commit.
- Timeline / local history (editor) — secondary safety for uncommitted buffers; git remains source of truth.
- Checkpoints in long agent runs: commit when verify goes green; reset to last green if next pass regresses.
Other tools
git worktree for parallel experiments, Time Machine / snapshots on local DBs — same mechanism: known restore point before risky automation.
Related mechanisms
- Checkpoint — approve before keeping; rollback when rejected
- Scope fence — smaller sessions make rollback smaller
- Branch-per-experiment — structural rollback via branch discard
Try it yourself
Exercise: On a throwaway branch, make a deliberate bad agent or manual edit. Practice git reset --hard or git checkout -- . back to your pre-session commit. Time how long it takes.
You need: Git repo; one branch; three minutes
Done when: You restored a clean tree in one command and can name the commit hash you restored to.

