anchor.diff:  %% @end
   %%--------------------------------------------------------------------
   -spec get_space_id_not_cached(KeyToCache :: term(), datastore:document()) ->
  -    {ok, SpaceId :: binary()} | {error, Reason :: term()}.
  -get_space_id_not_cached(KeyToCache, #document{} = Doc) ->
  +    {ok, SpaceId :: binary() | {space_doc, SpaceId :: binary()}} | {error, Reason :: term()}.
  +get_space_id_not_cached(KeyToCache, #document{key = Key} = Doc) ->
       Context = get_sync_context(Doc),
       case file_meta:get_scope(Context) of
           {ok, #document{key = <<"">> = Root}} ->
  -            state_put({sid, KeyToCache}, Root),
  -            {ok, Root};
  +            try
  +                SpaceId = fslogic_uuid:space_dir_uuid_to_spaceid(Key),
  +                state_put({sid, KeyToCache}, {space_doc, SpaceId}),
  +                {ok, {space_doc, SpaceId}}
  +            catch
  +                _:_ ->
  +                    state_put({sid, KeyToCache}, Root),
  +                    {ok, Root}
  +            end;
           {ok, #document{key = ScopeUUID}} ->
               try
                   SpaceId = fslogic_uuid:space_dir_uuid_to_spaceid(ScopeUUID),
  
positive.code:         Stream ->
              Since = state_get(global_resume_seq),
              state_update(changes_stream,
                  fun(_) ->
                      {ok, NewStream} = init_stream(Since, infinity, global),
                      NewStream
                  end);
          _ ->
              ?warning("Unknown stream crash ~p: ~p", [Stream, Reason])
  
negative.code: %% @end
  %%--------------------------------------------------------------------
  -spec get_space_id(datastore:document()) ->
      {ok, SpaceId :: binary() | {space_doc, SpaceId :: binary()}} | {error, Reason :: term()}.
  get_space_id(#document{key = Id, value = #monitoring_state{}}) ->
      case monitoring_state:decode_id(Id) of
          {space, SpaceId, _, _} ->
  