If Russia actually loses I'd expect someone behind the scenes would forcibly "retire" Putin. The new leader could then use Putin as a scapegoat, pull back, and negotiate for lifting of (at least some) sanctions, since they were implemented in response to the actual invasion.
If Putin persists and actually drops a nuke on Kyiv, then it's a clear sign he's given up and has no actual plan for the aftermath. Doing so only further increases Ukrainian resistance, and would only further accelerate Western aid to Ukraine. It wouldn't matter what, say, Joe Biden or Emmanuel Macron think: the *public* is going to be screaming for blood and it'll result in increased calls for modernization and funding of conventional military forces, nuclear forces, and missile defense. All of which Russia can't afford and certainly can't hope to match.
On the North Korea front...keep in mind that Russia being isolated to that degree is something that won't sit well with Russia's elites or its public. North Korea's 'juche' philosophy and centrality of the Kim family (built up over nearly 75 years) isn't something Russia has (and as it is, North Korea basically relies on China to remain afloat -a cost China absorbs to forestall the possibility of regime collapse and the ROK moving in and winding up with a major U.S. ally on the Yalu River).
Yes, Russia is not without assets...but its natural resources won't help if they're embargoed, nor will their intelligence agencies be able to do more than try and maintain internal security while going "Yep, the West still hates us and the Chinese are really annoyed" -Russian intelligence has historically been good at collecting information, but absolute shit at analyzing or using it effectively.
Space program? Again, yes, they *have* one, but without the money to operate it...won't really help.
Agriculture? Yeah, this is one that definitely hurts but at the same time, it's becoming increasingly clear that people are willing to put up with a lot of discomfort if it means making Russia pay. Same with potash, fertilizer products, and the like... Russia isn't the *only* source, so while costs will go up...in the long term it's more likely that shifts are made to alternate sources (same with energy and everything else).
People don't just roll over once economic hits start happening in situations like this; instead, they end up gritting their teeth and bearing it ("pay any price, bear any burden") because political concerns always wind up trumping economic ones.
And as far as China and Taiwan go: It wouldn't be just the U.S. they'd have to fight: at an absolute minimum, you'd have Japan, Australia, and South Korea all entering the fray. Taiwan is a major linchpin in hemming in the PLAN, and if Beijing seized it, then it threatens Japan directly and also places U.S. territory at a much greater risk.
Moreover, the relationship between the U.S. and Taiwan is very different from the relationship between the West and Ukraine: it's a de facto ally and if push really came to shove, China would have to risk India, Vietnam, and a bunch of other countries also throwing down with them...and at the same time get cut off from the Middle East and its oil supply. Oh, they threaten to nuke us for this? Congratulations, you've probably just managed to convince the Japanese to develop their own arsenal, in addition to the fact that we have our own and would respond *poorly* over a threat to stay out of it over an ally*.
*-Yes, I'm aware it's a "not actually set in stone" thing but Taiwan and the U.S. have a longstanding friendly relationship. And again, it isn't *just* the U.S. that would get dragged into this. Chinese thinking generally doesn't look favorably on Pyrrhic victories: their thinking is shape the battlefield in such a way as to guarantee absolute victory in a war...and this wouldn't get them that.