A patch gate can go green on the wrong parent commit. Tests pass, the diff applies cleanly, and main still breaks afterwards. The gap is usually base drift: the branch moved while the patch waited in the queue.
This is an illustrative scenario, not a reported incident. It describes a plausible failure mode for teams that queue AI-generated patches. No commands or pseudocode below were executed for this draft.
The decision this scenario raises
The team must choose one of two policies when a queued patch is finally applied.
- Apply onto whatever the branch looks like now, then run tests.
- Refuse to apply unless the base commit matches the one recorded at request time.
Policy 1 can avoid a wait when automatic integration is allowed. Policy 2 blocks on any base change. Neither policy predicts how often the tests pass. The tradeoff is whether a green result means "this patch works on current main" or only "this patch worked on some earlier main."
How drift enters the gate
Drift is a timing problem, not a logic bug. The gate is correct about the tree it sees. The tree is simply not the one the reviewer approved.
- A patch is generated at time T1 against base commit
A. - Human review or a queue delay runs until T2.
- Another merge lands on the branch, producing base commit
B. - The gate applies the patch onto
Bor onto a stale checkout ofA. - Tests pass, but the recorded base SHA still says
A.
Two variants matter, because they fail differently.
Variant A: stale checkout
The gate checks out A and never fetches B. Tests pass on a tree that no longer resembles the branch. The result is green and irrelevant. This is the quieter failure, because nothing conflicts.
Variant B: silent rebase
The gate applies onto B without recording it. If the merged commits touched shared files, the patch semantics can change even when no textual conflict appears. The gate reports success for a tree the reviewer never saw.
Steps: pin the base and revalidate
The procedure below is a proposal. Prerequisites: a patch queue with a recorded request time, an immutable base SHA per request, and a gate that can run tests on an arbitrary tree.
- Record
base_sha_at_requestwhen the patch is created, not when it is applied. - Fetch the branch at apply time and read
base_sha_now. - Compare the two SHAs before applying anything.
- If equal, apply and test as normal.
- If different, block with both SHAs and the list of commits in between.
- Offer exactly one revalidation path: rebase onto
base_sha_now, then rerun the full gate. - Store the resulting candidate commit or tree as well as the base SHA with the new verdict. Before merging, verify the destination still has the tested base and the candidate is unchanged, or use a merge queue that builds and checks an updated integration candidate. Preserve earlier records. GitHub merge queues
# Illustrative pseudocode. Not executed for this draft.
gate(request):
now = branch_head(request.branch)
if now != request.base_sha_at_request:
return BLOCKED(
reason="base moved",
requested=request.base_sha_at_request,
current=now,
commits_between=log(request.base_sha_at_request, now)
)
tree = apply(request.patch, onto=now)
if tree.has_conflicts:
return BLOCKED(reason="conflict", onto=now)
result = run_tests(tree)
return VERDICT(result, base=now, candidate=tree.object_id, patch_hash=hash(request.patch))
Expected observation
After step 5, a blocked patch should show two distinct SHAs. For a normal fast-forward, list intervening commits; for rewritten history, show divergence. After step 7, the green verdict should carry the SHA of the tree that was actually tested. If the verdict carries only a branch name, the gate is still unverifiable.
What the gate artifact must contain
A verdict is only auditable if it names its inputs. Capture these fields together with the exact integration candidate.
| Field | Purpose | Typical failure if missing |
|---|---|---|
base_sha_at_request |
Pins the reviewed context | Reviewer cannot tell which main was approved |
base_sha_tested |
Identifies the base of the tested candidate | Green result attaches to the wrong commit |
patch_hash |
Binds the result to one diff | A retried or edited patch reuses an old verdict |
test_selection |
Records which tests ran | Partial selection looks like full coverage |
Test: verify the pin actually blocks
This is a verification plan, not a recording of a completed run.
Prerequisites: a disposable repository, a gate callable on demand, and the ability to land a commit on the branch between request and apply.
- Create a patch request and capture
base_sha_at_request. - Land an unrelated commit on the branch, producing a new head.
- Invoke the gate on the unchanged request.
- Confirm the gate returns
BLOCKEDwith reasonbase moved. - Confirm the artifact contains both SHAs and the intervening commit.
- Deliberately update the request to the new base and review the candidate. Rerun with that base unchanged. The gate should now run the tests.
- Inspect the verdict and confirm the base and integration candidate match the commits that were actually tested. If the destination moved again, do not reuse the verdict for a different integration.
Expected observation: step 4 blocks; step 6 passes; step 7 shows a tested SHA, not a branch name.
Negative control: remove the SHA comparison and repeat step 3. A green verdict here confirms the check is what produces the block, rather than incidental test failures.
Step 7 catches a second class of bug. A gate that rebases silently can pass step 4 and still test a base it never records.
Common failure modes
- Recording the base at apply time. The pin becomes meaningless, because it always matches itself.
- Comparing branch names instead of SHAs. Moving branch pointers defeat the comparison entirely.
- Rebasing without rerunning the full suite. A rebase changes the tree; cached results belong to the old tree.
- Overwriting the blocked record. The audit trail disappears exactly where it matters most.
- Treating a conflict-free rebase as semantically safe. Textual cleanliness is not behavioural equivalence.
- Blaming flaky tests. Drift and flakiness look identical from a single red run; only the recorded SHAs separate them.
Tradeoffs and limits
Pinning costs throughput. On busy branches, a strict pin can block a large share of queued patches per hour. That cost is the point: those patches genuinely need a fresh run.
Some reductions are reasonable, if recorded.
- An age window can limit scheduling delays but cannot establish that a verdict applies to a different commit.
- Rerun only affected test groups when the intervening commits touch disjoint paths, and label the verdict as partial.
- Auto-rebase, then require a fresh full run before merge. This keeps the queue moving without reusing stale results.
This approach does not apply well in three situations. Single-writer repositories with no concurrent merges rarely drift. Patches that are pure documentation edits carry low semantic risk. A managed merge queue can own revalidation; verify how it treats a changed destination and retains the identity of the candidate.
The main unresolved question is conflict policy. Auto-rebase hides semantic conflicts, while hard blocking stalls the queue. Most teams end up with a hybrid: auto-rebase for disjoint paths, manual review otherwise.
What this draft does not establish
The scenario, timings, and artifact fields above are illustrative. They were chosen to make the mechanism clear, not measured. The pseudocode has not been executed or tested against a real gate. Anyone adopting the pin should verify their own queue behaviour, branch velocity, and test selection logic before relying on it.
This article was created with AI assistance.
Top comments (0)