Lesson 16 / 25

Diff Size and Scope Gates

Flag or block changes that are much larger or wider than the task justifies.

Big diffs hide mistakes

Reviewers cannot truly read a 3,000-line diff. Set limits on files changed and lines changed for an agent's pull request; going over the limit means "split it" or "get a deeper review", not an automatic merge. Combine it with the protected-path check so unexpected files stand out. A tiny task that changes forty files is a warning sign in itself.

A size gate, run

I ran this. Three files and 80 lines pass; forty files and 900 lines are rejected with reasons. In CI you would get the numbers from git diff --numstat.

def gate(files, lines, max_files=15, max_lines=400):
    reasons = []
    if files > max_files: reasons.append(f"too many files ({files})")
    if lines > max_lines: reasons.append(f"too many lines ({lines})")
    return reasons or ["ok"]

print(gate(3, 80), gate(40, 900))

Output:

['ok'] ['too many files (40)', 'too many lines (900)']

Ask for smaller pull requests

Put "one logical change per pull request" in the project guide for agents. Small diffs are easier to review, easier to revert and cheaper to retry when wrong.

Quick check: What should happen when an agent's pull request exceeds the size limit?

  • It merges automatically
  • The limit is raised silently
  • It is split or gets deeper review
  • The tests are deleted
Answer

It is split or gets deeper review — Large changes get more scrutiny, not less.