Premature channel hangup on AGI

We have an Asterisk 1.2.18 installation on Linux. After we upgraded Asterisk from 1.2.9.1 we seem to have some issues about AGI and Dial().

We are required to set up 2 separate servers (and thus 2 Asterisk instances) for incoming call reception and termination. The Asterisk on reception server remains at v1.2.9.1 while termination server upgraded to 1.2.18.

After executing the dialplan at reception server, a Dial() call would be made over IAX2 to the termination server. The connection details are specified in iax.conf. The termination server, on connection, will also execute a dialplan which involves some AGI calls and other things.

On the termination server, the context looks like this:

[testing-in]
exten => _02.,1,Answer
exten => _02.,n,AGI(empty.sh)
exten => _02.,n,Wait(5)
exten => _02.,n,Playback(demo-congrats)
exten => _02.,n,Hangup

When the call comes in from the reception server, the empty.sh shell script is executed. In our test, the script is executable but is empty (no executable statements inside, just the shebang line). But the channel seems to go haywire after executing the AGI script. Wait() no longer waits anymore, any the channel seems to hangup before playing back the clip. But if I remove the AGI() call, it is fine again.

The actual AGI script itself is a pretty complex one, but we have ascertained there is no error or even warning for the script, and the logging system implemented in the script itself also did not record any abnormal status. agi debug also does not show anything unusual too.

The same configuration was fine when all the servers were Asterisk 1.2.9.1. Grateful for any help.