One of the reasons this happens on such a repeated basis is because of the brain circuitry we've set up to this point. Your brain is built on experiences. Whatever you experience or think about the brain uses to build its network. After doing something for years, you develop a well-grooved neural pathway. We usually refer to these things as habits. You may recognize them in that you tend to do certain things without giving it much thought....you just seem to do it.
This helps us in many ways. It helps us learn to walk, talk, read, and write. Our ability to seemingly never forget how to ride a bike is due to the depth of brain circuits built around bike riding. In order to ride a bike we had to engage areas of the brain for balance, coordination, vision, pedaling, steering, etc. It took a lot of effort when we were just learning. And all that effort is rewarded in our ability to "never forget."
But when we want to change something, these circuits make it tough. Trying to get out of a habit of eating a super-sugary snack before bed is tough if your brain is wired for it. Self-sabotaging actions, thoughts, and feelings can arise and block our progress. Even after stating a true desire for change, it takes just a moment for the old circuitry to kick in and leave us once again....making the same mistake.
How do we get out of it? Use the bike example. Engage as many parts of you as possible in experiencing the "new" trait you wish to have. We remember how to ride a bike (even if we're wobbly) because of all the areas engaged. Do this with a new desired trait and you build deeper wiring in the brain to support it.
Do this by following some basic principles like the four Rs: Recognize, Release, Re-frame, Re-train. Notice the habit you wish to change, then walk yourself through the steps. Engage more of your mind and body by feeling the success. Create a blueprint for your brain to work from as it moves towards that new circuitry. This is one of the big problems with most programs, they simply try to avoid old habits. You will automatically go back to your old ways without establishing something new for your brain to grab hold of. If you can get a sense of what your success would feel, taste, smell, look, and sound like then you give your brain a new image of possibility.
And from there you build a network to support your new ideals, and stop making the same mistake.