Ler original em português

← All contents

dooopSoftware · Process · 10 min

How to Reduce Rework in AI-Generated Code

Classify failures as requirement, context, or verification before correcting AI code and reduce recurrence with smaller changes.

Published on September 6, 2026

MAIN THESIS

AI accelerates generation but also increases misclassified errors.

The solution is to trace the cause before requesting another response.

When an AI-generated change returns to the queue, asking the model for another response may only swap the symptom. The team reduces rework when it classifies the likely origin of the failure: requirement, context, or verification. Diagnosis comes before correction: the artificial intelligence implemented the wrong thing, decided with insufficient information, or passed through a process unable to block the failure.

Why AI-Generated Code Rework Needs Classification

When an AI-assisted change returns from review, the most common reaction is to treat everything as a code problem. Adjust a function, change a condition, swap a test, request another generation. Sometimes it works. But when the error reappears, the team realizes they corrected the symptom.

The annoyance is not only in the time spent. It is in the opacity of learning. If no one knows why the failure happened, all rework becomes a generic conversation about "the AI made a mistake," "the review was insufficient," or "the prompt was bad." These statements may be true but rarely guide the next decision.

The useful separation is simpler:

  • requirement error: the task allowed different interpretations;
  • context error: the task was reasonable, but the agent lacked sufficient information to decide well;
  • verification error: requirement and context existed, but the failure passed through review, tests, or integration.

This classification defines where the team should invest the next correction. Rewriting the demand is a different action from updating the context. Creating an objective verification is different from reviewing style or asking for more care.

This point also avoids a leadership trap: buying speed in generation and paying interest in integration. DORA recommends small, independent, and testable work units to get earlier feedback on changes and hypotheses. The same guidance warns about the difficulty of reviewing and integrating large AI-generated changes. To reduce rework, size and traceability matter.

Requirement Error: When AI Implements the Wrong Thing Well

A requirement error occurs when the code is a plausible answer to a poorly defined question. The AI did not necessarily "hallucinate." It chose a possible interpretation, but different from the team's intention.

Common signs:

  • the task described the general intention but not the expected behavior;
  • the business rule had undocumented exceptions;
  • the acceptance criterion was subjective, such as "improve," "correct," or "adjust";
  • product and engineering had different expectations about the same change;
  • the review only discovered the problem when simulating a case not in the task.

Fictional example: a team asks an agent to "correct the promotional discount." The agent changes the calculation for all customers with an active coupon. The change compiles and some tests pass. In review, someone realizes the promotion applied only to a specific segment during a limited campaign and should not override an existing loyalty rule.

In this case, asking the agent to "correct better" probably generates another guess. The main cause is requirement. Before changing the code, the task should specify segment, period, priority among rules, input and output examples, and acceptance condition.

A good practical test is this: if a human reviewer cannot write an acceptance criterion before the correction, the problem starts in the requirement. The code may be wrong, but the first intervention should be in the demand.

Context Error: When Information Is Missing to Decide the Change

Context is not dumping documentation into the model. It is selecting what the model needs to consider to infer correctly. Anthropic defines context engineering as selecting and maintaining the information available to the model during inference, including instructions, tools, external data, and history, within a limited window.

In software development, this changes the question. It is not enough to ask if the task was clear. It is necessary to ask if the agent had access to what made that solution correct in that repository.

Signs of context error:

  • the agent changes the wrong application layer;
  • replicates an old pattern the team already abandoned;
  • ignores an architectural decision recorded elsewhere;
  • creates a solution incompatible with nearby dependencies;
  • modifies files outside the scope because it did not receive clear boundaries;
  • solves the local case but breaks a convention used in the rest of the system.

Imagine, in another fictional example, a logistics application where deadline validations must be in a specific service. The agent receives a clear task: prevent scheduling on unavailable days. Without knowing the repository convention, it adds the rule directly in the controller. The visible behavior seems correct, but the solution violates the architecture and complicates maintenance.

The main cause is not requirement. A person could write the acceptance criterion. The problem is that the agent did not have the right set of information to decide where and how to change.

The corresponding action is to update the context provided to the agent: relevant conventions, architectural decisions, probable files, scope limits, and necessary internal examples. This does not require extensive documentation by default. It requires curation. More context does not always improve the decision; wrong or outdated context can worsen it.

This diagnosis also changes the conversation about AI use. Instead of only asking "does the team use AI?" it makes more sense to ask if it can select, maintain, and review the context that accompanies critical tasks. The number of tools says little if the process does not transform recurring errors into verifiable adjustments.

