Don't Fear the Roofer is the sixteenth episode of the Season 16.
It is 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 Homer declared insane.
Springfield becomes the target of a powerful thunderstorm and 742 Evergreen Terrace appears to be the main target and causes a leak in the roof. Homer plans to use a "Hot Wheels" track to stop the leak but Lisa's hamster goes down the chute and goes out the door via the mail slot and then Lisa has to open it to get her hamster and then he gets sick as he was the subject of Lisa's show and tell project. The leak also affects Bart cracks for his homework party and Maggie's teddy bear and causes Snowball to fall in quicksand which was his litter box wetted by rain. Homer then goes to Moe's Tavern but there he ruins a surprise party for Lenny (even though his 'ruining' it involved repeating what Moe said seconds before right before Lenny walks in, and sitting on a cake that looks exactly like a bar stool that is sitting on the floor not the counter) and is kicked out. Homer then goes to a bar named Knockers a parody of "Hooters" and there he meets a roofer named Ray Magini. Ray agrees to fix Homer's roof and while the kids go to visit Grandpa with Marge. Ray comes over to fix the roof, However, rather than fixing the roof the two goof offs and have a nail fight. The nails then hit Ned Flanders riding on his lawn mower. Homer then asks Ned if he met Ray but Ned does not seem to be sociable with Ray. Ray then has to leave when he finds out his child attempted "something" and Homer is on the roof alone and then falls through the hole.
Marge then comes back to find Homer doing nothing and Homer and Marge then have a discussion about Ray and Marge simply says Ray is non-existent. Homer is then sitting on the roof waiting for Ray to come while Marge tries to get Homer to believe Ray is a figment of his imagination. Ray Magini is also an anagram of "imaginary", leading Homer to believe that Ray was indeed not real. The next day Marge sends Homer and Bart to Builders' Barn and there Homer sees Ray however Bart only sees Homer talking to himself. The next day Marge takes Homer to the Calmwood Mental Hospital and 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. After the six weeks Marge returns with a little surprise—Ray. It turns out that Ray was real and Homer was right all along. 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 absorbed the light between Bart and Ray preventing Bart from seeing him, explained by Stephen Hawking and as for why Ray kept disappearing is because he is a contractor. However, as punishment for making Homer spend time in the mental asylum for no reason, Homer forces Dr. Hibbert to fix the roof while Homer and Ray sit on it drinking beer together.
In the meantime Marge and Lisa, visit the Retirement Castle and they see how miserable the old people are and then they 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.