Transactions & Rollback
Atomic code changes — beginChange, commitChange, rollbackChange.
On this page
Transactions & Rollback
Agent-driven edits fail. Tests break, lint explodes, or the new code just doesn't match the intent. Mandu's transaction API wraps every change in an atomic snapshot you can roll back with one call.
Reach this via mandu change begin/commit/rollback from the CLI, or
beginChange() / commitChange() / rollbackChange() from code.
Why
- Agent safety net: an agent can try, fail, and reset without git
branches or
stashgymnastics. - File-level atomicity: all files touched inside the transaction revert together — no half-applied refactor.
- ATE integration:
mandu.ate.apply_healcan seed a transaction before patching, so a failed heal auto-rolls back.
CLI
# Start a transaction
mandu change begin "Add user auth middleware"
# → Transaction started. snapshotId: abc123
# ... let the agent edit files ...
# If things look right:
mandu change commit
# If things look wrong:
mandu change rollback
# → Restored 7 files. Transaction cleared.
# Inspect
mandu change status
mandu change list
Programmatic API
import { beginChange, commitChange, rollbackChange } from "@mandujs/core";
const { changeId, snapshotId } = await beginChange(rootDir, "Add user API");
try {
await applyAgentPatch(); // your code-mutation step
await runTests();
await commitChange(rootDir);
} catch (err) {
await rollbackChange(rootDir);
throw err;
}
The transaction persists under .mandu/history/snapshots/ — it survives
process crashes, so you can recover from an interrupted agent run.
Scope
A transaction tracks every file Mandu knows about. Files outside the project
root and files in .gitignore'd paths are NOT snapshotted — keep secrets
and build artifacts out of transactions.
Prune old snapshots
History accumulates. Trim with:
mandu history prune --keep 10 # keep most recent 10
or programmatically via pruneHistory().
Compose with Guard and ATE
Typical agent workflow:
mandu change begin "refactor users service"
↓
<agent edits files>
↓
mandu guard check # fail fast on layer violations
↓
mandu ate run # run affected tests
↓
if all green:
mandu change commit
else:
mandu change rollback
This is what the landing page's "AI 실수, 원클릭 되돌리기" refers to.
🤖 Agent Prompt
Apply the guidance from the Mandu docs page at https://mandujs.com/docs/architect/transaction to my project.
Summary of the page:
Mandu transactions (beginChange/commitChange/rollbackChange) wrap agent edits in atomic snapshots. Begin takes a snapshot, edits happen, commit locks it in or rollback restores. Pairs with ATE/Guard for safe LLM-driven changes.
Then:
1. Make the change in my codebase consistent with the page.
2. Run `bun run guard` and `bun run check` to verify nothing
in src/ or app/ breaks Mandu's invariants.
3. Show me the diff and any guard violations.
Related
- Guard — rule enforcement during agent edits
- Decision Memory — long-term architectural record
- Build with agents — Change — agent-side usage
For Agents
Mandu transactions (beginChange/commitChange/rollbackChange) wrap agent edits in atomic snapshots. Begin takes a snapshot, edits happen, commit locks it in or rollback restores. Pairs with ATE/Guard for safe LLM-driven changes.