These are a common problem for soil growers who often over water and are also called sciarid flies dawning the appearance of tiny mosquitos with dark wings, roughly the size of a thickness of a quarter. Wet soil is the perfect home for decaying organic matter that fungus larvae thrive on, as well as growing fungus that may even be impossible for you to see. Hatched eggs appear to be tiny maggots that reside in the top couple inches of the soil, slowly destroying your roots as they eat the matter around it, even gnawing on tiny root hairs and tender, young roots, effectively slowing growth. The adults also spread diseases via their tiny stupid feet such as pythium which causes root rot, though other than this, do not show any damage. Be sure what you don’t have is fruit flies, which can be mistaken at first glance, but you’ll notice that fruit flies are larger and orangier. Also, they prefer fresh decomposing food. These are flies you’ll notice at home when you leave an apple out and can be easily gotten rid of by removing fresh fruits like these.
Cut up a fresh potato and bury it about two inches in or so. Larvae are attracted and will embed themselves in it each time you place a new one, but they will not completely take care of the problem. Use a yellow sticky card from your gardening store to attract gnats to it and trap them. They love this color for some reason. You typically only need to dry out your soil a little to kill the larvae. If not, use bacillus thuringiensis bacteria, which is a toxin producing bacteria harmful to larvae of fungus gnats, preventing them from eating,preferably subspecies israelensis an organic form, like found in mosquito dunks and mosquito bits, which is necessary in organic grows or your plant will be missing out on micronutrients and generally will mess up the soil. Other products containing this are often listed as BT or BTi and it is safe for anyone to ingest, but don’t. It can even be used in the middle of the budding phase and is 100% organic. It is rumored that powdered is the best form, so be sure to crinkle up pellet forms and avoid liquid. If this doesn’t work, you should water your plant with 1/5th diluted SM-90 or 1 part 35% pure hydrogen peroxide to 4 parts water to kill larvae in the soil. Hydrogen will sizzle up in bubbles and even kill eggs, dissolve then into oxygen molecules ,for your plant to ingest. Using rubbing alcohol, 1 cup in 1 liter of water can work, but is pretty harsh.
Permethrin and bifenthrin can be sprayed before an outbreak to prevent one but happening, but these are harmful chemicals and will kill positive pests that you have as well as your baby if ingested, so I would just avoid it. Tanlin is biological that maggots will eat, then swell up on and die, however it does not kill the adults. You can kill many adults by combining 2 tablespoons lemon dish detergent or Ivory soap with 1 gallon of water, drench the soil with this. When using this method you need to make sure the top soil is pretty dry, which is tricky because over drying will harm your plant. Spray leaves clean after one hour. This will kill many bugs residing on the plant, but to catch more flying around you also can use two tablespoons of apple cider vinegar with small amount of dish soap in a bowl. The adults will be attracted to the vinegar, but stuck once they touch it. Even after killing the larvae, adults can linger around a few days longer. Keep cigarettes around which are repulsatory to bugs, but do not bring them near your plant. Nematodes, predatory mites such as hyoaspis miles and hypoaspic aculeifer and predatory rove beetles atheta coriaria, or lady bugs and lacewings all eat these larvae and can assist in controlling a problem, but should not be used to eliminate it. Attract these bugs to your plant with traps and scents that will come in and bully out the bad bugs. Keep your compost pile about as dry as a rung out sponge, never ever wet. You do not generally want to use kitchen scraps because cannabis plants need specific nutrients, but if you must, bury them far down in to the pile to avoid gnats and flies. Cover your pile with something containing a lot of carbon, such as cardboard or shredded paper. Watch a close up video of gnats.