I wondered because I too had a very long alliance (not to the end, but it was quite useful for a long time) and I made some real efforts to keep it going - matching my foreign policy to my ally's, forgoing easy rebel conquests to leave my ally somewhere to expand that wasn't me, maybe occaisional small gifts. So it looked like I was doing something that worked, but maybe I was just plain lucky. It hasn't happened again, but then I haven't bothered trying.

Maybe alliances work better for short campaigns than for the full campaign, if only because your ally has less time to decide to do something silly?