There are two ways to always be correct.
The first is always know ahead of time what the correct position to hold on a topic is.
Knowing all of the facts ahead of time is clearly not a viable approach. Even assuming that you were a world-expert in the topic in question, the world is uncertain and chaotic, and the most logical opinion to hold shifts over time.
The alternative is essentially a Bayesian approach to knowledge acquisition. You adopt an initial position based on your knowledge at the time (the prior). If alternative evidence comes to light you incorporate it into your new position (the posterior).
In neither case you’re you ‘right’ or ‘wrong’ in an absolute sense - you took a view and acted upon it in a manner dictated by the best available facts.
But human beings are terrible at this! Sunk cost causes us to avoid or reject information that contradicts our past positions (or investments of time/energy/money). Ego can lead us to irrationally vouch for options that we supported in the past, even if we have no direct stake in their truth.
A useful heuristic to know when you are resisting changing your view when debating or arguing with someone is to monitor whether you are attempting to confabulate facts.
Imagine you are debating with a friend about a past position you held. As alternative evidence becomes available available in the discussion, you may be tempted to reject this new evidence, or question its relevance to your initial position.
You will likely start to reach for manufactured arguments to support your priors which were not at all related to your reasons for your support of your initial position.
This is the point at which it is time to admit your uncertainty, do more research, and openly state when you change your view. Arguing inflexibly will only cause you to deny the evidence in front of you, and prevent your evolution to a different position better supported by the evidence.
Purposefully adopting this mindset can be a very powerful way to improve your thinking, whether it be in an engineering context, to reflect on decisions made in the past, or as a lens with which to improve your opinions more broadly.
The above does not mean that you should not hold strong opinions. When you are aware of a body of strong empirical evidence, you should be slower to adopt a new belief (in keeping with a Bayesian approach).
When trying to make decisions with a small or nonexistent sample size, you will often need to adopt a strong prior belief (supported by logical reasoning) and follow it to its logical conclusion. It can can pay to be persistent.