AI Agents for Code Review, Fixes, and Tiered Approval
This article explains how to build a controlled delivery pipeline in which AI agents handle code review, constrained fixes, and approval recommendations without unlimited authority. It covers separating review, fix, and approval responsibilities; combining deterministic policy rules with model-assisted judgment; binding evidence to a specific commit; enforcing least privilege and runtime isolation; rolling out automation in phases; and measuring efficiency, quality, and governance outcomes rather than merge volume alone.
1. Faster Code Writing Does Not Mean Faster Delivery
AI-assisted programming lowers the cost of writing code, adding tests, and implementing routine features. But software delivery does not end when code generation is complete. A change usually still has to pass code review, automated tests, conflict resolution, owner confirmation, and merge checks.
When the number of changes grows quickly while review capacity stays the same, teams tend to run into three problems.
First, the review queue keeps growing. Developers wait for feedback, reviewers switch context frequently, and even a small change can be delayed for days.
Second, mechanical work crowds out professional judgment. Formatting issues, obvious null access, missing tests, and common configuration errors consume review time. More important concerns—architecture design, business semantics, and security boundaries—do not get enough attention.
Third, feedback and fixes turn into multiple round trips. Review comments must be understood, addressed, and verified again, and every new commit may introduce new issues. Without unified orchestration, more automation tools can actually increase state mismatches and unclear ownership.
The real goal of introducing agents into review, fixes, and approval is not to “let the model do more tasks.” It is to establish a delivery path that is verifiable, constrained, and traceable.
2. Split Responsibilities Across Three Agent Roles
In a general architecture, this type of system can be divided into three responsibility domains: review, fix, and approval. They may share necessary context, but they should not share unrestricted permissions.
1. Review Agent: Locate Issues and Explain the Evidence
The review agent analyzes changes, related code, test coverage, and existing engineering constraints to find issues that may affect correctness, maintainability, or security.
Useful review output should not stop at vague conclusions such as “consider optimizing.” It should include at least:
- The location of the issue and relevant context;
- Inputs or runtime conditions that may trigger the issue;
- Potential impact on users, data, or system behavior;
- The evidence behind the judgment;
- A suggested verification method or direction for a fix.
For example, if an authorization check has been moved after a data query, the agent should not simply say that “the check order is unreasonable.” It should explain whether unauthorized requests could access sensitive data earlier than expected, and whether existing tests cover that behavior.
At the same time, deterministic evidence and speculative risk should be separated. Compilation errors, failing tests, and type mismatches usually have direct evidence. Whether a business rule matches requirements may require confirmation from product or domain experts. Mixing the two increases false positives and weakens developer trust in the system.
2. Fix Agent: Generate Verifiable Patches Within Limits
The fix agent can handle issues with clear goals and verification methods, such as resolving local conflicts, correcting implementation errors behind failing tests, and applying confirmed review comments.
But “making checks pass” must not become the only goal. Deleting failing tests, weakening assertions, or skipping security checks may turn the status green without solving the real problem.
The fix process therefore needs a principle of minimal change: prefer modifying directly related code and avoid carrying out large-scale refactoring along the way; every round of modification should explain the reason, scope of impact, and verification result; and changes involving tests or check rules should explain why the original rule no longer applies instead of treating it as an obstacle by default.
When the failure comes from an environment fault, an unavailable external dependency, or unclear business requirements, the agent should stop guessing and request human intervention.
3. Approval Agent: Assess Whether Release Conditions Are Met
The approval agent’s job is to judge whether a change meets the established automatic release conditions, not to redefine risk standards.
Three actions must be distinguished here: providing an approval opinion, satisfying pre-merge checks, and actually performing a merge. They can be handled by different mechanisms, and a model’s conclusion that a change “can pass” should not directly grant the ability to modify the main branch.
Production releases also need separate release controls. A code change passing approval or being merged does not mean it already meets production deployment conditions.
3. Approval Policy Is Engineering Governance, Not a Prompt
Natural language is good for expressing business intent, but if a broad description is used directly as the basis for automatic approval, execution results may fluctuate with context.
A safer approach is to divide policy into two layers: deterministic rules constrain boundaries, while models interpret semantics and supplement evidence.
Deterministic rules can check file paths, change types, test status, required review records, and access to sensitive resources. Models can help judge whether a modification changes authorization semantics, whether it matches the requirement description, and whether there are risks that are hard to find through simple matching.
The following is an illustrative policy description, not a configuration format for any specific tool:
Default rules:Changes that do not meet explicit auto-release conditions go to human approval.Require human approval:Changes related to authentication, authorization, and secret management;Data structure migrations and data deletion logic;Approval policies, security checks, and delivery pipeline configuration;Public API behavior or compatibility changes.Eligible to request auto-release:Documentation fixes that do not affect runtime behavior;Formatting changes verified not to alter semantics;Low-risk maintenance changes that meet team-defined conditions.Common prerequisites:All required checks completed and passed;No unresolved high-risk issues;Evidence corresponds to the current commit;Cases with unconfirmed risk go to human handling.
Even “documentation fixes” should not automatically be treated as low risk. Documentation directories may contain scripts or configuration that participate in builds, and generated files may affect final artifacts. Risk classification should therefore consider file purpose, execution path, and business impact, not just file extensions.
Policy also needs a clearly assigned maintainer and should be version-controlled. Changes to approval rules themselves should receive independent review, so a change cannot gain passage by loosening the rules that govern it.
4. Use a State Machine to Orchestrate the Workflow
A reliable automation path needs explicit states and transition conditions. A general workflow can be represented as:
Prepare change → basic checks → agent review → constrained fix → revalidation → policy evaluation → human confirmation or merge conditions.
After every code update, the system must determine which evidence has become invalid. Test results, review comments, and approval conclusions from an older version cannot directly prove that a new version is safe.
At minimum, the following information should be bound to the same commit version:
- Change content and policy version;
- Automated check results;
- Review findings and how they were handled;
- Fix records;
- Approval conclusions and human confirmation records.
If code is modified after review is complete, the system should rerun the necessary checks to avoid a mismatch where “the old code was reviewed, but the new code was merged.”
Loop limits are also necessary. If repeated fixes still fail tests, if different agents keep modifying the same location, or if patch size keeps growing, the system should trigger a pause. Repeating attempts after failure does not automatically improve correctness; it may expand risk.
5. Permissions and Runtime Environment Set the Security Floor
When agents analyze code, they often need to read repositories, execute tests, or generate commits. These operations involve real permissions and cannot be constrained only by behavioral prompts.
1. Grant Least Privilege by Role
A review role usually only needs to read code and publish review comments. A fix role can submit patches on a limited branch but should not directly modify protected branches. An approval role can submit check results but should not change protection rules on its own.
Approval policies, permission configuration, and security check definitions should be treated as highly sensitive assets. The same agent should not be allowed both to modify rules and to approve its own changes based on the modified rules.
2. Treat Repository Content as Untrusted Input
Code comments, change descriptions, discussion records, and build logs may all contain text designed to induce a model to ignore rules or leak information.
The system needs to clearly distinguish trusted control instructions from material under analysis. Content such as “skip checks” appearing in a repository should not have the authority to modify workflow permissions. Telling the model “do not be influenced” is not enough. Boundaries should be established through permission limits, tool-call validation, and confirmation of sensitive operations.
3. Isolate Test and Build Execution
Test scripts are executable code themselves. When handling changes from untrusted sources, the execution environment should not receive production credentials, long-lived access tokens, or internal network permissions by default.
Safer practices include using temporary isolated environments, limiting network access, controlling resource quotas, and injecting short-lived credentials only when needed. Logs should also be processed for sensitive information to prevent debugging output from leaking secrets or business data.
6. Roll Out in Phases and Replace Confidence with Evidence
Teams should not make agent-based approval a mandatory gate from the start. A reasonable adoption path usually has three phases.
Phase 1: Observation Mode
The system generates review and approval recommendations but does not block merges. The team compares them with human judgment, recording false positives, false negatives, whether recommendations are actionable, and whether the policy is ambiguous.
This phase should cover different types of changes. Teams should not validate the system only with documentation edits and simple bug fixes, then infer that it can handle core business changes.
Phase 2: Limited Assistance Mode
Agents are allowed to generate fix patches, but humans confirm them. Approval recommendations can be used as references but do not independently determine release.
The focus is on checking whether patches preserve the original business intent, whether checks are weakened just to pass tests, and whether modification records are clear enough.
Phase 3: Low-Risk Auto-Release
Only changes that explicitly match policy, have complete evidence, and run stably enter the automatic release scope. Sensitive paths and cases that cannot be classified continue to be handled by humans.
As rules, models, or workflows change, the system’s performance should be re-evaluated. Stable behavior before launch does not mean the same risk level will remain after later upgrades.
7. Measure Outcomes Beyond Merge Count
An increase in merge count may indicate shorter waiting time, or it may simply mean changes are split more finely. Evaluating this type of system requires observing efficiency, quality, and governance cost together.
Efficiency metrics can include time to first feedback, review waiting time, human handling time, and repeated rework count. Quality metrics can include post-merge defects, hotfixes, rollback causes, and missed security issues. Governance metrics should focus on human coverage, policy maintenance cost, audit completeness, and abnormal stop count.
Rollback ratio also needs careful interpretation. Fewer rollbacks do not necessarily mean fewer defects; the result may be related to release strategy, change type, or incident handling. When comparing before and after results, teams should control for these factors as much as possible and distinguish gains from model contributions versus process changes.
For teams with small sample sizes, reviewing high-risk misses case by case is often more valuable than pursuing attractive percentages. One authorization bypass or data corruption incident can offset the time saved by many routine changes.
8. Human Roles Shift from Line-by-Line Review to Boundary Design and Accountability
The reasonable goal of this automation is to reduce mechanical labor, not to eliminate human judgment.
Developers still need to explain business intent and confirm whether fixes are correct. Maintainers need to define risk levels and approval policies. Security staff need to focus on permissions, data, and execution environments. Delivery owners need to decide which evidence is sufficient to support a release.
“Rollbackable” should also be reflected in engineering conditions. Code commits can be reverted, but data migrations, external notifications, and persistent side effects may not be easily reversed. Change records should therefore explain not only how to restore code, but also data compatibility, irreversible operations, and necessary recovery steps.
Overall, connecting review, fixes, and approval through agents has clear engineering value, but that value comes from controlled automation, not unlimited authorization. A mature approach should provide separated responsibilities, auditable policy, evidence bound to versions, least privilege, the ability to stop on failure, and human entry points for sensitive decisions. Only when these foundations are in place can faster code generation translate into more reliable delivery efficiency.
