Hi everyone! These days I had the same issue with my 16’ macbook pro M1 (2021) running Sonoma 14.5, and since I think I found the problem, or perhaps it would be better to say bug, I wanted to share with you what I did in order to charge my mac again and hoping I can help someone.
So, if you go to settings>battery, in this tab you have two energy mode options: battery power and plugged into a power adatapter . By default (I think) the energy mode plugged into a power adatapter should be set to automatic mode. When I switched this settings into low power or high power and plugged the magsafe, it magically started to work perfectly.
Another setting that might give you problems (not to me apparently) is the optimized battery charging , which you can find inside the battery health status, you can try to switch it on/off and see if you notice any changes.
I don’t think there is a particular rule to fix this, and since it is clear that it is something that Apple need to fix via software, the only thing that we can do is to play with these settings until you see some changes and maybe solve the problem.