What intermittent dirty dishes actually tell you
Here's the useful part: a dishwasher that fails randomly is giving you a clue. If it were a dead pump or a burned-out element, every load would come out dirty. It doesn't.
That means something is marginal. It works when conditions are easy and chokes when they're not. Your job is to find the variable.
The big three variables are water flow (blocked by a dirty filter or clogged spray jets), water temperature (too cool to dissolve detergent), and load geometry (dishes blocking the spray).
Almost every intermittent case Techs have seen traces back to one of those. The good news is all three are cheap or free to fix yourself.
The most likely culprits, in order
Start with the filter. It sits in the floor of the tub, usually a twist-out cylinder. Pull it and look. If you see a gray paste of food and grease, that's your answer more often than not.
A clogged filter starves the pump of clean water to recirculate. Light loads don't produce enough debris to matter. Heavy loads do, and that's when dishes come out gritty.
Next, the spray arms. Each little jet can plug with a seed, a scale flake, or a chunk of label. When half the holes are blocked, the water can't reach the top rack or the back corner.
Spin them by hand. They should turn with almost no resistance. If one drags or stops, water pressure alone won't move it during a cycle, and whole sections of the rack get missed.
Water temperature is the sneaky one. Detergent enzymes need around 120F to work. If your heater is set to 110F or the first fill draws cold pipe water, the wash runs weak and nobody suspects it.
Then there's loading. I've watched people wedge a sheet pan across the bottom rack that blocks the lower arm completely. The dishes above it never get washed. It looks fine until you unload.