anchor.diff:      credentials :: undefined | auth_manager:credentials(),
       validity_checkup_timer :: undefined | reference()
   }).
  +-type state() :: #state{}.
  +
   
   -define(REMOVE_SESSION, remove_session).
   -define(CHECK_SESSION_ACTIVITY, check_session_activity).
  
positive.code: %% Initializes the session watcher.
  %% @end
  %%--------------------------------------------------------------------
  -spec init(Args :: term()) ->
      {ok, State :: state()} | {ok, State :: state(), timeout() | hibernate} |
      {stop, Reason :: term()} | ignore.
  init([SessId, SessType]) ->
      process_flag(trap_exit, true),
      Self = self(),
      {ok, #document{value = #session{
          identity = Identity,
          credentials = Credentials
      }}} = session:update(SessId, fun(#session{} = Sess) ->
          {ok, Sess#session{
              status = active,
              watcher = Self
          }}
      end),
  
      GracePeriod = get_session_grace_period(SessType),
      schedule_session_activity_checkup(GracePeriod),
  
      ValidityCheckupTimer = case Credentials of
          undefined ->
              undefined;
          TokenCredentials ->
              AccessTokenBin = auth_manager:get_access_token(TokenCredentials),
              {ok, AccessToken} = tokens:deserialize(AccessTokenBin),
  
              NextCheckupDelay = case caveats:infer_ttl(tokens:get_caveats(AccessToken)) of
                  undefined ->
                      ?SESSION_VALIDITY_CHECK_INTERVAL;
                  TokenTTL ->
                      min(?SESSION_VALIDITY_CHECK_INTERVAL, TokenTTL)
              end,
              schedule_session_validity_checkup(NextCheckupDelay)
      end,
  
      {ok, #state{
          session_id = SessId,
          session_grace_period = GracePeriod,
          identity = Identity,
          credentials = Credentials,
          validity_checkup_timer = ValidityCheckupTimer
      }}.
  
  
  
negative.code:             end),
              NewState = State#state{
                  credentials = NewTokenCredentials,
                  validity_checkup_timer = schedule_auth_validity_checkup(NewTokenTTL)
              },
              {reply, ok, NewState, hibernate};
          false ->
              mark_session_as_inactive(SessionId),
              schedule_session_removal(0),
              {reply, ok, State}
      end;
  