private void invokeSafely(@NotNull Task<?, ?> task, int attempt) {
    try (AccessToken ignored = ClientId.withClientId(task.clientId)) {
      try {
        if (task.canInvoke(disposed)) {
          if (!delegate.run(task, task.promise)) {
            offerRestart(task, attempt);
            return;
          }
          if (task instanceof Task.Async<?> t) {
            Promise<?> incomplete = t.setDone();
            if (incomplete != null) {
              count.incrementAndGet();
              incomplete
                .onError(th -> handleTaskError(task, th, attempt))
                .onProcessed(r -> count.decrementAndGet());
            }
          }
          else if (task instanceof Task.Sync<?> t) {
            t.setDone();
          }
        }
      }
      catch (Throwable throwable) {
        handleTaskError(task, throwable, attempt);
      }
      finally {
        count.decrementAndGet();
      }
    }
  }
private void invokeSafely(@NotNull Task<?, ?> task, int attempt)