Shift-Left Architecture Review for Agent-Generated PRs
Executable rules and agentic checks catch design drift before merge.
Sponsored by Graphide

CI enforcement of architectural constraints requires executable rules that run during agent work and block merges when they fail. ArchUnit for Java and NetArchTest for.NET can enforce measurable boundaries, while agentic evaluation can examine design concerns those tests cannot express. Shift-left architecture review for agent-generated PRs means defining these constraints before generation begins, rather than asking a reviewer to reconstruct architectural intent from a finished diff.
Why agent-generated PRs broke the assumption that review can happen at merge time
The reviewer opens a diff spanning backend code, configuration, tests, and UI. Naming is clean, the implementation looks idiomatic, and the tests pass. Yet there is no clear starting point. The change does not preserve the narrative that would explain why these files belong together, which dependency changed first, or what the author considered risky.
Human PRs often provide that scaffolding through ordered commits, a lead file, and a description of the author's concerns. Agent PRs can arrive without it, leaving the reviewer to infer the relationship between changes. LinearB's 2026 Benchmarks Report, drawn from millions of PRs across thousands of teams, found AI-assisted PRs materially larger at the 75th percentile than unassisted ones. Size therefore adds more lines to inspect and compounds the loss of narrative.
A study analyzed 33,596 agent-authored PRs and found that agents wrote the majority of comments on reviewed agent PRs. A substantial fraction of human comments were instructions steering agents rather than technical evaluations, a pattern that barely appears in human-authored PR reviews.
An MSR 2026 study found that additional review activity correlates with higher merge likelihood for human PRs but lower merge likelihood for agentic PRs. That correlation casts doubt on the belief that more discussion will reliably help an agent PR get accepted, while leaving the cause of rejection unestablished. The inherited workflow depends on human attention resolving uncertainty that the agent's output has already multiplied.
How agents optimize locally and produce architectural violations that look like clean code
An agent asked to add a caching layer may put direct database queries in an API controller, bypassing the mandated data-access layer. The implementation can still be readable and functional. Its defect is the dependency it creates.
“More Code, Less Reuse,” a January 2026 study, found that agent-written changes introduce more redundancy and more technical debt per change, while reviewers feel better about approving them. Plausible new code can therefore conceal the failure to reuse an existing component. The visible quality of the implementation is not a reliable proxy for its fit within the system.
A task can consume millions of tokens across frontier LLMs on a software engineering benchmark, yet total token consumption is not the same as simultaneous understanding. As an agent touches more files, it holds less of any individual file in working context. Autonomous refactoring can consequently produce “stability gaps,” where locally functional code lacks systemic robustness.
The risk also varies by task. MSR '26 research found that documentation and CI tasks often get merged, while bug-fix and performance tasks get merged least often. The latter are especially likely to involve cross-cutting changes, where success depends on design intent.
For the reviewer, the difficulty is cognitive distance. Code can contain a boundary violation even when its names are correct, its structure is idiomatic, and its commit message sounds confident. Unlike a human contributor, an agent does not offer a consistent track record against which the reviewer can calibrate trust. Ordinary behavioral tests and surface fluency leave it unclear whether the code respects architectural boundaries.
Why the PR boundary is the wrong place to enforce architectural constraints
At PR time, structural review requires more than reading changed lines. The reviewer must work out what the architecture was meant to be, how the components now relate to each other, and how the change fits with both. A diff supplies the edits from which the reviewer must reconstruct that complete model. When changes span dozens of files, most of the work goes into piecing that model together.
The reference picture is also becoming less dependable. Under agent throughput, a developer's understanding of the system can decay weekly as previous agent runs alter the same codebase. Plan verification is a tempting shortcut because it takes less effort to review what was planned than to trace how it was carried out. But a plan is not evidence of adherence. The plan and the diff can diverge without the shortcut exposing that divergence.
The review study found that 61.38% of agent-authored PRs had no recorded human review. Most of the interaction in the study took place through automation, with less independent review by humans. MSR '26's Circuit Breaker study also identified two regimes, in which agents merge quickly on narrow automation or abandon PRs when faced with subjective feedback. Maintainers must spend attention before discovering which kind of interaction they have entered.
Greater adoption does not resolve this mismatch. The LinearB report found that agentic PRs merge at a fraction of the rate of unassisted ones, and organizations further along in agentic adoption do not show higher acceptance rates. The bottleneck is not simply unfamiliarity with the workflow. An architectural control that depends on a person reconstructing every large change cannot operate reliably at agent speed, so the enforcement point must move earlier.
What "shift left" actually means for architecture, not just for security
Architectural shift-left saves work in the same way as security shift-left. A violation costs less to undo when it is caught before it spreads across many files. Architecture includes design intent, so checks for known-bad patterns cannot catch every way a change can break that intent.
The first enforcement layer consists of deterministic fitness functions, which are executable rules for measurable invariants. ArchUnit expresses architectural tests for Java, while NetArchTest serves.NET. These tests belong in the repository and run on every PR, enforcing constraints such as dependency direction and layering. When an architectural test fails, it must block the merge.
The second layer places agentic fitness functions beside those rules. These examine judgment-heavy concerns including boundary fidelity, semantic contract drift, workflow coupling, and stale ADR assumptions. For example, an agentic evaluation can assess whether a new service interaction is intentional collaboration or accidental coupling. The deterministic rule establishes whether an explicit boundary was crossed, while the agentic assessment explains the design concern that a simple dependency test cannot settle.
The division of authority must remain explicit. Deterministic controls establish the governance posture, agent evaluation explains it, and humans decide what to do about ambiguity or high-risk designs. AI does not override policy gates. Open Policy Agent provides a policy-as-code precedent across microservices, Kubernetes, API gateways, and CI/CD pipelines, but the architectural constraints still have to be defined for the system being protected.
This model runs executable boundary tests and policy checks in CI and uses agentic evaluation to help with decisions those controls cannot make. A diagram alone supplies none of that enforcement.
Encoding constraints before the agent touches the repo, not after it opens the PR
The same constraints must be in place before the agent begins editing so they can prevent violations as well as reject them. An agent cannot reliably preserve boundaries it cannot see within its working context. Its input therefore needs a structured map of the codebase. That map gives repository context a form the agent can use under token limits.
The Aider Repository Map pattern combines tree-sitter parsing to an AST, a dependency graph ranked by PageRank, and dynamic fitting within token budgets. The pattern gives a compact view of how the code fits together, without treating every file as equally useful background. The map shows how the code is structured, and explicit constraints set out which changes are allowed.
Harness engineering adds control over execution itself. It defines the agent's permissions and stop conditions before a run, including which directories it may write to, which layers it may add dependencies across, and which contracts it may change. It also specifies changes that require a human checkpoint before work continues. These are operating limits.
Research on experienced developers working with agents identifies a priori control, co-planning, real-time monitoring, and post hoc review as distinct forms of oversight. Teams should put work into a priori control so that post hoc review has fewer failures to deal with. Constraints should version with the code so that the permitted architecture changes through the same controlled workflow as the implementation. A rule left in an external document cannot serve as an enforceable repository constraint.
This earlier layer makes CI the final check on work performed within known limits.
How CI enforcement of architectural constraints must block bad merges
A CI gate must both report that an analysis ran and reject architectural violations. For layered architecture, it must check dependency direction and detect code that crosses a forbidden boundary. For contracts, it must check whether a public interface changed without updates to the consumers that use it. Its result must decide whether the change can merge, with a check that exits non-zero when it fails.
Coverage of new code paths by tests the agent did not write provides evidence independent of the implementation task. Boundary-fidelity evaluation checks whether a new service interaction is intended collaboration or accidental coupling. These checks are complementary. A permitted import does not establish that the interaction has the intended meaning.
The enforcement mechanism also needs protection from the authoring agent. A team implementing these gates should prevent agent writes to CI configuration, because a gate cannot constrain work if the same agent can weaken it. Pre-review triage can then reserve human attention for changes likely to require it. The Circuit Breaker model found that simple static signals available at creation time, including file types touched and patch size, can predict high-effort, low-quality agent PRs with strong discriminative accuracy.
The strongest objection is that structural compliance is not semantic correctness. “Is Vibe Coding Safe?” evaluated SWE-Agent running Claude 4 Sonnet and found a majority of solutions functionally correct but only a small fraction secure. Passing automated tests can coexist with a violation of security intent, particularly when tests do not exercise adversarial behavior.
That objection sets a condition for effective enforcement. The test suite, architectural specification, and contract definition must form a trusted upstream oracle that pre-exists the agent's work. Without that oracle, automated gates can recognize permitted structure without knowing whether the result fulfills the intended design.
What the developer's role becomes when architecture enforcement is automated
The developer can therefore have the most impact by working before generation begins. It is defining intent, supplying context, and encoding the constraints against which the agent's output will be judged. This is more demanding than checking surface quality after the fact. The developer must turn what the design calls for into evidence that a pipeline can check, and decide which questions still need human judgment.
Automation changes who performs an action while ownership of its outcome remains unchanged. An agent can generate, refactor, and deploy code, but an engineer must own and maintain the architectural model that sets the conditions for acceptable code. Reviewing evidence, resolving ambiguity, and deciding what can ship remain human responsibilities. A green gate cannot assume responsibility for an incomplete specification.
A structured, live graph gives that responsibility a practical interface. It shows modules, dependencies, and architectural boundaries so the developer can guide agent work to fit how the system is built. A diff remains useful for inspecting edits. The graph shows how the parts relate when a change spans too many files for line-by-line reading to make the structure clear.
For a team applying this model, the work is concrete. Define the boundaries, encode the measurable rules, establish trusted contracts and tests, and give the agent a current map before it runs. Human checkpoints then address genuine ambiguity rather than rediscovering violations that a rule could have stopped.
Putting architectural checks in CI
Choose an architecture-test or dependency-rule tool that supports your language and the constraints you can explicitly encode. Commit its rules with the code, run the documented command in CI, and make the resulting check required where those rules should prevent a merge. Test the gate with an intentionally forbidden dependency before relying on it, and if the added checks stretch your push-to-verdict time, Graphide CI, a faster GitHub Actions runner service that runs existing jobs with warm caches, splitting long test steps only where a check shows every result stays the same, can shorten that wait, and a failing test still fails the job. Such checks enforce the rules you specify; they do not establish that every aspect of the architecture or runtime behavior is correct.
Updated November 5, 2026: obsolete CLI examples removed. Use the selected tool’s current installation and command documentation.
Sources
- Early-Stage Prediction of Review Effort in AI-Generated Pull Requests
- These Aren't the Reviews You're Looking For How Humans Review AI-Generated Pull Requests
- How Do AI Coding Agents Contribute to Software Development? an Empirical Study of Agentic Pull Requests
- What Is Shift Left Security? - Palo Alto Networks


