I think that is exactly what was going through Stalin's mind. He would be aware of the Tripartite Pact that Japan had signed, so he would never be 100% sure which way Japan would jump in honoring its treaty obligations
The Pact did not require another member to go to war if the first member was the one who attacked and started the war. Therefore, Japan was under no obligation to go to Hitler's aid when he invaded the USSR. Likewise, Hitler had no obligation to declare war on the US when the Japanese bombed Pearl Harbor.
What isn't commonly known is that the Japanese got and received assurances that if they did go to war with the US Hitler would do the same. Mind you, Der Fuhrer didn't know precisely when and how (or, technically, whether they would) the Japanese would attack so the bombing of Pearl Harbor was a surprise to him. However, the Germans were chomping at the bit to go to war with the US due to its interference in the Battle of the Atlantic where the US was already a belligerent in all but name. The German Navy had thus been advocating for war with the US for some time. The Japanese attack just proved a good excuse to do so. It also gave Hitler the false impression that gaining such a powerful naval fleet on his side - the lack of a proper navy being the one "big" weakness he saw in Germany's armed forces - "guaranteed" the Axis couldn't lose.
Of course, declaring war against the US was in fact the final nail in the coffin which only guaranteed that the Axis
would lose. However, at the time it was the German assurance of assistance that was the final factor in convincing the Japanese Empire to go to war. Previously, they had planned on doing so only after the US had left the Philippines in 1946, but in the face of the apparent sure victory of Nazi Germany in Russia the Japanese government wanted to strike when the situation seemed ideal (and before the US oil embargo forced Japan into a humiliating back down).
Ironically, if it had just waited another two weeks after the Russian counterattack in front of Moscow that practically broke the back of the German forces (yes, for a while there it was that serious) they might have pulled back from the brink. Probably not, however, since launching a war against the
vast economic superiority of the US was in any scenario tantamount to an act of national suicide (basically, if you want to know the moment Japan lost WW2 it was when the first bomb fell on Pearl Harbor).