One turn before open borders (and/or other trade agreements) are about to end, have an alert which will allow you to ask the other leader to renew the agreement(s). This way my units will not get pushed out of their territry as I am passing through, just because the open borders agreement ended on that turn.