hcju/stacksqa huggingface dataset:
The question is local on $X$ hence we may assume that $X$ and $Y$ are affine schemes. In this case we can factor $f : X \to Y$ as $$ X \xrightarrow{i} \mathbf{A}^n_Y \to \mathbf{A}^{n - 1}_Y \to \ldots \to \mathbf{A}^1_Y \to Y $$ where $i$ is a closed immersion. By Lemma \ref{lemma-shriek-affine-line} and Dualizing Complexes, Lemma \ref{dualizing-lemma-dualizing-polynomial-ring} and induction we see that the $p^!K$ is a dualizing complex on $\mathbf{A}^n_Y$ where $p : \mathbf{A}^n_Y \to Y$ is the projection. Similarly, by Dualizing Complexes, Lemma \ref{dualizing-lemma-dualizing-quotient} and Lemmas \ref{lemma-sheaf-with-exact-support-quasi-coherent} and \ref{lemma-shriek-closed-immersion} we see that $i^!$ transforms dualizing complexes into dualizing complexes.
Choose compactification $j : X \subset \overline{X}$ of $X$ over $Y$ (More on Flatness, Theorem \ref{flat-theorem-nagata} and Lemma \ref{flat-lemma-compactifyable}). Let $a$ be the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for $\overline{X} \to Y$. Set $D_{\overline{X}}(E) = R\SheafHom_{\mathcal{O}_{\overline{X}}}(E, a(K))$ for $E \in D_{\textit{Coh}}(\mathcal{O}_{\overline{X}})$. Since formation of $R\SheafHom$ commutes with restriction to opens and since $f^! = j^* \circ a$ we see that it suffices to prove that there is a canonical isomorphism $$ a(M) \longrightarrow D_{\overline{X}}(L\overline{f}^*D_Y(M)) $$ for $M \in D_{\textit{Coh}}(\mathcal{O}_Y)$. For $F \in D_\QCoh(\mathcal{O}_X)$ we have \begin{align*} \Hom_{\overline{X}}( F, D_{\overline{X}}(L\overline{f}^*D_Y(M))) & = \Hom_{\overline{X}}( F \otimes_{\mathcal{O}_X}^\mathbf{L} L\overline{f}^*D_Y(M), a(K)) \\ & = \Hom_Y( R\overline{f}_*(F \otimes_{\mathcal{O}_X}^\mathbf{L} L\overline{f}^*D_Y(M)), K) \\ & = \Hom_Y( R\overline{f}_*(F) \otimes_{\mathcal{O}_Y}^\mathbf{L} D_Y(M), K) \\ & = \Hom_Y( R\overline{f}_*(F), D_Y(D_Y(M))) \\ & = \Hom_Y(R\overline{f}_*(F), M) \\ & = \Hom_{\overline{X}}(F, a(M)) \end{align*} The first equality by Cohomology, Lemma \ref{cohomology-lemma-internal-hom}. The second by definition of $a$. The third by Derived Categories of Schemes, Lemma \ref{perfect-lemma-cohomology-base-change}. The fourth equality by Cohomology, Lemma \ref{cohomology-lemma-internal-hom} and the definition of $D_Y$. The fifth equality by Lemma \ref{lemma-dualizing-schemes}. The final equality by definition of $a$. Hence we see that $a(M) = D_{\overline{X}}(L\overline{f}^*D_Y(M))$ by Yoneda's lemma.
(A flat morphism of finite presentation is perfect, see More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-finite-presentation-perfect}.) We begin with a series of preliminary remarks. \begin{enumerate} \item We already know that $f^!$ sends $D_{\textit{Coh}}^+(\mathcal{O}_Y)$ into $D_{\textit{Coh}}^+(\mathcal{O}_X)$, see Lemma \ref{lemma-shriek-coherent}. \item If $f$ is an open immersion, then (a) and (b) are true because we can take $\overline{X} = Y$ in the construction of $f^!$ and $\mu_f$. See also Lemma \ref{lemma-shriek-open-immersion}. \item If $f$ is a perfect proper morphism, then (b) is true by Lemma \ref{lemma-compare-with-pullback-flat-proper-noetherian}. \item If there exists an open covering $X = \bigcup U_i$ and (a) is true for $U_i \to Y$, then (a) is true for $X \to Y$. Same for (b). This holds because the construction of $f^!$ and $\mu_f$ commutes with passing to open subschemes. \item If $g : Y \to Z$ is a second perfect morphism in $\textit{FTS}_S$ and (b) holds for $f$ and $g$, then $f^!g^!\mathcal{O}_Z = Lf^*g^!\mathcal{O}_Z \otimes_{\mathcal{O}_X}^\mathbf{L} f^!\mathcal{O}_Y$ and (b) holds for $g \circ f$ by the commutative diagram of Lemma \ref{lemma-map-pullback-to-shriek-well-defined}. \item If (a) and (b) hold for both $f$ and $g$, then (a) and (b) hold for $g \circ f$. Namely, then $f^!g^!\mathcal{O}_Z$ is bounded above (by the previous point) and $L(g \circ f)^*$ has finite cohomological dimension and (a) follows from (b) which we saw above. \end{enumerate} From these points we see it suffices to prove the result in case $X$ is affine. Choose an immersion $X \to \mathbf{A}^n_Y$ (Morphisms, Lemma \ref{morphisms-lemma-quasi-affine-finite-type-over-S}) which we factor as $X \to U \to \mathbf{A}^n_Y \to Y$ where $X \to U$ is a closed immersion and $U \subset \mathbf{A}^n_Y$ is open. Note that $X \to U$ is a perfect closed immersion by More on Morphisms, Lemma \ref{more-morphisms-lemma-perfect-permanence}. Thus it suffices to prove the lemma for a perfect closed immersion and for the projection $\mathbf{A}^n_Y \to Y$. \medskip\noindent Let $f : X \to Y$ be a perfect closed immersion. We already know (b) holds. Let $K \in D^b_{\textit{Coh}}(\mathcal{O}_Y)$. Then $f^!K = R\SheafHom(\mathcal{O}_X, K)$ (Lemma \ref{lemma-shriek-closed-immersion}) and $f_*f^!K = R\SheafHom_{\mathcal{O}_Y}(f_*\mathcal{O}_X, K)$. Since $f$ is perfect, the complex $f_*\mathcal{O}_X$ is perfect and hence $R\SheafHom_{\mathcal{O}_Y}(f_*\mathcal{O}_X, K)$ is bounded above. This proves that (a) holds. Some details omitted. \medskip\noindent Let $f : \mathbf{A}^n_Y \to Y$ be the projection. Then (a) holds by repeated application of Lemma \ref{lemma-shriek-affine-line}. Finally, (b) is true because it holds for $\mathbf{P}^n_Y \to Y$ (flat and proper) and because $\mathbf{A}^n_Y \subset \mathbf{P}^n_Y$ is an open.
Both assertions are local on $X$. Thus we may assume $X$ and $Y$ are affine. Then Remark \ref{remark-local-calculation-shriek} turns the lemma into an algebra lemma, namely Dualizing Complexes, Lemma \ref{dualizing-lemma-relative-dualizing-algebraic}. (Use Derived Categories of Schemes, Lemma \ref{perfect-lemma-affine-locally-rel-perfect} to match the languages.)
Recall that a local complete intersection morphism is perfect, see More on Morphisms, Lemma \ref{more-morphisms-lemma-lci-properties}. By Lemma \ref{lemma-perfect-comparison-shriek} it suffices to show that $f^!\mathcal{O}_Y$ is an invertible object in $D(\mathcal{O}_X)$. This question is local on $X$ and $Y$. Hence we may assume that $X \to Y$ factors as $X \to \mathbf{A}^n_Y \to Y$ where the first arrow is a Koszul regular immersion. See More on Morphisms, Section \ref{more-morphisms-section-lci}. The result holds for $\mathbf{A}^n_Y \to Y$ by Lemma \ref{lemma-shriek-affine-line}. Thus it suffices to prove the lemma when $f$ is a Koszul regular immersion. Working locally once again we reduce to the case $X = \Spec(A)$ and $Y = \Spec(B)$, where $A = B/(f_1, \ldots, f_r)$ for some regular sequence $f_1, \ldots, f_r \in B$ (use that for Noetherian local rings the notion of Koszul regular and regular are the same, see More on Algebra, Lemma \ref{more-algebra-lemma-noetherian-finite-all-equivalent}). Thus $X \to Y$ is a composition $$ X = X_r \to X_{r - 1} \to \ldots \to X_1 \to X_0 = Y $$ where each arrow is the inclusion of an effective Cartier divisor. In this way we reduce to the case of an inclusion of an effective Cartier divisor $i : D \to X$. In this case $i^!\mathcal{O}_X = \mathcal{N}[1]$ by Lemma \ref{lemma-compute-for-effective-Cartier} and the proof is complete.
Namely, because $g$ is flat, for every choice of compactification $j : X \to \overline{X}$ of $X$ over $Y$ the scheme $\overline{X}$ is Tor independent of $Y'$. Denote $j' : X' \to \overline{X}'$ the base change of $j$ and $\overline{g}' : \overline{X}' \to \overline{X}$ the projection. We define the base change map as the composition $$ L(g')^* \circ f^! = L(g')^* \circ j^* \circ a = (j')^* \circ L(\overline{g}')^* \circ a \longrightarrow (j')^* \circ a' \circ Lg^* = (f')^! \circ Lg^* $$ where the middle arrow is the base change map (\ref{equation-base-change-map}) and $a$ and $a'$ are the right adjoints to pushforward of Lemma \ref{lemma-twisted-inverse-image} for $\overline{X} \to Y$ and $\overline{X}' \to Y'$. This construction is independent of the choice of compactification (we will formulate a precise lemma and prove it, if we ever need this result). \medskip\noindent To finish the proof it suffices to show that the base change map $L(g')^* \circ a \to a' \circ Lg^*$ is an isomorphism on $D_\QCoh^+(\mathcal{O}_Y)$. By Lemma \ref{lemma-proper-noetherian} formation of $a$ and $a'$ commutes with restriction to affine opens of $Y$ and $Y'$. Thus by Remark \ref{remark-check-over-affines} we may assume that $Y$ and $Y'$ are affine. Thus the result by Lemma \ref{lemma-more-base-change}.
We are going to use that an \'etale morphism is flat, syntomic, and a local complete intersection morphism (Morphisms, Lemma \ref{morphisms-lemma-etale-syntomic} and \ref{morphisms-lemma-etale-flat} and More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-lci}). By Lemma \ref{lemma-perfect-comparison-shriek} it suffices to show $f^!\mathcal{O}_Y = \mathcal{O}_X$. By Lemma \ref{lemma-lci-shriek} we know that $f^!\mathcal{O}_Y$ is an invertible module. Consider the commutative diagram $$ \xymatrix{ X \times_Y X \ar[r]_{p_2} \ar[d]_{p_1} & X \ar[d]^f \\ X \ar[r]^f & Y } $$ and the diagonal $\Delta : X \to X \times_Y X$. Since $\Delta$ is an open immersion (by Morphisms, Lemmas \ref{morphisms-lemma-diagonal-unramified-morphism} and \ref{morphisms-lemma-etale-smooth-unramified}), by Lemma \ref{lemma-shriek-open-immersion} we have $\Delta^! = \Delta^*$. By Lemma \ref{lemma-upper-shriek-composition} we have $\Delta^! \circ p_1^! \circ f^! = f^!$. By Lemma \ref{lemma-base-change-shriek-flat} applied to the diagram we have $p_1^!\mathcal{O}_X = p_2^*f^!\mathcal{O}_Y$. Hence we conclude $$ f^!\mathcal{O}_X = \Delta^!p_1^!f^!\mathcal{O}_Y = \Delta^*(p_1^*f^!\mathcal{O}_Y \otimes p_1^!\mathcal{O}_X) = \Delta^*(p_2^*f^!\mathcal{O}_Y \otimes p_1^*f^!\mathcal{O}_Y) = (f^!\mathcal{O}_Y)^{\otimes 2} $$ where in the second step we have used Lemma \ref{lemma-perfect-comparison-shriek} once more. Thus $f^!\mathcal{O}_Y = \mathcal{O}_X$ as desired.
By our assumptions we immediately reduce to the case where $X$, $Y$, $Y'$, and $X'$ are affine. Say $Y = \Spec(R)$, $Y' = \Spec(R')$, $X = \Spec(A)$, and $X' = \Spec(A')$. Then $A' = A \otimes_R R'$. Let $E$ correspond to $K \in D^+(R)$. Denoting $\varphi : R \to A$ and $\varphi' : R' \to A'$ the given maps we see from Remark \ref{remark-local-calculation-shriek} that $L(g')^*f^!E$ and $(f')^!Lg^*E$ correspond to $\varphi^!(K) \otimes_A^\mathbf{L} A'$ and $(\varphi')^!(K \otimes_R^\mathbf{L} R')$ where $\varphi^!$ and $(\varphi')^!$ are the functors from Dualizing Complexes, Section \ref{dualizing-section-relative-dualizing-complex-algebraic}. The result follows from Dualizing Complexes, Lemma \ref{dualizing-lemma-bc-flat}.
The complex $\omega_{X/Y}^\bullet$ is in $D^b_{\textit{Coh}}$ by Lemma \ref{lemma-perfect-comparison-shriek}. Being a dualizing complex is a local property. Hence by Lemma \ref{lemma-base-change-locally} it suffices to show that $(X_y \to y)^!\mathcal{O}_y$ is a dualizing complex on $X_y$. This follows from Lemma \ref{lemma-shriek-dualizing}.
If $(K, \alpha_i)$ and $(K', \alpha_i')$ are two, then we consider $L = R\SheafHom_{\mathcal{O}_X}(K, K')$. By Lemma \ref{lemma-dualizing-unique-schemes} and its proof, this is an invertible object of $D(\mathcal{O}_X)$. Using $\alpha_i$ and $\alpha'_i$ we obtain an isomorphism $$ \alpha_i^t \otimes \alpha'_i : L|_{U_i} \longrightarrow R\SheafHom_{\mathcal{O}_X}(\omega_i^\bullet, \omega_i^\bullet) = \mathcal{O}_{U_i}[0] $$ This already implies that $L = H^0(L)[0]$ in $D(\mathcal{O}_X)$. Moreover, $H^0(L)$ is an invertible sheaf with given trivializations on the opens $U_i$ of $X$. Finally, the condition that $\alpha_j|_{U_i \cap U_j} \circ \alpha_i^{-1}|_{U_i \cap U_j}$ and $\alpha'_j|_{U_i \cap U_j} \circ (\alpha'_i)^{-1}|_{U_i \cap U_j}$ both give $\varphi_{ij}$ implies that the transition maps are $1$ and we get an isomorphism $H^0(L) = \mathcal{O}_X$.
It suffices to prove this when $\mathcal{U}$ is given by the opens $U_1, \ldots, U_n$ and $\mathcal{V}$ by the opens $U_1, \ldots, U_{n + m}$. In fact, we may and do even assume $m = 1$. To go from a dualizing complex $(K, \alpha_i)$ normalized relative to $\omega_S^\bullet$ and $\mathcal{V}$ to a dualizing complex normalized relative to $\omega_S^\bullet$ and $\mathcal{U}$ is achieved by forgetting about $\alpha_i$ for $i = n + 1$. Conversely, let $(K, \alpha_i)$ be a dualizing complex normalized relative to $\omega_S^\bullet$ and $\mathcal{U}$. To finish the proof we need to construct a map $\alpha_{n + 1} : K|_{U_{n + 1}} \to \omega_{n + 1}^\bullet$ satisfying the desired conditions. To do this we observe that $U_{n + 1} = \bigcup U_i \cap U_{n + 1}$ is an open covering. It is clear that $(K|_{U_{n + 1}}, \alpha_i|_{U_i \cap U_{n + 1}})$ is a dualizing complex normalized relative to $\omega_S^\bullet$ and the covering $U_{n + 1} = \bigcup U_i \cap U_{n + 1}$. On the other hand, by condition (\ref{item-cocycle-glueing}) the pair $(\omega_{n + 1}^\bullet|_{U_{n + 1}}, \varphi_{n + 1i})$ is another dualizing complex normalized relative to $\omega_S^\bullet$ and the covering $U_{n + 1} = \bigcup U_i \cap U_{n + 1}$. By Lemma \ref{lemma-good-dualizing-unique} we obtain a unique isomorphism $$ \alpha_{n + 1} : K|_{U_{n + 1}} \longrightarrow \omega_{n + 1}^\bullet $$ compatible with the given local isomorphisms. It is a pleasant exercise to show that this means it satisfies the required property.
Say $\mathcal{U} : X = \bigcup_{i = 1, \ldots, n} U_i$. We prove the lemma by induction on $n$. The base case $n = 1$ is immediate. Assume $n > 1$. Set $X' = U_1 \cup \ldots \cup U_{n - 1}$ and let $(K', \{\alpha'_i\}_{i = 1, \ldots, n - 1})$ be a dualizing complex normalized relative to $\omega_S^\bullet$ and $\mathcal{U}' : X' = \bigcup_{i = 1, \ldots, n - 1} U_i$. It is clear that $(K'|_{X' \cap U_n}, \alpha'_i|_{U_i \cap U_n})$ is a dualizing complex normalized relative to $\omega_S^\bullet$ and the covering $X' \cap U_n = \bigcup_{i = 1, \ldots, n - 1} U_i \cap U_n$. On the other hand, by condition (\ref{item-cocycle-glueing}) the pair $(\omega_n^\bullet|_{X' \cap U_n}, \varphi_{ni})$ is another dualizing complex normalized relative to $\omega_S^\bullet$ and the covering $X' \cap U_n = \bigcup_{i = 1, \ldots, n - 1} U_i \cap U_n$. By Lemma \ref{lemma-good-dualizing-unique} we obtain a unique isomorphism $$ \epsilon : K'|_{X' \cap U_n} \longrightarrow \omega_i^\bullet|_{X' \cap U_n} $$ compatible with the given local isomorphisms. By Cohomology, Lemma \ref{cohomology-lemma-glue} we obtain $K \in D(\mathcal{O}_X)$ together with isomorphisms $\beta : K|_{X'} \to K'$ and $\gamma : K|_{U_n} \to \omega_n^\bullet$ such that $\epsilon = \gamma|_{X'\cap U_n} \circ \beta|_{X' \cap U_n}^{-1}$. Then we define $$ \alpha_i = \alpha'_i \circ \beta|_{U_i}, i = 1, \ldots, n - 1, \text{ and } \alpha_n = \gamma $$ We still need to verify that $\varphi_{ij}$ is given by $\alpha_j|_{U_i \cap U_j} \circ \alpha_i^{-1}|_{U_i \cap U_j}$. For $i, j \leq n - 1$ this follows from the corresponding condition for $\alpha_i'$. For $i = j = n$ it is clear as well. If $i < j = n$, then we get $$ \alpha_n|_{U_i \cap U_n} \circ \alpha_i^{-1}|_{U_i \cap U_n} = \gamma|_{U_i \cap U_n} \circ \beta^{-1}|_{U_i \cap U_n} \circ (\alpha'_i)^{-1}|_{U_i \cap U_n} = \epsilon|_{U_i \cap U_n} \circ (\alpha'_i)^{-1}|_{U_i \cap U_n} $$ This is equal to $\alpha_{in}$ exactly because $\epsilon$ is the unique map compatible with the maps $\alpha_i'$ and $\alpha_{ni}$.
Let $p : X \to S$ and $q : Y \to S$ be the structure morphisms. If $X$ and $Y$ are separated over $S$, then this follows from the fact that $\omega_X^\bullet = p^!\omega_S^\bullet$, $\omega_Y^\bullet = q^!\omega_S^\bullet$, $f^! = a$, and $f^! \circ q^! = p^!$ (Lemma \ref{lemma-upper-shriek-composition}). In the general case we first use Lemma \ref{lemma-good-over-both} to reduce to the case $Y = S$. In this case $X$ and $Y$ are separated over $S$ and we've just seen the result.
Let $f : X \to Y$, $g : Y \to Z$, $h : Z \to T$ be morphisms of schemes of finite type over $S$. We have to show that $$ \xymatrix{ (h \circ g \circ f)^!_{new} \ar[r] \ar[d] & f^!_{new} \circ (h \circ g)^!_{new} \ar[d] \\ (g \circ f)^!_{new} \circ h^!_{new} \ar[r] & f^!_{new} \circ g^!_{new} \circ h^!_{new} } $$ is commutative. Let $\eta_Y : \text{id} \to D_Y^2$ and $\eta_Z : \text{id} \to D_Z^2$ be the canonical isomorphisms of Lemma \ref{lemma-dualizing-schemes}. Then, using Categories, Lemma \ref{categories-lemma-properties-2-cat-cats}, a computation (omitted) shows that both arrows $(h \circ g \circ f)^!_{new} \to f^!_{new} \circ g^!_{new} \circ h^!_{new}$ are given by $$ 1 \star \eta_Y \star 1 \star \eta_Z \star 1 : D_X \circ Lf^* \circ Lg^* \circ Lh^* \circ D_T \longrightarrow D_X \circ Lf^* \circ D_Y^2 \circ Lg^* \circ D_Z^2 \circ Lh^* \circ D_T $$ This proves (1). Part (2) is immediate from the definition of $(X \to S)^!_{new}$ and the fact that $D_S(\omega_S^\bullet) = \mathcal{O}_S$. Part (3) is Lemma \ref{lemma-dualizing-schemes}. Part (4) follows by the same argument as part (2). Part (5) is the definition of $f^!_{new}$. \medskip\noindent Proof of (6). Let $a$ be the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for the proper morphism $f : X \to Y$ of schemes of finite type over $S$. The issue is that we do not know $X$ or $Y$ is separated over $S$ (and in general this won't be true) hence we cannot immediately apply Lemma \ref{lemma-shriek-via-duality} to $f$ over $S$. To get around this we use the canonical identification $\omega_X^\bullet = a(\omega_Y^\bullet)$ of Lemma \ref{lemma-proper-map-good-dualizing-complex}. Hence $f^!_{new}$ is the restriction of $a$ to $D_{\textit{Coh}}^+(\mathcal{O}_Y)$ by Lemma \ref{lemma-shriek-via-duality} applied to $f : X \to Y$ over the base scheme $Y$! The displayed equalities hold by Example \ref{example-iso-on-RSheafHom-noetherian}. \medskip\noindent The final assertions follow from the construction of normalized dualizing complexes and the already used Lemma \ref{lemma-shriek-via-duality}.
We may replace $X$ by an affine neighbourhood of $x$, hence we may and do assume that $f : X \to S$ is separated. Then $\omega_X^\bullet = f^!\omega_S^\bullet$. We have to show that $R\Hom_{\mathcal{O}_{X, x}}(\kappa(x), \omega_{X, x}^\bullet)$ is sitting in degree $0$. Let $i_x : x \to X$ denote the inclusion morphism which is a closed immersion as $x$ is a closed point. Hence $R\Hom_{\mathcal{O}_{X, x}}(\kappa(x), \omega_{X, x}^\bullet)$ represents $i_x^!\omega_X^\bullet$ by Lemma \ref{lemma-shriek-closed-immersion}. Consider the commutative diagram $$ \xymatrix{ x \ar[r]_{i_x} \ar[d]_\pi & X \ar[d]^f \\ s \ar[r]^{i_s} & S } $$ By Morphisms, Lemma \ref{morphisms-lemma-closed-point-fibre-locally-finite-type} the extension $\kappa(s) \subset \kappa(x)$ is finite and hence $\pi$ is a finite morphism. We conclude that $$ i_x^!\omega_X^\bullet = i_x^! f^! \omega_S^\bullet = \pi^! i_s^! \omega_S^\bullet $$ Thus if $\omega_{S, s}^\bullet$ is a normalized dualizing complex over $\mathcal{O}_{S, s}$, then $i_s^!\omega_S^\bullet = \kappa(s)[0]$ by the same reasoning as above. We have $$ R\pi_*(\pi^!(\kappa(s)[0])) = R\SheafHom_{\mathcal{O}_s}(R\pi_*(\kappa(x)[0]), \kappa(s)[0]) = \widetilde{\Hom_{\kappa(s)}(\kappa(x), \kappa(s))} $$ The first equality by Example \ref{example-iso-on-RSheafHom-noetherian} applied with $L = \kappa(x)[0]$. The second equality holds because $\pi_*$ is exact. Thus $\pi^!(\kappa(s)[0])$ is supported in degree $0$ and we win.
We may replace $X$ by an affine neighbourhood of $x$. Hence we may and do assume there is a compactification $X \subset \overline{X}$ over $S$. Then we may replace $X$ by $\overline{X}$ and assume that $X$ is proper over $S$. We may also assume $X$ is connected by replacing $X$ by the connected component of $X$ containing $x$. Next, recall that both $\delta_X$ and the function $x \mapsto \delta_S(f(x)) + \text{trdeg}_{\kappa(f(x))}(\kappa(x))$ are dimension functions on $X$, see Morphisms, Lemma \ref{morphisms-lemma-dimension-function-propagates} (and the fact that $S$ is universally catenary by Lemma \ref{lemma-dimension-function-scheme}). By Topology, Lemma \ref{topology-lemma-dimension-function-unique} we see that the difference is locally constant, hence constant as $X$ is connected. Thus it suffices to prove equality in any point of $X$. By Properties, Lemma \ref{properties-lemma-locally-Noetherian-closed-point} the scheme $X$ has a closed point $x$. Since $X \to S$ is proper the image $s$ of $x$ is closed in $S$. Thus we may apply Lemma \ref{lemma-good-dualizing-normalized} to conclude.
Since the statement is local on $X$ we may assume $X$ and $Y$ are affine schemes. Write $X = \Spec(A)$ and $Y = \Spec(R)$. Then $f^!\mathcal{O}_Y$ corresponds to the relative dualizing complex $\omega_{A/R}^\bullet$ of Dualizing Complexes, Section \ref{dualizing-section-relative-dualizing-complexes-Noetherian} by Remark \ref{remark-local-calculation-shriek}. Thus the lemma follows from Dualizing Complexes, Lemma \ref{dualizing-lemma-relative-dualizing-trivial-vanishing}.
The relative dimension $d$ is well defined and locally constant by Morphisms, Lemma \ref{morphisms-lemma-flat-finite-presentation-CM-fibres-relative-dimension}. The cohomology sheaves of $f^!\mathcal{O}_Y$ are coherent by Lemma \ref{lemma-shriek-coherent}. We will get flatness of $\omega_{X/Y}$ from Lemma \ref{lemma-flat-shriek} if we can show the other cohomology sheaves of $f^!\mathcal{O}_Y$ are zero. \medskip\noindent The question is local on $X$, hence we may assume $X$ and $Y$ are affine and the morphism has relative dimension $d$. If $d = 0$, then the result follows directly from Lemma \ref{lemma-flat-quasi-finite-shriek}. If $d > 0$, then we may assume there is a factorization $$ X \xrightarrow{g} \mathbf{A}^d_Y \xrightarrow{p} Y $$ with $g$ quasi-finite and flat, see More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-finite-presentation-characterize-CM}. Then $f^! = g^! \circ p^!$. By Lemma \ref{lemma-shriek-affine-line} we see that $p^!\mathcal{O}_Y \cong \mathcal{O}_{\mathbf{A}^d_Y}[-d]$. We conclude by the case $d = 0$.
By our conventions discussed above there exists a dualizing complex $\omega_X^\bullet$ such that $\omega_X$ is the leftmost nonvanishing cohomology sheaf. Since $X$ is connected, any two dimension functions differ by a constant (Topology, Lemma \ref{topology-lemma-dimension-function-unique}). Hence we may use the dimension function associated to $\omega_X^\bullet$ (Lemma \ref{lemma-dimension-function-scheme}). With these remarks in place, the lemma now follows from Dualizing Complexes, Lemma \ref{dualizing-lemma-depth-dualizing-module} and the definitions (in particular Cohomology of Schemes, Definition \ref{coherent-definition-depth}).
Let $\delta_X$ and $\delta_S$ be the dimension functions associated to $\omega_X^\bullet$ and $\omega_S^\bullet$ as in Lemma \ref{lemma-good-dualizing-dimension-function}. As $X$ is proper over $A$, every closed subscheme of $X$ contains a closed point $x$ which maps to the closed point $s \in S$ and $\delta_X(x) = \delta_S(s) = 0$. Hence $\delta_X(\xi) = \dim(\overline{\{\xi\}})$ for any point $\xi \in X$. Hence we can check each of the statements of the lemma by looking at what happens over $\Spec(\mathcal{O}_{X, x})$ in which case the result follows from Dualizing Complexes, Lemmas \ref{dualizing-lemma-sitting-in-degrees} and \ref{dualizing-lemma-depth-dualizing-module}. Some details omitted. The last two statements can also be deduced from Lemma \ref{lemma-dualizing-module}.