I'm reminded of a story that's about motorcycling, but has some application here. A rider is in accident, cut off by a left-turning motorist. His friend stops, and as the friend approaches his injured comrade repeats over and over: "I knew that guy was going to turn in front of me! I knew it, I knew it, I knew it." And the friend replies, "well, if you knew it, why did you keep going?"
The point is that when it comes to safety on a bike trail, a dark street, or whatever, sometimes pride can keep us going when it makes perfect sense just to turn around. As I've mentioned on other threads, I think it perfectly appropriate to think seriously about violent self-defense, and even to carry weapons where that is legally allowed. But the lion's share of safety comes from avoiding problems.
I'm not a small guy. I've had a lot of self-defense training and where I can I'll carry weapons when I ride. But if I see even some adolescent who looks like he's a lookout somewhere ahead of me, I'll just stop and turn around. Yes, it may look silly, it may even seem demeaning. The kids may even get some satisfaction out of it. But if I know there's a dodgy character ahead, and some chance of an encounter, why would I keep going? Why wouldn't I avoid that? If turning around avoids a violent encounter it's almost always worth it. And whatever else is true this kind of thing communicates to prospective attackers that you're alert, which is never a bad thing.
Yes, call the cops afterward, and if you think you can do it safely bring a camera if you want. But avoidance has a lot to be said for it, more even than having the right body language when you ride through a group of violent kids or whatever. Something to think about.