Back to blog
data

Automerge: Letting a Change Prove Itself

Four of us own the Airflow repository that ninety authors commit to, and master deploys to production within minutes. Reviewing every change ourselves did not scale; skipping the review was not an option either. So we built a CI path where a change executes in an isolated Snowflake sandbox, gets diffed against production output, and merges itself when the evidence holds. In the week we measured, a third of merges needed no human. How the gates are designed, why the AI deliberately cannot grant the merge, what the funnel looks like, what it changed, and where it still refuses to help.

Vít Gabrhel
Vít Gabrhel
Senior Data Engineer
October 26, 202617 min read

A wrong number, and four people who could merge the fix

Picture a Tuesday morning. Someone in supply chain opens a report and finds a number that is wrong. Not dramatically wrong: a filter that should exclude cancelled orders doesn't. They know the domain, they can see the bug, and they know the fix. It is one line of SQL.

What happened next used to depend on how busy four people were.

Today, for about a third of the changes that reach that repository, it doesn't depend on us at all. Nobody reviews them. They merge themselves, having proved they are safe - and this post is about how we decided to trust that.

The repository that line belongs in is the core of Rohlik's data platform: the DAGs, the SQL, the table configs, everything that moves and models data for five countries. Since it was created it has taken commits from ninety distinct authors. The Data Engineering team that owns it has four.

That ninety-to-four ratio is not a staffing accident. It is the design. Analysts and people in supply chain, logistics and finance know their domain better than we do. The change they need is usually small: a column added to a model, a filter corrected, a new table to extract. The repository is deliberately open to them, and we want it to stay that way.

And ninety is the smaller half of the story, because the contributors are no longer all people. Eight of those authors are agent accounts, and roughly a fifth of all commits in the repository were made under one. Even that undercounts: an agent working alongside an engineer commits under the engineer's name, so it never appears in the author field at all. The honest measure comes from the week we examine later in this post, where 97% of the changes that merged automatically had been drafted by an agent.

That is what breaks the old arithmetic. Review load does not scale with headcount. It scales with the number of changes. For most of this repository's life those two moved together, because a person can only write so much SQL in a day. They have now come apart. One contributor with an agent opens more merge requests in an afternoon than they used to in a fortnight. A review process sized for ninety people is not sized for ninety people with agents.

Both ways out of that are bad. Keep the four of us as the only route to master, and that one-line fix waits for somebody's afternoon; the number stays wrong until then, and the person who spotted it learns that reporting a problem is slower than living with it. Drop the review instead, and a wrong join key reaches production in minutes, because master deploys straight through.

The second mistake is the expensive one. A wrong MERGE does not announce itself; it produces a number that still looks plausible. Our tables feed how the company generates insight and the actions taken on it: a replenishment decision, a supplier switched, an alert someone acts on at six in the morning. That is a decision made on a false premise, and it can be days before anyone notices.

So we wanted to fix three things at once:

  • Enable the people already contributing. Someone who can write a change, test it and explain it should not need us to read it before it ships.
  • Build something that still works later. A fix that only holds at today's contributor count is not a fix.
  • Get our own hands free. Four engineers working through a review queue are four engineers not building the platform those contributors depend on. This was the part we felt most.

The usual answers did not appeal. Hiring to keep up with a review queue is the wrong shape of fix. And "an AI reviews the diff and approves it" replaces a careful reader with a confident one. The failure mode of a language model reviewing SQL is that it says looks good about a query it never ran.

So we asked a narrower question. Which changes could prove themselves?

The idea: evidence, not opinion

If you have ever reviewed data changes, you know the shape of most of them. They touch SQL. They are small. And crucially, they are testable: you can run the new query and the old query and compare what comes out.

Reviewing one is fairly mechanical: convince yourself the query still returns roughly the right rows, doesn't scan the whole warehouse, and doesn't write somewhere it shouldn't. A reviewer can settle all three by running the thing - check out the branch, point it somewhere safe, run it, compare the output, clean up. That is the honest version of a careful review, and it is why careful reviews are expensive. It is a dozen manual steps, each easy to get subtly wrong, and it costs the reviewer the thing they are shortest of: an uninterrupted hour. A pipeline does the same work the same way every time, in parallel, while nobody is waiting on it.

That is what automerge is. For a ready merge request, CI runs the affected tasks in an isolated Snowflake sandbox and compares the output against production's own last scheduled run. The change merges only if every piece of evidence holds. It has been live since August 2026.

Software engineering settled this twenty years ago: a backend change arrives with tests, the pipeline runs them, and if they pass it merges itself. Nobody finds that remarkable.

