Knight at Arms
Thank you Duh.I don't think the friendly is trying to attack the player, probably "just" having trouble moving correctly. This may benefit from the upcoming ai movement changes.
I believe there was also a recent change to ranged enemies to improve their melee engagement of nearby enemies.
Edith: Just in case - the relevant developers are also looking at the cavalry targeting, though, that is still work in progress.
I was not sure about the friendly troop (that's why I put a question mark).
The behavior of the ranged units during sieges clearly improved over the last big patches, but yeah, those guys just ignoring you is kinda disturbing (nobody likes to be ignored).
Good luck to the devs who have to deal with the AI during battles, looks nightmarish to code...