Hi.

I have a rather simple case:

SIP client calls FreeSwitch, then IVR lua script is being executed. In IVR script I do the following logic (in pseudo code):

session:answer();

while session:isReady() then
  do http request to external service
  if response is ok then
     session:execute("deflect", "some other SIP URI");
  else
    do some other logic
  end
end

In dialplan I have something like this:
<extension name="xxx">
   <condition field="destination_number" expression="^\d+$">
      <action application="set" data="default_language=ru"/>
      <action application="lua" data="/etc/freeswitch/scripts/ivr/main.lua"/>
   </condition>
</extension>

SIP message flow looks like following:
INVITE -->
            <-- Trying
            <-- OK with SDP
ACK    -->
           <-- REFER

From my understanding of SIP (which obviously may be wrong:)) I expect session to become ready (session:isReady returns true) only after FreeSwitch receives ACK from SIP client. But seems that it's not so, because if I introduce small delay in SIP client before sending ACK it receives REFER before ACK is being send to FreeSwitch.

So as result I have several questions:

--
Best regards.