I agree, think stuff like the Leningrad Affair was incredibly stupid on Stalin's part. Like bruh you're gonna die soon anyway maybe don't purge thousands of your most popular cadres? Those guys would have been useful a few decades down the road.
Party should have thanked Stalin for his service throughout the 30s and 40s and then forcibly retired him post war in favor of Malenkov. Instead they let his brain melt which gave the Khrushchevites an opportunity to trash his entire legacy for a little temporary popular support, all while compromising the greater ideological project.
Hindsight is 20/20 and all though, and sticking with Stalin till death for stability's sake probably looked like the best option at the time after the most destructive war in human history