The answer has been repeated multiple times, so I'm just gonna try to sum it all up.
Basically, the % chance of a masterwork with critical crafting is 40%, or whatever the item states, but whether or not the item will actually work is determined by when you pick it up. And that item will not affect the likelihood of any other such masterwork, whether it has the same item name or not. If it's the 3rd item in a stack, using the masterwork with that name will always work on the 3rd attempt, even if the other 2 do work.
I think technically, the chance is determined when the loot item spawns into your game, not when you pick it up, but it doesn't really matter, since you can't know if it will work until you pick it up and use it. And you can't leave the area/cell and come back, because the item will just disappear. Also, seeing the item as loot then exiting the menu without picking it up, will not alter the outcome of the masterwork when it does reach your inventory