anchor.diff:              maybe_start_replication(State, DocId, JsonRepDoc);
           <<"triggered">> ->
               maybe_start_replication(State, DocId, JsonRepDoc);
  -        _ ->
  -           State
  +        <<"completed">> ->
  +            replication_complete(DocId),
  +            State;
  +        <<"error">> ->
  +            replication_error(State, DocId)
           end
       end.
   
  
positive.code:         [Loop | StartPids]),
      true = ets:delete(?REP_TO_STATE),
      true = ets:delete(?DOC_TO_REP),
      couch_db_update_notifier:stop(Notifier).
  
  
  code_change(_OldVsn, State, _Extra) ->
  
negative.code:     {reply, ok, process_update(State, Change)};
  
  handle_call({rep_started, {BaseId, _Ext} = RepId}, _From, State) ->
      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_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_error, RepId, Error}, _From, State) ->
      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}),
          % 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",
  