On the third flight of SpaceX's Falcon 1, the following failure occurred according to one narrative.
We turned off the first-stage engine and then proceeded to separate the vehicle stages; however, when the stages uncoupled, there was still a little leftover "kick," or thrust, in the first-stage engine. Our first stage literally rear-ended our second stage immediately after we had tried to separate the two sections of the vehicle. It was a devastating, emotional experience.
Sounds logical. You wouldn't want to wait until your prior stage fully putters out completely before separating because (among other things) you'll lose altitude. Ideally, you'd want to be delivering as much thrust as possible as constantly as possible, and that might entail having some kick left in the prior stage.
In the general sense (not specific to SpaceX), how is this avoided in vertically staged rockets?