{"slug": "first-rollback-revert-the-agent-pr-you-cannot-explain", "title": "First Rollback: Revert the Agent PR You Cannot Explain", "summary": "A developer has published a practical guide for engineers rolling back a first AI-generated pull request, arguing that a rollback plan should be prepared before any agent-authored code is merged. The guide recommends halting the agent and CI pipeline, inventorying the diff with git rather than chat logs, and using a decision table to choose between reverting and fixing forward, with the rule that two or more warning signals should trigger a revert. It also warns against resetting shared main or force-pushing branches others have pulled, and requires the rollback PR to include the diff inventory and a written decision file.", "body_md": "Your first AI pull request will often need rollback.\n\nPlan that rollback before you merge anything.\n\nYou lack repo history on day one.\n\nAgents still produce large and confident diffs today.\n\nA rollback plan keeps that blast radius tiny.\n\nFirst rollback means undoing your own agent PR.\n\nIt does not mean rewriting team history casually.\n\nYou revert a branch you still control.\n\nYou leave other people's commits completely untouched.\n\nYou treat revert as an admission of failure.\n\nIt is a safety move, not a performance review.\n\nYou also wait for perfect understanding of every hunk.\n\nThat wait lets CI keep building a bad branch.\n\nDo not keep generating patches during a bad merge.\n\nStop the agent, the pipeline, and extra pushes now.\n\n```\ngh pr ready --undo\ngh run cancel --branch \"$BRANCH\"\ngit status -sb\n```\n\nThose three commands buy you quiet thinking time.\n\nYou need that quiet before you touch git history.\n\nYou cannot revert a change you cannot list.\n\nAsk git, not the chat log, for the truth.\n\n```\nBASE=\"${BASE_SHA:-origin/main}\"\nHEAD=\"${HEAD_SHA:-HEAD}\"\n\ngit fetch origin\ngit diff --name-status \"$BASE\"...\"$HEAD\"\ngit diff --stat \"$BASE\"...\"$HEAD\"\ngit log --oneline \"$BASE\"..\"$HEAD\"\n```\n\nSave that inventory into a local file immediately.\n\n```\nmkdir -p .onboarding\ngit diff --name-status \"$BASE\"...\"$HEAD\" \\\n  > .onboarding/first-pr-files.txt\ngit diff \"$BASE\"...\"$HEAD\" \\\n  > .onboarding/first-pr.patch\n```\n\nRead the name-status list before any revert.\n\nLook for migrations, lockfiles, and generated assets.\n\nYou do not read the patch from top to bottom.\n\nYou read it in three passes with git only.\n\n```\ngit diff --name-only \"$BASE\"...HEAD | wc -l\ngit diff --stat \"$BASE\"...HEAD | tail -n 1\n```\n\nIf the file count exceeds the ticket's expected paths, revert.\n\nA junior should not debug a thirty-file agent surprise.\n\nUse a hard table. Do not improvise under pressure.\n\n| Signal | Prefer revert | Prefer fix-forward | \n|---|---|---|\n| Files outside the ticket | Yes | No | \n| Tests red on your branch | Yes | Only if one test fails | \n| Schema or migration changed | Yes | No | \n| Reviewer already approved | Ask first | Maybe | \n| You cannot explain one hunk | Yes | No | \n\nIf two or more Yes cells fire, revert.\n\nFix-forward is for a single, obvious typo only.\n\nWrite the decision into the same onboarding folder.\n\n```\ncat > .onboarding/rollback-decision.md <<'EOF'\n# First PR rollback decision\n- Ticket:\n- Files outside ticket:\n- Tests:\n- Migrations:\n- Choice: revert | fix-forward\n- Why:\nEOF\n```\n\nFill every bullet before you run git revert.\n\nEmpty bullets mean you are still guessing, so stop.\n\nNever reset shared main on day one.\n\nNever force-push a branch others already pulled.\n\n```\nset -euo pipefail\nTICKET=\"${TICKET:-ONBOARD-0}\"\nSAFE=\"rollback/${TICKET}-first-pr\"\n\ngit switch -c \"$SAFE\"\n# If the PR was a single merge commit:\ngit revert -m 1 \"${MERGE_SHA}\" --no-edit\n# If the PR was a linear range:\n# git revert --no-edit \"${BASE}\"..\"${HEAD}\"\n```\n\nIf revert conflicts, abort and re-read the inventory.\n\n```\ngit diff --name-only --diff-filter=U\n# After you understand each conflict:\n# git revert --abort\n```\n\nDo not ask an agent to resolve conflicts yet.\n\nConflict markers hide product rules you just learned.\n\nA revert is not done when git says success.\n\nA revert is done when tests match the base branch.\n\n```\ngit fetch origin\ngit diff --stat origin/main...HEAD\n```\n\nPin the test command from the README only.\n\nDo not invent npm scripts the agent suggested.\n\n```\n# Proposed example. Replace with the README command.\n# npm test\n# go test ./...\n# pytest -q\n```\n\nIf tests fail on the rollback branch, stop shipping.\n\nYour revert missed a generated file or a migration.\n\nThe rollback PR should contain almost no story.\n\nIt should contain the inventory and the decision file.\n\n```\ngit add .onboarding/first-pr-files.txt \\\n        .onboarding/rollback-decision.md\ngit commit -m \"revert: ${TICKET} first AI PR\"\ngh pr create --draft --title \"revert: ${TICKET}\" \\\n  --body-file .onboarding/rollback-decision.md\n```\n\nKeep the original PR closed or converted to draft.\n\nDo not delete it; you need the transcript later.\n\nYou still need a second pair of eyes on the diff.\n\nYou do not need that pair of eyes to rewrite files.\n\nDisclosure: This article was prepared as part of MonkeyCode's product outreach.\n\nMonkeyCode is an open-source coding assistant for local work.\n\nIt offers free model access and a free server option.\n\nUse it to narrate the patch, not to apply another patch.\n\nPaste the inventory file and ask for a file-risk list.\n\nAsk which paths look like migrations or generated code.\n\nThen you run git while the agent stays in explain mode.\n\nThat split matters on a junior's first hour.\n\nExplanation is cheap, but a second bad patch is not.\n\nSave this script under scripts in your clone.\n\nRun it from the repo root on your PR branch.\n\n``` bash\n#!/usr/bin/env bash\n# Proposed local helper. Not team policy.\nset -euo pipefail\n\nBASE=\"${1:-origin/main}\"\nOUT=\"${2:-.onboarding}\"\nmkdir -p \"$OUT\"\n\ngit rev-parse --abbrev-ref HEAD > \"$OUT/branch.txt\"\ngit diff --name-status \"$BASE\"...HEAD > \"$OUT/name-status.txt\"\ngit diff --stat \"$BASE\"...HEAD > \"$OUT/stat.txt\"\ngit log --oneline \"$BASE\"..HEAD > \"$OUT/commits.txt\"\n\necho \"Risky paths:\" > \"$OUT/risks.txt\"\nif command -v rg >/dev/null 2>&1; then\n  rg -n -i \"migration|schema|lock|generated|dist/\" \\\n    \"$OUT/name-status.txt\" >> \"$OUT/risks.txt\" || true\nelse\n  grep -Ei \"migration|schema|lock|generated|dist/\" \\\n    \"$OUT/name-status.txt\" >> \"$OUT/risks.txt\" || true\nfi\n\necho \"Inventory written to $OUT\"\n```\n\nLabel this as a proposed local helper, not team policy.\n\nYour new team may already have a revert runbook.\n\nCommit the script only if the team wants it.\n\nDo not sneak tooling into the rollback PR itself.\n\nThis workflow assumes you still own the branch.\n\nIt assumes main is protected and you can open drafts.\n\nIt does not cover broken production traffic today.\n\nIt does not cover signed commits you cannot reproduce.\n\nRevert can miss submodule pointers and LFS files.\n\nIt can also miss squashed commits on a rewritten branch.\n\nThe decision table is a heuristic, not a proof.\n\nTwo yes cells do not replace a staff engineer's call.\n\nFree model access will not know your production topology.\n\nA free server will not hold your private incident facts.\n\nDo not paste secrets, tokens, or customer data into prompts.\n\nSkip this if you are not the PR author.\n\nSkip this if the change already shipped to customers.\n\nSkip this if the repo uses a required merge queue.\n\nTalk to the maintainer before any revert there.\n\nSkip this if you cannot run the README test command.\n\nA green revert you cannot test is still a guess.\n\nJuniors on regulated codebases should wait for a buddy.\n\nPair on the revert and do not solo a schema undo.\n\nWrite three notes before you log off.\n\nThose notes become your second-day review checklist.\n\nThey also keep the next agent session much smaller.\n\nPractice this workflow on a throwaway clone first.\n\nA free explain-only session can walk the inventory.\n\nKeep every git command in your own terminal.", "url": "https://wpnews.pro/news/first-rollback-revert-the-agent-pr-you-cannot-explain", "canonical_source": "https://dev.to/gitgo_5662/first-rollback-revert-the-agent-pr-you-cannot-explain-3akh", "published_at": "2026-09-13 20:37:07+00:00", "updated_at": "2026-09-13 21:22:03.861398+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-tools", "mlops"], "entities": ["Git", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/first-rollback-revert-the-agent-pr-you-cannot-explain", "markdown": "https://wpnews.pro/news/first-rollback-revert-the-agent-pr-you-cannot-explain.md", "text": "https://wpnews.pro/news/first-rollback-revert-the-agent-pr-you-cannot-explain.txt", "jsonld": "https://wpnews.pro/news/first-rollback-revert-the-agent-pr-you-cannot-explain.jsonld"}}