If you login a session user all tasks that where were resumed by the session are reset. This also includes the current task that executes the script step with the login statements. To avoid this use the overloaded method that takes an additional third parameter an provide it the identifier of the current task.
E.g.
ivy.session.loginSessionUser("user1", "password1", ivy.task.getId());
In this case all tasks that where were resumed by the session are reset except the one with the given id.