Some node's styles are not processed by plugin

Hi! I’m building a plugin that converts remote color styles to local.
The logic is very basic: If node’s style name is the same as local style then assign local style to node otherwise create new local style.
I scan and process nodes in parallel with promise.all and in some cases I’m getting this error in console: unhandled promise rejection: Throw: Cannot set style successfully: Internal Figma Error: Node not found.
I can’t catch it with try catch, but I was able to identify the nodes that are the problem. So it’s mostly remote instances with shapes inside. And the thing is, if you select instance in Figma you can see remote style assigned to it’s child. But if you directly select the child of instance you see only a fill i Figma UI, not a style. And that’s why plugin gives an error (or rather Figma does).
Anyone also encountered this? Any ideas how to solve it?

Also I’ve already built this plugin but scanning and processing nodes were recursive. It was just very slow because of it. But there was no such error in that version, all the nodes were processed correctly (even the ones that don’t show remote style if you select them directly in Figma) although new version uses pretty much the same processing algorithm. So I’m kinda lost.