Governing AI Multi-Turn Coding Decay with Patterned Workflows

    AI coding agents often perform well in single-turn tasks, but multi-turn collaboration can erode a codebase through duplicated logic, implicit dependencies, drifting interface contracts, declining test coverage, and changes that are hard to trace. This article presents a patterned workflow—research, innovation, planning, execution, and review—with document-first outputs, strict mode boundaries, small closed-loop changes, rule-file examples, team adoption guidance, and metrics to keep AI-assisted coding reviewable and maintainable.

    Governing AI Multi-Turn Coding Decay with Patterned Workflows

    1. The Real Problem: It Is Not That the Model Cannot Write Code, but That the Engineering Process Is Missing

    Intelligent coding agents often shine in single-turn tasks: completing a function, generating tests, or explaining an error is rarely difficult. But when developers involve AI across multiple turns in requirements analysis, technology selection, coding, debugging, and refactoring, the codebase can easily become “corrupted”: duplicated logic increases, implicit dependencies spread, directory responsibilities become unclear, interface contracts drift, test coverage drops, and changes become untraceable. Maintenance costs then rise sharply.

    This is not entirely a model-capability problem. It is a missing engineering-process problem. AI is good at learning the “form” from massive amounts of code—common patterns, library calls, and idioms. But it lacks the “spirit” that experienced human developers bring to project-level, from-zero-to-one construction: which constraints must not be violated, which modules may be changed, when documentation should come first, when design review must happen, and how to control the scope of a single change. Without these constraints, multi-turn dialogue becomes a series of locally optimal additions. Each turn may look reasonable, but together they damage the overall architecture.

    The solution is therefore not simply to switch to a stronger model, nor to rely on unconstrained “vibe coding.” It is to give coding agents a set of expert-level rules: brainstorm first, clarify thinking, write documentation, and only then code and review. The value of rules is that they make human engineering experience explicit and let AI do the right thing at the right stage.

    2. Core Principles: Mode Isolation, Documentation First, and Small Closed Loops

    The first principle of a patterned workflow is “stage isolation.” Different stages have different goals, and the operations allowed and forbidden in each stage must also differ. The research stage reads but does not write. The innovation stage proposes options but does not implement them. The planning stage breaks down tasks but does not change business code. The execution stage makes small changes strictly according to the plan. The review stage independently verifies the result. This prevents AI from writing code before requirements are clear and from casually expanding scope during execution.

    The second principle is “documentation first.” Every mode must have clear outputs: research notes, option comparisons, task plans, change notes, and review conclusions. Documentation is not formalism; it is the entry ticket for the next stage. Without research notes, planning lacks a factual basis. Without planning, execution easily goes out of bounds. Without a review checklist, merging lacks a quality gate.

    The third principle is “small closed loops.” Each round solves one verifiable problem, and each commit contains a change with a single responsibility. If execution deviates from the plan, the workflow returns to planning mode instead of forcing the code forward. Combined with continuous integration, test baselines, and rollback strategies, this keeps multi-turn AI collaboration controllable.

    3. A Five-Stage Patterned Workflow

    3.1 Research Mode: Establish Facts and Constraints

    The purpose of research mode is not to write code but to establish a factual basis. Allowed operations include reading code, documentation, tests, logs, and configuration, and producing a module map, problem definition, impact scope, technical constraints, unknowns, and a risk list. Modifying business code, adding dependencies, making final technology choices, or directly giving an implementation are forbidden.

    Exit conditions should be explicit: Is the problem clearly defined? Are the relevant modules located? Are existing constraints fully listed? Are unknowns verifiable? When research mode is done well, later planning will not be built on guesswork.

    3.2 Innovation Mode: Propose Alternatives and Weigh Trade-offs

    Innovation mode is for option divergence. Allowed operations include drawing flowcharts, writing interface drafts, listing pseudocode, and comparing two or three alternatives. Direct implementation or large-scale file changes are forbidden. Outputs should include a recommended option, trade-off rationale, risks, rollback approach, and impact scope.

    This stage must prevent AI from “starting to write as soon as it thinks of one option.” Alternatives do not need to be numerous, but they must be comparable: change scope, compatibility, testing cost, maintainability, and release risk should all enter the decision table.

    3.3 Planning Mode: Break the Option into an Executable Plan

    Planning mode is responsible for breaking the recommended option into tasks, a file list, interface contracts, a test plan, and commit granularity. Writing planning documents, listing files to be changed, and defining acceptance criteria are allowed. Modifying business code is forbidden. The exit condition is that the plan is executable: every task has inputs and outputs, dependencies, verification methods, and rollback points.

    The clearer the plan, the less execution drifts. In particular, the plan should state “what will not be done in this change,” using boundary constraints to prevent AI from refactoring unrelated modules during execution.

    3.4 Execution Mode: Make Small Changes Strictly According to the Plan

    Only execution mode allows code changes, and they must be strictly limited to the planned scope. Allowed operations include modifying specified files, adding tests, and updating necessary documentation. Expanding requirements, changing architectural direction, and introducing unapproved dependencies are forbidden. Each commit should keep a single responsibility and output change notes, test results, and review points.

    If the plan proves invalid during execution, coding should stop and the workflow should return to planning mode rather than changing the goal while writing. Small commits and rollback-friendly design are key to controlling multi-turn coding decay.

    3.5 Review Mode: Independent Verification Forms a Closed Loop

    Review mode independently checks correctness, consistency, security, performance, and maintainability. Comments, suggestions, and additional tests are allowed. Large-scale direct rewrites are forbidden. Review conclusions should be classified as pass, block, or rework, and should record issue density and risk items.

    Review is not a final checkbox; it is a quality gate. Without a review closed loop, the earlier modes are easily bypassed as formalities.

    4. Example Rule File and Mode-Switch Instructions

    A rule file should preferably use a declarative structure that clearly states each mode’s purpose, allowed operations, forbidden operations, outputs, and exit conditions. The following is an illustrative configuration, not a real API:

    1. Mode: Research
    2. Purpose: Establish facts, constraints, and a risk list
    3. Allowed actions: Read code/docs/tests/logs; output research notes
    4. Forbidden actions: Modify business code; add dependencies; make final technology choices
    5. Output: Problem definition, affected modules, constraints, unknowns, risk list
    6. Exit criteria: Facts are sufficient and unknowns are verifiable
    7. Mode: Innovation
    8. Purpose: Propose alternatives and weigh trade-offs
    9. Allowed actions: Option comparison, interface drafts, pseudocode
    10. Forbidden actions: Implement solutions; make large-scale file changes
    11. Output: Recommended option, trade-off rationale, risks, and rollback approach
    12. Mode: Planning
    13. Purpose: Break down tasks and acceptance criteria
    14. Allowed actions: Write plans, list files, define test plans
    15. Forbidden actions: Modify business code
    16. Output: Task list, interface contracts, commit granularity, rollback points
    17. Mode: Execution
    18. Purpose: Implement in small steps according to the plan
    19. Allowed actions: Modify planned files, add tests, update necessary documentation
    20. Forbidden actions: Expand requirements, change architecture, introduce unapproved dependencies
    21. Output: Change notes, test results, review points
    22. Mode: Review
    23. Purpose: Independently verify and form a conclusion
    24. Allowed actions: Comment, suggest, add tests
    25. Forbidden actions: Large-scale direct rewrites
    26. Output: Pass/block/rework conclusion and issue list

    Mode-switch instructions can be designed as explicit phrases, such as “Enter research mode,” “Enter innovation mode,” “Enter planning mode,” “Enter execution mode,” and “Enter review mode.” On each switch, require the AI to first restate the current goal, allowed operations, and exit conditions. At the end, require it to output this stage’s deliverables and a recommendation for the next stage. The rules should also include project-level knowledge: directory responsibilities, naming conventions, dependency direction, error handling, logging standards, and testing requirements.

    5. Team Adoption and Measurement

    When adopting the workflow, first establish a baseline: architecture description, module map, test baseline, coding standards, and review checklist. Each task round starts with research and then proceeds through innovation, planning, execution, and review. Execution must not begin before prerequisite stages are complete, and merging must not happen without a passed review. For example, on Baidu AI Cloud, generic capabilities such as code hosting, CI pipelines, artifact repositories, log services, and monitoring and alerting can bring mode-switch records, review conclusions, and test results into gates and observability systems.

    For measurement, focus on rework rate, average change size, review issue density, rollback rate, test pass rate, documentation coverage, and requirement-to-merge cycle time. Common pitfalls include turning rules into slogans, making mode switches formalistic, keeping reviews non-independent, and failing to maintain documentation. The real goal is to let AI contribute coding efficiency within a controlled process, not to let multi-turn dialogue accumulate complexity without limit. Only by codifying engineering experience into rules and gates can coding agents evolve from “machines that can only write code” into collaborative, reviewable, and maintainable engineering assistants.