New: Auto Approval Workflows and Agent Session Review

See what shipped →

How to prevent agents from approving unreviewed code

Coding agents can keep editing while tests run, reviews finish, and other agents pick up the next task. That creates an awkward situation: a review can be correct about code that’s already changed by the time someone acts on it.

An approval needs to answer a specific question: which version did we actually check? As we give agents more responsibility across the software development lifecycle, the connection between evidence and action needs to survive those overlapping steps.

Qodo’s review and approval architecture binds evidence to the change it describes. That’s a useful foundation for an agentic workflow: an approval belongs to a revision, and the system needs to check that identity again when it’s about to act.

Bind the review to the code it checked

Picture an agent fixing a timeout in a database client. Revision A adjusts how long the client waits. A review finishes, and its findings meet the team’s approval policy.

While that review runs, the agent pushes revision B, adding retries. Retrying a write can change application behavior, so the earlier review’s conclusions need to be reconsidered against that change. This is an illustrative example of the timing problem.

Both revisions belong to the same pull request. They might share a title, ticket, and conversation. Those familiar identifiers make it easy to treat the review as covering the current work. The commit identifies the particular code the reviewer examined.

Even that needs context: a diff compares two revisions. If the comparison base changes, the evidence may describe a different change from the one we’re about to accept.

Carry evidence through every handoff

There’s a name for this in systems engineering: time of check to time of use, or TOCTOU. You check a condition, something changes, and you act using the earlier result.

In our client example, the condition was that revision A met the configured approval criteria. By the time the approval operation runs, the pull request points to B. The review may have done its job perfectly. The workflow has lost track of what that review covered.

An agent loop makes the handoff worth examining because editing, evaluation, and tool calls can overlap. A status such as “review complete” needs enough information for the next process to establish which code and evidence it can use.

That includes a completed assessment and its run identity. A newer assessment can change the decision even when the code’s unchanged.

A sequence shows an agent pushing revision A, a reviewer assessing A, the agent pushing B, and an execution check comparing current B with reviewed A. The mismatch leads to reassessment or human review.
The timeout and retry changes are illustrative. A review of revision A needs fresh evidence when the pull request advances to B before the action check.

Enforce approval conditions in code

A model can analyze whether the retry introduces duplicate writes. Deterministic code can compare revision identifiers, require complete evidence, and enforce the configured action policy.

That separation connects to Anthropic’s work on containing agents, which describes enforcing boundaries on the actions an agent can take through its environment. For a review workflow, the action boundary includes whether the available evidence still qualifies an approval.

Qodo’s risk gate checks the current head and comparison base against the assessment’s snapshot. It requires the latest risk run, a completed assessment, compatible schema, prompt, scoring and context versions, and verified external context where applicable. The risk level must also satisfy the configured ceiling.

The approval path can fetch the current pull request head directly from the Git provider and compare it with the reviewed revision. Missing or mismatched evidence withholds eligibility. Passing the risk check still leaves the ordinary review and approval requirements to satisfy.

Reviewed head and base, the latest completed assessment, and compatible versions and context supply the eligibility check. Qualifying evidence proceeds through other review requirements to an approval vote. No or unknown evidence withholds approval. A separate human-owned merge retains required checks and repository protections.
Evidence must be current, complete and eligible before an approval vote. Other review requirements, human merge ownership and repository protections remain part of the workflow.

Test changes between decision and execution

Qodo’s regression cases capture this boundary by starting with an eligible risk-based decision, then changing the evidence before execution. That lets the checks exercise the handoff directly.

The unchanged case invokes the action executor. Six variations with a changed head, comparison base, risk level, assessment identity, or stale revision snapshot leave that executor uncalled. That’s the behavior our timeout example needs when A becomes B: the earlier decision can’t authorize the changed work.

A separate six-case test checks the provider’s current head. Only the exact expected revision passes, including rejection of missing, malformed, and different values. Controlled provider responses make those cases repeatable and let the test target each authorization condition.

Treat the final provider read and the approval operation as separate steps in the design. A fresh read establishes what was current at that moment. Stronger guarantees depend on revision-bound provider operations where available, plus handling changes that arrive afterward.

Keep approval and merge ownership clear

Carry the reviewed revisions, assessment identity, and approval conditions into the handoff from review to action. If those conditions change, route the work toward fresh evidence or human review.

For teams using Qodo’s Reviewer skill, that reasoning starts inside the coding loop: review the local changes, let the agent address findings, and validate the resulting pushed changes in pull request review. Each edit can change what the earlier evidence supports.

An approval vote is one step in that process. Required checks, repository protections, and the human owner still govern the merge. As agents take on more work, preserving that chain gives engineers a clear answer to what was reviewed and why an action was allowed.

Get started with Qodo for AI Code Review

Start trial
Share this post

More from our blog

Check out our musings on generative AI, code integrity, and other geeky stuff: