Most likely the larvae of the Phorid and or the Sciarid Fly. The eggs are laid in the substrate, from there they consume the underground portion of the mycelium. When mushrooms start growing, they will eat their way up the stem and eventually make their way to the cap. Here they will pupate and then hatch as adult flies from the cap. Look for pinprick holes in the cap to check.
Most of the damage is occurring at the substrate level. If there are enough of them they may eventually consume the entire mushroom patch from the inside, killing it. There's more info about them, plus what to do here:
https://mycobio.co.nz/mushroom-growing-pests-what-to-look-out-for/
Some commercial mushroom growers use nematodes as a biological agent to deal with them. I use yellow sticky flytraps to try and keep the adult population under control, so less egg-laying.
They're okay to eat, they've been living and eating mushrooms all their life! We usually refrigerate the harvested for a few hours, in a plastic container (using paper for longer-term storage. The cold forces them out, as does soaking in salty water.
On harvesting, as soon as we harvest mushrooms we put them in plastic containers. These are lined with kitchen cloth (used for catering) to prevent condensation. After the mushrooms are harvested their respiration rate increases tremendously, and the plastic container allows a buildup of CO2 which will quickly put the mushrooms to sleep. This, plus dropping the temp to just above freezing will allow a longer storage life. If you like, you can move them into paper bags after 24 hours.
Hope this helps