Yesterday Flow release a “Run code” action that makes it possible to write this code in JavaScript instead, which is far easier to get correct. We have an example here for how to convert tags to metafields. Personally, I’d replace your conditions and code with a single Run code step and then this action could be a single “Update product metafield” step with a simple variable in it.