Graph-Constraint Guardrails for Teams Whose AI-Assisted Codebase Has Already Lost Coherence
Recover drifted AI codebases with architectural constraints that block new violations.
Sponsored by Graphide

Architecture drift in AI-generated codebases occurs when locally correct changes accumulate into a structure that no longer matches the intended design. Once coherence is lost, line-by-line review cannot bring it back. Recovery requires graph-derived architectural constraints that block new violations, tolerate a recorded baseline of existing ones, and support incremental repair, with architectural context supplied to agents before generation.
Why AI agents degrade structural coherence faster than review can catch it
Context explosion and silent spec-code drift make each other worse. Without principled scoping, an agent working on one module can read the entire repository, conflate concerns, and produce “global fixes” across boundaries it was never asked to change. The Spec Growth Engine paper describes the underlying degradation as “context rot,” where performance on long-context coding benchmarks collapses as context length grows. Architectural coherence therefore requires a boundary around the information needed for the task as well as model quality.
Silent drift compounds that loss of focus. An agent reads existing code as ground truth, including relationships that already depart from the intended design. It then optimizes for the current prompt, leaving that accumulated divergence uncorrected. Meanwhile, the code evolves without corresponding changes to the specification. The next task begins from a baseline that is less faithful to the design but no less authoritative to the agent.
This creates a speed asymmetry between generation and supervision. Agents can extend an existing structural mistake through individually defensible changes faster than reviewers can reconstruct the relationships those changes affect. No single decision needs to look catastrophic. Over weeks or months, what looks like normal progress can hide the breakdown of module boundaries. Coherence loss is thus a property of the evolving system.
How do you detect when AI-generated code is diverging from your intended architecture?
The first signal is disproportionate change scope. A task that should be simple touches an unexpectedly large number of files because the architecture’s seams have shifted. The second signal is uncertain ownership. The answer to “where does this logic live?” becomes “it depends,” names stop matching behavior, and the same concept appears in slightly different forms across modules. These symptoms can look like routine development friction even while they reveal structural divergence.
The third signal is more deceptive than either. Tests keep passing, but developers start saying “don't touch that, it's fragile”. A suite written against current behavior does not necessarily test the design that behavior was meant to respect. A green build therefore offers false assurance when the architectural relationships themselves remain untested.
Stolze and Strässle’s ESEM 2026 study found that AI-assisted artifacts “may remain difficult to validate contextually despite appearing locally plausible or functionally correct”. Salesforce’s internal signals exposed a related weakness in supervision. Review time for the largest pull requests began to plateau or decline, indicating that reviewers were no longer meaningfully engaging with the changes. Review remained present in the workflow, but its depth had eroded. Many teams also adopted AI coding assistants without updating architecture decision records, review checklists, or security review processes, leaving governance designed around human cognitive patterns to supervise agent-generated output.
Why line-by-line review cannot recover coherence once it is gone
More careful review cannot fill in a missing architectural baseline. Once meaningful drift has accumulated, reviewing each new diff primarily maintains the system as it exists, including relationships that should not exist. Stolze and Strässle characterize organizations as facing “growing pressure to supervise AI-assisted development at scales that cannot rely on downstream human review alone”. Generating more code adds work to review, the binding constraint that already struggles most to keep up.
JetBrains Research and Lund University’s participatory design study with practitioners found that traditional line-by-line review struggles to keep up as agents generate larger change sets. It also found that this approach forces developers to skip high-level reviewing, even though they need more architectural reasoning when AI-generated changes are large. Attention shifts toward line-level pattern matching. Review automation has not closed that gap, and preserving a review step does not preserve the reasoning that step was supposed to provide.
The limitation is also built into the diff. It shows changes between two states while leaving their conformity to the overall architecture unassessed. A downstream call site untouched by the pull request may be difficult to see from that local view. The reviewer must reconstruct context that the artifact does not directly present. To recover, teams therefore need to check the relationships between modules and the rules those relationships must meet.
What graph-derived architectural constraints actually are and how they work
Graph-derived architectural constraints are executable rules that check dependency relationships and fail a build when those relationships break the intended design. They are one form of architectural fitness function. Building Evolutionary Architectures, by Neal Ford, Rebecca Parsons, and Patrick Kua, defines fitness functions as mechanisms that provide an objective integrity assessment of architectural characteristics. The category is broader than build-blocking tests. It also includes metrics, monitoring, and other mechanisms that may run continuously or when triggered.
For dependency enforcement, the relevant model is a graph of code elements and their relationships. Analysis of syntax or compiled code supplies the dependencies that the validator checks against architectural assertions. A rule might state that “classes in package X should not depend on classes in package Y”. At merge time, the check asks whether the actual graph conforms to that assertion.
ArchUnit implements this pattern for Java. Dependency Cruiser supports JavaScript, TypeScript, and CoffeeScript, while eslint-plugin-boundaries supports JavaScript and TypeScript. These are implementations of dependency enforcement with a bounded architectural scope. Their shared role is to turn dependency invariants into checks that run in CI. The strength of the check depends on the structural rule the team has expressed.
A closed loop also compares the constraint model with the live graph. If the architecture specifies that service A depends on service B and only service B, the validator checks the actual relationships against that contract. Architectural intent is made machine-interpretable before generation, while enforcement evaluates the resulting code afterward. The Spec Growth Engine adds a complementary drift gate that makes divergence between the specification graph and the actual dependency graph a blocking merge condition. The gap between design and implementation becomes an explicit CI failure rather than an inference left to a reviewer.
The specific problem of applying enforcement to a codebase that has already drifted
Immediate enforcement against an ideal architecture can make an existing codebase fail throughout. That creates an all-or-nothing choice between halting development and abandoning the rules. Neither option provides a workable recovery path. Teams need to distinguish inherited violations from newly introduced ones while preserving the intended architecture as the target. A recorded baseline lets them do that without treating the current structure as correct.
ArchUnit 0.11.0 introduced FreezingArchRule in July 2019 to support this form of incremental adoption. Violations present when a rule is introduced are frozen as a baseline, so existing violations do not block builds while new violations do. The recorded violation set establishes how much drift already exists, and refactoring works that set down over time.
CodeSai’s April 2026 evaluation compared architecture tests, agent-assisted review, and approaches that use documentation. It concluded that architecture tests integrated into CI/CD provide deterministic adherence because a rule violation prevents the build from passing. That guarantee applies to the encoded rule. It distinguishes enforcement from approaches that depend on interpretation or compliance.
Truffle Graphics’ October 2026 implementation put this into practice with a pull-request dependency guard that had a limited scope. It checked production targets, target dependency declarations, and public-header imports without the need for a full rewrite. Keeping the scope small made it possible to enforce the rules on an existing codebase. The Spec Growth Engine addresses a related baseline problem by co-evolving the specification and code in the same commit. Its gate enforces agreement between what was specified and what was built without requiring a perfect specification to exist before recovery begins.
How enforcement and upstream context injection work together to prevent recurrence

