When is the quality of an item determined? Is it when you first start crafting the item or is it using your Mastery points when you claim the item?

Why is this important? I have 2000+ Mastery while using Jack of all Trades. I want to try firing all workers besides Jack to see if I can level him up faster while producing Ocarinas. If the quality of the item is determined at time of crafting, then this poses no risk (just a few Million gold that I can certainly afford to rehire with). However, if the Ocarinas' quality is determined at time of "clicking" or "popping" the craft, then I'm losing more than just a few Million here and there. I'm also losing potential Net Worth for a chance to increase infrastructure.

When you first start crafting, it rolls the dice on the server (rng) This can be proven by starting crafting while connected to server, turning off wifi with the game open, and letting the timer run out, then collecting. You will see what the item is with the quality, then when you go back online, it will force you to reload the game and you can collect the item (for real this time), and the quality will be the same as when you collected it offline.