r/devops • • 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

40 comments sorted by

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 :)

1

u/basvandriel Jul 19 '26

Yes, the first. I find myself inserting log statements and comparing environments which can be painful. Do you experience the same?

3

u/bilingual-german Jul 19 '26

A lot depends on what kind of code it is and how it differs from when you run it on you development environment. That's why all environment, including CI should be as similar as possible.

If your integration tests fail in CI, it might be because of network issues (e.g. containers aren't up, CI worker IP is not allowed in firewalls yet) or permissions (e.g. cloud iam roles for service accounts missing).

When unit tests fail, maybe something on the filesystem is different, e.g. is some folder missing or is the filesystem it case sensitive (Mac filesystems are not case sensitive, Linux filesystems are)?

Usually you would deploy your app in containers, so running your tests locally in containers would be something I would try at first. This should clear some of the assumptions.

1

u/Blunap0 Jul 19 '26

Yeah that's a way. We've also had some luck trying to run tests in an isolated constrained container locally until we can reproduce the error if the environments differ on resources or to more likely reproduce race conditions. But ultimately I do find myself doing trial and error. Curious what others think.

1

u/techretort Jul 20 '26

Did it work before? What changes did you make in this release? And what errors are shown?

Work back from there if you can. Or do like my Devs and just spam the ticket system with requests from the ops teams

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

1

u/hegde10122 Sep 07 '26

What kind of steps u take to resolve such errors. Do you escalate to developer

1

u/blueghosts Sep 07 '26

They're set at the PR level, PR doesn't complete until the build is fixed, developer's problem until the code is checked in. They get notifications for build statuses etc

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/basvandriel Jul 20 '26

Yes, I totally agree. Your split between dependency drift and state/timing issues matches exactly what I keep seeing.

I run into this problem myself quite often — restarting the pipeline, tweaking something locally, pushing again, few rounds of that. I'm now exploring whether it's worth building something that lets you attach a debugger directly to the remote process, e.g. the actual CI run. Would something like that actually change your way of working, or does reproducing the constraint locally (like you describe) basically cover it?

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/basvandriel Jul 20 '26

Yeah, that's classic. Had the same stuff. Pretty painful since locally it never reproduces. How do you usually track down where the missing 'order by' is? Log statements, or something smarter?

I'm asking because I'm exploring whether attaching a debugger to the actual CI run would help for exactly this class of bug. Would this help for you?

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:

  1. Save the exact failing job metadata: commit SHA, runner image, language/runtime versions, dependency cache key, env vars that are safe to print, database/service versions, test seed, timezone, locale, CPU/memory limits, and parallelism settings.
  2. Re-run the single failing test in CI once with max verbosity and no dependency/build cache. If it passes, mark it as flaky and keep investigating; do not just merge.
  3. Reproduce the CI constraints locally, not just the command: fresh clone, clean dependency install from lockfile, same container image, same test shard, same env, same TZ/locale, same CPU count if possible.
  4. Look for the usual hidden differences: filesystem case sensitivity, test order, shared fixtures, clock/timezone, random seeds, network/service readiness, permissions, missing files not committed, stale generated code, and unordered DB queries.
  5. If still not reproducible, add diagnostics that explain state rather than just "got here" logs: print resolved dependency versions, paths, config source, DB migration version, feature flags, and external service endpoints.
  6. Once fixed, keep the reproducer as a regression: pinned test seed, explicit ordering, containerized integration test, or a preflight check that fails with a useful message.

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.

1

u/basvandriel Jul 20 '26

Thanks! I totally agree with your sequence. Especially the 'diagnostics that explain state rather than got-here logs' part. That step is basically manual debugging through print statements.

I'm validating whether it's worth building something that lets you attach an actual debugger to the CI run or any other remote process— would that replace parts or improve this for you, or does the metadata/repro approach cover it once it's this systematic?

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

2

u/forever-butlerian Solaris 8 Enjoyer Jul 20 '26

it's always DNS

4

u/[deleted] Jul 19 '26

[removed] — view removed comment

2

u/forever-butlerian Solaris 8 Enjoyer Jul 20 '26

I don't always test my code, but when I do, I test it in production.

1

u/[deleted] Jul 20 '26

[removed] — view removed comment

1

u/basvandriel Jul 20 '26

Thanks. Yeah, I feel system divergence is also one of the biggest problems.

I'm exploring whether building a tool for attaching a debugger to the actual CI run or any other remote process would help for exactly this. Would this help for you?