Animals in a pen will start pathfinding towards open fence gates, even if they are not being led with the appropriate food type. This makes it very time-consuming and difficult to sort mobs properly as random animal mobs will pathfind through the fence gates that have been opened to let a wanted animal type through. It would be a lot simpler if animal pathfinding through open gates was turned off and only turns on if the animal mob is being led with the appropriate food type for that animal.
Note: Animal movement in pens really needs a complete overhaul, and I need a food type that would only lead sheep so I could separate them from cows, but this random pathfinding behavior of the animals I'm not leading towards fence gates is very annoying, especially if there are large groups of animals.
Also related to this issue is the fact that I have noticed that only a few pigs will be able to make it through double fence gates and that other pigs trying to follow carrots will suddenly get stuck on the fence instead and not pathfind properly towards the fence gate. Perhaps this is an issue with too many other mobs trying to pathfind at the same time towards an opening, which is the only reason I mention it in this issue report. The pigs appear to get stuck "into" the fence, like they've suddenly been captured by the fence instead of pathfinding towards an open gate in it. Possibly this is a bounding box issue with pigs and fences, if so please let me know so I can report it as a separate issue.