hcju/stacksqa huggingface dataset:
We have \begin{align*} \Hom_X(\mathcal{F}, \omega_X) & = \Ext^{-\dim(X)}_X(\mathcal{F}, \omega_X^\bullet) \\ & = \Hom_X(\mathcal{F}[\dim(X)], \omega_X^\bullet) \\ & = \Hom_X(\mathcal{F}[\dim(X)], f^!(\omega_A^\bullet)) \\ & = \Hom_S(Rf_*\mathcal{F}[\dim(X)], \omega_A^\bullet) \\ & = \Hom_A(H^d(X, \mathcal{F}), \omega_A) \end{align*} The first equality because $H^i(\omega_X^\bullet) = 0$ for $i < -\dim(X)$, see Lemma \ref{lemma-vanishing-good-dualizing} and Derived Categories, Lemma \ref{derived-lemma-negative-exts}. The second equality is follows from the definition of Ext groups. The third equality is our choice of $\omega_X^\bullet$. The fourth equality holds because $f^!$ is the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for $f$, see Section \ref{section-duality}. The final equality holds because $R^if_*\mathcal{F}$ is zero for $i > d$ (Cohomology of Schemes, Lemma \ref{coherent-lemma-higher-direct-images-zero-above-dimension-fibre}) and $H^j(\omega_A^\bullet)$ is zero for $j < -\dim(A)$.
By definition and Dualizing Complexes, Lemma \ref{dualizing-lemma-dualizing-localize} for every $x \in X$ the complex $\omega_{X, x}^\bullet$ is a dualizing complex over $\mathcal{O}_{X, x}$. By Dualizing Complexes, Lemma \ref{dualizing-lemma-apply-CM} we see that (2) holds. \medskip\noindent To see (3) assume that $\mathcal{O}_{X, x}$ is Cohen-Macaulay. Let $n_x$ be the unique integer such that $H^{n_{x}}(\omega_{X, x}^\bullet)$ is nonzero. For an affine neighbourhood $V \subset X$ of $x$ we have $\omega_X^\bullet|_V$ is in $D^b_{\textit{Coh}}(\mathcal{O}_V)$ hence there are finitely many nonzero coherent modules $H^i(\omega_X^\bullet)|_V$. Thus after shrinking $V$ we may assume only $H^{n_x}$ is nonzero, see Modules, Lemma \ref{modules-lemma-finite-type-stalk-zero}. In this way we see that $\mathcal{O}_{X, v}$ is Cohen-Macaulay for every $v \in V$. This proves that $U$ is open as well as a Cohen-Macaulay scheme. \medskip\noindent Proof of (1). The implication $\Leftarrow$ follows from (2). The implication $\Rightarrow$ follows from the discussion in the previous paragraph, where we showed that if $\mathcal{O}_{X, x}$ is Cohen-Macaulay, then in a neighbourhood of $x$ the complex $\omega_X^\bullet$ has only one nonzero cohomology sheaf. \medskip\noindent Assume $X$ is connected and Cohen-Macaulay. The above shows that the map $x \mapsto n_x$ is locally constant. Since $X$ is connected it is constant, say equal to $n$. Setting $\omega_X = H^n(\omega_X^\bullet)$ we see that the lemma holds because $\omega_X$ is Cohen-Macaulay by Dualizing Complexes, Lemma \ref{dualizing-lemma-apply-CM} (and Cohomology of Schemes, Definition \ref{coherent-definition-Cohen-Macaulay}).
One direction of the lemma follows from Lemma \ref{lemma-CM-shriek}. To prove the converse, we may assume $f^!\mathcal{O}_Y$ has a unique nonzero cohomology sheaf. Let $y = f(x)$. Let $\xi_1, \ldots, \xi_n \in X_y$ be the generic points of the fibre $X_y$ specializing to $x$. Let $d_1, \ldots, d_n$ be the dimensions of the corresponding irreducible components of $X_y$. The morphism $f : X \to Y$ is Cohen-Macaulay at $\eta_i$ by More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-finite-presentation-CM-open}. Hence by Lemma \ref{lemma-CM-shriek} we see that $d_1 = \ldots = d_n$. If $d$ denotes the common value, then $d = \dim_x(X_y)$. After shrinking $X$ we may assume all fibres have dimension at most $d$ (Morphisms, Lemma \ref{morphisms-lemma-openness-bounded-dimension-fibres}). Then the only nonzero cohomology sheaf $\omega = H^{-d}(f^!\mathcal{O}_Y)$ is flat over $Y$ by Lemma \ref{lemma-flat-shriek}. Hence, if $h : X_y \to X$ denotes the canonical morphism, then $Lh^*(f^!\mathcal{O}_Y) = Lh^*(\omega[d]) = (h^*\omega)[d]$ by Derived Categories of Schemes, Lemma \ref{perfect-lemma-tor-independence-and-tor-amplitude}. Thus $h^*\omega[d]$ is the dualizing complex of $X_y$ by Lemma \ref{lemma-relative-dualizing-fibres}. Hence $X_y$ is Cohen-Macaulay by Lemma \ref{lemma-dualizing-module-CM-scheme}. This proves $f$ is Cohen-Macaulay at $x$ as desired.
Let $\{S_i \to S\}$ be a syntomic covering. The scheme $S$ is locally Noetherian if and only if each $S_i$ is Noetherian, see Descent, Lemma \ref{descent-lemma-Noetherian-local-fppf}. Thus we may now assume $S$ and $S_i$ are locally Noetherian. If $S$ is Gorenstein, then each $S_i$ is Gorenstein by Lemma \ref{lemma-gorenstein-lci}. Conversely, if each $S_i$ is Gorenstein, then for each point $s \in S$ we can pick $i$ and $t \in S_i$ mapping to $s$. Then $\mathcal{O}_{S, s} \to \mathcal{O}_{S_i, t}$ is a flat local ring homomorphism with $\mathcal{O}_{S_i, t}$ Gorenstein. Hence $\mathcal{O}_{S, s}$ is Gorenstein by Dualizing Complexes, Lemma \ref{dualizing-lemma-flat-under-gorenstein}.
In both cases the ring map $\mathcal{O}_{X, x} \to \mathcal{O}_{X_{k'}, x'}$ is a faithfully flat local homomorphism of Noetherian local rings. Thus if $\mathcal{O}_{X_{k'}, x'}$ is Gorenstein, then so is $\mathcal{O}_{X, x}$ by Dualizing Complexes, Lemma \ref{dualizing-lemma-flat-under-gorenstein}. To go up, we use Dualizing Complexes, Lemma \ref{dualizing-lemma-flat-under-gorenstein} as well. Thus we have to show that $$ \mathcal{O}_{X_{k'}, x'}/\mathfrak m_x \mathcal{O}_{X_{k'}, x'} = \kappa(x) \otimes_k k' $$ is Gorenstein. Note that in the first case $k \to k'$ is finitely generated and in the second case $k \to \kappa(x)$ is finitely generated. Hence this follows as property (A) holds for Gorenstein, see Dualizing Complexes, Lemma \ref{dualizing-lemma-formal-fibres-gorenstein}.
Recall that a syntomic morphism is flat and its fibres are local complete intersections over fields, see Morphisms, Lemma \ref{morphisms-lemma-syntomic-flat-fibres}. Since a local complete intersection over a field is a Gorenstein scheme by Lemma \ref{lemma-gorenstein-lci} we conclude. The properties ``syntomic'' and ``flat and local complete intersection morphism'' are equivalent by More on Morphisms, Lemma \ref{more-morphisms-lemma-flat-lci}.
Note that the assumption on $Y' \to Y$ implies that for $y' \in Y'$ mapping to $y \in Y$ the field extension $\kappa(y) \subset \kappa(y')$ is finitely generated. Hence also all the fibres $X'_{y'} = (X_y)_{\kappa(y')}$ are locally Noetherian, see Varieties, Lemma \ref{varieties-lemma-locally-Noetherian-base-change}. Thus the lemma makes sense. Set $y' = f'(x')$ and $y = f(x)$. Hence we get the following commutative diagram of local rings $$ \xymatrix{ \mathcal{O}_{X', x'} & \mathcal{O}_{X, x} \ar[l] \\ \mathcal{O}_{Y', y'} \ar[u] & \mathcal{O}_{Y, y} \ar[l] \ar[u] } $$ where the upper left corner is a localization of the tensor product of the upper right and lower left corners over the lower right corner. \medskip\noindent Assume $f$ is Gorenstein at $x$. The flatness of $\mathcal{O}_{Y, y} \to \mathcal{O}_{X, x}$ implies the flatness of $\mathcal{O}_{Y', y'} \to \mathcal{O}_{X', x'}$, see Algebra, Lemma \ref{algebra-lemma-base-change-flat-up-down}. The fact that $\mathcal{O}_{X, x}/\mathfrak m_y\mathcal{O}_{X, x}$ is Gorenstein implies that $\mathcal{O}_{X', x'}/\mathfrak m_{y'}\mathcal{O}_{X', x'}$ is Gorenstein, see Lemma \ref{lemma-gorenstein-base-change}. Hence we see that $f'$ is Gorenstein at $x'$. \medskip\noindent Assume $f$ is flat at $x$ and $f'$ is Gorenstein at $x'$. The fact that $\mathcal{O}_{X', x'}/\mathfrak m_{y'}\mathcal{O}_{X', x'}$ is Gorenstein implies that $\mathcal{O}_{X, x}/\mathfrak m_y\mathcal{O}_{X, x}$ is Gorenstein, see Lemma \ref{lemma-gorenstein-base-change}. Hence we see that $f$ is Gorenstein at $x$. \medskip\noindent Assume $Y' \to Y$ is flat at $y'$ and $f'$ is Gorenstein at $x'$. The flatness of $\mathcal{O}_{Y', y'} \to \mathcal{O}_{X', x'}$ and $\mathcal{O}_{Y, y} \to \mathcal{O}_{Y', y'}$ implies the flatness of $\mathcal{O}_{Y, y} \to \mathcal{O}_{X, x}$, see Algebra, Lemma \ref{algebra-lemma-base-change-flat-up-down}. The fact that $\mathcal{O}_{X', x'}/\mathfrak m_{y'}\mathcal{O}_{X', x'}$ is Gorenstein implies that $\mathcal{O}_{X, x}/\mathfrak m_y\mathcal{O}_{X, x}$ is Gorenstein, see Lemma \ref{lemma-gorenstein-base-change}. Hence we see that $f$ is Gorenstein at $x$.
The assumption implies any fibre of $f$ is locally of finite type over a field and hence locally Noetherian and the same is true for any base change. Thus the statement makes sense. Looking at fibres we reduce to the following problem: let $X$ be a scheme locally of finite type over a field $k$, let $K/k$ be a field extension, and let $x_K \in X_K$ be a point with image $x \in X$. Problem: show that $\mathcal{O}_{X_K, x_K}$ is Gorenstein if and only if $\mathcal{O}_{X, x}$ is Gorenstein. \medskip\noindent The problem can be solved using a bit of algebra as follows. Choose an affine open $\Spec(A) \subset X$ containing $x$. Say $x$ corresponds to $\mathfrak p \subset A$. With $A_K = A \otimes_k K$ we see that $\Spec(A_K) \subset X_K$ contains $x_K$. Say $x_K$ corresponds to $\mathfrak p_K \subset A_K$. Let $\omega_A^\bullet$ be a dualizing complex for $A$. By Dualizing Complexes, Lemma \ref{dualizing-lemma-base-change-dualizing-over-field} $\omega_A^\bullet \otimes_A A_K$ is a dualizing complex for $A_K$. Now we are done because $A_\mathfrak p \to (A_K)_{\mathfrak p_K}$ is a flat local homomorphism of Noetherian rings and hence $(\omega_A^\bullet)_\mathfrak p$ is an invertible object of $D(A_\mathfrak p)$ if and only if $(\omega_A^\bullet)_\mathfrak p \otimes_{A_\mathfrak p} (A_K)_{\mathfrak p_K}$ is an invertible object of $D((A_K)_{\mathfrak p_K})$. Some details omitted; hint: look at cohomology modules.
Set $\omega^\bullet = f^!\mathcal{O}_Y$. By Lemma \ref{lemma-relative-dualizing-fibres} this is a bounded complex with coherent cohomology sheaves whose derived restriction $Lh^*\omega^\bullet$ to the fibre $X_y$ is a dualizing complex on $X_y$. Denote $i : x \to X_y$ the inclusion of a point. Then the following are equivalent \begin{enumerate} \item $f$ is Gorenstein at $x$, \item $\mathcal{O}_{X_y, x}$ is Gorenstein, \item $Lh^*\omega^\bullet$ is invertible in a neighbourhood of $x$, \item $Li^* Lh^* \omega^\bullet$ has exactly one nonzero cohomology of dimension $1$ over $\kappa(x)$, \item $L(h \circ i)^* \omega^\bullet$ has exactly one nonzero cohomology of dimension $1$ over $\kappa(x)$, \item $\omega^\bullet$ is invertible in a neighbourhood of $x$. \end{enumerate} The equivalence of (1) and (2) is by definition (as $f$ is flat). The equivalence of (2) and (3) follows from Lemma \ref{lemma-gorenstein}. The equivalence of (3) and (4) follows from More on Algebra, Lemma \ref{more-algebra-lemma-lift-bounded-pseudo-coherent-to-perfect}. The equivalence of (4) and (5) holds because $Li^* Lh^* = L(h \circ i)^*$. The equivalence of (5) and (6) holds by More on Algebra, Lemma \ref{more-algebra-lemma-lift-bounded-pseudo-coherent-to-perfect}. Thus the lemma is clear.
Choose affine open $U = \Spec(A) \subset X$ with $x \in U$ and $V = \Spec(R) \subset S$ with $f(U) \subset V$. Then $R \to A$ is a flat ring map of finite presentation. Let $\mathfrak p \subset A$ be the prime ideal corresponding to $x$. After replacing $A$ by a principal localization we may assume there exists a quasi-finite map $R[x_1, \ldots, x_d]  \to A$, see Algebra, Lemma \ref{algebra-lemma-quasi-finite-over-polynomial-algebra}. Thus there exists at least one pair $(U, g)$ consisting of an open neighbourhood $U \subset X$ of $x$ and a locally\footnote{If $S$ is quasi-separated, then $g$ will be quasi-finite.} quasi-finite morphism $g : U \to \mathbf{A}^d_S$. \medskip\noindent Having said this, the lemma translates into the following algebra problem (translation omitted). Given $R \to A$ flat and of finite presentation, a prime $\mathfrak p \subset A$ and $\varphi : R[x_1, \ldots, x_d] \to A$ quasi-finite at $\mathfrak p$ the following are equivalent \begin{enumerate} \item[(a)] $\Spec(\varphi)$ is Gorenstein at $\mathfrak p$, and \item[(b)] $\Spec(A) \to \Spec(R)$ is Gorenstein at $\mathfrak p$. \item[(c)] $\Spec(A) \to \Spec(R)$ is Gorenstein in an open neighbourhood of $\mathfrak p$. \end{enumerate} In each case $R[x_1, \ldots, x_n] \to A$ is flat at $\mathfrak p$ hence by openness of flatness (Algebra, Theorem \ref{algebra-theorem-openness-flatness}), we may assume $R[x_1, \ldots, x_n] \to A$ is flat (replace $A$ by a suitable principal localization). By Algebra, Lemma \ref{algebra-lemma-flat-finite-presentation-limit-flat} there exists $R_0 \subset R$ and $R_0[x_1, \ldots, x_n] \to A_0$ such that $R_0$ is of finite type over $\mathbf{Z}$ and $R_0 \to A_0$ is of finite type and $R_0[x_1, \ldots, x_n] \to A_0$ is flat. Note that the set of points where a flat finite type morphism is Gorenstein commutes with base change by Lemma \ref{lemma-base-change-gorenstein}. In this way we reduce to the case where $R$ is Noetherian. \medskip\noindent Thus we may assume $X$ and $S$ affine and that we have a factorization of $f$ of the form $$ X \xrightarrow{g} \mathbf{A}^n_S \xrightarrow{p} S $$ with $g$ flat and quasi-finite and $S$ Noetherian. Then $X$ and $\mathbf{A}^n_S$ are separated over $S$ and we have $$ f^!\mathcal{O}_S = g^!p^!\mathcal{O}_S = g^!\mathcal{O}_{\mathbf{A}^n_S}[n] $$ by know properties of upper shriek functors (Lemmas \ref{lemma-upper-shriek-composition} and \ref{lemma-shriek-affine-line}). Hence the equivalence of (a), (b), and (c) by Lemma \ref{lemma-affine-flat-Noetherian-gorenstein}.
We have $\mathcal{P}(f) = \mathcal{P}_1(f) \wedge \mathcal{P}_2(f)$ where $\mathcal{P}_1(f)=$``$f$ is flat'', and $\mathcal{P}_2(f)=$``the fibres of $f$ are locally Noetherian and Gorenstein''. We know that $\mathcal{P}_1$ is local in the fppf topology on the source and the target, see Descent, Lemmas \ref{descent-lemma-descending-property-flat} and \ref{descent-lemma-flat-fpqc-local-source}. Thus we have to deal with $\mathcal{P}_2$. \medskip\noindent Let $f : X \to Y$ be a morphism of schemes. Let $\{\varphi_i : Y_i \to Y\}_{i \in I}$ be an fppf covering of $Y$. Denote $f_i : X_i \to Y_i$ the base change of $f$ by $\varphi_i$. Let $i \in I$ and let $y_i \in Y_i$ be a point. Set $y = \varphi_i(y_i)$. Note that $$ X_{i, y_i} = \Spec(\kappa(y_i)) \times_{\Spec(\kappa(y))} X_y. $$ and that $\kappa(y) \subset \kappa(y_i)$ is a finitely generated field extension. Hence if $X_y$ is locally Noetherian, then $X_{i, y_i}$ is locally Noetherian, see Varieties, Lemma \ref{varieties-lemma-locally-Noetherian-base-change}. And if in addition $X_y$ is Gorenstein, then $X_{i, y_i}$ is Gorenstein, see Lemma \ref{lemma-gorenstein-base-change}. Thus $\mathcal{P}_2$ is fppf local on the target. \medskip\noindent Let $\{X_i \to X\}$ be a syntomic covering of $X$. Let $y \in Y$. In this case $\{X_{i, y} \to X_y\}$ is a syntomic covering of the fibre. Hence the locality of $\mathcal{P}_2$ for the syntomic topology on the source follows from Lemma \ref{lemma-gorenstein-local-syntomic}.
Denote $f : X \to \Spec(k)$ the structure morphism. Let $a$ be the right adjoint of pushforward of this morphism, see Lemma \ref{lemma-twisted-inverse-image}. Consider the relative dualizing complex $$ \omega_X^\bullet = a(\mathcal{O}_{\Spec(k)}) $$ Compare with Remark \ref{remark-relative-dualizing-complex}. Since $f$ is proper we have $f^!(\mathcal{O}_{\Spec(k)}) = a(\mathcal{O}_{\Spec(k)})$ by definition, see Section \ref{section-upper-shriek}. Applying Lemma \ref{lemma-shriek-dualizing} we find that $\omega_X^\bullet$ is a dualizing complex. Moreover, we see that $\omega_X^\bullet$ and $\omega_X$ are as in Example \ref{example-proper-over-local} and as in Example \ref{example-equidimensional-over-field}. \medskip\noindent Parts (1), (2), and (3) follow from Lemma \ref{lemma-vanishing-good-dualizing}. \medskip\noindent For a closed point $x \in X$ we see that $\omega_{X, x}^\bullet$ is a normalized dualizing complex over $\mathcal{O}_{X, x}$, see Lemma \ref{lemma-good-dualizing-normalized}. Part (4) then follows from Dualizing Complexes, Lemma \ref{dualizing-lemma-depth-in-terms-dualizing-complex}. \medskip\noindent Part (5) holds by construction as $a$ is the right adjoint to $Rf_* : D_\QCoh(\mathcal{O}_X) \to D(\mathcal{O}_{\Spec(k)}) = D(k)$ which we can identify with $K \mapsto R\Gamma(X, K)$. We also use that the derived category $D(k)$ of $k$-modules is the same as the category of graded $k$-vector spaces. \medskip\noindent Part (6) follows from Lemma \ref{lemma-dualizing-module-proper-over-A} for coherent $\mathcal{F}$ and in general by unwinding (5) for $K = \mathcal{F}[0]$ and $i = -\dim(X)$. \medskip\noindent Part (7) follows from Lemma \ref{lemma-smooth-proper}.
It is clear from Lemma \ref{lemma-duality-proper-over-field} that $\omega_X$ is a dualizing module (as it is the left most nonvanishing cohomology sheaf of a dualizing complex). We have $\omega_X^\bullet = \omega_X[d]$ and $\omega_X$ is Cohen-Macaulay as $X$ is Cohen-Macualay, see Lemma \ref{lemma-dualizing-module-CM-scheme}. The other statements follow from this combined with the corresponding statements of Lemma \ref{lemma-duality-proper-over-field}.
Denote $f : X \to \Spec(k)$ the structure morphism and denote $f' : X \to \Spec(k')$ the given factorization. In the proof of Lemma \ref{lemma-duality-proper-over-field} we took $\omega_X^\bullet = a(\mathcal{O}_{\Spec(k)})$ where $a$ be is the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for $f$. Thus we have to show $a(\mathcal{O}_{\Spec(k)}) \cong a'(\mathcal{O}_{\Spec(k)})$ where $a'$ be is the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for $f'$. Since $k' \subset H^0(X, \mathcal{O}_X)$ we see that $k'/k$ is a finite extension (Cohomology of Schemes, Lemma \ref{coherent-lemma-proper-over-affine-cohomology-finite}). By uniqueness of adjoints we have $a = a' \circ b$ where $b$ is the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for $g : \Spec(k') \to \Spec(k)$. Another way to say this: we have $f^! = (f')^! \circ g^!$. Thus it suffices to show that $\Hom_k(k', k) \cong k'$ as $k'$-modules, see Example \ref{example-affine-twisted-inverse-image}. This holds because these are $k'$-vector spaces of the same dimension (namely dimension $1$). \medskip\noindent Proof of (2). This holds because we have base change for $a$ by Lemma \ref{lemma-more-base-change}. See discussion in Remark \ref{remark-relative-dualizing-complex}.
Since formation of $R\SheafHom$ commutes with restrictions to opens we may as well assume $X = \Spec(A)$ and $S = \Spec(R)$. Observe that relatively perfect objects of $D(\mathcal{O}_X)$ are pseudo-coherent and hence are in $D_\QCoh(\mathcal{O}_X)$ (Derived Categories of Schemes, Lemma \ref{perfect-lemma-pseudo-coherent}). Thus the statement makes sense. Observe that taking $\Delta_*$, $L\text{pr}_1^*$, and $R\SheafHom$ is compatible with what happens on the algebraic side by Derived Categories of Schemes, Lemmas \ref{perfect-lemma-quasi-coherence-pushforward}, \ref{perfect-lemma-quasi-coherence-pullback}, \ref{perfect-lemma-quasi-coherence-internal-hom}. For the last one we observe that $L\text{pr}_1^*K$ is $S$-perfect (hence bounded below) and that $\Delta_*\mathcal{O}_X$ is a pseudo-coherent object of $D(\mathcal{O}_W)$; translated into algebra this means that $A$ is pseudo-coherent as an $A \otimes_R A$-module which follows from More on Algebra, Lemma \ref{more-algebra-lemma-more-relative-pseudo-coherent-is-moot} applied to $R \to A \otimes_R A \to A$. Thus we recover exactly the conditions in Dualizing Complexes, Definition \ref{dualizing-definition-relative-dualizing-complex}.
Let $U \subset X$ be an affine open mapping into an affine open of $S$. Then there is an isomorphism $K|_U \to L|_U$ by Lemma \ref{lemma-relative-dualizing-complex-algebra} and Dualizing Complexes, Lemma \ref{dualizing-lemma-uniqueness-relative-dualizing}. The reader can reuse the argument of that lemma in the schemes case to obtain a proof in this case. We will instead use a glueing argument. \medskip\noindent Suppose we have an isomorphism $\alpha : K \to L$. Then $\alpha(\xi) = u \eta$ for some invertible section $u \in H^0(W, \Delta_*\mathcal{O}_X) = H^0(X, \mathcal{O}_X)$. (Because both $\eta$ and $\alpha(\xi)$ are generators of an invertible $\Delta_*\mathcal{O}_X$-module by assumption.) Hence after replacing $\alpha$ by $u^{-1}\alpha$ we see that $\alpha(\xi) = \eta$. Since the automorphism group of $K$ is $H^0(X, \mathcal{O}_X^*)$ by Lemma \ref{lemma-relative-dualizing-RHom} there is at most one such $\alpha$. \medskip\noindent Let $\mathcal{B}$ be the collection of affine opens of $X$ which map into an affine open of $S$. For each $U \in \mathcal{B}$ we have a unique isomorphism $\alpha_U : K|_U \to L|_U$ mapping $\xi$ to $\eta$ by the discussion in the previous two paragraphs. Observe that $\text{Ext}^i(K|_U, K|_U) = 0$ for $i < 0$ and any open $U$ of $X$ by Lemma \ref{lemma-relative-dualizing-RHom}. By Cohomology, Lemma \ref{cohomology-lemma-vanishing-and-glueing} applied to $\text{id} : X \to X$ we get a unique morphism $\alpha : K \to L$ agreeing with $\alpha_U$ for all $U \in \mathcal{B}$. Then $\alpha$ sends $\xi$ to $\eta$ as this is true locally.
Consider the cartesian square $$ \xymatrix{ X' \ar[d]_{\Delta_{X'/S'}} \ar[r] & X \ar[d]^{\Delta_{X/S}} \\ X' \times_{S'} X' \ar[r]^{g' \times g'} & X \times_S X } $$ Choose $W \subset X \times_S X$ open such that $\Delta_{X/S}$ factors through a closed immersion $\Delta : X \to W$. Choose $W' \subset X' \times_{S'} X'$ open such that $\Delta_{X'/S'}$ factors through a closed immersion $\Delta' : X \to W'$ and such that $(g' \times g')(W') \subset W$. Let us still denote $g' \times g' : W' \to W$ the induced morphism. We have $$ L(g' \times g')^*\Delta_*\mathcal{O}_X = \Delta'_*\mathcal{O}_{X'} \quad\text{and}\quad L(g' \times g')^*L\text{pr}_1^*K|_W = L\text{pr}_1^*K'|_{W'} $$ The first equality holds because $X$ and $X' \times_{S'} X'$ are tor independent over $X \times_S X$ (see for example More on Morphisms, Lemma \ref{more-morphisms-lemma-case-of-tor-independence}). The second holds by transitivity of derived pullback (Cohomology, Lemma \ref{cohomology-lemma-derived-pullback-composition}). Thus $\xi' = L(g' \times g')^*\xi$ can be viewed as a map $$ \xi' : \Delta'_*\mathcal{O}_{X'} \longrightarrow L\text{pr}_1^*K'|_{W'} $$ Having said this the proof of the lemma is straightforward. First, $K'$ is $S'$-perfect by Derived Categories of Schemes, Lemma \ref{perfect-lemma-base-change-relatively-perfect}. To check that $\xi'$ induces an isomorphism of $\Delta'_*\mathcal{O}_{X'}$ to $R\SheafHom_{\mathcal{O}_{W'}}( \Delta'_*\mathcal{O}_{X'}, L\text{pr}_1^*K'|_{W'})$ we may work affine locally. By Lemma \ref{lemma-relative-dualizing-complex-algebra} we reduce to the corresponding statement in algebra which is proven in Dualizing Complexes, Lemma \ref{dualizing-lemma-base-change-relative-dualizing}.
In Lemma \ref{lemma-properties-relative-dualizing} we proved that $\omega_{X/S}^\bullet$ is $S$-perfect. Let $c$ be the right adjoint of Lemma \ref{lemma-twisted-inverse-image} for the diagonal $\Delta : X \to X \times_S X$. Then we can apply $\Delta_*$ to (\ref{equation-pre-rigid}) to get an isomorphism $$ \Delta_*\mathcal{O}_X \to \Delta_*(c(L\text{pr}_1^*\omega_{X/S}^\bullet)) = R\SheafHom_{\mathcal{O}_{X \times_S X}}( \Delta_*\mathcal{O}_X, L\text{pr}_1^*\omega_{X/S}^\bullet) $$ The equality holds by Lemmas \ref{lemma-twisted-inverse-image-closed} and \ref{lemma-sheaf-with-exact-support-ext}. This finishes the proof.
By Lemma \ref{lemma-flat-shriek-relatively-perfect} we have that $f^!\mathcal{O}_Y$ is $Y$-perfect. As $f$ is separated the diagonal $\Delta : X \to X \times_Y X$ is a closed immersion and $\Delta_*\Delta^!(-) = R\SheafHom_{\mathcal{O}_{X \times_Y X}}(\mathcal{O}_X, -)$, see Lemmas \ref{lemma-twisted-inverse-image-closed} and \ref{lemma-sheaf-with-exact-support-ext}. Hence to finish the proof it suffices to show $\Delta^!(L\text{pr}_1^*f^!(\mathcal{O}_Y)) \cong \mathcal{O}_X$ where $\text{pr}_1 : X \times_Y X \to X$ is the first projection. We have $$ \mathcal{O}_X = \Delta^! \text{pr}_1^!\mathcal{O}_X = \Delta^! \text{pr}_1^! L\text{pr}_2^*\mathcal{O}_Y = \Delta^!(L\text{pr}_1^* f^!\mathcal{O}_Y) $$ where $\text{pr}_2 : X \times_Y X \to X$ is the second projection and where we have used the base change isomorphism $\text{pr}_1^! \circ L\text{pr}_2^* = L\text{pr}_1^* \circ f^!$ of Lemma \ref{lemma-base-change-shriek-flat}.