The Rambam (Chapter 29 of Hilchot Shabbat) writes: “There is a positive Torah commandment to sanctify the Shabbat with words, as the verse states, ‘Remember the day of Shabbat to make it holy,’ meaning remember it through words of praise and sanctification when it begins and when it ends. When it begins through Kiddush and when it ends through Havdala.”
The Havdala that we perform on Motza’ei Shabbat is comprised of two parts: The Havdala we recite within the Amida prayer of Arvit (which is the addition of the “Ata Chonantanu” text within the “Ata Chonen” blessing, as printed in all Siddurim) and the Havdala recited on a cup of wine.
The Gemara (Berachot 33a) states that one who erred and did not recite “Ata Chonantanu” within the Arvit prayer is not required to repeat one’s prayer since one will be reciting Havdala on a cup of wine afterwards. Nevertheless, Rav Sheshat says that if one forgets to recite “Ata Chonantanu” in Arvit and also eats before reciting Havdala on a cup of wine, one must then repeat the Amida prayer while making sure to recite “Ata Chonantanu” this time. Maran Ha’Shulchan Aruch (Chapter 294) rules likewise.
Nevertheless, in his commentary Bet Yosef, when discussing the source of the law that one who eats before reciting Havdala on a cup of wine from the Gemara and Poskim, Maran wonders why the Rambam did not mention this law at all. Nonetheless, in his Shulchan Aruch, Maran rules that halachically, one must repeat the Arvit Amida if one ate before reciting Havdala on a cup of wine since several Rishonim rule likewise explicitly.
Maran Rabbeinu Ovadia Yosef zt”l discusses this matter in his Chazon Ovadia-Shabbat (Volume 2, page 379) and quotes several works of Rishonim printed after the time of Maran Ha’Bet Yosef who rule explicitly that even if one mistakenly eats before reciting Havdala on a cup of wine, one would not repeat the Arvit Amida prayer. These Rishonim explain the above statement of Rav Sheshat to mean that if one mistakenly forgets to recite “Ata Chonantanu” in the Arvit prayer and later realizes that he has no wine to recite Havdala on either, one must then repeat the Amida prayer so that one may at least recite Havdala in the prayer. Maran zt”l writes that this may indeed be the opinion of the Rambam and why he omitted this law because he may maintain that one need not repeat the Amida prayer even if one mistakenly eats before reciting Havdala on a cup of wine.
Halachically speaking, Maran zt”l writes that the correct ruling on this matter follows the opinion of Maran Ha’Shulchan Aruch who rules that one who mistakenly eats before reciting Havdala on a cup of wine must repeat the Arvit Amida. Nevertheless, it is preferable to stipulate before repeating the Amida that “if I am not obligated to repeat this Amida prayer, this prayer is hereby a voluntary, donated prayer.”