Sending an IM right as a user goes offline fires back an OnlineNotification right after the offline notification.
I assume this is a racing condition on the server side.
The issue comes from the fact this then leaves the user in a permanent online state on your end unless you relog / send another IM.
Example:
[11:34:14] Kalimaru: Gotta dash
[11:34:19] Willow (kalimaru) is offline.
[11:34:20] TrishAce: ok
[11:34:21] Willow (kalimaru) is online.
[11:45:35] TrishAce: <testing>
[11:45:35] Willow (kalimaru) is offline.
[11:45:35] User not online - message will be stored and delivered later.
In this example, the notice at 11:34:11 is wrong, the user went offline.
Sending an IM later (while they are offline) then correctly syncs the status as you see here