The data equivalent is somewhat specific and harder, and precisely why matters. The question a test has to answer is not does this function return 3. It is does this transformation still produce the right rows, against real data, at real volume. You cannot fixture that convincingly - a synthetic ten-row table will pass almost anything - so the only honest test runs the real thing against real data. Which means production-scale work without touching production, cheap enough to repeat on every merge request, and a way to tell afterwards whether the result was right. That is the part that has to be built, and it is why "just add CI" was never a one-line answer for us. The merge automation at the end was the easier half.

The design rule that everything else follows from:

The AI can recommend a merge. It cannot cause one.

An AI does take part, and it earns its place. Some of this job needs judgement that is hard to write as a rule. Does a rewritten CASE still mean what it meant? Is a renamed column the one the downstream model reads? Is a 4% row change the point of the change, or a symptom of a bug? An agent is also good at the part humans do worst: reading line three hundred of a diff at four in the afternoon with the same attention as line one. And it is available the moment the author is ready, which is most of where the waiting used to go.

What it does not get is the final say. Its verdict is a precondition: a red review stops the chain, but a green one only permits the next step. The merge itself is granted by a separate deterministic script, and that script reads only measured facts. Did the task execute? Did it write only where it was allowed to? Is the row delta within budget? Was the sandbox torn down? So if the agent is wrong, over-enthusiastic, or manipulated by something in the diff, the worst it can do is let a change reach the gates. The gates do not read English.

The chain

Five stages. Each can only ever send a change back to a human.

1 - Draft is the safe state. While an MR is a draft every job in the chain is skipped, and only the blocking validate stage runs. So a draft's green pipeline says nothing about the SQL: no gate, no sandbox, no comparison ran. Marking the MR ready is the deliberate act that starts everything, and it needs no push.

2 - The AI review must be green. A reviewer agent - a service that watches merge requests across the company, not something built for this pipeline - posts a summary with findings classified as blocking or merely suggestions. Green means no blocking finding is open.

The care is in the waiting. The summary must belong to the current head commit: the bot stamps the reviewed SHA into its comment, so a green summary from two commits ago cannot be inherited by a third. A non-green verdict stops the chain, and so does a timeout, an API error, a missing credential, or a head that moved mid-review.

3 - The deterministic gate. A plain Python script, no model involved, asks two questions. Is this change the kind we can execute? What will executing it cost?

The first is narrower than "is it SQL". The gate refuses anything it cannot reason about statically or redirect safely: dynamic SQL assembled at runtime, procedure calls outside a sanctioned list, DDL for objects beyond the sandbox's reach, any write whose target cannot be rewritten. If it cannot prove where a statement will write, it does not run it. It also caps the blast radius at five tasks per review.

The second is answered with production's own history. The gate averages bytes_scanned over the task's last five scheduled runs, taken from a 30-day copy of Snowflake query history; above 1 TB the task is parsed but not executed. A task with no history falls back to a heuristic over the SQL itself.

4 - The sandbox. The change executes for real, against a sandbox built by zero-copy clone, so provisioning is a metadata operation and only what the review has to write is cloned. Reads deliberately still name production, so the run meets current data: if a change breaks on today's rows, we want to find out today.

Writes cannot escape. Every production target is rewritten onto the sandbox before anything runs, and the sandbox role holds no write grant anywhere else.

5 - The merge. The output is compared against production's last scheduled run on master. If the checks below hold, CI applies the automerge label, approves as the code owner, and arms merge-on-pipeline-success. There is no "reviewed but hold" state.

What the flag actually requires

The label is granted only when all of these hold, and any missing, stale or partial one withholds it:

ConditionWhy it exists
Agent exited cleanly, gate decision was runA crashed or skipped review proves nothing
Outcome file valid, and its commit matches the reviewed headStops a green review from a previous commit authorising this one
Sandbox was provisioned and torn downCI re-verifies teardown itself rather than believing the agent
Every gate-cleared task executed, none failed, all SQL-backed"It would probably work" is not evidence
Row delta within 5% on every compared targetMeasured against the data already there, to catch a change that quietly rewrites or drops existing rows
Linting passedCheap, and already a precondition
No changed file touches the control planeSee below

That last row is the load-bearing boundary. An MR touching CI scripts, the pipeline definition, agent instructions, CODEOWNERS or the lockfiles is never eligible: a change to the thing doing the checking cannot be checked by it. Lockfiles are there for a subtler reason - they are pinned from the target branch, so a branch bumping a dependency would be reviewed running the old set.

Two honest notes. It is a guard against the careless case, not a security control; the trust boundary remains who can push to the repository and what CODEOWNERS requires. And the label alone never merges - the merge script requires both the label and a fresh flag for that exact head sha, so a hand-applied label can only withhold a merge, never authorise one.

