AI-generated image.

WritingInfrastructure

The merge conflicts Git can’t see.

Two changes get reviewed, both are correct, and the system breaks only when they meet. I first ran into this years ago in Kolkata. It took me an old parable about an elephant (and a theorem prover) to understand the whole thing.

TL;DR

  • Git merges text. Infrastructure breaks because of how values in different files relate to each other.
  • Two changes can each be safe alone and unsafe together. No line conflicts, so nothing flags it.
  • Write the merge down as constraints and ask an SMT solver if they can all hold at once. You get an answer in milliseconds, and it points at the exact lines that collide.

I first ran into this kind of failure years ago, when I was working in industry in Kolkata. I can’t share the details of that system (you don’t really need them anyway), but I remember how it happened. Two changes went in. Both were reviewed, both were correct, and the system broke only after the two of them met. Nobody could point at a bad line because there wasn’t one, and everyone involved had been right about the part they could see.

I still think that’s an unfair way for a system to fail. It stayed with me long enough that it’s now what my research is about. Below is the simplest version of it I know, cut down so it fits in your head.

Say you run a shop on Kubernetes. The cart service uses Redis, and Redis is capped at 100 client connections. There are 3 replicas of the cart service right now. Each replica keeps a pool of 20 connections, so all together they use 60. That leaves plenty of room.

On Monday an engineer scales the cart service up for a sale, from 3 replicas to 5. That makes it 5 times 20, which is 100. It’s right at the limit but it fits, so the review goes through and CI passes.

The same Monday a second engineer is looking at spiky p99 latency and raises the connection pool from 20 to 30. On that branch the replica count hasn’t changed, so the math is 3 times 30, which is 90. That fits too. Review and CI pass again.

Both branches get merged. Git is happy, because the two edits are in different files. But the cart service now has both of them, so it asks for 5 times 30 = 150 connections, and Redis still only allows 100.

Each branch is individually valid. The merge is not.
base 3×20 = 60 branch A branch B merge Redis maxclients = 100 replicas conn_per_pod
Every point on the surface is a config; its height is how many connections it asks Redis for. The glass ceiling is Redis’s limit, and the glowing curve is where replicas × conn_per_pod = 100. Drag the sliders: both branches can sit under the glass while their merge goes straight through it.

Neither engineer did anything wrong. Review and CI were both looking at something real when they said yes. The bug only exists once the two changes are put together. A normal pipeline has nothing that looks at them together.

The elephant in the merge

There’s an old Indian parable about blind men and an elephant. You can find Jain, Buddhist and Hindu versions of it, and the core is the same in all of them. Some men who have never seen an elephant are asked to describe one, and each of them gets hold of a different part. The man with the trunk says it’s a snake. The man at a leg says it’s a tree. The ear gets called a fan and the side gets called a wall. Each of them is describing something real, and they’re all still wrong about the elephant.

Japanese woodblock print of a group of blind monks crowded around a large white elephant, each feeling a different part of it: trunk, tusk, ear, leg and tail

Blind monks examining an elephant

Artist
After Hanabusa Itchō (1652 to 1724)
What
Japanese woodblock print
Source
Wikimedia Commons
License
Public domain
I actually learnt this parable from an AI, and I recommend it: having AI teach you history is one of its best uses. Here it is all the way over in Japan, blind monks arguing over an elephant, after a print by Hanabusa Itchō. Every one of them is right about his part. From Wikimedia Commons, public domain.

Jain philosophers took that story and built a whole idea on it: anekantavada, roughly “the many-sidedness of truth.” It says any single view of a thing is partial, and there isn’t one correct observer you can go and find. The way to get closer to the truth is to hold several partial views together and ask what’s consistent with all of them.

In our case the elephant is the merged configuration, and in a normal pipeline nobody ever touches it. A code review is one of the blind men. The engineer who scaled the replicas had the trunk and described it correctly. The one who raised the pool had a leg, and got that right too.

Why the usual tools miss it

The standard toolchain is blind to this kind of bug, and it took me a while to accept how blind. The bug sits between the diffs, which is a space our tools don’t model. Each layer has a fair excuse:

  • Git merges line by line, as text. Our two changes aren’t on the same line (often they aren’t even in the same file), so as far as Git can tell there’s nothing to resolve.
  • Linters and scanners take one snapshot and check it against rules like “replicas must be at least 2” or “set a memory limit.” Both branches pass. These tools don’t reason about two branches at once.
  • Policy engines look at one configuration at a time. A policy can say “connections must fit the limit,” but somebody has to have written that exact policy first, and even then it only sees the state it gets handed.
  • A reviewer sees a diff. The diff says “3 to 5 replicas” and that’s what they review. They aren’t looking at a ConfigMap in some other directory that someone else is editing in parallel.
Railway tracks seen from a bridge, two lines converging and crossing at a junction between green trees

Effingham Junction

Where
New Guildford Line, Surrey, England
When
June 2025
By
Mertbiol
License
Public domain (CC0)
When I lived in England, I missed train rides more than I expected. On the way to the Lake District I listened to “Trains” by Porcupine Tree. This junction is in Surrey: two lines, each fine on its own, that have to agree where they meet. Photo by Mertbiol, public domain.

The fix is to stop thinking in lines

The problem got tractable for me once I stopped reading a configuration as text and started treating it as a set of variables with constraints between them. Later I realised it’s the elephant parable again, written as math. You have several partial views, and you want to know if they can all be true together.

In the shop example, replicas is a variable. Connections per pod is one too, and so is Redis max clients. And there’s a rule the system depends on that it never states anywhere:

