It would depend on where they initiated contact. For instance, let’s say a cop from City A pulls someone over on the boundary with City B. Even if you pull over on City B’s side, it’s still a valid stop because they initiated it (turned their lights on) while still within their own legal jurisdiction. Even though you’re outside of their jurisdiction at the moment, what matters is that they first initiated contact when it was legal to do so.