What is the model and type?
Single cylinder or dual cylinder?
Assuming you have checked the valve lash:
If single replace the magneto if new correct spark plug does not correct.
If dual cylinder see if runs same on both cylinders when it gets weak, might be dropping a cylinder.
If one cylinder dropping replace the magneto if it has a new spark plug, but also compare the compression to the good cylinder.
If valve lash is correct and you cannot determine which cylinder replace both magneto's.
Clone magnetos are not that expensive AND what you describe is a symptom of the erratic nature of electronics inside a Magneto.