The actual solution to this is the Xinjiang model.
I partially wonder if the massive propaganda campaign against it was partly because the US don't want political pressure to adopt something that actually rehabilitates people. The ideology is a useful tool to unleash when it benefits them, ending it completely would therefore be viewed as detrimental to US interests.
This piece written in 2019 (removed since) is the best short summary writeup: https://archive.is/q1dnh
If you want a super super tl;dr: The model is to improve people's lives, extremism feeds off of poverty and poor outlooks, improving infrastructure, teaching languages and skills, raising the standards of living, these things all function to remove the material conditions that allow radical extremist behaviour to foster. The model was marxist theory in purist essence - change the material conditions. Xinjiang went from having dozens and dozens of actually very serious attacks per year (gunmen attacking railway stations, bombings and that kind of thing) to nothing within the space of a few years starting with the initial crackdowns and surveillance followed by the education program and infrastructure. One thing that libs always miss out with the mandatory school centres which is the most controversial part of it all is that these things weren't prisons, it was mandatory attendance and sleeping over Mon-Fri, they were free to go home on weekends.