Let's say that Peter asked Alice to run a process (X) with the objective of achieving (A). Peter gave Alice part of the execution plan to achieve (A). I other words, the idea of doing (X) to achieve (A) completely came from Peter. Now, while doing (X), Alice made a discovery that lead to (B), where (B) is something completely different to (A) but it is something innovative and new. Now Peter wants to take credit for the entire invention of (B) because according to him the idea and execution was entirely conceived by him, and saying that Alice was merely the executioner of a request. Can Peter legally claim all the inventorship of (B)?
That is going to depend on the relationship, if any, between (B) and (A), and the evidence, if any, that Peter instructed Alice to do (B), or in some way suggested (B) to Alice. It will also depend on whether Alice was Peter's employee, or a contractor, or if they had some other relationship for purposes of doing (X).
It may also depend to some extent on the jurisdiction involved.
If, as the question seems to say, (B) and (A) are related only in that both achieve (X), and Peter never mentioned (B), nor suggested it in any way, and further if Alice was not Peter's employee, then Peter should have no valid claim, and if he tries to establish one, should fail.