SIP Trunking not completing succesfully 2 out of 3 times

I have an inconsistent behaviour validated with SIP trunks from 2 different providers
The call flow which has an issue is like follows
twinkle or bria -> asterisk 1.8 -> SIP trunk1 or SIP trunk2
What I’m doing is placing a PSTN call through asterisk.
I’m seeing the 2 possible results:
1- as soon as asterisk places the call requested by the softphone on the corresponding trunk, the softphone starts ringing back as if the other end is ringing, and looking at asterisk logs, it shows that the trunk is ringing, although actually it is not (since i’m calling my own PSTN line, I can track the progress on that end). After that, asterisk shows that trunk answered the sip phone, while actually the phone would be still ringing for some seconds. The interesting part here is that it’s obvious that asterisk did not get the time to reach the other trunk by the time it shows the message that it’s ringing.
2- when asterisk places the call requested by the softphone on the corresponding trunk, the softphone doesn’t immediately start ringing back, and asterisk logs are waiting on the ‘called trunk/xxxx’. After few seconds, the softphone starts ringing back, asterisk shows now that the trunk is ringing, and the PSTN line actually rings this time, and only after answering the call on the PSTN line that asterisk shows that the trunk answer the softphone. This scenario is the correct one, but it’s only happening 1/3 of the times. It’s worthy noting that in this case, the ringback tone on the softphone sounds like the real ringtone you’d hear if making a pstn-to-pstn call, in contrast with the ringback tone heard in 1st scenario where it sounds like a generic, non noisy one.

here’s a sample of the logs. They look the same, the only difference is their evolvment time based on call progress (as explained above)

-- Executing [00961*******@personal:1] Dial("SIP/100-00000000", "SIP/mediafone-steelman-trunk/00961*******") in new stack

== Using SIP RTP CoS mark 5
– Called mediafone-steelman-trunk/00961*******
– SIP/mediafone-steelman-trunk-00000001 is ringing
– SIP/mediafone-steelman-trunk-00000001 is making progress passing it to SIP/100-00000000
– SIP/mediafone-steelman-trunk-00000001 answered SIP/100-00000000
== Spawn extension (personal, 00961*******, 1) exited non-zero on ‘SIP/100-00000000’

Local ringback is triggered by the downstream SIP system sending 180 Ringing. To be able to get in band call progress and therefore hear the network ring back tone, the downstream SIP system would need to send 183 Progress. I think you will find this difference if you actually look at the SIP dialogue.

You will need to ask the downstream system operators why this is happening.

You should maybe check that your dialplan isn’t calling the Ringing() application, which will force a 180 Ringing upstream.

Actually, in the example you show it looks as though the upstream system has done both. It’s first sent 180 Ringing, and then, probably almost immediately, sent 183 Progress.