SIP ReInvite and Dial Plan

I’ve fought this problem long enough… looking for some expertise here.

I’m trying to make an outbound call from my Asterisk server using SIP. The SIP provider always performs a reinvite after the initial Invite/Trying/Session Progress/OK protocol.

My problem is that Asterisk starts executing the dial plan extension after the OK… this is not good since the media stream on the inbound side won’t be established until after the reinvite negotiation. Hence, any inbound functions don’t work properly or are erratic (such as BackgroundDetect, AMD, etc.)

Any ideas on how ti get around this problem would be greatly appreciated.