Like Rob stated, you should never allow your horse to swing sideways or turn backwards while being in the hole (gate). If you are sideways, not facing the cattle, it is very easy for trash (strays) to slip past your horse's hip through the opening. You also have to be in position where your horse can freely move from side to side and foward towards the cattle.
In the situation you described a few things sound like the went wrong. But the biggest was lack of communication not who did what. It is the responsibilty of the sorter pushing the cow to first pull clean and second to be aware of where the other cattle are. Sounds like your team mate did not realize that there was trash coming up the other side at you, that they were focused on the cattle they were pushing. As well, when you are pulling and have a dirty, you need to make every attempt to sort that dirty off before you get to the gate not depend on your team mate in the hole to stop the trash. Until you are clean you do not push hard towards the gate. As the sorter you should also tell your partner which is the good cow as it is dificult to read a number on a cow facing directly towards you.
In your situation, in the hole with cattle coming from both sides, I say before you even make a move you need to let your partner know they need to pull up. Unless you are on an experienced cow horse the chances that you can stop the trash on one side and make the dive back to face the cattle being pushed towards you by your partner is very slim. Even on an experienced horse this is a very difficult move to make if the catle are coming with any speed. So basically you should tell your partner to pull up, quit pushing, as you stop the trash coming from the other side then swing back to face your partner and the cattle they are pushing, keeping your focus fully on the trash (strays). Your partner should, pull up and allow you the time needed and if unable to slow down the cattle in front of them help you in the hole then take all the cattle back and pull again. Never leave trash at the gate and if at all possible never sort at the gate.
Hope this makes sense. Lol The team made the mistake, not one or the other.