Spoiler alert: This story contains details from Sunday's series finale of HBO's "Silicon Valley."
The critically acclaimed HBO comedy chronicling the rise and fall and rise again of a tech startup finished its six-season roller-coaster ride in fitting fashion Sunday, with a giant achievement, a bigger reversal, oodles of self-inflicted humiliation and hundreds of swarming rodents.
The 48-minute finale toggles between the present and 10 years into the future, as the older, wiser characters contemplate what happened to their company, Pied Piper, and their own lives.
As the episode opens, the gang celebrates its creation of the world's greatest digital network, a supreme accomplishment designed to make the world a better place while yielding billions of dollars in profits. And then ...
It's the motherboard of all catastrophes, as CEO Richard Hendricks (Thomas Middleditch) discovers their invention is so smart and powerful that it will destroy encryption, eventually eliminating all privacy and jeopardizing the security of electrical grids, banks and nuclear codes. This budding Skynet would destroy society.
As Gilfoyle (Martin Starr), Richard's mordantly misanthropic lieutenant, puts it in signature monotone: "We built a monster. We need to kill it."
To save the world, Richard's crew must concoct an epic fail, one so humiliating that no one will ever try to resurrect their doomsday code.
"It seemed like a good objective for the finale. It's about 'How do you define success?' In this case, success is not destroying the world," says executive producer Alec Berg, who wrote and directed the episode.
Middleditch, a master of awkwardness and angst as man-child genius Richard, loves the characters' predicament.
"The show is equal parts about failure (and) success. As the characters (said), they're going to succeed at failing. To do that to the thing you've dedicated your life to is the ultimate falling on one's sword," he says.
The Pied Piper public failure takes place at the launch event with network partner AT&T (which happens to own HBO), as Richard and Gilfoyle substitute destructive code.
Subordinates who aren't in on the plan detect the substitution and switch back to the doomsday code. That leads to an action-movie-style climax in which reluctant Pied Piper exec Dinesh (Kumail Nanjiani), who so wanted to be a billionaire, rushes to a node connection at the top of a skyscraper to reverse that change at the last second. He's winded, of course; this isn't "Mission: Impossible."
And then … the rats arrive. The corrupted code creates an ultrasonic sound that causes rats to swarm across the country, including a pack that pours down the steps of the launch auditorium, leading to a frenzied evacuation.
"That it pays off in an actual depiction of the Pied Piper fable … was an incredible stroke of genius," Middleditch says.
The debacle sparks a wave of celebrity cameos: Conan O'Brien jokes about it in a late-night monologue; CNBC's Jim Cramer pillories the AT&T deal; and tech columnist Kara Swisher consigns the company to the trash bin with Theranos, Pets.com and WeWork.
But the biggest get is tech titan Gates, who can only express bafflement with the Pied Piper crash in a documentary-style interview: "It’s weird. It really seemed like Pied Piper was going to work. Something doesn’t add up."
The Gates appearance "worked out perfectly. He was actually a really good actor," says executive producer Mike Judge, who says the show tried to recruit Facebook's Mark Zuckerberg and Sheryl Sandberg earlier in its run. "It was pretty amazing to have Bill Gates in it. Somebody had asked me around Season 2, 'If you could get anybody in the show …?' and I just threw out, 'Bill Gates.' We finally got (him)."
Ten years after their digital disaster, the characters reunite for a documentary, and almost all have survived in decent shape, if not as Masters of the Universe.
Richard is now a Stanford University professor, thanks to his oblivious friend, Big Head (Josh Brener), who once again has risen above his abilities to become the university's president.
Ever-bickering Gilfoyle and Dinesh are neighbors and partners in their own tech company and still behaving like an old married couple. Chief financial officer Monica (Amanda Crew) apparently works for the National Security Agency, but won't cop to it. And sweet, disturbed Jared (Zach Woods) now cares for the elderly. (The show also honors Christopher Evan Welch, who died during first-season filming, with a tribute to his character, investor Peter Gregory.)
"Silicon" hints at a cameo by T.J. Miller, who left the show abruptly after Season 4, but a documentary crew's search through an Asian jungle for his character, blowhard investor Erlich Bachman, yields only his enemy, Jian Yang (Jimmy O. Yang), who may have killed Erlich.
"We just liked doing the mislead. It was a tease," Judge says. "It's funny that you don't know exactly what happened, but somehow Jian Yang got all of Erlich's money."
As the finale closes, Richard tells his interviewer that he still has one copy of the Pied Piper super code, but true to form, he can't find the thumb drive that holds it. Does that mean the gang might return to destroy and then save the world again?
"I'd be open to it," Berg says. "I love working with the guys. Nobody died in the finale – well, we don't know that for sure – but they're all around. So who knows?"
Middleditch is open to revisiting the tech band, but "I'm really happy with how it ended. Series finales are tough and this one was so satisfying. Where Richard ends up in a classic 'Silicon Valley' bittersweet ending is perfect."
This article originally appeared on USA TODAY: 'Silicon Valley' finale: Star Thomas Middleditch on how it all ended