Skip to content

Backup, Recovery, and Rollback

The AI agent just refactored your authentication module across 47 files. The tests pass. The types check. You merge the PR. Two hours later, session tokens are not being validated in the admin API — the agent removed a middleware registration that was not covered by tests. You need to roll back, but three other PRs have merged on top. This is the disaster recovery scenario that every team using AI tools eventually faces.

  • Checkpoint and rollback strategies specific to AI-assisted development
  • Recovery procedures for AI-introduced regressions at every stage of the pipeline
  • Pre-flight safety checks that prevent disasters before they happen
  • Incident response patterns for AI-related production issues
  • Audit practices that make root cause analysis fast and reliable

The best disaster recovery is preventing disasters. Build safety nets at every stage.

Cursor’s checkpoint system provides automatic rollback points:

  • Checkpoints are created automatically before each agent action
  • Use the Timeline panel to view and restore any checkpoint
  • Create manual checkpoints before high-risk operations: right-click in the timeline

Add explicit safety rules:

.cursor/rules
SAFETY REQUIREMENTS:
Before any multi-file refactoring:
1. List all files that will be modified
2. Verify the test suite passes BEFORE making changes
3. After changes, run the full test suite
4. If any test fails, revert ALL changes and report what went wrong
NEVER delete files without explicit user confirmation.
NEVER modify configuration files (*.config.*, .env*, Dockerfile) without showing the diff first.
  1. Feature flags for AI-generated changes

    Deploy AI-assisted changes behind feature flags. If something goes wrong, flip the flag instead of rolling back the deployment.

  2. Canary deployments

    Route 5% of traffic to the new version. Monitor error rates, latency, and key business metrics for 30 minutes before expanding.

  3. Automated rollback triggers

    Set up automatic rollback when error rate exceeds 2x baseline or p99 latency exceeds 3x baseline.

  4. Post-deployment monitoring

    Watch dashboards for 4 hours after deploying AI-generated changes. The failure modes of AI code are often subtle — edge cases and race conditions rather than crashes.

This is the easiest recovery. The AI made changes that break the test suite.

Use Cursor’s checkpoint timeline to restore the last good state:

  1. Open the Timeline panel
  2. Find the checkpoint before the breaking change
  3. Click “Restore” to return to that state
  4. Alternatively, use Cmd+Z aggressively — Cursor tracks AI changes separately from manual edits

Scenario 2: AI-Generated Code Merged But Causes Production Issues

Section titled “Scenario 2: AI-Generated Code Merged But Causes Production Issues”

The most dangerous scenario. AI-generated code introduced a data corruption bug.

  1. Stop the bleeding

    Deploy the rollback immediately. Do not try to fix forward when data integrity is at risk.

  2. Assess the damage

    Query the database for records modified during the incident window. Determine the scope of corruption.

  3. Restore from backup

    Use your point-in-time recovery to restore affected data to the state before the incident.

  4. Root cause analysis

    Identify which AI-generated code caused the corruption. Was it a missing validation? A wrong query? A race condition?

  5. Prevent recurrence

    Add specific test cases for the failure mode. Add database constraints that would catch the corruption at the data layer. Update AI rules to prevent similar patterns.

Never let an AI agent make 47 file changes in a single commit. Break large changes into small, reviewable, revertable commits.

Before any AI-generated change, create a test that captures the current behavior.

“We merged AI code without proper review and now production is down.” Roll back immediately. Do not try to fix forward during an active incident. After rolling back, conduct a blameless post-mortem focused on what safety net was missing, not who approved the PR.

“We cannot roll back because other changes depend on the AI-generated code.” This is why incremental commits matter. If you can identify which specific commit introduced the issue, you can revert just that commit. If changes are tangled together, you may need to create a targeted hotfix rather than a full rollback.

“The AI deleted files we need and we did not notice until much later.” Git has your back. Use git log --diff-filter=D to find deleted files and git checkout <commit>^ -- <filepath> to restore them. Add a CI check that flags file deletions for extra scrutiny during code review.

“Our backup strategy does not cover AI-specific failure modes.” Standard backup strategies (database backups, code in Git) cover most AI failure modes. The unique risk with AI is subtle behavioral changes that pass all checks. Add behavioral regression tests for critical paths and deploy behind feature flags.