AI Coding Keeps Causing Rework? Stabilize Complex Development with a Four-Stage Workflow

    This article explains why AI coding tools tend to produce rework on complex features and how to control it with a four-stage workflow: research, planning, implementation, and validation. It covers practical context management, how to turn requirements into verifiable acceptance criteria, how to keep each change small and reviewable, and how to prove completion with evidence rather than letting the tool declare success. You will find prompt templates, artifact structures, and a closing checklist you can apply directly.

    1. Why Complex Features Get Messier With Every Change

    When you use AI coding tools for simple features, you usually just describe the requirement, provide the relevant code, and review the generated result. Complex features are different: they span multiple modules, data consistency, permission rules, and error handling. If you still rely on “state the requirement and generate all the code at once,” the probability of rework rises sharply.

    Take an order-cancellation feature as an example. It looks like adding a single entry point, but in practice it may involve order-state checks, inventory release, payment handling, duplicate-request control, and operation auditing. If even one of these rules is left undefined, the generated code may run yet still fail to meet the business requirement.

    The common causes of rework fall into four categories:

    1. The requirement never becomes a verifiable constraint. “Support order cancellation” says nothing about which states can be canceled or what side effects cancellation triggers.
    2. The context contains conflicting information. Old designs, deprecated interfaces, and new requirements are mixed together, so the tool cannot tell which one is authoritative.
    3. The scope of the change has no boundary. A task that should only touch one business flow ends up refactoring shared modules, increasing review and regression costs.
    4. Validation happens only at the end. You discover an architectural misunderstanding only after a large amount of code is written, when the cost of correction is already high.

    So the core of a mature workflow is not making the tool write more in a single pass. It is making every input clearer, every change smaller, and every conclusion backed by evidence.

    2. Context Management: More Information Does Not Mean Better Results

    2.1 The Context Window Is Not the Same as Effective Working Space

    When an AI coding tool handles a task, it may simultaneously receive base instructions, project conventions, tool descriptions, conversation history, file contents, and execution results. All of this consumes context space.

    But “it fits” does not mean “it all belongs there.” Large volumes of repetitive logs, irrelevant files, and outdated discussions can drown out the key constraints. Even before you hit the capacity limit, you can still see missed requirements, mixed-up old designs, or repeated exploration.

    The common rule of thumb from experience—“stop once usage reaches a certain percentage”—is only a personal habit, not a universal technical red line. Behavior varies across models, tools, task types, and how information is organized, and you cannot assume that staying under some ratio guarantees reliability.

    A more reliable approach is:

    • If the tool exposes context-usage information, check it periodically;
    • Reserve space for upcoming file reads, execution results, and fixes;
    • As soon as you see signs of repeated reasoning, forgotten constraints, or version confusion, actively tidy up the context;
    • Filter logs, search results, and large files first, then supply only the necessary fragments.

    The context budget should serve the task, not chase a fixed number.

    2.2 Split Information Into Three Layers

    To reduce noise, you can divide the context into three layers:

    Layer Typical Content How to Manage
    Stable constraints Coding standards, architectural boundaries, security requirements Keep brief, avoid repetition
    Current task Requirements, acceptance criteria, relevant files, implementation plan Organize separately for each task
    Temporary material Debug logs, exploration, failed attempts Extract conclusions, then move out of the working context

    Stable constraints should not become a project encyclopedia. They only need to answer: which rules must not be violated, where the key entry points are, and how to check results.

    Current-task material, by contrast, must be specific. For example, “do not change the existing interface response structure” is far more binding than “be careful about compatibility.”

    2.3 Complete the Handoff Before Clearing the Session

    When switching stages, you can start a new session or use the tool’s context-consolidation features, but do not treat “clearing” as the only goal. Clearing without a handoff forces the next stage to re-investigate problems that were already solved.

    An effective handoff record should include:

    • The current task and its boundaries;
    • Confirmed facts and their evidence;
    • Decisions already made and the reasons behind them;
    • Unresolved questions;
    • Relevant files and location information;
    • The actions the next stage needs to perform.

    The key principle: you can discard the exploration process, but you must not discard facts, decisions, and acceptance criteria.

    3. Build a Four-Stage Workflow and Its Artifacts

    A common recommendation is to split complex development into four stages: research, planning, implementation, and validation. The stages are not strictly one-directional; if validation reveals a misunderstanding of the requirement, you should go back to research or planning rather than piling on more patches.

    You can create a plain documentation directory in the project:

    1. docs/
    2. tasks/
    3. order-cancel/
    4. research.md
    5. plan.md
    6. implementation.md
    7. validation.md
    8. handoff.md

    This directory and these files are just an example of how to organize documentation; they do not mean the tool will automatically recognize or execute them. When you use them, explicitly tell the tool which files to read, what task to complete, and where to record the results.

    The basic relationship among the four stages is:

    1. Research the current state → Confirm the plan → Implement step by step → Validate the result
    2. ↑ ↑ │
    3. └────────────────────┴──── Roll back when a problem is found ──┘

    Each stage should have entry conditions, clear artifacts, and exit criteria.

    4. Research Stage: Establish the Facts Before Deciding What to Change

    4.1 What to Research

    The goal of the research stage is to answer “how does the existing system work,” not to generate code immediately.

    Using order cancellation as the example, you need to confirm at least:

    • Where order states are defined;
    • Which state-transition entry points currently exist;
    • How authentication and resource-ownership checks are implemented;
    • Whether a shared capability for inventory release already exists;
    • How payment-related flows handle cancellation and refunds;
    • Which tests cover the relevant behavior;
    • Whether asynchronous tasks, retries, and compensation mechanisms exist.

    The research scope should converge around the requirement; there is no need to read the entire codebase in the name of “full understanding.”

    4.2 You Can Split the Work, but You Must Consolidate It

    If the environment supports parallel tasks, you can break research into independent directions such as business flow, data model, interface permissions, and test risk. But parallelism is not mandatory; completing the work serially is equally valid.

    Parallel research has two pitfalls: multiple tasks may read the same batch of files repeatedly, and different tasks may reach different conclusions about the same fact. So define each task’s boundary first, then handle conflicts in a unified consolidation step.

    Conclusions in the research document should be distinguished as:

    • Confirmed facts: backed by actual code, configuration, or tests;
    • Reasonable inferences: deduced from the current implementation but not yet verified;
    • Open questions: decisions that the business side or developers must make.

    4.3 Use Verifiable Code References

    Important conclusions should include the file path, symbol name, and, where useful, line numbers. For example:

    1. Conclusion: The cancellation entry currently only handles orders awaiting payment.
    2. Evidence: src/orders/cancel_service.ext:42-68
    3. Symbol: cancel_order
    4. Nature: Confirmed fact

    The above is only a reference-format example; a real report must come from code you have actually read. Line numbers shift as code changes, so it is best to also keep the function, class, or field name. Never ask the tool to guess paths or fabricate locations just to fill out the report.

    4.4 Research Stage Prompt Template

    1. Goal: Research the order-cancellation flow. Do not modify code yet.
    2. Requirements:
    3. 1. Read only the files necessary for order state, permissions, inventory, and payment.
    4. 2. Describe the existing call chain, state transitions, and side effects.
    5. 3. Attach actual file paths, symbol names, and available line numbers to important conclusions.
    6. 4. Distinguish facts, inferences, and open questions.
    7. 5. When uncertain, say so explicitly; do not invent business rules.
    8. Output:
    9. A summary of the current state, an evidence list, a risk list, and open questions.

    The exit criterion is: the key flows are understood, the questions that affect the choice of approach are answered, or they are explicitly marked as blockers.

    5. Planning Stage: Turn Requirements Into Executable, Verifiable Steps

    5.1 Write the Acceptance Criteria First

    An implementation plan cannot just list “modify the interface, add tests.” First it must define what “done” means.

    Acceptance criteria for order cancellation might include:

    • Only order states that satisfy the business rules can be canceled;
    • A user can only cancel orders they are authorized to operate on;
    • For requests that allow retries, repeated calls do not release inventory twice;
    • States that do not allow cancellation return an agreed error;
    • The state after cancellation and its related side effects stay consistent;
    • Existing query and payment flows are unaffected.

    Among these, duplicate requests, asynchronous processing, and refund strategy should be decided by business rules; do not assume every system uses the same approach.

    5.2 Define the Scope of Change and the Non-Goals

    The plan should list the modules expected to change, their dependencies, data changes, and test scope, and it should also state clearly what this task will not do.

    For example:

    1. Goal of this task:
    2. Add cancellation-condition checks and duplicate-request protection.
    3. Non-goals:
    4. Do not change the order-state enum;
    5. Do not refactor the shared payment module;
    6. Do not change the existing query response structure.

    Non-goals effectively curb “optimizations along the way.” If implementation reveals that a boundary must be crossed, pause and update the plan rather than silently expanding the scope.

    5.3 Break It Into Small Steps That Can Be Checked Independently

    A reasonable order is usually:

    1. Fill in the rule definitions and related tests;
    2. Implement the core state checks;
    3. Handle side effects such as inventory;
    4. Wire up the interface and error mapping;
    5. Run regression and review the diff.

    When database schema changes are involved, you also need to discuss data migration, backward compatibility with old data, deployment order, and rollback limits. Do not assume that “rolling back the code” can undo a data change.

    Before the planning stage ends, the developer should confirm the key decisions. The tool can propose options, but it cannot decide undefined rules on behalf of the business owner.

    6. Implementation Stage: Follow the Plan and Limit the Scope of Each Change

    During implementation, give one clear subtask per round, along with the research conclusions, plan fragments, and acceptance criteria that subtask needs.

    You can use the following prompt structure:

    1. Based on the confirmed plan, complete step 2: core state checks.
    2. Allowed to modify:
    3. The order business service and its corresponding tests.
    4. Constraints:
    5. Do not change the interface response structure;
    6. Do not touch unrelated modules;
    7. Report first if you find dependencies outside the plan.
    8. When done, describe:
    9. Files modified, behavior changes, checks performed, and unresolved issues.

    After each logical unit is complete, run a check, so you avoid stacking multiple unknowns until the end.

    The implementation record should at least state:

    • What was actually modified;
    • Whether it deviated from the original plan;
    • Which checks were performed;
    • Which checks were not performed and why;
    • What risks remain.

    The developer should also review the actual diff, not just read the summary the tool provides. Pay particular attention to permission checks, exception branches, database queries, and changes to shared interfaces.

    When secrets, credentials, production configuration, or sensitive business data are involved, redact them first and follow the team’s data-usage rules. Execution suggestions from the tool should also be reviewed; never follow them blindly when they involve deleting data, changing permissions, or operating on production.

    7. Validation Stage: Prove Completion With Evidence, Not With the Tool’s Declaration

    7.1 Layered Checks

    Validation should cover risks at different levels:

    • Static checks: syntax, types, unused code, and style issues;
    • Unit tests: state decisions, boundary conditions, error branches;
    • Integration tests: how business modules cooperate with the database and message handling;
    • End-to-end checks: from the request entry point to the final business result;
    • Manual review: missing permission checks, breaking changes, and unreasonable complexity.

    The tool can help generate tests, but the tests themselves need review. If both the implementation and the tests are based on the same wrong assumption, everything passing still does not prove the requirement is correct.

    7.2 Beyond the Happy Path, Focus on Errors and Concurrency

    The risks of complex features often concentrate in edge cases. Order cancellation should at least consider:

    • Duplicate request submissions;
    • Attempts by users without permission;
    • Payment and cancellation happening at the same time;
    • A side effect failing midway;
    • The order state already changed by another flow;
    • Old data not satisfying the new validation conditions.

    If you use transactions, conditional updates, or compensation mechanisms, check whether they actually cover race conditions. Merely reading the state and then updating it in application code does not, by itself, guarantee concurrency safety.

    7.3 A Validation Report Must Not Write “Suggested to Run” as “Already Passed”

    The validation report should record, item by item, the acceptance criteria, the method used, the actual result, and the supporting evidence. Tests that were not run must be explicitly marked “not executed”; do not substitute “expected to pass.”

    1. Acceptance item: Repeated requests do not release inventory twice
    2. Verification method: Integration test and data-state check
    3. Actual result: Pass / Fail / Not executed
    4. Evidence: Location of the test record or execution output
    5. Remaining risk: Uncovered concurrency or environment conditions

    If the current environment lacks dependencies and only a code review was completed, the conclusion should be “implementation is complete, validation is incomplete,” not “the feature is complete.”

    8. Adjust the Process to the Task Size, Do Not Mechanically Add Steps

    The four-stage workflow does not mean every small change requires several long documents. For a fix with a clear scope and low risk, you can include all four parts—research, planning, implementation, and validation—in a single brief task record.

    But in the following situations, it is advisable to keep separate stage artifacts and set up human confirmation points:

    • The change spans multiple business modules;
    • It involves permissions, money, or sensitive data;
    • It includes a database migration;
    • It changes a shared interface;
    • It involves asynchronous, retry, or concurrency-consistency issues.

    Teams can also continuously record the causes of rework, missed acceptance items, and out-of-plan changes, rather than only counting lines of generated code. If rework concentrates on misunderstood requirements, strengthen research and acceptance criteria; if it concentrates on integration failures, improve the test environment and dependency checks.

    9. A Ready-to-Use Closed-Loop Checklist

    Before starting a task:

    • Does the requirement have clear boundaries?
    • Have you written verifiable acceptance criteria?
    • Have you provided only the relevant context?

    After research:

    • Are the key conclusions backed by code evidence?
    • Are facts, inferences, and questions kept separate?
    • Have the blocking questions been resolved?

    After planning:

    • Can each step be checked independently?
    • Are the non-goals and the scope of change clear?
    • Have compatibility, migration, and rollback risks been discussed?

    During implementation:

    • Are you modifying according to the confirmed plan?
    • Have you reviewed the actual code diff?
    • Have out-of-plan changes been reconfirmed?

    After validation:

    • Have the acceptance criteria been checked item by item?
    • Are error, permission, and concurrency scenarios covered?
    • Are unexecuted checks and remaining risks recorded truthfully?

    The reliability of AI coding does not come from stuffing in more files at once, nor from repeatedly appending “check again” instructions. What actually works is carrying a clear task with a lean context, preserving evidence and decisions in stage documents, controlling risk with small changes, and finally closing the loop with real validation. Only then does the tool become a controlled development collaborator, rather than another source of uncertainty that keeps driving rework.