Sequence flow not shown proper when generated with api

When I generate the shapes in code with sequence flow between activities in different lanes then the flow is not shown properly, till I manually move one of the shapes…
I fired ‘elements.changed’ event but that does not help. Can you please help me?

After moving it shows properly as below

The first diagram is visually invalid, as it shows two Activities in different Participants/Pools, connected by a sequence flow.

Activities may only be connected via message flows (message passing semantics) when crossing Pool boundaries. This is properly reflected in the second image you posted.

Thank you . That fixes it.