That is what got Petraeus in trouble with that biographer lady.
In Petraeus' case the Army JAG decided he was not caught in time before his retirement.
Since he was resigning from the CIA, and from all US civil service, there was no reason to take any action against him nor to remove any of his stars.
Had he been caught while on duty then he would have lost 2 stars at least and received some kind of discharge.
Depending on the military judge, it could have been a Donald Duck, or a Bad Chicken Dinner, or a General-D.