I can relate to the OP's issues. I raced for a few years in my 30-40's, when I lived in Cozumel, Mexico (1990-2000's) , and though i was very diet and hydration conscious, I was plagued with late-race quad cramps. I was frequently in the small breakaway at the end of the race, but rarely had anything left to contest the finish with. I naturally considered all the usual suspects ( dehydration, deficiency in electrolytes,etc.), and worked hard to minimize those as being the cause.
I heavily researched the issue, yakking on the bike forums, and tried several highly rated supplement drinks, made for pre,during, and post ride, and nothing seemed to work, at least not consistently. I suspect it could been a genetic predisposition, and/or my "advanced' age, as well as riding in a very hot,humid jungle environment (though i was highly acclimated).
I even had a couple freinds, one a massage therapist, and the other a chiropractor, who used to hook me up regularly, and even those never really helped (that I could tell).
Other than what's already been suggested...... sorry, I got nuthin'