Cannot update item when querying in hook

I can’t use the code provided. The multi-reference field won’t save if I treat it as a normal array. Although it says “all changes saved”, the change will disappear if I close the view of the collection and reopen it. I’m using insert reference instead but it’s working half of the times. Also, I can’t use remove referen/ce because it will run out of time quota.