It has happened to me long long time ago around 2018 when I was ganking miners.
Yes AG cannot know which ship you going to target unless they already know you, your target selection and whats on the grid. For example I was ganking hulks and mackinaws almost exclusively, so the smart AG would know that I will going to target this lone Hulk inside crowd of Covetors on this belt.
I was also multiboxing just 2 + scout/looter so then if the Hulk has been anti-gank tanked and there was cloaked T3C that oneshotted my cat, then I would fail.
That being said, 99% of my gank failures ever were caused either by miscalculating the required DPS - not bringing enough to break the tank in case it was tanked exclusively to survive the usual 2man (back at that time or 5 man today) gank. Which was a risk I deliberately chose to take. Or by some action performed by the victim. That included victim orbiting and me not realizing it, victim having stabs and me not having or activating scrambler on other ships (fast enough), victim pre-spawning CONCORD and me not noticing it, victim swapping their Hulk for anti-gank procurer stored in nearby Orca, remote reps on victim’s multiboxed Orca, victim simply burning away with afterburned and me not noticing that and staying still after arrival, or victim moving away a few km from the time I made a combat probe scan and me not noticing that or deciding to try it regardless because I already spent too much time getting there/etc. and then failing from any of the above reasons.
And of course multiple possible errors in my gank execution that can happen - me losing one ship on the way due to bug at gate and me not noticing it or simply being too slow and then deciding to still try it regardless and then fail, or not activating guns at any of my client for whatever reason, or shooting wrong target with one of my clients etc.
I failed gank due to AG (counting only ganks I did myself, not ganks where I was +1) was when I was ganking ventures (because I was alpha back then) in Minmatar and Knowledgeminer was cloaked there in his T3C oneshotting or just preventing me to shoot. I really don’t recall any other case where I would fail due to AG, not that they didn’t try although there weren’t that many attempts - often they simply thought that when they field a “response fleet” I will go elsewhere, but I didn’t and I still managed to pull it off.
Oh and I should note that I didn’t count activating killright. Sure I lost several mallers and sometimes even thrashers, but since that was mostly done by KM whowers or random party and not clearly someone with AG agenda, does it really count?
EDIT: now I actually remember that I ocassionally lost a trasher to NEPF- around Jita when getting bored and roaming around with criminal -10 char and trying to kill a random autopilotting pod or venture mining. Not much a nuisance, but I should definitely credit them this small win. Unfortunately, that never really resulted in anything other than delaying the ineviable, I still found some pod or venture minutes later as I immediatelly undocked from Jita with new trasher again and avoided the said ag.