[KongchangAI]
· 3 min read· 1,767 words

How to Review a 22,505-Line PR? Matt Pocock's Stacked PRs and Ratchet Rules

How to Review a 22,505-Line PR? Matt Pocock's Stacked PRs and Ratchet Rules

Split giant AI PRs into stacked PRs, review only irreversible one-way doors line by line, read the rest for patterns, and constrain with ratchet rules.

Using Matt Pocock's handling of a 22,505-line agent-generated PR as the throughline, the article presents a review methodology for large-scale AI code delivery. The core is the two-way/one-way door framework to distinguish reversible from hard-to-undo changes, splitting the PR into 9 stacked PRs and compressing the danger surface to four lines of SQL. Humans decide first; line-by-line review only for one-way doors; recurring issues become ratcheted lint rules; retro reveals the agent imitating bad doc examples.

AI agents delivering PRs with thousands of lines of code at once is becoming a daily reality for developers. Matt Pocock's skills repository is one of the most-starred projects on GitHub, and his agent once handed him a 22,505-line PR outright. Faced with that volume, most people either skim the green checkmark and merge, or let it rot in the queue. But Matt didn't do either — he split the giant PR into 9 smaller stacked PRs and merged them within an hour.

Behind this lies a more fundamental question: when an agent writes an entire feature for you, what exactly should you review?

And that turns into nine tickets.

The Core Tension: What You Can Undo vs. What You Can't

A PR touching 40 files might simultaneously contain a settings UI, business logic, and a database change. A broken UI can be reverted; a database migration that has already run against production data cannot be taken back. The problem is that they're bundled into the same PR, and to find that one irreversible change, you have to read all 22,505 lines.

Matt borrows Jeff Bezos's "two-way door / one-way door" framework to break down the problem. Two-way doors are changes you can roll back if something goes wrong after merging; one-way doors are changes that are hard to undo once merged — mutating data, calling external services, or opening a security hole. His strategy: have the agent split the large PR into a series of two-way doors, ultimately converging on a single one-way door.

Of the 9 resulting PRs, the only true one-way door was PR 6 — four lines of SQL adding four columns to the thumbnail table. Because it only adds columns, existing code is unaffected; the PR description explicitly states "merged by Matt, the agent must not merge." PR 9 handles turning on the feature flag and includes rollback instructions. The other eight PRs are all reversible two-way doors.

In the end, the "danger surface" of this feature delivery was compressed from over twenty thousand lines down to four lines of SQL.

Before Splitting the PR: Decide First, Code Later

Matt was able to get a splittable PR because he completed the key decisions before the agent started writing. He first told the agent why the feature should exist — drawing diagrams directly on YouTube thumbnails — rather than just saying what to do. His experience: describe only what to build, and the agent often returns a less creative answer.

Next, a skill repeatedly asks questions until every part of the feature has a name, both sides use the same vocabulary, and those names are written into a glossary file. When he encounters an unexpected decision, he writes a short note — that's an ADR (Architecture Decision Record). He also built three throwaway prototypes, then produced a requirements spec with 47 user stories, which was then broken into 9 tickets.

The key division of labor here: decisions are made by humans, execution is handed to the agent. In Matt's own words, once you let the agent make its own decisions, it may make bad ones.

Then PR 9 turns the flag on.

ADR (Architecture Decision Record) is a lightweight documentation format used to record an important technical decision along with its context, alternatives, and trade-off rationale. It typically lives in the repository as a short Markdown file, one record per decision, numbered in chronological order. The value of ADRs is that they crystallize "why it was designed this way" out of individual memory or chat logs, letting future maintainers (including agents) understand the constraints and avoid unknowingly overturning existing decisions. For AI agents, ADRs also serve as explicit boundary statements, reducing the probability of them making architecture-level judgments on their own during implementation.

Reviewing Agent Code: Look at Patterns, Not Every Line

Is splitting the PR enough? The industry is not unanimous on this. According to the video's citations, Guillermo Rauch believes skipping review means taking on debt and risk; Mitchell Hashimoto says engineers should be able to explain any customer-facing system they ship at any time, but he doesn't require line-by-line familiarity. Kent C. Dodds takes a more radical view — AI can prove code correct, so review might be eliminated entirely.

Matt's stance is a middle ground: review is a spectrum, with line-by-line reading at one end and not reading at all at the other, with many stops in between. The only review object he considers mandatory is the one-way door. As for the other eight PRs, he reads for patterns — both what the code does and the system that produced it.

His comments repeatedly point to the same categories of problems: too many code comments, overuse of as type assertions, scattered bare fetch calls. Under each comment he wrote the same line: find a lint rule that can be ratcheted.