A blocking gate can still be an expensive safeguard. If an agent generates thousands of lines before discovering that a dependency is forbidden, the team has spent compute and developer time on work that cannot merge. The constraint existed, but the generator did not see it. Supplying architectural context before generation addresses that waste without weakening the gate.
Stolze and Strässle distinguish preventive guardrails from executable guardrails. Specifications and steering files guide the work before there is output, while linting, tests, and CI check it afterward. The distinction separates guidance from enforcement. A complete supervision model needs both because they intervene at different points in the workflow.
Salesforce’s Prizm illustrates the value of preserving structural context within review analysis. It centers on intent reconstruction rather than treating a diff as flat text, preserving file, function, and module boundaries. Token-aware chunking keeps logical units intact. The shape of context affects what supervision can see because flattened text obscures relationships that architecture-aware analysis needs to retain.
The strongest objection to enforcement alone is therefore valid. It can catch a forbidden dependency deterministically while doing so inefficiently, after substantial work has already been produced. The reverse approach has a different weakness. Upstream injection without enforcement relies on the agent respecting the context it receives, with no blocking fallback when it does not. Guidance makes enforcement more efficient, but enforcement remains essential.
A practical sequence for teams starting recovery from an already-incoherent codebase
For a team beginning recovery, the first action is to map the actual dependency graph. That map needs to include accumulated violations. Dependency Cruiser and graph-based editors that expose module and call relationships can make the current structure visible. Memory is not a sufficient baseline for enforcement. Rules need to be grounded in the system that exists before they can govern its recovery.
The next action is to freeze existing violations, deferring their repair. FreezingArchRule or an equivalent baseline ratchet lets the team introduce constraints without making every inherited violation a new release blocker. The first rules should cover the boundaries with the largest blast radius. These include security boundaries that stop UI code from importing DB code directly, service ownership boundaries, and public-API contracts. The purpose is to stop new damage at high-risk seams while leaving room for deliberate refactoring.
Truffle Graphics documented architecture ownership and orchestrator boundaries before adding its dependency guard to CI. That ordering connected an explicit design contract to an enforceable set of checks on existing code. The Spec Growth Engine’s vertical-slice growth protocol adds hardest-first ordering, so constraints cover the most structurally complex and highest-risk boundaries before they cover lower-risk ones. This avoids polishing the periphery while the core relationships that threaten coherence remain unconstrained.
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.


