SolveLang Blog · CI
Why do my tests pass locally but fail in CI?
Published
Your laptop is warm: dependencies installed months ago, caches full, 32 GB of RAM, a filesystem that remembers everything. A private-repository GitHub Actions runner is close to the opposite — the standard Linux runner has 2 vCPU and about 8 GB of memory, starts from a clean image, and was born roughly ninety seconds before your job started. A test suite that passes on the first machine and fails on the second is not haunted. It is telling you which hidden assumption your tests were making.
The usual differences, in the order they usually bite
Resources come first. Tests that run in parallel on your machine can exhaust memory or CPU on a 2-vCPU runner, and the failure often appears in an unrelated test that happened to be running when the pressure peaked. Timeouts tuned on a fast laptop fail on a loaded shared runner for the same reason.
Environment comes second. Environment variables you exported once and forgot, a .env file that is not committed, a database seeded on your machine but empty in CI, a different Node, Python, or JDK patch version, a different timezone or locale — each one produces failures that look random until you diff the two environments side by side.
State and ordering come third. Tests that pass in one order and fail in another are sharing state: a file, a table, a global, a port. Locally you run them in the order that works; CI sharding or a different runner changes the order and the sharing shows up.
The filesystem is a quiet fourth. Linux CI is case-sensitive and your Mac or Windows checkout may not be, so an import that resolves locally fails remotely. Line endings, file permissions, and paths built with backslashes fail the same way.
How to find which one it is
Read the first failure, not the loudest one. In a resource or ordering failure, later failures are usually debris. Then reproduce in a clean environment locally: a fresh clone, a container, or CI's own debug logging — if it passes in a clean local environment too, the difference is the runner's size or timing, not the code.
The most useful single habit: when a test fails in CI and passes locally, write down the difference that caused it before you fix it. Teams that keep that list discover their failures cluster into two or three causes, and those causes are fixable once — in the test setup, not in a hundred individual tests.
Questions, answered briefly
Should I just re-run the CI job when this happens?
A re-run tells you one thing: whether the failure repeats. If it goes green with no code change, you are looking at flakiness or resource pressure, not a code bug — and the re-run has hidden the evidence. Capture the failing logs first, then re-run.
Why does it fail only sometimes in CI?
Intermittent CI-only failures usually mean timing, shared state, or runner load: the test depends on something that is usually fast enough or usually free. The fix is to remove the dependency — wait on a condition instead of a sleep, isolate the state — not to raise the timeout until it stops complaining.