[guided]The goal of this step is to separate the variation of the integrand from the variation of the weighted density. Let $n := \dim M$, and let $S_g \in C^\infty(M)$ denote the scalar curvature of the metric $g$. For any smooth function $u \in C^\infty(M)$, we use the Laplace-Beltrami sign convention
\begin{align*}
\Delta_g u := \operatorname{div}_g(\nabla u).
\end{align*}
For any smooth function $u \in C^\infty(M)$, define $\operatorname{Hess}_g u \in \Gamma(T^*M\otimes T^*M)$ by
\begin{align*}
\operatorname{Hess}_g u(X,Y) := X(Yu) - (\nabla_XY)u
\end{align*}
for all vector fields $X,Y \in \mathfrak X(M)$, where $\nabla$ is the Levi-Civita connection of $g$.
In a local $g$-orthonormal frame, define
\begin{align*}
(\operatorname{div}_g h)_j := \sum_{i=1}^n \nabla_i h_{ij}
\end{align*}
and
\begin{align*}
\operatorname{div}_g\operatorname{div}_g h := \sum_{i,j=1}^n \nabla_j\nabla_i h_{ij}.
\end{align*}
We now compute the scalar-curvature variation rather than treating it as a black box. In a local $g$-orthonormal frame at a point, write a dot for $\frac{d}{ds}\big|_{s=0}$. If $h^\sharp \in \Gamma(\operatorname{End}(TM))$ is defined by $g(h^\sharp X,Y)=h(X,Y)$ for vector fields $X,Y \in \mathfrak X(M)$, then differentiating $g(s)^{ik}g(s)_{kj}=\delta^i_j$ gives
\begin{align*}
\frac{d}{ds}\Big|_{s=0}g(s)^{-1}=-h^\sharp,
\end{align*}
or, in components, $\dot g^{ij}=-h_{ij}$. Next, differentiating the formula for the Levi-Civita connection gives
\begin{align*}
\dot\Gamma_{ij}^k
=
\frac{1}{2}\left(\nabla_i h_{jk}+\nabla_j h_{ik}-\nabla_k h_{ij}\right).
\end{align*}
The Ricci tensor is the contraction $\operatorname{Ric}_{ij}=R_{kij}^{\phantom{kij}k}$ with the curvature convention used here, so its variation is
\begin{align*}
\dot{\operatorname{Ric}}_{ij}
=
\nabla_k\dot\Gamma_{ij}^k-\nabla_j\dot\Gamma_{ik}^k.
\end{align*}
Substituting the displayed expression for $\dot\Gamma$ gives
\begin{align*}
\dot{\operatorname{Ric}}_{ij}
=
\frac{1}{2}\left(
\nabla_k\nabla_i h_{jk}
+
\nabla_k\nabla_j h_{ik}
-
\nabla_k\nabla_k h_{ij}
-
\nabla_i\nabla_j\operatorname{tr}_g h
\right).
\end{align*}
After contraction with $g^{ij}$, the two mixed-divergence terms combine to $\operatorname{div}_g\operatorname{div}_g h$, and the trace term gives $-\Delta_g(\operatorname{tr}_g h)$, so
\begin{align*}
g^{ij}\dot{\operatorname{Ric}}_{ij}
=
\operatorname{div}_g\operatorname{div}_g h
-
\Delta_g(\operatorname{tr}_g h).
\end{align*}
Finally, differentiating $S_{g(s)}=g(s)^{ij}\operatorname{Ric}_{ij}(g(s))$ gives
\begin{align*}
\frac{d}{ds}\Big|_{s=0}S_{g(s)}
=
-\langle h,\operatorname{Ric}_g\rangle_g
+
\operatorname{div}_g\operatorname{div}_g h
-
\Delta_g(\operatorname{tr}_g h).
\end{align*}
The other moving part of the integrand is $|\nabla^{g(s)} f(s)|_{g(s)}^2$. Differentiating the inverse metric gives the tensor term $-\langle h,\nabla f\otimes\nabla f\rangle_g$, while differentiating the function $f(s)$ gives $2\langle \nabla f,\nabla v\rangle_g$. Hence
\begin{align*}
\frac{d}{ds}\Big|_{s=0}|\nabla^{g(s)} f(s)|_{g(s)}^2
=
-\langle h,\nabla f\otimes\nabla f\rangle_g
+
2\langle \nabla f,\nabla v\rangle_g.
\end{align*}
The product rule for the functional $\mathcal F$ therefore gives three contributions: scalar curvature, gradient norm, and weighted-density variation. Using the previous step for the density term, we get
\begin{align*}
\frac{d}{ds}\Big|_{s=0}\mathcal F[g(s),f(s)]
=
\int_M
\left[
-\langle h,\operatorname{Ric}_g\rangle_g
+
\operatorname{div}_g\operatorname{div}_g h
-
\Delta_g(\operatorname{tr}_g h)
\right]e^{-f}\,d\mu_g
+
\int_M
\left[
-\langle h,\nabla f\otimes\nabla f\rangle_g
+
2\langle \nabla f,\nabla v\rangle_g
\right]e^{-f}\,d\mu_g
+
\int_M
\left(S_g+|\nabla f|_g^2\right)
\left(\frac{1}{2}\operatorname{tr}_g(h)-v\right)e^{-f}\,d\mu_g.
\end{align*}
The constraint from the first step says $v=\frac{1}{2}\operatorname{tr}_g(h)$, so the entire density-variation contribution is zero. This leaves only the curvature and gradient-norm variations to be simplified by [integration by parts](/theorems/2098).[/guided]