I do have a very experienced buddy who is a Rescue Diver and can help in a difficult situation. He stayed amazingly calm while I was on the edge of panic and helped me sort out the issue fast.
At the last dive, I made a mistake of buying a huge sized mask. It kept flooding and after trying to clear it for about 5 minutes while following the group, I felt the creeping onset of panic and had to stop my buddy to try and sort out the issue. Didn't work, I started panicking more and lost the regulator for a second. Right away realized it won't work this way, so caught it, cleared and then since I couldn't calm down or clear the mask, we surfaced to fix the issue.
Continued the dive normally after that. I always make sure to check the air gauge often, so I notified my buddy about half tank, then 1200psi, then 1000, then 800 and then at 500 showed there is little air left. We started going up and he offered to share the air. I was surprised cause I thought my 500 would be enough to finish the ascent from 20ft. So not entirely OOA, but close enough.
The underwater time was about 45 minutes total including the attempts to clear the mask, and I didn't panic at all at 500psi since I wasn't entirely out of air.
Thank you for the advices! I do plan to take it slow and do the skill drills in safe shallow water until it's second nature.