Japan was faced with a choice in 1940: attack the Soviet Union in an escalation of the border clashes, or attack south to capture the Indonesian oil fields and Indochina rubber plantations (rubber for vehicle tires was definitely a strategic material) in response to the US and Britain cutting off fuel sales to Japan, which threatened their ability to wage war. And attack east to disable the US Pacific fleet, so it couldn't interfere.
This was the fateful decision to throw in with the Axis powers, but also sign a neutrality pact with the Soviet Union, which worked to the advantage of both countries... at that time. Japan had done poorly in the border clashes with Soviet forces (commanded by a fast rising Georgi Zhukov), and there weren't really any strategic materials to be had by taking eastern Russia, while the Soviets were reeling from the initial German attack and only too happy to free up most of the troops on the eastern front.
One of the key individuals in this situation was Soviet spy Richard Sorge. Masquerading as a German journalist, Sorge kept the Soviet Union appraised of Japan's intentions during the initial German invasion of the Soviet Union, allowing the Soviets to focus almost all of their troops against Germany when Sorge reported that Japan had no intention of attacking northward, and that the border clashes had been largely a matter of over zealous local commanders and not policy dictated from Tokyo.
Sorge was unmasked late in 1941, and executed by the Japanese in 1944.
In short, Japan didn't go with a war against the Soviet Union in the early 1940's, because it wasn't in their strategic interests to do so. It would definitely have been in Germany's interests, but not Japan's.
In 1945, when the Soviet Union attacked, Japan's military capability had been degraded considerably. Most of their navy was on the bottom of the ocean, and what little aviation gasoline they had was being reserved largely for kamikaze attacks on the US fleet, so they didn't have the naval or air assets to attack Vladivostok in August, 1945. On top of that, the considerable number of Japanese troops in Manchuria were not equipped to fight an armored opponent, especially not the Red Army and it's thousands of tanks, so the Kwantung Army simply didn't have the means to oppose the Soviet invasion, let alone counterattack.