The Official Opposition has always been the 2nd largest party in the House of Commons, and is formally recognised in Erskine May: Parliamentary Practice. See section 2 of this note cited by wikipedia:
The importance of the Opposition in the system of parliamentary government has long received practical recognition in the procedure of Parliament. In 1937 statutory recognition was accorded through the grant of a salary to the Leader of the Opposition. The prevalence (on the whole) of the two-party system has usually obviated any uncertainty as to which party has the right to be called the ‘Official Opposition’: it is the largest minority party which is prepared, in the event of the resignation of the government, to assume office [and in a footnote: The Speaker’s decision on the identity of the Leader of the Opposition is final (Ministerial and other Salaries Act 1975 (c27) s2 (2))].
(emphasis mine)
What edge cases do you have in mind?
I'm not @LukeShadwell, but:
Formally, the Official Opposition is whomever the Speaker chooses.
Practically, the Official Opposition is whichever non-governing party (party not in the governing coalition) has the most seats. Vote percentage is irrelevant.
@mongo If the 2 largest non-governing parties have the same number of seats — that's an actual edge case.
Likely they will negotiate — perhaps they may agree to be Official Opposition on alternating years (Parliamentary sessions).
But if negotiations fail, then it'll be the Speaker's decision. This will probably cause a minor constitutional crisis.
If the second and third parties have equal seats I will cancel the whole market.