Probably also due to the fact that he purged the military in 1937, sending some of the best officers to rot in gulag, and demoralizing the rest, and the fact that he honestly thought Hitler was his best bud and would never ever attack him, so he didn’t plan.
I once knew a man who lived in a small Polish village in the Russian-occupied side. The Soviet officer allowed German officers to walk through their positions freely. They took notes, made plans, and then attacked all the weak points and just rolled the Soviets up. My elderly friend escaped on horseback and fought in the woods as a partisan. He was 13 at the time.
I think Stalin knew eventually there would be war with Germany....but he had hoped it would have occurred after the Germans got bogged down in the West....one little problem.....France fell in six weeks. Then Stalin desperately tried to buy time by placating the Germans, while trying to build up his military...but Hitler beat him to the punch.