Maybe my job is easier than yours, i.e. a software developer.
The traditional psychology of software development includes the psychology of "flow".
One of the doctrines of that psychology is that flow can happen when a job is neither too easy (which isn't interesting or demanding, doesn't engage or satisfy), nor too difficult (if it's too difficult it promotes anxiety, regret, hopelessness, and desire to quit etc.).
So there's a happy medium: when it's neither too hard nor too easy.
I read once that they used functional MRI to measure of brains in "flow" state and discovered that brains in that state are less active than
usual, or more specifically have fewer areas which are active. I suppose that (limited number of active areas) is associated with concentrating on one task, with a lack of afflictive emotions, etc.
What does this have to do with Buddhism?
I think one comment to make is that the flow state is pleasurable. For example you say "I could not find any relief until it was fixed" which implies that you feel relief; and you said, "I also know that being consumed is powerful", where I suppose that "powerful" is pleasurable in a Nietzschean sense. So maybe beware that it (what you're doing) is something of a pleasure-feedback loop, like any other (sugar, alcohol, you know, sex, social status, whatever your weaknesses are). Your "obsessive thinking" might be a result of subconscious desire or craving "I want to carry on thinking like this, to feel relief and power again". The fact that Mathematics seems relatively harmless activity doesn't confer immunity: see e.g. Saptha's comment here, about sukha giving rise to dukkha and the consequence of our indulgence in pleasure.
A phenomenon from Buddhist practice which might perhaps be analogous are Jhāna concentration states. I think that doctrine says that practicitioners sometimes mistakenly take these states as an end instead of a means. They should be a means (to improve insight) but might be taken as an end in themselves (because of their (temporary) relief from suffering).
You wrote "I have made incredible progress over the last 6 months with my practice" though I don't know what your practice is. In any case you might try some explicitly Buddhist practice as well as (or, at least sometimes, instead of) Mathematical pursuit.
Also, in my experience and I think in everyone's, often a problem is solved in routine concentration; and sometimes that routine fails and is counterproductive, because you don't see the problem in a proper context, e.g. "you don't see the forest for the trees". So even if your only motive were to solve the mathematical problem, you might find it beneficial to let "obsessive" thinking subside when it is failing.