DIAGNOSIS The magnet in the anvil has lost its pull. This is often caused by metal shavings coating it (acting as a barrier) or the magnet itself getting physically damaged or demagnetized from repeated impacts.
FIX Clean the magnet. Remove any bit. Look into the hex collet—you'll see a silver magnetic ring at the bottom. Use a strong magnet or a piece of sticky tape (like duct tape) to carefully lift out any accumulated tiny metal flakes. Then, wipe the magnet surface with a clean cloth. For a weak magnet, you can try to 'recharge' it by holding a much stronger neodymium magnet against it for a few minutes, though this isn't always permanent.
IF THAT DIDN'T WORK The magnet is a press-fit part. If it's cracked or completely lost its strength, the entire anvil assembly needs to be replaced to fix the magnetic hold.
HEADS UP The magnet is primarily for convenience, not retention. The ball detent lock is what's supposed to hold the bit in under load. If bits are physically launching out, that's a detent issue, not a magnet issue.