anchor.diff:      {reply, ok, process_update(State, Change)};
   
   handle_call({rep_started, {BaseId, _Ext} = RepId}, _From, State) ->
  -    #rep_state{rep = #rep{doc_id = DocId}} = RepState = rep_state(RepId),
  -    true = ets:insert(
  -        ?REP_TO_STATE, {RepId, RepState#rep_state{starting = false}}),
  -    update_rep_doc(DocId, [
  -        {<<"_replication_state">>, <<"triggered">>},
  -        {<<"_replication_id">>, ?l2b(BaseId)}]),
  +    case rep_state(RepId) of
  +    nil ->
  +        ok;
  +    #rep_state{rep = #rep{doc_id = DocId}} = RepState ->
  +        true = ets:insert(
  +            ?REP_TO_STATE, {RepId, RepState#rep_state{starting = false}}),
  +        update_rep_doc(DocId, [
  +            {<<"_replication_state">>, <<"triggered">>},
  +            {<<"_replication_id">>, ?l2b(BaseId)}]),
  +        ?LOG_INFO("Document `~s` triggered replication `~s`",
  +            [DocId, pp_rep_id(RepId)])
  +    end,
       {reply, ok, State};
   
  -handle_call({rep_start_failure, Rep, Error}, _From, State) ->
  -    #rep{id = {BaseId, _} = RepId, doc_id = DocId} = Rep,
  -    #rep_state{max_retries = MaxRetries} = rep_state(RepId),
  -    ?LOG_ERROR("Failed to start replication `~s` after ~p attempts using "
  -        "the document `~s`. Last error reason was: ~p",
  -        [pp_rep_id(RepId), MaxRetries, DocId, Error]),
  -    update_rep_doc(
  -        DocId,
  -        [{<<"_replication_state">>, <<"error">>},
  -            {<<"_replication_id">>, ?l2b(BaseId)}]),
  -    true = ets:delete(?REP_TO_STATE, RepId),
  -    true = ets:delete(?DOC_TO_REP, DocId),
  +handle_call({rep_complete, RepId}, _From, State) ->
  +    case rep_state(RepId) of
  +    nil ->
  +        ok;
  +    #rep_state{rep = #rep{doc_id = DocId}} ->
  +        update_rep_doc(DocId, [{<<"_replication_state">>, <<"completed">>}])
  +    end,
       {reply, ok, State};
   
  -handle_call({rep_complete, RepId}, _From, State) ->
  -    #rep_state{rep = #rep{doc_id = DocId}} = rep_state(RepId),
  -    couch_replicator:cancel_replication(RepId),
  -    true = ets:delete(?REP_TO_STATE, RepId),
  -    true = ets:delete(?DOC_TO_REP, DocId),
  -    ?LOG_INFO("Replication `~s` finished (triggered by document `~s`)",
  -        [pp_rep_id(RepId), DocId]),
  -    update_rep_doc(DocId, [{<<"_replication_state">>, <<"completed">>}]),
  -    {reply, ok, State};
  -
   handle_call({rep_error, RepId, Error}, _From, State) ->
  -    #rep_state{
  -        rep = #rep{doc_id = DocId} = Rep,
  -        retries_left = RetriesLeft,
  -        max_retries = MaxRetries
  -    } = RepState = rep_state(RepId),
  -    NewState = case RetriesLeft > 0 of
  -    false ->
  -        couch_replicator:cancel_replication(RepId),
  -        true = ets:delete(?REP_TO_STATE, RepId),
  -        true = ets:delete(?DOC_TO_REP, DocId),
  -        ?LOG_ERROR("Error in replication `~s` (triggered by document `~s`): ~s"
  -            "~nReached maximum retry attempts (~p).",
  -            [pp_rep_id(RepId), DocId,
  -                to_binary(error_reason(Error)), MaxRetries]),
  -        State;
  -    true ->
  -        NewRepState = RepState#rep_state{retries_left = RetriesLeft - 1},
  +    case rep_state(RepId) of
  +    nil ->
  +        {reply, ok, State};
  +    #rep_state{rep = #rep{doc_id = DocId}} = RepState ->
  +        NewRepState = RepState#rep_state{last_error = Error},
           true = ets:insert(?REP_TO_STATE, {RepId, NewRepState}),
  -        Wait = wait_period(NewRepState),
  -        ?LOG_ERROR("Error in replication `~s` (triggered by document `~s`): ~s"
  -            "~nRestarting replication in ~p seconds.",
  -            [pp_rep_id(RepId), DocId,
  -                to_binary(error_reason(Error)), Wait]),
  -        Server = self(),
  -        Pid = spawn_link(fun() -> start_replication(Server, Rep, Wait) end),
  -        State#state{rep_start_pids = [Pid | State#state.rep_start_pids]}
  -    end,
  -    % TODO: maybe add error reason to replication document
  -     update_rep_doc(DocId, [{<<"_replication_state">>, <<"error">>}]),
  -    {reply, ok, NewState};
  +        % TODO: maybe add error reason to replication document
  +        update_rep_doc(DocId, [{<<"_replication_state">>, <<"error">>}]),
  +        {reply, ok, State}
  +    end;
   
   handle_call(Msg, From, State) ->
       ?LOG_ERROR("Replication manager received unexpected call ~p from ~p",
  
positive.code:             maybe_start_replication(State, DocId, JsonRepDoc);
          <<"triggered">> ->
              maybe_start_replication(State, DocId, JsonRepDoc);
          _ ->
             State
          end
      end.
  
  
negative.code:     #state{
          rep_start_pids = StartPids,
          changes_feed_loop = Loop,
          db_notifier = DbNotifier,
          rep_notifier = RepNotifier
      } = State,
      stop_all_replications(),
      lists:foreach(
  