Join our Newsletter — 33% off our NHI Course

What happens when a coding agent tries to merge code that was not the revision it reviewed?

The merge should fail rather than silently proceed. By sending the reviewed head commit SHA in the merge request, GitHub can detect that the pull request has moved on and return a 409 Conflict. That forces the agent or reviewer to recheck the current code and obtain any required approvals before retrying.

Why a Review-and-Merge Check Exists

A coding agent should not be able to merge code against an outdated review state. The safeguard is simple: the merge request includes the reviewed head commit SHA, so the platform can compare what was reviewed with what is actually being merged. If the branch has advanced, the system stops the merge instead of assuming the review still applies.

That behaviour protects the review boundary. A human or agent may have approved a specific revision, but new commits can introduce new defects, change the risk profile, or alter the implementation in ways that require fresh scrutiny. The merge gate turns that mismatch into an explicit failure, not a silent drift.

For teams using AI coding agents, the control matters because the agent can move quickly and can also continue acting after the code has changed. A failed merge is the correct outcome because it forces revalidation of the current branch state before any code lands in the protected target branch.

What a 409 Conflict Is Telling You

A 409 Conflict in this context means the repository state no longer matches the state that was reviewed and approved. It is not a generic API error, it is a concurrency and integrity signal: the request is valid in form, but the underlying object has changed since the review decision was made.

That makes the error operationally useful. It tells the agent, reviewer, or automation that the task is no longer a simple retry. The branch must be rechecked, and any required approvals must be reobtained against the current revision before another merge attempt.

This also preserves traceability. The merge attempt can be tied to a specific commit SHA, which helps teams prove that the approval matched the exact code state that was reviewed. For workflow reliability, that is better than relying on timestamps, comments, or informal “looks good” signals.

Why This Matters for Agentic Code Changes

Agent-driven development increases the chance of stale assumptions because code, tests, and approvals can change in rapid succession. A merge guard based on the reviewed head commit is a practical way to stop an agent from using an obsolete approval to push forward on a different revision.

That is especially important when the review was narrow or time-sensitive. Even small changes can affect build behaviour, security checks, dependency resolution, or deployment impact. The failure forces a fresh decision at the point where the code actually exists, rather than at the point where it was first inspected.

In practice, this is part of keeping automation bounded by current state. The agent can still draft, test, and propose changes, but it should not be able to convert an approval for one revision into permission to merge a later one without revalidation.

Risk and Threat Considerations

Without this check, an agent or workflow can slip past review boundaries and merge code that was never approved in its final form. The main risk is stale approval, where the reviewed revision and the merged revision diverge enough to bypass the intended control point.

Failure mechanism: The merge process accepts a branch that has advanced since review, so the approval is applied to the wrong commit or to an altered code path. That can let unreviewed changes, hidden regressions, or policy-relevant edits reach the target branch.

Impact: Teams lose assurance that the merged code matches what was reviewed, which weakens change control, auditability, and the security value of approvals. In agentic workflows, it also creates a path for rapid, repeated retries against an outdated decision.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-53 Rev 5, NIST CSF 2.0 and OWASP ASVS set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

Framework Control / Reference Relevance
NIST SP 800-53 Rev 5 CM-3 — Configuration Change Control Controls merge state changes so only approved revisions are promoted.
AC-3 — Access Enforcement Enforces whether a merge action may proceed based on current authorization state.
Recommendation — Require approval of each code-state change before merging. Block merges when the reviewed revision is no longer current.
NIST CSF 2.0 PR.AA-05 — Authorization Applies because the merge decision depends on enforcing current access and approval conditions.
Recommendation — Enforce approval-bound authorization against the current commit.
ISO/IEC 27001:2022 A.8.32 — Change management Merge gating is a change-control safeguard for software revisions.
Recommendation — Require current-review validation before promoting code changes.
OWASP ASVS V15 — Secure Coding and Architecture Repository merge controls support safe code promotion and integrity of reviewed changes.
Recommendation — Make code promotion fail when the reviewed revision changes.

Practitioner Guidance

What to verify: Ensure the merge request ties approval to an exact commit SHA or equivalent immutable revision marker, and confirm the platform rejects merges when the branch head has moved.

Decision rule: If the merge fails with a state mismatch, treat that as a required re-review, not a transient build glitch. Re-run checks, confirm the diff against the current head, and obtain any approvals again before retrying.

What good looks like: The agent can merge only when the reviewed revision is still the current revision, and any later change automatically forces a fresh review cycle.

Practitioner takeaway: The control is valuable because it makes review state explicit and machine-enforced, which is exactly what you want when automation can change code faster than humans can re-approve it.