跪拜 Guibai
← All articles
Frontend · Backend · Agent

AI changed your code but you can't tell what it did: Architecture drift is the real cost

By 张一凡93 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

As AI agents automate more refactoring, teams lose the ability to answer "what did the code become?" without costly manual review. Tools like Jin reintroduce architectural oversight at the moment of change, keeping human control over the structure AI writes.

Summary

AI coding agents routinely change many files at once, and while tests pass, the resulting architecture can drift silently. Dependency layering gets pierced, module boundaries blur, and responsibilities shift under the same names. The author, Zhang Yifan, argues this "architecture drift" is a growing cost in AI programming: line-level diffs can't show whether a new module appeared, whether a dependency was added, or whether an entity moved from one module to another.

Jin, a community fork of OpenCode, addresses this by maintaining a two-layer architecture model — L0 for systems, packages, modules, and external dependencies, and L1 for entities, fields, and relationships inside each module. Agents propose structural changes as editable snapshots, and a validation step checks references, public entities, and layering constraints. After applying, a drift check compares real code against the declared architecture, flagging unregistered symbols, misplaced entities, and missing module paths. Humans approve changes before they become part of the formal `arch/` definition.

The author is clear that Jin is not a proof of correctness and doesn't replace code review. It only makes structural change visible. But that visibility is exactly what's missing when a human is left staring at a diff of a dozen files, unable to say what the system became.

Takeaways
— Line-level diffs don't reveal whether a new module was added, a cross-layer dependency appeared, or an entity moved between modules.
— Architecture drift has three common forms: dependency drift, boundary drift, and semantic drift, all of which can pass tests and evade code review.
— Prompt constraints like "don't touch the payment module" are soft; they get diluted in long contexts and can't form checkable structural facts.
— Jin uses a two-layer architecture model: L0 for coarse structure (systems, packages, modules, external dependencies) and L1 for per-module entities, fields, methods, and relationships.
— Agents propose structural changes via editable target snapshots rather than editing the formal architecture directly.
— Validation checks references in the target architecture, public entities, and layering constraints before approval.
— Post-application drift checks verify that module paths exist, entity positions and symbols are real, public entities are registered, cross-layer dependencies don't violate constraints, and no unregistered public symbols appear.
— Jin's drift check is declarative, not a full compiler; it cannot prove business correctness, performance, security, or test coverage.
— Jin is a community fork of OpenCode, not an official product, and is still early-stage.
— The real goal is not faster AI but leaving a human-readable record of before/after structure, reasons, touched modules, and approval.
Conclusions

Soft constraints in prompts degrade as context grows; treating architecture as a set of hard, checkable facts is a more reliable way to govern AI-driven changes than static instructions.

Local optimal edits made by the agent, when aggregated, produce global structural chaos — a classic emergent failure mode of LLM-driven coding that no amount of testing catches.

Making structural changes explicit as a separate review step before writing to a formal architecture file preserves human judgment without slowing the agent down.

The distinction between "the same name, different responsibility" is subtle: semantic drift is the hardest form to catch with automated checks, yet it's the most dangerous for long-term maintainability.

A declarative drift checker is a pragmatic middle ground between no oversight and a full formal verification, acknowledging that architecture correctness is not the same as code correctness.

Concepts & terms
Architecture drift
A situation where an AI agent's code changes accumulate so that the system's actual structure (dependencies, module boundaries, entity locations, responsibilities) diverges from what was intended, even though tests pass and individual changes look reasonable.
L0/L1 two-layer architecture
Jin's model of architecture as two layers: L0 describes coarse-grained structure (systems, packages, modules, layering, external dependencies, constraints); L1 describes fine-grained contents of each module (entities, fields, methods, relationships).
Declarative drift check
A validation that compares the actual codebase against a declared architecture snapshot, checking for missing symbols, misplaced entities, unregistered public API members, and constraint violations. It's declarative because it only asserts what should be true, not how to compute it.
Soft constraints in prompts
Instructions written in natural language like "don't modify the payment module" that act as guidelines for an AI agent. They're soft because they can be diluted by long context windows and aren't enforceable as structural facts.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