MessageSend returns success even when delivery fails

Really simple dialplan which works when the device (linphone) is on and connected.

exten => 6101,1,NoOp(Testing MessageSend)
same => n,Set(ACTUALTO=pjsip:jellypro)
same => n,NoOp(DEVSTATE={DEVICE_STATE({LINPHONE_JELLYPRO})})
same => n,MessageSend({ACTUALTO},{MESSAGE(from)})
same => n,NoOp(Send status is ${MESSAGE_SEND_STATUS})
same => n,Hangup()

But when the device is switched off (so the message cannot be delivered), MESSAGE_SEND_STATUS is still SUCCESS.

I can detect that the device is off by checking DEVICE_STATE but this doesn’t change immediately leading to lost messages.

Is this expected behaviour? Am I doing something wrong?

Logs below.

-- Executing [6101@local_users_msg:1] NoOp("Message/ast_msg_queue", "Testing MessageSend") in new stack
-- Executing [6101@local_users_msg:2] Set("Message/ast_msg_queue", "ACTUALTO=pjsip:jellypro") in new stack
-- Executing [6101@local_users_msg:3] NoOp("Message/ast_msg_queue", "DEVSTATE=NOT_INUSE") in new stack
-- Executing [6101@local_users_msg:4] MessageSend("Message/ast_msg_queue", "pjsip:jellypro,<sip:csipsimple@asterisk>") in new stack
-- Executing [6101@local_users_msg:5] NoOp("Message/ast_msg_queue", "Send status is SUCCESS") in new stack
-- Executing [6101@local_users_msg:6] Hangup("Message/ast_msg_queue", "") in new stack

== Spawn extension (local_users_msg, 6101, 6) exited non-zero on ‘Message/ast_msg_queue’

-- Executing [6101@local_users_msg:1] NoOp("Message/ast_msg_queue", "Testing MessageSend") in new stack
-- Executing [6101@local_users_msg:2] Set("Message/ast_msg_queue", "ACTUALTO=pjsip:jellypro") in new stack
-- Executing [6101@local_users_msg:3] NoOp("Message/ast_msg_queue", "DEVSTATE=UNAVAILABLE") in new stack
-- Executing [6101@local_users_msg:4] MessageSend("Message/ast_msg_queue", "pjsip:jellypro,<sip:csipsimple@asterisk>") in new stack
-- Executing [6101@local_users_msg:5] NoOp("Message/ast_msg_queue", "Send status is SUCCESS") in new stack
-- Executing [6101@local_users_msg:6] Hangup("Message/ast_msg_queue", "") in new stack

== Spawn extension (local_users_msg, 6101, 6) exited non-zero on ‘Message/ast_msg_queue’

The messaging functionality of PJSIP does not currently return back information like that. Messaging is something only a few people do, so noone has taken on further extending and improving it. The issue itself is in JIRA[1].

[1] https://issues.asterisk.org/jira/browse/ASTERISK-25421

Thank you. You have saved me many hours of trying to work out what I’m doing wrong.