Record sync issue after logic hook

1. Open a case.
2. Send an email 
3. Return to case.
4. Update any field - you get the "resolve conflict page".

This seems to be caused by a custom after_relationship_add logic hook on Emails.

When the email is saved (depending on some custom parameters) the Case Status is changed but does not appear changed in the interface when the Email drawer is closed. When the user then changes any other field they receive a conflict.

The resolve conflict window suggests that the logic hook change happened *after* my edit of the Case.

 

Logic hook example: if the case was unassigned (customization has all new cases unassigned) it is then assigned to the person who answered it:

<?php
class email_case_handling
{
   // Email RELATED to a case
   function update_on_relationship ($bean,$event,$arguments){
        //bean = Email
        //case retrieved from related_id
        global $current_user;
        require_once('custom/entry_points/Cases/saveCaseAttachments.php');
        $today = TimeDate::getInstance()->nowDb();
        if ($arguments['related_module'] =='Cases'){
           $case = BeanFactory::retrieveBean('Cases', $arguments['related_id']);
           <....do some other stuff....>
           if($case->assigned_user_id == '' && $case->status == 'New'){
              //if the case is still unassigned and new, assign to whomever sent the case
              $case->assigned_user_id = $current_user->id;
              $case->status = 'Assigned';
           }
           <....do some other stuff....>
           $case->save();
        }
    }
}

Any thoughts on how to address this?

thanks,
Francesca