I think it's simple. Have linesman's call, in the same way there's umpire's call in cricket.

For those who don't know what that means, in cricket, when there's an LBW decision to be made by the 3rd umpire, if there's a degree of ambiguity as to whether the ball would definitely have hit the stumps, the umpire's original decision is final. I don't know what the figure is, but if the ball is showing to clip (or miss) the stumps by a very small margin, the original decision takes precedence.

In football, it's surely possible to agree on an acceptable margin of error. Say the rule was the attacker had to be within 3 inches of the offside line. If the linesman gave offside and the attacker was such a small fraction onside, linesman's decision counts. Similarly, if they give onside and the attacker is that small fraction offside, linesman's decision counts. There also needs to be a decision as to what body parts count for offside and onside decisions.