« All posts

Building a Deterministic Merge Gate for AI-Generated Code

A POSIX shell gate checks AI-generated patches before merge: size budgets, sensitive path ownership, and Git diff hygiene, independent of the model that wrote the code.

This piece argues that code produced by AI coding agents should not merge directly into main just because an agent reports success; it needs to pass through the same disciplined gate as human-authored changes. The proposed solution is a small, dependency-free POSIX shell script (verify-patch.sh) that checks three narrow things: whether a patch stays within a reviewable file/line budget, whether it touches sensitive paths like .env, infra/, migrations/, or CODEOWNERS without explicit escalation, and whether it passes Git's own whitespace and conflict-marker checks. The script deliberately does not judge correctness, run tests, or perform security scanning—keeping its scope narrow makes its pass/fail result explainable.

The author demonstrates the gate in a disposable Git repository, showing both a passing safe change and a failing sensitive-path change, then wires it into GitHub Actions against pull requests. Size thresholds are presented as team-specific starting points rather than universal safety numbers—generated lockfiles may legitimately add thousands of lines, while a one-line authorization change can be high risk despite its size.

The approach is framed as applicable to any coding agent, including managed platforms like MonkeyCode, with the key principle being that merge policy should live in the target repository and stay independent of whichever model or interface generated the patch. For engineers, the takeaway is that as agent-generated contributions scale, a deterministic, repository-owned gate—rather than trust in an agent's self-reported success—is what keeps review accountable and merges auditable.