replicas * conn_per_pod <= redis_max_clients

Once you write it like that, a merge becomes a question: after taking every branch’s changes, can all the constraints still be true at the same time? That’s what an SMT solver is built to answer. I used Z3.

from z3 import Real, Solver

replicas    = Real("replicas")
conn        = Real("conn_per_pod")
max_clients = Real("redis_max_clients")

s = Solver()
s.set(unsat_core=True)
s.assert_and_track(replicas == 5,      "branch-a  deployment.yaml:7")
s.assert_and_track(conn == 30,         "branch-b  redis-cart.yaml:12")
s.assert_and_track(max_clients == 100, "base      redis.yaml:4")
s.add(replicas * conn <= max_clients)  # the invariant

print(s.check())       # unsat
print(s.unsat_core())  # the exact lines that can't coexist

I love that unsat is a proof. It means there’s no assignment of those values that satisfies the rule. The other thing I love is the unsat core, which gives you the minimal set of facts that collide. Every value carries its provenance, so the report reads like “branch A, deployment.yaml line 7, and branch B, redis-cart.yaml line 12 cannot both be true,” and a person can act on that in ten seconds.

What the real tool does

The core idea is all in that snippet. I built a tool around it called MERLIN. The solver call was the easy part, and the hard parts were everywhere else.

1. Read every IaC dialect into one model

Teams write their infrastructure in different formats. MERLIN has a front end for Kubernetes manifests, for Helm values and overlays, for Terraform, and for Pulumi previews. Whatever comes in gets lowered into one intermediate representation, and every value in it remembers which file, line and branch it came from.

2. Model the merge, not two full configs

Comparing two complete configurations gets you mostly noise. MERLIN reduces each branch to what it changed versus the common base and compares those. That’s what a merge is anyway, two sets of intentional changes against a shared base, and most of the design depends on it.

3. Handle logic, not just numbers

Infrastructure code has conditionals too, and the conflicts they cause are sneakier. Two engineers can both write “scale up under load” and pick different thresholds:

# branch A
replicas = var.peak_qps > 500 ? 10 : 3

# branch B
replicas = var.peak_qps > 800 ? 12 : 4

Neither of them is wrong. At 600 queries per second, though, branch A asks for 10 replicas and branch B asks for 4. The solver handles this by turning each conditional into an If(guard, then, else) term, and then it can find the exact load range where the two branches disagree.

4. Suggest a repair, carefully

A conflict report is only half the job. MERLIN also proposes a fix, and for that it uses Z3’s optimizer. The safety rules go in as hard constraints, and “change as little as possible” goes in as a soft objective. In the shop example it keeps the 5 replicas (someone wanted those for the sale) and puts the pool back to 20 per pod.

In the repair step, the rule I care about most is that a value stays fixed unless someone opted in. For a Kubernetes field, opting in means its owner marks it # merlin:adjustable. If there’s no marker, MERLIN reports the conflict and the exact lines, and a human decides. A tfvars entry is somebody’s decision. If a tool moves it without asking, that’s how you end up with a connection pool “fixed” by setting it to zero.

Does it work?

I trust it because of these numbers:

  • Across 9,504 conflict scenarios, MERLIN had zero false positives and caught about 98.8% of the conflicts. Many of those scenarios were derived from real resource values in Online Boutique and DeathStarBench.
  • Median solver time was about 5 ms. At that speed it can run on every pull request and nobody notices.
  • On the same set, a popular IaC scanner caught about 61%. It took around 2 seconds per check and missed every threshold divergence. It’s a decent tool. Nobody built it to answer this question.

The live result is the one I show people, though. On a running cluster, a merged config asked Redis for 200 connections and Redis allowed 100. Add-to-cart calls failed 8.7% of the time, and checkout p99 climbed to almost 2.5 seconds. MERLIN needed a few milliseconds to compute the repair. With the repair applied there were zero errors, and p99 was back to about 312 ms.

What I learned building it

  1. A miss you never hear about is worse than a false alarm. MERLIN matches variables across branches by name, so a field renamed by an injected sidecar would make the conflict vanish, and nothing would tell you. I wrote more tests for that naming contract than for the solver itself.
  2. Almost no single number in these incidents is wrong on its own. The trouble is the product of two of them, so the dangerous bugs are in the relationships between values.
  3. People skip a check that takes 2 seconds, and one that takes 5 ms turns into infrastructure nobody sees, so speed decides whether it gets adopted.
  4. The opt-in marker felt like friction at first. Now it’s the reason I’d trust this in a real repo, because a tool shouldn’t automate somebody else’s decision.

Where it falls short

MERLIN doesn’t render Helm templates, so a conditional inside a template is invisible to it. The set of knobs it models is fixed for now: CPU, memory, replicas and connection pools. And if two adjustable values multiply each other, the repair is nonlinear. In that case it falls back to reporting the conflict and doesn’t attempt a fix. All of this can be solved, but I haven’t got to any of it yet.

The bigger idea holds up anyway, and it’s the reason I moved my research here from diagnosis. Diagnosing a broken system is expensive, however clever you are about it. The cheapest way to deal with an incident is to refuse it at the moment it’s introduced, and for config conflicts that moment is the merge.

Back in Kolkata, where I first saw this, people were already careful, and each of them was right about their part of the animal. So I don’t believe a smarter reviewer or a more careful engineer was ever the answer. The missing piece was something whose whole job is to hold every partial view at once and tell you, with a proof, whether they fit. The old philosophers called that many-sidedness and I call it a solver. Both start from the same humility, that nobody sees the whole elephant alone.