anchor.diff:  %% Resends stored messages in inclusive range [LowerSeqNum, UpperSeqNum].
   %% @end
   %%--------------------------------------------------------------------
  --spec resend_messages(LowerSeqNum :: sequence_number(), UpperSeqNum :: sequence_number(),
  -    Msgs :: messages(), StmId :: stream_id(), Con :: pid()) -> ok | {error, Reason :: term()}.
  +-spec resend_messages(LowerSeqNum :: sequence_number(), UpperSeqNum ::
  +    sequence_number(), Msgs :: messages(), StmId :: stream_id(),
  +    SessId :: session:id()) -> ok | {error, Reason :: term()}.
   resend_messages(LowerSeqNum, UpperSeqNum, _, _, _) when LowerSeqNum > UpperSeqNum ->
       ok;
   
  -resend_messages(LowerSeqNum, UpperSeqNum, Msgs, StmId, Con) ->
  +resend_messages(LowerSeqNum, UpperSeqNum, Msgs, StmId, SessId) ->
       case queue:peek(Msgs) of
           {value, #server_message{message_stream = #message_stream{
               sequence_number = LowerSeqNum
           }} = Msg} ->
  -            ok = communicator:send_to_client(Msg, Con),
  -            resend_messages(LowerSeqNum + 1, UpperSeqNum, queue:drop(Msgs), StmId, Con);
  +            ok = communicator:send_to_client(Msg, SessId),
  +            resend_messages(LowerSeqNum + 1, UpperSeqNum, queue:drop(Msgs), StmId, SessId);
           {value, #server_message{message_stream = #message_stream{
               sequence_number = SeqNum
           }}} when SeqNum < LowerSeqNum ->
  -            resend_messages(LowerSeqNum, UpperSeqNum, queue:drop(Msgs), StmId, Con);
  +            resend_messages(LowerSeqNum, UpperSeqNum, queue:drop(Msgs), StmId, SessId);
           _ ->
               ?warning("Received request for messages unavailable in sequencer stream "
               "queue. Stream ID: ~p, range: [~p,~p].", [StmId, LowerSeqNum, UpperSeqNum])
  
positive.code: -spec resend_all_messages(Msgs :: messages(), SessId :: session:id()) ->
      {NewSeqNum :: sequence_number(), NewMsgs :: messages()}.
  resend_all_messages(Msgs, SessId) ->
      {ok, Con} = session_connections:get_random_connection(SessId),
      resend_all_messages(Msgs, Con, 0, queue:new()).
  
  %%--------------------------------------------------------------------
  %% @private
  
negative.code: %% sequence number.
  %% @end
  %%--------------------------------------------------------------------
  -spec resend_all_messages(Msgs :: messages(), SessId :: session:id(),
      SeqNum :: sequence_number(), MsgsAcc :: messages()) ->
      {NewSeqNum :: sequence_number(), NewMsgs :: messages()}.
  resend_all_messages(Msgs, SessId, SeqNum, MsgsAcc) ->
      case queue:peek(Msgs) of
          {value, #server_message{message_stream = MsgStm} = Msg} ->
              NewMsg = Msg#server_message{
                  message_stream = MsgStm#message_stream{sequence_number = SeqNum}
              },
              ok = communicator:send_to_client(NewMsg, SessId),
              resend_all_messages(queue:drop(Msgs), SessId, SeqNum + 1, queue:in(NewMsg, MsgsAcc));
          {value, #client_message{message_stream = MsgStm} = Msg} ->
              NewMsg = Msg#client_message{
                  message_stream = MsgStm#message_stream{sequence_number = SeqNum}
              },
              ok = communicator:send_to_provider(NewMsg, SessId),
              resend_all_messages(queue:drop(Msgs), SessId, SeqNum + 1, queue:in(NewMsg, MsgsAcc));
          empty ->
              {SeqNum, MsgsAcc}
      end.
  