
Green PR, Broken Main: Why a Passing Pull Request Can Still Break Your Branch
A squash-merge script that did not re-run CI left a real gap: a green pull request could break main. A small Git and .NET reproduction of a clean merge that does not build, how keeping both sides of a conflict can drop a closing brace, a local trial-merge rule, and what the GitHub merge queue does about it.
How this started
In one of my projects, which is a .NET 10 and Next.js application, I used a coding agent in an autonomous loop. Specifically, an issue became a pull request, the pull request went through CI until it was green, and then it was squash-merged. About 23 pull requests went through this loop in one stretch, and during that stretch we found several problems in the way our changes reached main.
One of these problems was in our merge script. That script squashed each pull request onto the latest main without running CI again, so a pull request could be completely green and still break main. I should be clear that I did not see this break main in that project, but the gap was real. In this article, I will show how it can happen with a small reproduction, what we changed, and why the GitHub merge queue is the proper answer. Additionally, I will cover a few related cases in which "merged" did not mean what we assumed.
What a green pull request actually tells you
To understand the problem, we should first look at what CI is testing. When a GitHub Actions workflow runs on the pull_request event, the commit it receives is the merge commit on refs/pull/N/merge, so it tests the pull request combined with the base branch. This is very useful, but that result belongs to the base branch as it was when the run started. If another pull request lands afterwards, the green check is describing a combination that no longer exists.
GitHub documents this risk very directly in the branch protection settings. If "Require branches to be up to date before merging" is not selected, the documentation warns that status checks may fail after you merge if there are incompatible changes with the base branch. Our script had the same weakness for a similar reason, because nothing ran on the squashed result before it became main.
You might expect Git to warn you in such a case, but Git only compares text. That's because a merge conflict means that two changes touched the same lines, so two changes which disagree in meaning and live in different files will merge without any complaint.
A clean merge that does not build
Now let's examine this with a small example, using a real Git repository and a real dotnet build. On main we have a price service, and one existing caller in Checkout.cs.
namespace Shop;
public static class PriceService
{
public static decimal Total(decimal net) => net * 1.25m;
}The first pull request changes the signature so that the caller provides the rate, and it also updates Checkout.cs, so it builds without any problem.
namespace Shop;
public static class PriceService
{
public static decimal Total(decimal net, decimal vatRate) => net * (1 + vatRate);
}The second pull request was branched from the same main, and it only adds a new file. On its own branch the old signature still exists, so this one is green as well.
namespace Shop;
public static class Refund
{
public static decimal Amount(decimal net) => PriceService.Total(net);
}For the merge itself, the following script is a simplified version of the old behaviour for this reproduction. As you can see, there is no check of any kind after the merge.
#!/usr/bin/env bash
# squash-merge.sh: the old behaviour, reduced; nothing runs on the result
set -euo pipefail
branch="$1"
git switch --quiet main
git pull --quiet --ff-only origin main
git merge --squash --quiet "$branch"
git commit --quiet -m "$branch"
git push --quiet origin mainWhen this script runs for both branches, each merge succeeds, git merge-tree also reports no conflict between them, and both commits reach main. However, main does not build any more, and the build gives the following error.
Refund.cs(5,63): error CS7036: There is no argument given that corresponds to the required parameter 'vatRate' of 'PriceService.Total(decimal, decimal)'When "keep both" removes a brace
We also had a second kind of failure, and this one really happened. Two branches appended a block to the same place, and the closing } which they shared was left outside the conflict markers. The agent resolved the conflict with a one-off regular expression which kept both sides, and its only check was that no markers were left. As a result, a closing } was missing and the typecheck failed with TS1005. This reached a pull request branch, but it did not reach main, and it was fixed before the merge.
The interesting part is that the checks did run, and they did fail. However, the commands were chained with ;, so the push ran anyway. If they had been chained with &&, the push would have stopped at the first failure. Later the same thing nearly happened again in a test file, and this time a local typecheck caught it.
The reproduction shows the same mechanism in C#. Suppose that two branches each add a method at the end of the same class. Since both new methods end with an identical line, Git moves that line out of the conflict, and it writes the following in the default conflict style.
<<<<<<< HEAD
public static int Monthly()
{
return 3000;
=======
public static int Weekly()
{
return 700;
>>>>>>> origin/main
}
}If you now keep both sides by removing only the three marker lines, the first method has lost its closing brace, because a single } is left for two methods. The compiler then reports the following.
Limits.cs(12,21): error CS1513: } expectedAdditionally, in the reproduction the built-in merge=union driver in .gitattributes produced the same missing brace without reporting any conflict at all. The Git documentation also warns that the user should verify its result. On the other hand, with merge.conflictStyle set to diff3, each side kept its own closing brace inside the conflict, and keeping both sides while removing the base section built correctly. Therefore, diff3 is a very cheap setting to consider if conflicts are resolved by a tool or an agent, although it does not replace running the checks.
The rule we added
After these cases, we added a new rule: before merging, trial-merge with main locally and run typecheck, lint, tests and l10n on the result. The next script shows the idea in a small form, where check.sh stands for your own list of checks. It uses a temporary worktree, so neither your working copy nor main are touched.
#!/usr/bin/env bash
# trial-merge.sh: run the checks on what main would become, before merging anything
set -euo pipefail
branch="$1"
git fetch --quiet origin main "$branch"
tree="$(mktemp -d)"
trap 'git worktree remove --force "$tree"' EXIT
git worktree add --quiet --detach "$tree" origin/main
git -C "$tree" merge --squash --quiet "origin/$branch"
(cd "$tree" && ./check.sh)
echo "trial merge of $branch onto $(git rev-parse --short origin/main) passed"In the reproduction, this script passes the first pull request. After that one lands, it refuses the second pull request with the same CS7036 error, while main stays where it was and still builds. Once the second branch is updated to pass the rate, the trial merge passes. It also refuses the branch with the missing brace, which the old script accepted.
However, this rule has a limit, since the result is only valid for the main that the script fetched. If something lands while the checks are running, we are back to the original problem with a smaller window.
The merge queue is the proper answer
The reproduction above does not include a merge queue, because a queue only runs on GitHub, so this section comes from the GitHub documentation as of November 2026. According to that documentation, the queue checks that a pull request's changes pass all required status checks when applied to the latest version of the target branch and any pull requests already in the queue. Specifically, it creates a temporary branch which contains the target branch, the pull requests ahead in the queue and your pull request. It merges only when the required checks pass on that branch. If they fail, the pull request is removed from the queue and the branches behind it are rebuilt without it, so the window from the previous section is closed.
There are a few practical details to know before enabling it. Your GitHub Actions workflows must also have the merge_group trigger next to pull_request, otherwise the required checks are never reported and the merge fails. Squash is one of the supported merge methods. In addition, merge queues are available in public repositories owned by an organization and in private repositories of organizations using GitHub Enterprise Cloud, so a private repository on another plan needs a different solution. For such a repository, "Require branches to be up to date before merging" gives the same benefit at the cost of more builds and manual updates.
In my view, we should also remember that the queue is only as good as the required checks. If your l10n check is not a required check on the merge group, the queue can't protect you from a broken l10n file.
Merged does not always mean arrived
Three other cases from the same work were not about broken builds, although in each of them something looked finished when it was not.
The first one was a stacked pull request that was merged into its old base branch and never reached main, while everything about it looked green. Today GitHub has native stacked pull requests, which became generally available on 6 October 2026. According to the documentation, each pull request in a stack is evaluated against the rules of the stack's base, and a stack enters the merge queue as a single group. If you stack branches by hand, it is worth verifying after the merge that the commit is really on main.
The second one was about multiple repositories, in which merge order is not deploy order. An API removal was merged before the matching UI change, and the only thing that stopped an out-of-order deploy was a guard for an unset SSH secret. That was luck, and I don't consider it a safety mechanism. A merge queue would not help here, because it works on one base branch of one repository. In my view, the better approach for a removal is to do it in two steps, so the UI stops using the API first and the API is removed afterwards.
The third one was a merged infrastructure pull request that sat undeployed, because the builds on main only validated it. So it is very useful to know, for each kind of change in a project, which pipeline really deploys it, because the answer may be different for infrastructure and for application code.
If you let an agent merge on its own, I think these are the questions to answer before the loop starts, because the loop will stop only at the checks that you have given it.
References
Keep reading

November 3, 2026 · 8 min
10 November: What Actually Breaks When .NET 8 and In-Process Azure Functions Run Out of Support
.NET 8, .NET 9 and the Azure Functions in-process model all reach end of support on 10 November 2026. What is confirmed, what happens to running apps, how to find what you run, and the JSON attribute trap that fails without any error.
Read
October 29, 2026 · 8 min
Idempotent Bulk Ingestion into NebulaGraph from .NET: Solving the Duplicate Problem at the VID Level
Duplicates in a graph database are a key-design problem, not a row-uniqueness problem. This article shows how to engineer idempotency into NebulaGraph imports from .NET by controlling VIDs, edge ranks, and batch checkpointing.
Read
October 29, 2026 · 7 min
Sharing State Across Sessions and Agents: Memory, MCP, and Handoffs in .NET
Agents forget everything between sessions and cannot see each other's work by default. This third part of Agentic Engineering for .NET Teams covers the practical patterns: persistent memory, MCP servers, multi agent coordination, and the C# wiring that makes them work together.
Read