.agents/skills/ai-rollback/SKILL.md
Rollback a bad release or revert a merged PR. Use when something broke after a merge or release. Also triggered by 'something broke', 'undo the last release', 'revert'.
npx skillsauth add svange/tagmania ai-rollbackInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Rollback a bad release or revert a merged PR: $ARGUMENTS
Gathers diagnostic context, identifies the breaking change, shows a dry-run plan, and executes a revert. Handles staging/production scope and database migration awareness.
/ai-rollback - Interactive rollback with diagnostic questions/ai-rollback 98 - Revert PR #98/ai-rollback abc1234 - Revert specific commit/ai-rollback --dry-run - Show what would be reverted without executingAsk these questions all at once to minimize back-and-forth:
Something went wrong -- let's figure out where. Please answer what you can:
1. Which environment is broken? (staging/dev, production/main, or both?)
2. When was the last time you can confirm it worked as expected?
3. What change do you think broke it? (PR number, feature name, or "not sure")
4. What symptoms are you seeing? (error messages, wrong behavior, crashes, data issues?)
5. Is this causing active harm right now, or is it safe to take a few minutes to investigate?
6. Did the breaking change include any database migrations or infrastructure changes?
7. Are other people actively working on this branch right now?
If the user provided a PR number or commit SHA as an argument, skip questions 2-3 and use the provided reference directly. Still ask the remaining questions.
gh pr view $PR_NUMBER --json mergeCommit,title,headRefName,mergedAt,files
MERGE_COMMIT=$(gh pr view $PR_NUMBER --json mergeCommit -q .mergeCommit.oid)
git log --oneline -1 $COMMIT_SHA
# Show recent merges on the affected branch
git log --oneline --merges -20 origin/$BRANCH
# Show recent PRs
gh pr list --state merged --limit 10 --json number,title,mergedAt,headRefName
Use the user's "last time it worked" answer and the "symptoms" to narrow the window. Show the commits in that window and ask: "Which of these looks suspicious?"
# Check if the target PR/commit included migration files
git diff --name-only $MERGE_COMMIT^..$MERGE_COMMIT | grep -iE 'migration|alembic|flyway|schema'
If migration files are found, warn prominently:
WARNING: This change includes database migrations.
Code rollback alone will NOT revert schema changes. You may need to:
- Write a reverse migration
- Restore from a database backup
- Fix forward instead of rolling back
Proceed with code-only rollback? [y/n]
Detect the branch detection algorithm from CLAUDE.md (Architecture > Branch Detection Algorithm).
# Which branch was affected?
DEV_BRANCH=""
for candidate in dev develop staging; do
if git show-ref --verify --quiet refs/remotes/origin/$candidate; then
DEV_BRANCH=$candidate
break
fi
done
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
Based on user's answer to "which environment":
$DEV_BRANCH$DEFAULT_BRANCH, then ask about dev$DEFAULT_BRANCH first (stop the bleeding), then address $DEV_BRANCHWhether --dry-run was passed or not, ALWAYS show this plan and get confirmation:
=== Rollback Plan ===
Environment: production (main)
Action: Revert merge commit abc1234 (PR #98: "feat: add auth timeout")
Effect: Creates a new commit that undoes PR #98's changes
Version impact: Semantic-release will create a new patch version (e.g., 0.21.1)
Database: No migrations detected in PR #98
Other environment: dev -- will ask after main revert
This will NOT roll back to a previous deployed artifact -- it creates a new
release with the breaking change removed. The version number moves forward,
which provides a clear audit trail of when the rollback happened.
Proceed? [y/n]
If --dry-run was passed, stop here. Otherwise, proceed after user confirmation.
# Checkout the target branch
git checkout $BRANCH
git pull origin $BRANCH
# Revert the merge commit (use -m 1 for merge commits)
git revert $MERGE_COMMIT -m 1 --no-edit
# Push the revert
git push origin $BRANCH
For non-merge commits (direct pushes):
git revert $COMMIT_SHA --no-edit
git push origin $BRANCH
After the primary revert is pushed, ask about the other environment:
Revert pushed to main. Now about dev:
- (a) Revert this PR on dev too (mirror the rollback)
- (b) Fix forward on dev (keep the changes, fix the bug there)
- (c) Skip -- I'll handle dev separately
If the user chooses (a), repeat the revert on the dev branch.
If the user wants to fix the issue (not just revert):
git checkout -b fix/revert-issue-$ISSUE_NUM $BRANCH
git push -u origin fix/revert-issue-$ISSUE_NUM
Hotfix branch created: fix/revert-issue-42
The reverted changes are available in git history if you need to reference them.
When ready: /ai-submit-work
After pushing the revert, automatically invoke /ai-monitor-pipeline to watch the pipeline. The revert commit will trigger CI, and for main branch, will trigger semantic-release (creating a new patch version).
development
Deploy or validate Renovate dependency update configuration. Detects repo type (library vs IaC), package ecosystem, and generates or fixes renovate.json5.
development
Deploy or validate semantic-release configuration. Handles Python (python-semantic-release) and Node (JS semantic-release) repos with correct Renovate prefix alignment.
development
Audit and fix pre-commit hook configuration. Ensures consistent developer-side quality gates for formatting, linting, type checking, and secret protection.
testing
Audit and fix CI/CD GitHub Actions workflows. Checks security scanning, coverage enforcement, type checking, CVE ignores, and concurrency settings.