A lot of stays fall apart not because a dog doesn't understand the cue, but because duration, distance, and distraction were all trained at once from day one, and no dog can generalize that fast.
The three variables
Every stay is really three separate skills layered together: how long your dog holds position, how far you can move away, and how much distraction is present while they hold it. Training all three at full difficulty simultaneously — a long stay, far away, next to another dog — sets your dog up to fail even if they've technically learned the word "stay."
Train one variable at a time
Start by holding two variables at their easiest setting while you build the third. Increase duration first, with you standing close and no distraction, adding a few seconds at a time. Once duration is solid, reset it to something easy and start building distance instead, staying close in time but stepping further away. Do the same for distraction last, since it's usually the hardest variable for most dogs.
Don't build on failure
If your dog breaks the stay, that's information: you asked for more than the current combination of variables could support. Rather than repeating the same difficulty and hoping for a different result, drop back to the last point your dog succeeded and rebuild from there more gradually.
Use a clear release cue
A stay needs an equally clear ending as it does a beginning. Pick one consistent release word and use it every single time, rather than letting your dog decide when the stay is over — a dog who releases themselves has actually learned "stay until I feel like moving," not the cue itself.
A realistic training order
Most dogs progress fastest through roughly this sequence: short duration close by, then longer duration close by, then short duration at a distance, then combining moderate versions of all three, and only then adding real-world distraction. It's slower than trying to rush a park-ready stay in one session, but it holds up far better once you get there.
If you're working through a stay with a dog who has a history of anxiety or resource guarding around being restrained, it's worth mentioning to a trainer directly — not every dog should be pushed through duration work the same way.