It is heavily raining in Springfield, and Homer's roof is leaking, so Homer takes the only sensible course of action; he heads off to Moe's Tavern. However, he spoils a surprise party for Lenny, and makes it worse when the barstool he sits on turns to be a cake in the shape of Lenny's favorite seat, so Homer gets tossed out by Moe. Homer ends up at Knockers, where he meets a fellow loner (voiced by Ray Romano), who turns out to be a roofer. However, no one but Homer ever seems to be able to see Ray - not even Bart, who was in the home repair warehouse with the pair - so Marge and Dr. Hibbert have declared Homer insane.
Springfield becomes the target of a powerful thunderstorm and 742 Evergreen Terrace appears to be the main target, suffering a leak in the roof. Homer plans to use a Hot Wheels track to stop the leak (by causing the leaking water in his and Marge's bedroom to flow out through the letter slot on the front door); however, Lisa's hamster falls victim to the chute and is sent out the letter slot before he can be rescued. Lisa has to open the door to get her hamster (in the process, causing the Hot Wheels track to break); although the hamster is safely rescued, he is sick with a cold. Lisa reveals that he was the subject of her show and tell project, which will now not happen due to his cold. The leak also affects Bart's plans for his (uncharacteristic) homework party, ruins Maggie's teddy bear and soaks Snowball's litter box, causing him to fall into quicksand. Dejected, Homer then goes to Moe's Tavern, but even there, trouble follows him; he ruins a surprise party for Lenny (even though his 'ruining' it involved repeating what Moe said just seconds before right before Lenny walks in, and sitting on a cake (that, bizarrely, looks exactly like a bar stool) which is sitting on the floor, not the counter) and is kicked out but not before Moe scrapes the frosting off Homer's butt. Homer then goes to a bar named Knockers (a parody of Hooters); there, he meets a roofer named Ray Magini. After much banter, and eating nachos and drinking beer with Homer, Ray agrees to fix the Simpsons' roof the following day, while the kids go to visit Grampa with Marge.
Ray comes over to fix the roof, as soon as the rest of the family leaves; however, rather than fixing the roof, he and Homer goof off and have a nail fight with nail guns. The nails then hit Ned Flanders riding on his lawnmower, bursting all its tires. Homer then asks Ned if he has met Ray, but Ned does not seem to know him. Ray then has to leave when he finds out his child attempted "something" on his pager, and Homer is on the roof alone; he then falls through the hole, making it bigger.
Marge then comes back to find Homer doing nothing; they then have a discussion about Ray, and Marge simply says Ray is non-existent, as he is never in the same place as she is. Homer is then shown sitting on the roof, waiting for Ray to come, while Marge tries to get Homer to believe Ray is a figment of his imagination, after failing to convince Homer that it is too late in the day for anybody to come and do work. Moreover, the name 'Ray Magini' is also an anagram of "imaginary" as demonstrated by Lisa, leading Homer to believe that Ray is indeed not real. The next day, still disbelieving the Ray issue, Marge sends Homer and Bart to Builders' Barn to get roofing supplies; there, Homer sees Ray again and talks to him, but Bart only sees Homer talking to himself.
After Homer falls off the roof talking about Ray, Marge takes him to the Calmwood Mental Hospital, where Dr. Hibbert tells Homer that Ray is a figment of his imagination he created because he was lonely and needed a friend. Homer then spends six weeks at the hospital receiving electric shock treatment, to cure him of this 'mental breakdown'. After the six weeks have elapsed, Marge returns with a little surprise—Ray. It turns out that Ray is real, and that Homer was right all along. Moreover, there were plausible explanations for why nobody else saw him: the bartender at Knockers had an eyepatch and could only see Homer's side of the table, Ray was hiding behind the chimney when he saw Flanders, and a localized black hole at Builders' Barn absorbed the light between Bart and Ray, preventing Bart from seeing him, explained by Stephen Hawking. When Marge questions Ray about his constant disappearances at unorthodox times, he explains this is because he is a contractor, to which Marge jokingly replies "you're all crooks!". However, as punishment for making him spend time in the mental asylum for no good reason, Homer forces Dr. Hibbert to fix the roof, while Homer and Ray drink beer and watch Hibbert work.
In the meantime, Marge and Lisa visit the Springfield Retirement Castle and they see how miserable the old people initially are. They then see how happy they are with Santa's Little Helper's company and let him stay there for a while, but a day later, he has become just as old and miserable as the seniors.
Behind the Laughter
Although it was advertised as the 350th episode, it is not the actual 350th episode (see "The Heartbroke Kid" and "Future-Drama").