Like so many nightmare scenarios in modern life, Central Intelligence begins with a Facebook friend request.

In high school, Calvin Joyner (Kevin Hart) was voted Most Likely to Succeed. He did not; the day before his 20-year reunion, he works as a low-level accountant. Too embarrassed and frustrated by the way his life has turned out (despite his relatively happy marriage to his high-school girlfriend Maggie, played by Danielle Nicolet), he’s decided to skip the reunion. That’s when the friend request arrives, from someone named Bob Stone. Calvin doesn’t know any Bob Stones, but he reluctantly accepts the friend request anyway. It turns out Bob Stone is actually Robert Weirdicht (say it out loud), who was involved in a horrific bullying incident back in high school.

Chubby and a little weird, Robert was yanked out of the shower and tossed, completely naked, into the middle of a school assembly, where the entire student body laughed at his entire student body. (Teenage Robert is played by a real guy with CGI face replacement, which makes the whole scenario even more terrifying.) The only person who took pity on Bob was Calvin, who helped him up and offered him his letter jacket. Robert never came back to school; Calvin never saw him again. When he returns 20 years later, his name is Stone, he looks like the Rock (because he’s played by Dwayne Johnson), and he works for the CIA. The secret of his metamorphosis? “I worked out for six hours a day, six days a week, for 20 years.” Oh. Well then.

These are the makings of a very good, very awkward comedy about getting older and coping with life’s expectations and disappointments. But for all the conflict between Hart and Johnson during their subsequent spy misadventures, their tension pales in comparison to the tension in the actual film between the generic and forgettable buddy action flick that springs from Calvin and Bob’s reunion and the more interesting story about their shared past and sad present that keeps trying to come to the surface.

Sometimes it does, and those are the best moments in Central Intelligence, when Hart can channel his manic energy into Calvin’s sense of discomfort with Bob’s return (and successful reinvention) and Johnson gets to showcase his offbeat comic timing in Bob’s peculiar personality traits. (He’s a fan of unicorns, or as he puts it, “I’m big time in the ’corns!”) 20 years later, Bob’s come back into Calvin’s life because he needs his accounting skills to help solve a CIA case involving foreign bank accounts and stolen government secrets, but he also seems a little obsessed with his former savior — maybe even in love with him.

But any time Central Intelligence gets a little too personal, comes close to these men’s true feelings about one another, it retreats into its espionage plot, which also involves Amy Ryan as a no-nonsense CIA agent and Aaron Paul as Bob’s former partner. Maybe the spy stuff would feel more welcome if it made any sense at all — but it doesn’t. (Not even a real CIA agent could make sense of this convoluted conspiracy.) It doesn’t help that the movie’s director, Rawson Marshall Thurber (DodgeballWe’re the Millers), is a comedy guy, not an action guy, which means the shootouts and chases that pop up every 15 minutes run the gamut from inoffensive to incomprehensible. This is a much better comedy than it is an action movie.

In isolated sequences, it’s a very good comedy. There are several surprise cameos that haven’t been advertised in any of the movie’s trailers, and they all nail their supporting roles. (One plays Bob’s high-school bully as an adult; another plays his unrequited crush.) More importantly, Johnson and Hart are a perfect buddy duo, and they pull the movie through its roughest moments. Johnson is so much bigger than Hart that he looks like the Incredible Hulk to Hart’s Bruce Banner, as if Bob’s the living embodiment of Calvin’s repressed id that’s been stifled all these years. Their temperaments mesh well too; Calvin’s constantly complaining about something, and Bob can’t stop flashing his movie-star smile. Their relationship feels genuine, even if Thurber and co-screenwriters Ike Barinholtz and Davis Stassen keep pushing their personal stories to the background to make room for more mediocre action. If there’s any justice in the world, this will be the first of many Johnson and Hart movies. (“Johnson and Hart” even sounds like a classic comedy duo.)

The film only hits one truly sour note. Bob’s story is all about the lingering trauma from getting picked on in high school, and Central Intelligence’s anti-bullying theme gives the film the sort of heart and sweetness that’s rare in macho action movies. But that theme is undercut by several tasteless gags, including occasional homophobic moments between the heroes (Calvin freaks out when Bob gives him an innocent peck on the lips as part of an elaborate ruse) and a really tacky joke about Koreans. A character onscreen calls out the Korean joke as offensive, and they’re right. But it’s still in the movie. And these moments make the movie’s otherwise sincere message about embracing difference and loving yourself for who really you are feel a little bit disingenuous. (They also suggest the Lonely Island was really onto something with Popstar’s “Equal Rights” song.)

Those scenes stand out so starkly because the rest of Central Intelligence is so fun and so warm. Calvin and Bob are generally good guys, and they like each other. We like them too. Possibly even more than the movie they’re in.