How to run a deterministic AI merge train
A merge train for AI coding agents needs more than a queue. It needs explicit ownership, immutable review inputs, conflict boundaries, and a safe definition of “stop.”
Adding more coding agents does not automatically add more throughput. Without coordination, agents can edit the same pull request, review a commit that is no longer the branch head, or wait forever on a check whose owner has disappeared. The result is activity without a reliable path to merge.
MergeGantry is our in-development design for a deterministic AI coding fleet and merge-train control plane. The product page describes its core pieces—single-owner PR leases, exact-head multi-model review gates, head-bound conflict guards, quota-safe GitHub caching, and automated stall recovery. This post explains the engineering model behind those pieces without claiming benchmarks or production outcomes that we have not published.
Define the merge train as a state machine
A useful merge train has a small number of states and explicit transitions. The agent can propose work, but the control plane owns transitions that change repository state.
| State | Owner | Required evidence to advance |
|---|---|---|
| Queued | Scheduler | Repository, branch, and task are normalized. |
| Leased | One agent | Unexpired PR lease with a recorded owner and base head. |
| Reviewable | Control plane | Agent has produced a commit; checks are bound to that exact head. |
| Gated | Review ladder | Required model reviews and CI checks agree on the same head. |
| Mergeable | Merge train | Head and conflict guards still hold at the merge decision. |
| Stalled | Tripwire | Progress or dependency evidence has expired; work is paused or reclaimed. |
The important property is that every transition has evidence. “The agent said it finished” is an event; it is not proof that the branch is safe to merge.
1. Give every PR a single-owner lease
Parallelism should happen across independent PRs, not through multiple writers racing inside one PR. A PR lease is a short-lived record with an owner, PR identifier, expected base, lease expiry, and renewal token. The agent must present the token when it pushes, requests review, or marks a step complete.
Lease ownership answers three questions that otherwise become ambiguous: who may mutate this PR, which task is that mutation serving, and when may another worker reclaim it? The lease is not a permanent lock. It is an expiring claim that makes abandoned work recoverable.
Use compare-and-swap semantics for acquisition and renewal. If two agents see an unleased PR, only one should be able to create the lease version that wins. If a worker pauses past expiry, the next worker may reclaim it, but it must re-read the PR and branch head before doing anything destructive.
2. Bind every review to an exact head
“Review passed” is incomplete without a commit identifier. A review result should include the PR, commit SHA, model or reviewer identity, policy version, timestamp, and result. The gate may consume a result only when its SHA equals the current PR head.
review = {
pullRequest: 184,
headSha: "abc123...",
reviewer: "model-ladder/primary",
policyVersion: "protected-paths-v3",
result: "pass"
}
gate(currentHead, reviews) {
return reviews.every(review => review.headSha === currentHead)
&& requiredReviewsPresent(reviews)
}
If an agent pushes a new commit after review, the old result is historical evidence, not a current approval. Invalidation should be automatic and cheap. The control plane can retain the old review for auditability while refusing to use it for the new head.
3. Make conflicts head-bound
A file-overlap guard should never be a vague “agent A owns auth.js.” It should describe the branch head and the lease under which the claim was made. A conflict record can include PR number, head SHA, normalized path set, owner, lease version, and expiry.
When a worker wants to modify files, the control plane checks for overlap against active claims. If the PR head changed since the claim was calculated, the claim is stale and must be recomputed. This prevents an agent from relying on a file set derived from an old tree.
Path normalization matters: case handling, separators, generated files, and directory-level policies should be deterministic. Protected areas such as authentication, billing, privacy, and migrations can require stricter review ladders, as the MergeGantry product page describes.
4. Use models as a reversible review ladder
Different models can be useful for different review questions, but model count is not a safety property by itself. A ladder should be a policy: which checks run for which path classes, what happens when a model is unavailable, and which results are required before merge.
- Start with deterministic checks. Formatting, tests, type checks, secret scanning, and policy checks should not depend on a model’s prose.
- Route by risk. A low-risk documentation change need not use the same review path as an authentication or migration change.
- Record the input. Store the exact head SHA, diff or snapshot reference, prompt/policy version, model identity, and result.
- Make fallback explicit. If a preferred reviewer is unavailable, pause, use a policy-approved alternate, or downgrade to human review. Do not silently convert “unavailable” into “passed.”
- Keep ladders reversible. A model can be removed or reordered without changing the lease and merge invariants.
MergeGantry describes reversible Gemini, Grok, Codex, and Claude ladders with dual-model checks on protected paths. The durable idea is the policy boundary, not a particular vendor list.
5. Add stall tripwires that know how to stop
A stall tripwire is not a generic timeout. It is a condition that identifies missing progress and specifies the safe action. Examples include a lease that cannot renew, a review job with no heartbeat, a PR head that changes repeatedly without a new gate, a dependency that remains blocked beyond its allowed window, or a quota/cache condition that prevents the next read.
| Tripwire | Signal | Safe action |
|---|---|---|
| Lease heartbeat | No renewal before the lease deadline. | Mark stale; do not let a second writer mutate until ownership is reclaimed. |
| Review heartbeat | Review job has no terminal event or progress marker. | Cancel or retry according to policy; keep the gate closed. |
| Head churn | Repeated pushes invalidate reviews without reaching a stable head. | Pause the agent and request human or scheduler intervention. |
| Systemic blocker | Shared API, CI, or cache failure affects multiple lanes. | Stop starting new work and surface one actionable incident. |
| Burn-rate guard | Usage grows while useful progress does not. | Throttle or stop the lane; preserve the audit trail. |
The desired outcome is a system that becomes quieter when it is uncertain. A stalled lane should be visible, reclaimable, and safe to inspect—not an endlessly retrying source of new repository state.
6. Cache reads without making state stale
GitHub metadata can be expensive to read repeatedly, especially when many agents ask the same questions. A quota-safe cache helps, but a cache must declare what it knows and when it was observed. Cache immutable objects by identifier, cache branch and PR views with a freshness window, and force a fresh head read at mutation and merge boundaries.
In practice, the control plane should distinguish “a cached view used for planning” from “the current head verified immediately before a write.” That distinction lets the fleet reduce duplicate reads without allowing an old PR view to authorize a new push or merge.
Putting the invariants together
A deterministic merge decision can be expressed as a short checklist:
- The PR has one unexpired lease, and the writer presents the current lease token.
- The current head was read at the decision boundary.
- Required CI and model reviews all reference that exact head.
- Path claims are still valid for that head and do not overlap an active conflicting lease.
- No stall tripwire is active, and the merge action is recorded with the evidence it consumed.
These invariants do not make AI-generated code correct. They make the control plane honest about what it knows, which is the prerequisite for deciding where automation is appropriate and where a human must intervene.
Product context and early-access pricing
MergeGantry is currently in development. The MergeGantry product page describes the current design, and the pricing page lists early-access target pricing: Free/Solo at $0/mo, Team at $49/seat or $149/org/mo, and Enterprise at $499+/mo. Those are explicitly target tiers subject to change before general availability, not a promise of final billing.
This post describes engineering patterns and the current MergeGantry product direction. It does not claim benchmark results, customer outcomes, or that a multi-model fleet can replace human review.
← Back to Journal Subscribe to the Journal →