Like so many classic Western anti-heroes before him, he rolled (literally) into town with a singular goal in mind: cleaning up the streets, which had become a gritty hotbed of harassment, vandalism, break-ins and grift.

The only difference was that he was a slow-moving, 400-pound robot with a penchant for snapping hundreds of photos a minute without people’s permission, and this was San Francisco’s Mission District in 2017.

What could go wrong? Quite a bit, as it turns out.

In the past month, his first on the job, “K-9” — a 5-foot-tall, 3-foot-wide K5 Autonomous Data Machine that can be rented for $6 an hour from Silicon Valley startup Knightscope — was battered with barbecue sauce, allegedly smeared with feces, covered by a tarp and nearly toppled by an attacker.

As if those incidents weren’t bad enough, K-9 was also accused of discriminating against homeless people who had taken up refuge on the sidewalks he was assigned to patrol. It was those troubling allegations, which went viral this week, that sparked public outrage and prompted K-9’s employers — the San Francisco chapter of the animal rescue group SPCA — to pull the plug on their newly minted robot security pilot program.