r/devops • u/basvandriel • Jul 19 '26
Discussion What's your actual workflow when a test fails in CI but passes locally
Just curious, standard procedure, you have something working locally, you push your code and your CI/CD pipeline fails. Locally everything seems OK and you fail to reproduce the error.
What do you actually do at that point? Genuinely curious what people's real routine looks like here — not the textbook answer, the actual "it's 5pm and CI fails" routine 😅
Also wondering: is this even still a big thing in 2026 now that lockfiles and containers have gotten so good, or is it basically a solved problem for most of you?
3
Upvotes
8
u/Blunap0 Jul 19 '26
Are you asking how to find the root cause of a rest which fails in CI but passes locally? Or what to do if CI fails consistently Friday 5pm? For the former, lots of options depending on the specifics. For the latter, revert and it's a problem for Monday :)
54
u/blueghosts Jul 19 '26
Doesn’t get deployed until it passes on the pipeline, end of. Doesn’t matter what time it is and what’s supposed to go out
29
u/d47 Jul 19 '26
If this is a common problem then you'll just need to understand what makes the CI environment different and make it more reproducible. Many ways to do that, you already mentioned containerisation, which would be my initial go-to.
7
u/franktheworm Jul 19 '26
CI is god. It is testing the commit that will be built and promoted to prod, why would I allow that through if the tests fail?
If they fail there but pass elsewhere at best you have a flaky test, at worst you have a bug that could present itself in prod. Again, why would I allow that through?
Your CI should track prod very closely, ideally the environment it is tested under should be identical to prod. Your local is less likely to do that, though it also should be as close as possible (there are local test approaches that will get you pretty close typically).
If ci tests fail, we understand why it failed. If it happens to be something incorrect in the pipeline we will correct that and re-run. If not, the release is aborted and we understand why there is a difference between local and CI. Our standard bug squashing approach is replicat locally, write a regression test that detects the failure, then remediate that and ensure that all tests (including the new regression test) pass
If I was hitting this class of issue my concern would be how we have enough of a variance in our local and CI envs that this is possible. I'd be making sure this is not a sign of something deeper
6
u/spiralenator Jul 19 '26
5pm, CI fails: I say fuck it, this can wait until the next day when I can focus on reading the logs and understand the errors. Forcing the deployment is a great way to end up with an incident and a rollback anyway.
1
u/Floss_Patrol_76 Jul 20 '26
lockfiles and containers killed the 'works on my machine' dependency drift, so when CI still fails it's almost always state or timing: test ordering / shared fixtures, TZ or locale differences, or a race that only shows because the runner has 2 cores and your laptop has 10. i stopped adding log lines and started reproducing the constraint instead - run the suite pinned to one cpu (--cpus=1 or cgroups) with randomized test order, and the flaky ones usually fall out fast.
1
u/sfboots Jul 20 '26
For us, it’s most often some implicit assumption about order of objects read from database. Write data in order a,b,c,d. Read might come back as d,b,c,a. Locally db indexes are in a different state from CI. We need to find where to add the “order by” clause when reading data
1
u/Next-Task-3905 Jul 20 '26
My routine is to treat CI as the source of truth and make the mismatch observable before trying random fixes.
A practical sequence:
Lockfiles and containers removed a lot of dependency drift, but they did not remove state, timing, resource, and environment assumptions. Those are still very much alive.
3
u/MDivisor Jul 19 '26
It happens sometimes, not super often. There is no standard worklfow for this, it depends on what the error is and what part of the pipeline it comes from. Read the build logs, try to understand why it fails. Trying to reproduce the error locally is not usually the first step I take since it's often not necessary.
After 5pm I'm not doing shit to it though, it'll keep until the next morning.
3
u/Low-Opening25 Jul 19 '26
this is sign that you are not testing the same in both scenarios and it’s for you to dig and find out where the difference is
1
u/TransCapybara Jul 19 '26
Something between the build environments became misaligned, like different package shas between them.
1
u/Wyrmnax Jul 19 '26
>Also wondering: is this even still a big thing in 2026 now that lockfiles and containers have gotten so good, or is it basically a solved problem for most of you?
Yes.
They are still different environments. So there are issues.
Passing locally but not on the CI? Something is missing on the CI environment. It is *not* going to production until it passes the CI, because whatever it is missing in the CI will be also missing in PRD.
Baseline is get the dev who broke the branch (yes, that branch is broken) on line. Standard procedure should be fresh clone from git, try to build locally. That usually does the trick, because it is very likely to be something that is on the local machine but is not part of the package created on git.
Failing that, we would usually clean a dev -non local - environment, remove all existing code from there, and push that version. Again, its likely to be one dependency that is not linked in the project. Visual studio in particular is *very* keen on doing that - adding a .js on the project, but not adding it on the publish package.
Those are usually the very first steps, because they solve 99% of the cases. Its either some dependency that got lost, or something that for whatever reason is not being included on the deploy package.
1
u/veritable_squandry Jul 20 '26
there usually a log for the CI hosting layer like in jenkins or harness or whatever
1
u/techretort Jul 20 '26
In my experience they escalate it to the ops team and ask why it's failing - usually without reading the logs that say it's failing for XYZ reason.
Source - am sysops
1
u/db720 Jul 20 '26
"it works on my machine" overrule the failure, push to prod.
Well thats what a few devs I've worked with would want to do.
Typically work through an rca sort of process. Foes the test have any data involved? What environmental factors affect the test..
I've had some that have taken quite a bit of time to figure out. Data, tz settings, env var, kernel settings have been a few places. More often than not, the test failure would have caused an intermittent bug in prod (ci hosts are closer to prod than dev machines), so tend to value ci failures over local runs
1
u/dager003 Jul 21 '26
the log-statements-and-compare-environments loop is exactly the thing that made me build something. it's not that CI shouldn't gate — it should, "doesn't ship till green" is correct — it's that figuring out WHY it's red is the part that eats an hour.
what helped me was realizing most of these failures fall into like 4-5 buckets and you can tell them apart from evidence without reproducing locally. did a dep version change vs the last green run? (someone above nailed the stale-base-image case). is the failing test in a file your diff even touched, or is it in some module you never went near? did the same test just pass on a rerun of the identical commit — that's a flake, not you. is it a runner/OOM/network thing — also not you.
so instead of debugging, i just classify it and say which bucket + show the evidence, and auto-rerun the ones that are provably not the code's fault. no llm guessing, just rules you can audit. it can't touch your code so there's no "made it green dishonestly" risk.
couple public PRs if you want to see it call each bucket: github.com/chaturvediabhinav692-lgtm/koredex-gauntlet/pulls — curious if the "is the failing file even in your diff" check would've saved you any of those push-tweak-push rounds
1
u/DevOps-Op Jul 22 '26
honestly my first move now is to just re-run only the failing test by itself in ci before i touch anything else. if it passes on its own but dies in the full run, that's not your env, that's some other test leaving crap behind. had one last year where a test like three files earlier wasn't rolling back a db row, and everything after it that assumed a clean table fell over, but only in ci because it ran them in a different order than my laptop did. took me embarrassingly long to stop squinting at env vars and realise it was that.
re the debugger thing, i dunno. by the time i'd actually get attached the run's usually already dead, and the ones that ruin my afternoon are the flaky ones that won't even fire again on a rerun. what i'd actually kill for is just the seed and the test order it ran with so i can replay the exact thing locally. a live poke at a run that might not repro doesn't do much for me. does yours give you that, or is it more the live-view thing?
1
u/Commercial-Virus2627 Jul 22 '26
“Works on my machine” in the merge request. 🤷♂️
0
u/[deleted] Jul 19 '26
[deleted] — view deleted comment
4
u/[deleted] Jul 19 '26
[removed] — view removed comment
1
u/[deleted] Jul 20 '26
[removed] — view removed comment