Lint rules are checks defined in static code analysis tools (such as ESLint) that find potential problems, style violations, or dangerous patterns without running the code. Each rule can be configured as off, warning, or error, and can be enforced in CI. The advantage of lint rules is that they turn "recurring feedback in code review" into automatically enforceable constraints, so that the same class of problem is caught at commit time instead of relying on a human pointing it out in a PR. For the large volume of agent-generated code, rule-based constraints are far more scalable than line-by-line review.

What Are Ratchet Rules?

So what does ratchet mean?

New lint rules face a practical obstacle: Matt's repository already has 2,078 as assertions across 698 files. Ban them outright today and the entire repository lights up with errors.

The ratchet approach: put existing problems on a whitelist and let them through; fail new code that violates the rule; and when an old problem is fixed, cross it off the list. The list only gets shorter — 2078, 2077, never back up. In Matt's words, it's a rule that doesn't have to be enforced on day one but tightens gradually over time.

The payoff of these two kinds of fixes differs by an order of magnitude: fixing a line of code fixes one PR; adding a rule fixes every PR the agent writes afterward.

Ratchet is borrowed from mechanical engineering, referring to a gear mechanism that can only turn in one direction. In software engineering, "ratchet pattern" broadly refers to a constraint mechanism that allows a metric to change in only one direction: existing state is tolerated, but deterioration is forbidden. Beyond lint rules, ratchet thinking is also common for test coverage (coverage must not fall below the current baseline), type-checking strictness, the number of dependency warnings, and similar scenarios. Its core value is bypassing the deadlock of "the backlog is too large to fix all at once," spreading governance cost across every incremental change, so the system gradually converges toward stricter standards while continuing to deliver.

Using retro to Find Out Why the Agent Keeps Writing Bad Code

Matt has a command called retro that runs over the roughly 30 sessions he saved, while also pulling in the 12 comments he left on those PRs. The result: all 12 comments pointed to the same cause — his written guidelines didn't cover these issues, and his docs even demonstrated the patterns he hated. The coding standards file recommended using as assertions; the docs used bare fetch as an example. There were already thousands of copies on main, and the agent was simply imitating the repository.

He also found that 18% of the lines in the new feature were comments, versus a repository-wide average of 12%; 18 of those comments were masking a workaround. That afternoon he added ratcheted lint rules, corrected the docs, and filed an issue against his own skill.

And Matt says,

Does retro itself work? According to the video's citations, research published in October by two researchers tested the seven changes proposed by retro: two eliminated the problem, one mitigated it, and four changed nothing. Matt's response: we need to retro the retro itself.

Feature flags are a technique that decouples code deployment from feature release: code can be merged and shipped early, with a configuration option controlling whether the new feature is visible to users. Their key role is to split "merging" and "taking effect" into two independent events, shrinking the risk window of any single change — if something goes wrong, turn off the flag and you're back to the original state, no code rollback needed. In the stacked-PR scenario, a feature flag lets the last PR bear only the responsibility of "turning on the switch," keeping all the foundational changes before it in a state that can be safely merged without affecting production.

An Action Checklist for Yourself

Matt's skills are free and open source. The next time an agent hands you a giant PR, you can follow this process:

  1. Ask the agent to split the PR into stacked PRs — two-way doors first, the one-way door last, all hidden behind a feature flag
  2. Read the one-way door yourself, line by line — usually a database migration
  3. Read the rest for patterns; every time you spot a pattern you dislike, ask for a ratchetable lint rule
  4. Run retro before clearing the conversation, feeding in your review comments too, to find out which bad examples the agent was imitating

So the answer is not to review those thousands of lines, but to review the few lines you can't undo — and the system that wrote the rest.

One-line Summary

Split giant AI PRs into stacked PRs, review only the irreversible one-way door line by line, read the rest for patterns, and constrain with ratchet rules.

Paragraph Summary

Using Matt Pocock's handling of a 22,505-line agent-generated PR as the throughline, the article presents a review methodology for large-scale AI code delivery. The core is the "two-way door / one-way door" framework to distinguish reversible changes from hard-to-undo ones, splitting a large PR into 9 stacked PRs and compressing the danger surface from over twenty thousand lines to four lines of SQL migration. On the decision side, humans first complete requirements definition, a glossary, and ADRs, then let the agent execute. On the review side, it advocates line-by-line reading only of the one-way door, observing code patterns for the rest, and converting recurring issues into ratcheted lint rules. Finally, the retro command reveals that the agent is imitating bad examples in the docs, pointing to fixing the guidelines themselves rather than patching issue by issue.

#AI code review#stacked pull requests#one-way door#ratchet lint rules#feature flag#architecture decision record#agent-generated code
Share:

Related articles