Hi Adrian,
What happens if you rewrite the query to:
lmg.traversal().V(analysisVertex).out().emit().repeat(
__.in().choose(
__.hasLabel("result"),
__.has("analysisId", analysisId),
__.identity()
)
).tree().next().getTreesAtDepth(3);
I do not understand how leaving out the else clause leads to the random behavior you describe, but it won't hurt to state the intended else clause explicitly. If the else clause is not a valid case in your data model, you do not need the choose() step.
Best wishes, Marc