I don't really understand the process for establishing what "the halacha" is in a particular case. I know that there are rules in the talmud to decide whom the halacha follows when there are particular parties involved, but I don't know all the rules and I don't see how they work in every case.
In masechet brachot, 30a, there is the following mishna (about whether one has to daven mussaf on his own) " ר' אלעזר בן עזריה אומר אין תפלת המוספין אלא בחבר עיר וחכ"א בחבר עיר ושלא בחבר עיר ר' יהודה אומר משמו כל מקום שיש שם חבר עיר יחיד פטור מתפלת המוספין"
Two opinions are given, the Chachamim and R. Elazar Ben Azaryah. The gemara points out that there are actually 2 versions of R. Elazar Ben Azaryah's statement, one filtered through R. Yehudah.
The section continues with "א"ר הונא בר חיננא אמר ר' חייא בר רב הלכה כר' יהודה " that the halacha accords with R. Yehudah's version of the statement and corroborates the ruling (through R. Chiya and Shmuel) The gemara continues to cite R. Yannai who, disagreeing with that ruling, practiced like the Chachamim, before returning to give another example of an Amora who ruled in the same way as R. Huna et al.
This seems fine except for one thing -- the halacha seems to follow the Chachamim (and R. Yannai). The little letter chaf next to that opinion in the mishna (5 lines from the bottom) indicates that the halacha (as published in the S"A, O"C 286:2) and our normative established practice is not at all what R. Elazar Ben Azaryah said, with or without the framing of R. Yehudah.
I don't know the rule that would allow the singular voice of R. Yehuda to hold sway over the Chachamim, but I'm more curious about how later authorities can decide that the halacha doesn't go along with what the plurality quoted in the gemara explicitly said the halacha is (and that position, while challenged, is never refuted). What is the value of quoting "R. X says halacha k..." if it isn't establishing that the rule follows that position? When there are multiple opinions cited in the gemara and a plurality of voices seem to support one view, how does a rule get codified in accordance with another view?
Any insight would be appreciated.