Oracle First: Routing AI-Generated Diffs With a Glossary and Four Leaves An engineer proposes a routing framework for AI-generated code diffs, introducing a glossary and a decision tree to classify patches as keep, quarantine, or rewrite. The approach includes a heuristic classifier script that flags architecture touches, secret hints, and silent expansion, aiming to reduce the cost of reviewing cheaply generated code. Consider this scene. It is a composite, not a personal war story. An agent ran overnight on a leftover prompt. Morning git status showed fourteen files. Two of them implemented the requested endpoint. The rest were a new logger, a renamed helper, a rewritten Dockerfile, and a README that now contradicted the tests. Generation cost was close to zero. The next four hours were not. That gap is the actual product problem. When a patch is cheap to produce, the expensive work is routing: keep, quarantine, or rewrite. Skip the routing and the cheap code becomes expensive debt with extra files attached. This article is a glossary, a routing tree, and a worked example at each leaf. The artifact is a small classifier plus a quarantine command sequence. Treat the code as a proposal unless you run it on your own repo. Free-model loops optimize for “a diff appeared.” Reviewers optimize for “this diff is safe to merge.” Those are different objective functions. A green unit test on a helper you did not ask for is not evidence that the architecture still holds. Cheap generation also changes failure shape. The common failure is no longer “the model wrote nothing.” It is silent expansion: extra modules, extra dependencies, extra comments that drift from the contract. Routing has to detect that shape before anyone debates style. Use these terms as they are defined here. Nearby words in vendor blogs do not override them. Walk the questions in order. Do not skip to a leaf because the diff “looks small.” Step 1 — Is there an oracle that already fails, or an oracle you can add in under fifteen minutes? Step 2 — Is surface area bounded? Bound means: requested paths only, or requested paths plus test files. A hard cap helps. A working default is “three production files and their tests.” Step 3 — Does the patch need network, secrets, or write access outside a temp directory? .env reads : go to Step 4 — Can an isolated process execute the oracle? The tree is deliberately biased toward discard and rewrite. Cheap generation makes “try it locally” the risky default, not the brave one. The script below does not prove safety. It only encodes the tree’s cheap heuristics so a human does not re-litigate them every morning. Label: proposal, unexecuted on your tree until you run it. bash /usr/bin/env python3 """classify patch.py — proposal heuristic, not a security scanner.""" from future import annotations import subprocess import sys from pathlib import Path ALLOWED PREFIXES = "src/", "lib/", "tests/", "test/" ARCH HINTS = "auth", "middleware", "migration", "dockerfile", "compose", ".github/" SECRET HINTS = "os.environ", "getenv ", "api key", "BEGIN ", ".env" MAX PROD FILES = 3 def git names diff range: str - list str : out = subprocess.check output "git", "diff", "--name-only", diff range , text=True return line.strip for line in out.splitlines if line.strip def patch text diff range: str - str: return subprocess.check output "git", "diff", diff range , text=True def classify diff range: str, requested: set str - str: names = git names diff range body = patch text diff range .lower prod = n for n in names if not Path n .parts 0 .startswith "test" extra = n for n in names if n not in requested and not n.startswith "test" if any h in n.lower for n in names for h in ARCH HINTS : return "LEAF D REWRITE architecture touch" if any h in body for h in SECRET HINTS : return "LEAF A DISCARD secret or env touch" if extra or len prod MAX PROD FILES: return "LEAF A DISCARD silent expansion" if not names: return "LEAF A DISCARD empty" if all n.startswith ALLOWED PREFIXES for n in names and len prod <= 2: return "LEAF C LOCAL allowlist" return "LEAF B QUARANTINE" if name == " main ": if len sys.argv < 3: print "usage: classify patch.py