My CI gate failed on changes it could never see
I designed a CI gate badly, and it made a lot of commits harder than they needed to be. Here’s what I did and what I should have done.
The setup
We have a superrepo that pulls a number of other repositories in as git submodules. I wrote a “dependency graph” gate for it. It runs as a pre-commit hook on every superrepo commit and checks that the repositories fit together the way our design says they should.
I set the hook to run on every commit, with no file filter. My reasoning, which I also wrote into our build docs, was that a commit that only moves a submodule pointer stages no file a pattern could match, so the gate had to run every time. It made sense to me then. Looking back, it was the warning sign.
How it grew
Over about a month the gate picked up four new checks, and each one read further into the submodules’ own files:
- Each submodule’s pipeline config had to use the same CI image tags as the superrepo’s CI image script.
- Each submodule’s database service container had to match a rendered table and image.
- Every package manifest in a checked-out workspace had to carry the same version as the sibling repository that produces the package.
- Every git dependency pin in each submodule had to follow our pinning rules against the sibling checkouts: the tag had to exist, and each repository could be referenced only once across the dependency tree.
Each check was reasonable taken alone. The problem is that every one of them judges a submodule’s committed files, and those files change through commits in the submodule’s own repository. Those commits run that repository’s hooks and pipeline. They never run the superrepo’s hook.
So the gate only ran when someone committed to the superrepo, and it judged whatever happened to be in the submodules’ working trees at that moment.
What went wrong
- It went red when nothing in the superrepo had changed. Several upstream repositories moved to newer versions of a shared contracts package and engine in their own repos. One downstream repository still pinned the older versions. The next superrepo commit, whatever it contained, failed with a list of pin mismatches. The commit that actually caused the mismatch ran in another repository and never triggered this hook.
- It went red on one person’s machine only. One developer’s local checkouts sat at older commits whose pipelines named older CI image tags. The gate reported eighteen image-tag failures for them, and no superrepo commit could fix any of them.
- People had to skip the hook. For a whole day, every superrepo commit that ran the hook needed explicit consent to skip it, and some commit messages recorded the skip. The same thing had already happened on an earlier piece of work. A gate that people routinely skip is not gating anything.
- Real failures would have been lost in the noise. Agents and developers read the failures as pre-existing and unrelated to their change, and they were right. But if the gate had caught a real problem in the same run, such as a forbidden dependency or a patch entry pointing at a directory that doesn’t exist, it would have been one more line in a wall of output everyone had learned to ignore.
- The fix it suggested was in the wrong place. The error messages said things like “re-render this repo’s config” or “move the pin.” Both of those are commits in a different repository, so the message sent the committer away from the commit they were trying to make.
What I should have done
A gate on a repository should judge only what a commit to that repository can change. For the superrepo, that means its own files, the submodule list, the patch tables, the package links and the submodule pointers. It also covers the structural shape the design describes across the repositories: which repo depends on which, what kind each entry is, and which crates each patch table covers. The gate should have been limited to that list.
Facts about a submodule’s files belong to that submodule’s gates. Pin rules, workspace package versions and CI image tags should be checked by the repository where they live, in the hooks and pipeline that run when they change. If the superrepo wants the same rule enforced, the rule should be shared and run where the change happens, not where it doesn’t.
Before adding a check to an always-run hook, ask two questions: which commit turns this red, and does that commit run this hook? If the answer to the second is no, the check shouldn’t be a failure. At most it can be a notice, and it’s usually better left to the gate that actually runs.
When the trigger is hard to scope, fix the scope instead of widening the trigger. My reasoning, “it has to run on every commit because pointer moves don’t match any file pattern,” meant the gate was judging trees that change somewhere else. At that point I should have narrowed what the gate checks, not made it run everywhere to compensate.
How it would have gone
With the gate written this way, the pin mismatch would have failed the pin checks in the downstream and upstream repositories, the places where the pins were actually moved. Every superrepo commit that day would have passed its hooks, and nobody would have needed to skip anything.
What I’m changing
- I’m cutting the superrepo gate back to the superrepo’s own files and the cross-repo structure the design defines.
- I’m moving the per-repository checks (pins, workspace versions, CI image tags) into each repository’s own gates, sharing the rules where that makes sense.
- I’m updating the build docs so they describe the gate’s narrower job instead of justifying the always-run trigger.
- For any new gate check, I’ll write down which commit makes it fail and confirm that commit runs the gate. If I can’t, the check doesn’t go in as a failure.
A gate is only useful if the person it blocks can fix the problem in the commit they’re making. I lost sight of that, and I’m sorry for the friction it caused.