Our Merge Gate Failed Good PRs. Four Bugs, One Day.
Six pull requests sat red on our merge gate this morning. By the evening all six had merged, and four of the failures had never been in the PRs. They were in the gate.
That matters more than it sounds. We do not merge on a hosted CI badge. Every PR
head needs a local-verify status from a run on our own hardware, plus a recorded
review, or the merge guard refuses it. Agents open most of our PRs and agents
merge them. A gate that fails good work does not just cost time. It teaches
everyone, people and agents, to stop believing red.
So the job was never "make the PRs green". It was: find out why the gate lied, fix the gate, and leave a check that fails if it lies that way again.
How local-verify works
One host runs at most three verifies at once. Each verify:
- fetches the PR head and its base branch,
- computes the merge-base,
- builds a sparse worktree holding only what the change touches and what its tests import,
- runs ruff, the quality gates and the tests on the head, and
- runs anything red again on the merge-base, so only what the head broke can fail the PR.
Every one of the four bugs lived in that list.
| # | symptom on the PR | real cause | lives in |
|---|---|---|---|
| 1 | COULD NOT JUDGE: no merge-base: Not a valid object name FETCH_HEAD | two verifies racing on one git file | step 1-2 |
| 2 | cannot import name 'media' from partially initialized module | sparse cone missed a sibling package | step 3 |
| 3 | 15/15 tests pass, file marked failed | CUDA teardown segfault at interpreter exit | step 4-5 |
| 4 | ABSENT: unbound variable on every deploy | bash 5.2 leaves declare -A X unset | the deploy that follows |
1. Two verifies, one FETCH_HEAD
Step 1 fetched the base with a plain git fetch origin develop, and step 2 ran
git merge-base <head> FETCH_HEAD.
FETCH_HEAD is one file per repository. Every fetch rewrites it. With three
verify slots sharing a source repo, a second run's fetch could land between our
fetch and our merge-base. Our merge-base then read a file that named someone
else's refs, or nothing at all. A land-siting PR hit it twice in a row.
The fix fetches the base into a ref that belongs to this run alone:
git fetch origin +refs/heads/develop:refs/local-verify/base-<pr>
git merge-base <head> refs/local-verify/base-<pr>
The path for verifying PRs in other repositories already did exactly this. The main path had never been brought into line.
The check: a fake git that wipes FETCH_HEAD on every fetch, the way a
concurrent run would. The test passes with the fix. Put FETCH_HEAD back on the
merge-base line and it fails. We ran that mutation before merging.
2. A sparse checkout is only as good as its import graph
A To Do importer PR failed one test with
cannot import name 'media' from partially initialized module 'apps.awnode.tools'.
The same test passed 15 of 15 in a full checkout.
The test imported apps.awnode.tools.mcp.mcp_tasks. The verifier read that
import, found the tools/mcp/ package and put it in the sparse cone. Correct, and
not enough. Python runs every ancestor package's __init__.py first, and
tools/__init__.py begins:
from . import mcp
from . import media
from . import ai
from . import infrastructure
from . import comfy
from . import workflows
The cone held mcp/ and the ancestor files, but none of the five sibling
packages. In the sparse tree import media failed partway through initialising
tools, and Python reports that as a circular import. The real cause was a
missing directory.
The fix walks each resolved package's ancestors, parses each __init__.py with
ast, and adds the subpackages its relative imports name, transitively and
bounded at 200 files read. Run against the real PR head, the cone now holds
exactly the six packages that __init__.py lists.
The check: a synthetic package tree with nested relative imports, plus an end-to-end call through the cone builder. Remove the one line that merges the new directories in and the integration test fails.
3. A test that passed and still failed
Our land-siting PR had a companion test, test_embed_sync_circuit_breaker, that
finished with 15 passed and still came back failed. pytest's exit code was
139, a segmentation fault, and the base-branch run crashed the same way. A crash
on both sides is "could not judge", and could-not-judge is never green.
python -X faulthandler gave the shape:
1 passed, 14 deselected, 1 warning in 51.27s
Windows fatal exception: access violation
Current thread 0x000035a8 (most recent call first):
<no Python frame>
No Python frame means native code, and the warning above it was a PyTorch CUDA
allocator message. One test, about an HTTP response with no vector in it, was
loading an embedding model onto the GPU. The client's embed() tries an
in-process engine before the HTTP path the test stubs. On a machine with a
GPU, that engine is real. It loaded torch, took 50 seconds, and the CUDA teardown
crashed the interpreter after every assertion had passed.
The fix makes the engine unavailable inside that one test, so embed() falls
through to the stubbed HTTP path:
| before | after | |
|---|---|---|
| wall time | 112 s | 9.6 s |
| exit code | 139 | 0 |
| GPU touched | yes | no |
A unit test that quietly needs a GPU is a test that passes on one machine and lies on the next.
4. bash 5.2 changed what declare -A means
Rolling the MCP gateway onto its new image, our pull script printed:
bash: line 315: ABSENT: unbound variable
and carried on. The line was if [ "${#ABSENT[@]}" -gt 0 ] under set -u, after
a bare declare -A ABSENT.
| bash | set -u; declare -A A; echo ${#A[@]} |
|---|---|
| 5.1.8 (the fleet host) | 0 |
| 5.2.37 (the Windows controller) | A: unbound variable |
In 5.2 a declared but never-assigned associative array is still unset. The same script behaved differently depending on which machine ran that block. That block decides whether a unit has been moved to another node, so silently skipping it is not cosmetic.
The fix is declare -A ABSENT=(). We applied it to all 13 bare array declares in
six deploy scripts. A new test scans every deploy script for a bare declare -a,
-A or local -a. It fails on the old scripts and passes on the new ones. One
script is a printed exception: the deploy-tree sync runs it continuously, and we
do not edit a bash script while it executes. Bash reads scripts as it goes, so
shifting the bytes under a running instance crashes it.
The rule
When a gate fails good work, the gate is the bug. Every fix above came with a check that fails when the bug returns, and every one of those checks was run against the broken version first. A test that has only ever passed proves nothing.
Keep the journal free
Sponsorship pays for the compute, the hardware and the hours behind these entries.
by email
New journal entries, in your inbox.
What the agents built, broke and fixed. One message per entry.