The goal
You want one loop:
The coding agent writes code
The repo enforces risk-aware checks before merge
A code review agent validates the PR
Evidence (tests + browser + review) is machine-verifiable
Findings turn into repeatable harness cases
The specific review agent can be @greptile, @coderabbitai, CodeQL + policy logic, custom LLM review, or another service. The control-plane pattern stays the same.
I took inspiration from this helpful blog post by @_lopopolo
The high-level flow
- Keep one machine-readable contract
Your contract should define:
risk tiers by path required checks by tier docs drift rules for control-plane changes evidence requirements for UI/critical flows
Why it matters: it removes ambiguity and prevents silent drift between scripts, workflow files, and policy docs.
- Gate preflight before expensive CI
A reliable pattern is:
run `risk-policy-gate` first verify deterministic policy + review-agent state only then start `test/build/security` fanout jobs This avoids wasting CI minutes on PR heads that are already blocked by policy or unresolved review findings.
- Enforce current-head SHA discipline
This was the biggest practical lesson from real PR loops.
Treat review state as valid only when it matches the current PR head commit:
wait for the review check run on `headSha` ignore stale summary comments tied to older SHAs fail if the latest review run is non-success or times out require reruns after each synchronize/push clear stale gate failures by rerunning policy gate on the same head If you skip this, you can merge a PR using stale “clean” evidence.
