IAmSinistar: The ones you buy here are theoretically unlimited, except in rare cases when a game is removed from the catalogue
Grargar: Not really. When GOG announced Linux support, someone gifted a still-working copy of XIII as a cause for celebration.
chean: Supposedly purchased codes stay active even if the purchased game is later removed from the catalogue, at least I recall this being said when it was announced that the free Fallout codes had been invalidated. Which makes sense to me, since we do still have and can download the Fallout games from our shelves; a purchased code is a purchased game in a sense, albeit one that hasn't been "activated" yet.
Ach, you both are correct. That was indeed an aberrant case. So the answer really is that most codes should stay valid forever, except when the code is part of a limited offer or certain circumstances cause them to be invalided.