Every run then appends a row to a telemetry table in our own warehouse: which stage it reached, what the gate decided and why, the agent's reasons in its own words, which tasks executed against which baseline, and what the whole thing cost. One row per merge request, kept for a year. Reading that table is how we decide what to widen next.

A real week

Here is the week of 10–16 October - every merge request that merged, and how far down the chain each got.

StageReached itDropped outWhy they dropped
Merged that week176-
Reviewed1697The chain never ran
AI review green15019Not green, or timed out
Cleared the gate7971Not SQL-only, or nothing to run
Out of the sandbox6811A task failed or needed a look
Merged themselves635A final check did not hold

63 of 176 - 36% of everything merged that week needed no human at all. That share was 0% in late August. Counting from the first automerge on 18 August up to the end of that week, 155 changes had merged this way.

Two things in that funnel are worth sitting with.

The gate is where it ends for most of them. 71 of 176 - the single biggest drop - are refused before anything runs, almost entirely because the diff is not SQL-only. That is the design working as specified, not a bug, but it is also the honest ceiling on the current mechanism, and it is where the next work goes.

The last two stages are small, and that is the point. Only 11 changes failed in the sandbox and 5 at the final checks. Automerge is not catching a flood of bad changes; the AI review and the gate already filtered those. What the sandbox earns is the right to trust the remainder without a person reading them.

Who actually uses it

Over the same window: sixteen people plus our coding agent, across nine work streams, with one team accounting for 48% of all automerges on its own.

The median automerged change is 17 lines in a single file - not features, but the steady stream of small, domain-driven corrections a platform accumulates. 97% of them were written by an agent, roughly 80% Claude and 17% Devin.

The number we actually act on is not the aggregate but adoption per person: what share of each contributor's merges go through automerge. The spread is wide, and it is almost never about the changes being different. It is whether someone marks an MR ready and lets the chain run, or waits for a person out of reflex. That tells us who to talk to next, which an aggregate hides completely.

What it actually changes

Four things, roughly in order of how much they surprised us.

Review capacity stopped being a function of our headcount. This is the obvious one, and still the one that matters most. A third of merges no longer consume any of the four people who used to read all of them. More usefully, that share does not fall as contributors are added. The chain runs in parallel and does not get tired.

A domain expert can ship the same day. The person from the opening - the one who spotted the filter on a Tuesday morning - fixes it, opens the merge request, and watches it land. Nobody's calendar is involved. That sounds like a convenience. It is really a change in who gets to improve the platform, and how fast a known-wrong number stops being wrong.

Agent-written data changes became practical. 97% of automerged changes in that week were written by an agent, which reads like a surprising statistic until you look at what automerge actually removes. The constraint on agent-written data code was not generation - models have been able to write a MERGE for a while. It was verification: we were not willing to merge SQL from an agent on the strength of reading it. Once correctness is established by executing the change and diffing the result, the question of who or what typed it loses most of its force. The pipeline is not kinder to an agent than to a person. It is equally unimpressed by both, which turns out to be exactly what lets an agent contribute.

And the evidence behind a merge got better, not worse. This is the one we did not expect. A human approval leaves behind a click and, if you are fortunate, a comment. An automerged change leaves that telemetry row, and behind it a recorded execution against production-shaped data, a comparison against the last scheduled run, and a measured row delta - still queryable a year later. We set out to merge some changes without review and ended up with a stronger audit trail on those changes than on the ones a person approved.

The honest framing of all four: we did not remove the review. We moved it from a person reading code to a machine running it, kept a person for everything that cannot be run, and got a record out of it.

What's next

Widen what is eligible. The telemetry is unambiguous about where: the gate refuses 71 changes a week - almost entirely for not being SQL-only, the rest for having nothing executable to run - and that is the ceiling. The first extension already landed: additions to the YAML table configs - a new table to extract - now execute in the sandbox too, for the operator families where a review engine exists. The pattern generalises. Anything we can execute and compare, we can gate.

Close the adoption gap. The per-person spread says the mechanism is further along than its usage. Some of that is onboarding and some is habit; both are fixable, and neither needs new code.

Keep the boundary honest. Every extension widens what merges without a person. So each one has to arrive with its own evidence: a way to execute the change, and a way to compare the result. We would rather refuse a change we could have merged than merge one we could not prove.

Thanks

To the Data Engineering team, and to everyone who let their merge request be an early experiment while the gates were still learning what to refuse.

If you are solving the same ratio problem somewhere else, we would like to compare notes - particularly on what you found safe to execute automatically, and what you decided never to.

#data-engineering#ci-cd#airflow#snowflake#code-review#ai-agents#gitlab