Verification Error: When the Process Fails to Block the Failure

There are cases where requirement and context were sufficient, but the bad change passed. The main cause then is verification.

Verification includes automated tests, automated builds, human review with criteria, executable acceptance criteria, and frequent integration. DORA describes continuous integration as frequent integration into the main code, accompanied by automated build and tests. It also advises prioritizing fixing a broken build over new changes.

This does not turn continuous integration into quality assurance. A poorly designed test may confirm the happy path and ignore the important case. A review may focus on style and let a behavior change pass. A build may pass because there is no check for the affected rule.

Signs of verification error:

  • the bug only appears in exploratory manual review;
  • there was no test for the relevant exception;
  • the review approved because the diff seemed small;
  • the build passed but did not exercise the changed behavior;
  • the acceptance criterion was not converted into an objective check;
  • the same failure reappears after a previous correction.

GitHub's documentation on Copilot agents describes features with distinct environments and permissions and emphasizes human supervision and output review. For this article, the practical implication is direct: human review should not be a final stamp. It needs criteria, evidence, and authority to stop the change.

If the failure passed, the next correction must produce evidence. It can be a new test, a build check, a reproducible acceptance scenario, or a more objective scope restriction. The point is to avoid the team accepting a change just because it "now seems right."

How to Decide the Main Cause Before Correcting the Code

In real changes, there are almost always secondary causes. An ambiguous requirement may come with incomplete context. A weak verification may hide a poorly written demand. Still, the team needs to choose a main cause to act on.

An operational rule helps:

  • if a person cannot write a test or acceptance criterion before correction, start with requirement;
  • if they can write the test but the agent lacked information to reach the right solution, start with context;
  • if the agent had sufficient requirement and context but the failure passed, start with verification;
  • if the change mixed correction, refactoring, and behavior change, classify as inconclusive until the work is divided;
  • if the failure reappeared, investigate the process point that continued allowing the error.

These criteria should be used before correction, not after. Once someone fixes manually, the conversation tends to shift to the solution found. The team loses the chance to observe what was missing in the work system.

A simple record suffices:

  • main cause marked: requirement, context, verification, or inconclusive;
  • evidence used for the decision;
  • adjustment made in requirement, context, or verification;
  • criterion to recognize if the same type of error returned.

This discipline avoids two distortions. The first is always blaming the model. The second is turning every error into documentation debt. Sometimes the task was clear and the context adequate, but an objective check was missing. Sometimes the tests were good, but the agent never received the relevant architectural decision.

How to Reduce Rework Size with Smaller Changes

Rework grows when the change is too large to be understood, reviewed, and safely reverted. This applies to human code and AI-generated code but becomes more visible when an agent produces many files quickly.

DORA's small batch guidance offers an applicable criterion: small, independent, and testable work units help review hypotheses earlier. In an AI-assisted task, this can be translated into four limits:

  • one verifiable hypothesis per task;
  • expected files or probable areas of change;
  • expected behavior described before generation;
  • stopping condition to avoid mixing correction with refactoring.

If the task asks to "fix the checkout flow," the review becomes archaeology. If it asks to "prevent an expired coupon from being applied in the final calculation without changing the shipping rule," the team can better classify any failure.

The small unit preserves decision capacity. The smaller the change, the easier it is to say if the problem was in requirement, context, or verification.

What to Record After an AI-Generated or Reviewed Correction

The record after correction should be short enough to survive routine and precise enough to generate learning.

A good record answers:

  • what was the intended change;
  • what failure was observed;
  • what main cause was marked;
  • what evidence supported this marking;
  • what adjustment was made in requirement, context, or verification;
  • what signal will indicate repetition of the same problem.

If the cause was requirement, the record should improve the way of requesting. If it was context, it should update the set of information accompanying similar tasks. If it was verification, it should strengthen the check before accepting a new change.

This is the difference between rework as invisible cost and rework as operational data. The team reduces recurrence when it learns where the process allowed the failure.

Operational rule: when an AI-assisted change returns to the queue, mark the main cause as requirement, context, or verification before correcting the code.

If you want to discuss this decision in your company's context, talk to dooop.

Further Reading

Sources

NEXT DECISION

Discuss Application in Your Company

Conversation about your software company’s context

Content from dooop. Registration allows linking this topic to the reader’s journey and tracking interest in the subject.

Conversation about your software company’s context

We will use your details to deliver this content and contact you about related topics.