Continuous Architecture Conformance Checks for AI-Generated Pull Requests
Blocking CI gates catch the structural violations that passing tests miss.
Sponsored by Graphide

Architecture drift in AI-generated codebases happens when changes meet functional requirements but break the rules for module boundaries, dependency direction, or domain isolation. Continuous architecture conformance checks find those violations by testing the structure of the code on every agent-generated pull request. To preserve the design at agent speed, those checks must be blocking CI gates that exit non-zero on violations.
Why AI agents create architectural violations that standard tests cannot catch
The CI pipeline is green, the tests pass, and the build ships, but the architecture has silently degraded. A domain entity now imports an infrastructure module directly, closing a dependency loop that the design forbids. The code still produces the expected result. A unit test that checks that result therefore has no reason to fail, even though the change breaks the intended separation between domain logic and infrastructure. Structural analysis of the dependency graph exposes what the passing test leaves unexamined.
This failure mode concerns the architectural conformance of AI-generated code. Agents satisfy prompts at the function and file level without reliably preserving constraints across modules, layers, and services. A cross-cutting feature can therefore be locally correct while structurally nonconforming. Functional tests check what code does, while architectural conformance checks whether its dependencies respect the design.
Kashif et al. 2026 identifies prevalent design issues including Code Duplication, high Code Complexity, Large Methods, Framework Best-Practice Violations, Exception-Handling Issues, and Accessibility Issues. Passing tests do not establish the absence of those problems. For architectural enforcement, however, the narrower concern is whether a change introduces a relationship that should never exist. Ordinary style linting cannot answer that question by checking only whether each file follows coding conventions. The check needs an encoded model of which parts of the system may depend on which others.
How agent speed turns an occasional structural slip into a systemic drift problem
An occasional boundary violation grows into systemic drift when changes arrive faster than people can check how they affect the structure. Agent-generated PRs can change many files of several file types as they work through a prompt end-to-end. Each change may look reasonable in isolation. Together, though, those changes can cross layers that a reviewer can see should be kept apart only by looking at the wider dependency graph. The review burden grows with both the relationships affected and the amount of code added.
Minh et al., MSR '26 finds that high-effort PRs are distinguishable at creation time through signals including patch size and file-type composition. Those signals exist before anyone reads the diff. They reveal where a change will demand more attention. A large, cross-layer diff asks the reviewer to reconstruct both the implementation and the boundaries it should respect. Producing code faster does not speed up that work for the reviewer.
The same study documents “agentic ghosting,” in which agents abandon PRs mid-review when faced with iterative subjective feedback. That leaves partially reviewed changes in the queue with the correction loop incomplete. The queue becomes part of the structural problem. A reviewer must retain context about unresolved changes while new changes continue to arrive, and potentially compromised boundaries remain unsettled.
Whether the code does what the ticket requests is usually easier to answer than whether every new relationship belongs in the design. Correctness therefore provides a persuasive but incomplete basis for approval. Drift accumulates through individually plausible changes rather than announcing itself as an architectural rewrite. By the time the collective pattern becomes obvious, the issue is no longer one misplaced import.
Why the PR review queue cannot absorb the architectural review burden
Human review assumes that producing code costs the author enough effort to constrain how quickly it reaches the queue. Agent PRs weaken that constraint without removing the reviewer's need to understand the result. A small fraction of high-complexity agent PRs consumes the majority of maintainer review effort. This creates an uneven attention tax. The hardest changes use up the time reviewers would otherwise have to check the structure of the changes left in the queue.
Correct naming, idiomatic style, confident commit messages, and passing tests can all coexist with an illegal dependency. Nothing necessarily looks wrong at first glance. The cues that often help a reviewer spot a defect may be missing, so structural review has to compare the code with the architecture even when the code looks sound. Even a more careful read takes time for that comparison.
Agents lack the track record that lets reviewers calibrate a lighter read, leaving every PR with a broad verification burden. Kashif et al. states that design issues “require careful review by experienced developers.” Those developers are already the scarce resource in the queue. Assigning them an additional mandatory architectural examination for every agent PR concentrates the work at the existing bottleneck.
Better prompts and agent instructions can state how the architecture should work, but rules still need to be enforced. Constraint decay means that layering requirements into prose does not reliably preserve structural compliance. Instructions are not a merge condition. A rule expressed only in a prompt still depends on the agent remembering and applying it throughout the change, followed by a reviewer noticing any departure. If human review cannot reliably perform the architectural check at this volume and speed, the check must run before the human ever sees the diff.
How to detect when AI-generated code diverges from the intended architecture
The implementation task is to encode structural invariants. In layered or hexagonal architecture, those invariants include controllers not accessing the database directly, domain entities not importing infrastructure, and use-case logic not leaking into presentation code. Each restriction identifies an illegal relationship. A conformance check must detect that relationship even when the resulting program builds and behaves correctly, because execution success does not make the dependency permissible.
Dependency direction makes these restrictions mechanically testable. The check encodes the legal direction of imports between modules and fails when an import reverses it. This gives dependency inversion an enforceable structural expression. Instead of asking whether a file appears well designed, the gate asks whether its outgoing dependencies belong to the allowed graph. A locally convenient import can then be rejected without a reviewer having to rediscover the governing rule.
DDD bounded contexts require a related but distinct form of isolation. Services within one bounded context must not import domain objects from another, while any shared-kernel boundary must be explicit and deliberate. Module ownership adds another constraint. A file may use another module's published interface, but that does not let it call the module's internal APIs directly. Agents can shortcut either boundary to satisfy a prompt, so checking only broad layer membership leaves important violations undetected.
PR description-to-code alignment is a separate conformance signal. Phantom changes, omitted modifications, and file-type mismatches can reveal that the agent's account no longer matches the actual diff. This check tests whether the change being presented for review is described consistently. Functional correctness, security vulnerabilities, and test coverage also need their own pipeline stages, since folding them into one architecture score would make that score unclear.
How to fit conformance checks into a CI pipeline without making them a bottleneck
For implementation, the pipeline should first identify that a PR is agent-generated, then run architectural conformance, followed by security validation and functional tests. The ordering is deliberate. Fast static checks can reject a structurally invalid change before expensive stages begin, avoiding work on a PR that cannot merge in its current form. Appending conformance after the full test run forfeits that short-circuit benefit and delays the agent's opportunity to correct the violation.
Latency is a design constraint for enforcement. Static analysis of dependency graphs and import relationships is computationally cheap compared with test execution or LLM-based review, and graph constraints can typically be evaluated in seconds. Developers push back on stages that take more than a few minutes. They are liable to be disabled or moved to nightly runs, which removes the per-PR protection the architecture needs. 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, keeps the same pass/fail verdict with less waiting for supported workloads.
Policy-as-code provides a way to express the constraints as machine-readable rules. Open Policy Agent with Rego can encode policies that check structural relationships, in the same way that policies block deployment when there are critical vulnerabilities. Here, the prohibited condition is architectural. A policy can reject a domain entity's infrastructure import. The useful property is a definite outcome tied to a stated rule.
The MSR '26 circuit-breaker model complements those rules with early triage. Patch size, the number of files touched, and configuration edits can flag high-effort, high-risk PRs before a person switches tasks to review them. Those signals support routing to deeper checks. Changes with a simple structure can take the faster path, while more complex changes get a closer look, so every PR need not take the same amount of review time. This triage adds to the conformance gate, whose rules still apply to changes that look simple.
The CodeSai team's April 2026 result shows why the gate must block. A violation that physically prevents the build from passing achieves adherence that agentic review does not, because the agent cannot proceed until the constraint is satisfied. The check must exit non-zero on violation and block the merge. Warnings and comments leave compliance dependent on later attention, reproducing the queue problem in another form. Enforcement changes the workflow from requesting an architectural correction to requiring it before acceptance.
Keeping the encoded rules current as the architecture itself evolves
Static rules encode yesterday's design. That is the strongest objection to automated conformance, and it is valid when rules remain fixed while the architecture intentionally changes. A subsystem refactor can make an old boundary inappropriate. Rules that still enforce it then cause false positives, which can lead people to bypass or remove the rules to get a green build again. Rule evolution must be part of architectural change as the original design evolves.
Rule files must therefore live in the repository and version with the code they govern. A change to an architectural boundary is incomplete until the rule encoding that boundary changes in the same PR. This keeps the decision visible in the diff. Git history then records both the implementation change and the corresponding change in what the architecture permits. Review can examine the intentional boundary revision instead of repeatedly adjudicating unexplained failures against an obsolete rule.
The shared model also addresses coordination across multiple agents and agent-human pairs working concurrently. All contributors face the same architectural constraints rather than separate interpretations of prose in a wiki. The graph becomes the coordination artifact. People still need to judge when a boundary should change, but routine enforcement no longer has to wait for an experienced reviewer to spot each breach. CI becomes the architectural contract, recording what the design permits and refusing every agent-generated PR that violates it.
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. 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.


