跪拜 Guibai
← All articles
Artificial Intelligence · AI Programming · Coding Standards

AI Coding Won't Stop Breaking Your Code—Here's the Three-Stage Fix

By 蓝瑟 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Teams burning velocity on AI-generated regressions are treating a governance problem as a model problem. Tightening CI, writing specs before prompts, and isolating agent roles costs less than the rework from trusting probabilistic output on production code.

Summary

AI coding tools produce code that gets messier over time, and the root cause is structural: models generate by probability, not by understanding cause and effect. Errors are not occasional bugs but an ineliminable property of the system. The fix is not a better prompt or a stronger model; it is a staged governance framework that escalates constraints as a project matures. Vibe Coding lets the model run freely during the 0-to-1 prototype phase, with only a causal-chain discussion and a collaboration spec set upfront. Once the MVP is validated and changes start breaking unrelated features, Spec-driven development locks intent, context, and process into living documents that act as AI's onboarding material for every fresh session. When documentation alone can no longer keep the project stable, Harness engineering layers on hard enforcement—CI gates, generator-evaluator loops, role-isolated agents, and automated verification—that AI cannot bypass. The upgrade signal is blunt: when the current layer stops working, move up. Don't pile on governance too early, and don't delay it once complexity demands it.

Takeaways
AI is a probabilistic model, not a causal one; errors are structural and cannot be eliminated, only contained.
Vibe Coding suits the 0-to-1 prototype phase—let the model run with minimal constraints, but first establish the project's causal chain and a collaboration spec in AGENTS.md.
Move to Spec-driven development when changes start breaking unrelated features; document intent, boundaries, and decisions so AI works inside a constrained context.
Treat every new AI session as day one: re-onboard it with the spec instead of continuing a polluted long conversation.
Write specs as causal chains (what, why, desired effect, boundaries, forbidden actions), not as encyclopedias of technical detail.
Use EARS notation for acceptance criteria so requirements are unambiguous and testable by both AI and humans.
Adopt a four-stage SDD loop—Specify, Plan, Tasks, Implement—with mandatory human review at each stage boundary before proceeding.
Introduce Harness when spec documents can no longer prevent AI from breaking critical functions; hard enforcement replaces voluntary compliance.
Harness mechanisms include generator-evaluator loops, CI as a non-negotiable gate, role-isolated agents with fixed tool permissions, and JSON-based feature tracking to prevent fake completion.
CI is the cheapest, highest-leverage harness: move lint, typecheck, tests, and pre-commit hooks forward so violations block merges.
Refactor the MVP before layering on Spec and Harness; governance attached to a messy codebase will still produce messy output.
Upgrade governance when the current layer fails—not before the project needs it, and not after complexity has already caused damage.
Conclusions

The framework reframes AI coding failures as a governance maturity problem rather than a model capability problem, which shifts investment from chasing stronger models to building tighter processes.

Calling every new AI session 'day one' and re-onboarding it with a spec is a cheap, high-impact practice that most teams overlook; they instead burn tokens fighting context pollution in long conversations.

The recommendation to refactor the MVP before applying Spec or Harness is underappreciated—governance layered onto unstructured code inherits the chaos it's meant to fix.

Harness engineering formalizes what senior engineers already do instinctively (strict CI, role separation, automated checks) but makes it explicit and non-optional for AI-generated code, where the failure rate is higher and less predictable.

EARS notation for acceptance criteria is a small, concrete technique that bridges the gap between human intent and machine-executable tests; its adoption could reduce the 'it runs but it's wrong' failure mode significantly.

Concepts & terms
Vibe Coding
An AI coding approach coined by Andrej Karpathy where developers give minimal constraints and let the model freely generate a prototype, prioritizing speed and exploration over correctness.
Spec-Driven Development (SDD)
An engineering practice where a formal specification—covering intent, boundaries, decisions, and acceptance criteria—is written before code and serves as the prompt and constraint system for AI throughout the development lifecycle.
Harness Engineering
A governance layer for AI coding that enforces hard, non-bypassable constraints through CI gates, generator-evaluator loops, role-isolated agents, and automated verification, turning voluntary compliance into physical locks.
EARS (Easy Approach to Requirements Syntax)
A notation with five sentence patterns that transforms vague requirements into unambiguous, testable statements, enabling both humans and AI to verify whether a feature is correctly implemented.
MCP (Model Context Protocol)
A protocol that connects AI coding tools directly to live data sources such as API documentation or cloud documents, eliminating information gaps that cause hallucination.
ADR (Architecture Decision Record)
A document capturing a significant architectural decision, its context, and its rationale, serving as project long-term memory so AI understands past trade-offs during future iterations.
Generator-Evaluator Loop
A Harness pattern where one AI agent generates code and a separate agent or automated checker reviews it, rejecting output that fails validation until it passes, replacing human-to-human code review with agent-to-agent review.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