hcju/stacksqa huggingface dataset:
The statement on base change is Lemma \ref{lemma-base-change-tensor}. Thus it suffices to show that $K$ is a perfect object. If $S$ is Noetherian, then this follows from Lemma \ref{lemma-tensor-perfect}. We will reduce to this case by Noetherian approximation. We encourage the reader to skip the rest of this proof. \medskip\noindent The question is local on $S$, hence we may assume $S$ is affine. Say $S = \Spec(R)$. We write $R = \colim R_i$ as a filtered colimit of Noetherian rings $R_i$. By Limits, Lemma \ref{limits-lemma-descend-finite-presentation} there exists an $i$ and a scheme $X_i$ of finite presentation over $R_i$ whose base change to $R$ is $X$. By Limits, Lemma \ref{limits-lemma-descend-modules-finite-presentation} we may assume after increasing $i$, that there exists a bounded complex of finitely presented $\mathcal{O}_{X_i}$-modules $\mathcal{G}_i^\bullet$ whose pullback to $X$ is $\mathcal{G}^\bullet$. After increasing $i$ we may assume $\mathcal{G}_i^n$ is flat over $R_i$, see Limits, Lemma \ref{limits-lemma-descend-module-flat-finite-presentation}. After increasing $i$ we may assume the support of $\mathcal{G}_i^n$ is proper over $R_i$, see Limits, Lemma \ref{limits-lemma-eventually-proper-support} and Cohomology of Schemes, Lemma \ref{coherent-lemma-module-support-proper-over-base}. Finally, by Lemma \ref{lemma-descend-perfect} we may, after increasing $i$, assume there exists a perfect object $E_i$ of $D(\mathcal{O}_{X_i})$ whose pullback to $X$ is $E$. Applying Lemma \ref{lemma-tensor-perfect} to $X_i \to \Spec(R_i)$, $E_i$, $\mathcal{G}_i^\bullet$ and using the base change property already shown we obtain the result.
The statement on base change is Lemma \ref{lemma-base-change-tensor}. Thus it suffices to show that $K$ is a pseudo-coherent object. This will follow from Lemma \ref{lemma-base-change-tensor-perfect} by approximation by perfect complexes. We encourage the reader to skip the rest of the proof. \medskip\noindent The question is local on $S$, hence we may assume $S$ is affine. Then $X$ is quasi-compact and quasi-separated. Moreover, there exists an integer $N$ such that total direct image $Rf_* : D_\QCoh(\mathcal{O}_X) \to D_\QCoh(\mathcal{O}_S)$ has cohomological dimension $N$ as explained in Lemma \ref{lemma-quasi-coherence-direct-image}. Choose an integer $b$ such that $\mathcal{G}^i = 0$ for $i > b$. It suffices to show that $K$ is $m$-pseudo-coherent for every $m$. Choose an approximation $P \to E$ by a perfect complex $P$ of $(X, E, m - N - 1 - b)$. This is possible by Theorem \ref{theorem-approximation}. Choose a distinguished triangle $$ P \to E \to C \to P[1] $$ in $D_\QCoh(\mathcal{O}_X)$. The cohomology sheaves of $C$ are zero in degrees $\geq m - N - 1 - b$. Hence the cohomology sheaves of $C \otimes^\mathbf{L} \mathcal{G}^\bullet$ are zero in degrees $\geq m - N - 1$. Thus the cohomology sheaves of $Rf_*(C \otimes^\mathbf{L} \mathcal{G}^\bullet)$ are zero in degrees $\geq m - 1$. Hence $$ Rf_*(P \otimes^\mathbf{L} \mathcal{G}^\bullet) \to Rf_*(E \otimes^\mathbf{L} \mathcal{G}^\bullet) $$ is an isomorphism on cohomology sheaves in degrees $\geq m$. Next, suppose that $H^i(P) = 0$ for $i > a$. Then $ P \otimes^\mathbf{L} \sigma_{\geq m - N - 1 - a}\mathcal{G}^\bullet \longrightarrow P \otimes^\mathbf{L} \mathcal{G}^\bullet $ is an isomorphism on cohomology sheaves in degrees $\geq m - N - 1$. Thus again we find that $$ Rf_*(P \otimes^\mathbf{L} \sigma_{\geq m - N - 1 - a}\mathcal{G}^\bullet) \to Rf_*(P \otimes^\mathbf{L} \mathcal{G}^\bullet) $$ is an isomorphism on cohomology sheaves in degrees $\geq m$. By Lemma \ref{lemma-base-change-tensor-perfect} the source is a perfect complex. We conclude that $K$ is $m$-pseudo-coherent as desired.
The statement means that for any object $E$ of $D_\QCoh(\mathcal{O}_X)$ the induced map $$ \Hom(E, \mathcal{O}_X \otimes_R (\lim M_n)) \longrightarrow \Hom(E, \lim \mathcal{O}_X \otimes_R M_n) $$ is an isomorphism. Since $D_\QCoh(\mathcal{O}_X)$ has a perfect generator (Theorem \ref{theorem-bondal-van-den-Bergh}) it suffices to check this for perfect $E$. By Lemma \ref{lemma-Rlim-quasi-coherent} we have $\lim \mathcal{O}_X \otimes_R M_n = R\lim \mathcal{O}_X \otimes_R M_n$. The exact functor $R\Hom_X(E, -) : D_\QCoh(\mathcal{O}_X) \to D(R)$ of Cohomology, Section \ref{cohomology-section-global-RHom} commutes with products and hence with derived limits, whence $$ R\Hom_X(E, \lim \mathcal{O}_X \otimes_R M_n) = R\lim R\Hom_X(E, \mathcal{O}_X \otimes_R M_n) $$ Let $E^\vee$ be the dual perfect complex, see Cohomology, Lemma \ref{cohomology-lemma-dual-perfect-complex}. We have $$ R\Hom_X(E, \mathcal{O}_X \otimes_R M_n) = R\Gamma(X, E^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} Lf^*M_n) = R\Gamma(X, E^\vee) \otimes_R^\mathbf{L} M_n $$ by Lemma \ref{lemma-cohomology-base-change}. From Lemma \ref{lemma-flat-proper-perfect-direct-image-general} we see $R\Gamma(X, E^\vee)$ is a perfect complex of $R$-modules. In particular it is a pseudo-coherent complex and by More on Algebra, Lemma \ref{more-algebra-lemma-pseudo-coherent-tensor-limit} we obtain $$ R\lim R\Gamma(X, E^\vee) \otimes_R^\mathbf{L} M_n = R\Gamma(X, E^\vee) \otimes_R^\mathbf{L} \lim M_n $$ as desired.
The statement on base change is Lemma \ref{lemma-base-change-RHom}. Thus it suffices to show that $K$ is a perfect object. If $S$ is Noetherian, then this follows from Lemma \ref{lemma-ext-perfect}. We will reduce to this case by Noetherian approximation. We encourage the reader to skip the rest of this proof. \medskip\noindent The question is local on $S$, hence we may assume $S$ is affine. Say $S = \Spec(R)$. We write $R = \colim R_i$ as a filtered colimit of Noetherian rings $R_i$. By Limits, Lemma \ref{limits-lemma-descend-finite-presentation} there exists an $i$ and a scheme $X_i$ of finite presentation over $R_i$ whose base change to $R$ is $X$. By Limits, Lemma \ref{limits-lemma-descend-modules-finite-presentation} we may assume after increasing $i$, that there exists a bounded complex of finitely presented $\mathcal{O}_{X_i}$-modules $\mathcal{G}_i^\bullet$ whose pullback to $X$ is $\mathcal{G}^\bullet$. After increasing $i$ we may assume $\mathcal{G}_i^n$ is flat over $R_i$, see Limits, Lemma \ref{limits-lemma-descend-module-flat-finite-presentation}. After increasing $i$ we may assume the support of $\mathcal{G}_i^n$ is proper over $R_i$, see Limits, Lemma \ref{limits-lemma-eventually-proper-support} and Cohomology of Schemes, Lemma \ref{coherent-lemma-module-support-proper-over-base}. Finally, by Lemma \ref{lemma-descend-perfect} we may, after increasing $i$, assume there exists a perfect object $E_i$ of $D(\mathcal{O}_{X_i})$ whose pullback to $X$ is $E$. Applying Lemma \ref{lemma-ext-perfect} to $X_i \to \Spec(R_i)$, $E_i$, $\mathcal{G}_i^\bullet$ and using the base change property already shown we obtain the result.
Consider a morphism of schemes $f : Y \to X$ and a point $y \in Y$. Let $x$ be the image of $y$ and consider the commutative diagram $$ \xymatrix{ y \ar[r]_j \ar[d]_g & Y \ar[d]^f \\ x \ar[r]^i & X } $$ Then we see that $Lg^* \circ Li^* = Lj^* \circ Lf^*$. This implies that the function $\beta'_i$ associated to the pseudo-coherent complex $Lf^*E$ is the pullback of the function $\beta_i$, in a formula: $\beta'_i = \beta_i \circ f$. This is the meaning of (1). \medskip\noindent Fix $i$ and let $x \in X$. It is enough to prove (2) and (3) holds in an open neighbourhood of $x$, hence we may assume $X$ affine. Then we can represent $E$ by a bounded above complex $\mathcal{F}^\bullet$ of finite free modules (Lemma \ref{lemma-lift-pseudo-coherent}). Then $P = \sigma_{\geq i - 1}\mathcal{F}^\bullet$ is a perfect object and $P \to E$ induces an isomorphism $$ H^i(P \otimes_{\mathcal{O}_X}^\mathbf{L} \kappa(x')) \to H^i(E \otimes_{\mathcal{O}_X}^\mathbf{L} \kappa(x')) $$ for all $x' \in X$. Thus we may assume $E$ is perfect. In this case by More on Algebra, Lemma \ref{more-algebra-lemma-lift-perfect-from-residue-field} there exists an affine open neighbourhood $U$ of $x$ and $a \leq b$ such that $E|_U$ is represented by a complex $$ \ldots \to 0 \to \mathcal{O}_U^{\oplus \beta_a(x)} \to \mathcal{O}_U^{\oplus \beta_{a + 1}(x)} \to \ldots \to \mathcal{O}_U^{\oplus \beta_{b - 1}(x)} \to \mathcal{O}_U^{\oplus \beta_b(x)} \to 0 \to \ldots $$ (This also uses earlier results to turn the problem into algebra, for example Lemmas \ref{lemma-affine-compare-bounded} and \ref{lemma-perfect-affine}.) It follows immediately that $\beta_i(x') \leq \beta_i(x)$ for all $x' \in U$. This proves that $\beta_i$ is upper semi-continuous. \medskip\noindent To prove (3) we may assume that $X$ is affine and $E$ is given by a complex of finite free $\mathcal{O}_X$-modules (for example by arguing as in the previous paragraph, or by using Cohomology, Lemma \ref{cohomology-lemma-perfect-on-locally-ringed}). Thus we have to show that given a complex $$ \mathcal{O}_X^{\oplus a} \to \mathcal{O}_X^{\oplus b} \to \mathcal{O}_X^{\oplus c} $$ the function associated to a point $x \in X$ the dimension of the cohomology of $\kappa_x^{\oplus a} \to \kappa_x^{\oplus b} \to \kappa_x^{\oplus c}$ in the middle has constructible level sets. Let $A \in \text{Mat}(a \times b, \Gamma(X, \mathcal{O}_X))$ be the matrix of the first arrow. The rank of the image of $A$ in $\text{Mat}(a \times b, \kappa(x))$ is equal to $r$ if all $(r + 1) \times (r + 1)$-minors of $A$ vanish at $x$ and there is some $r \times r$-minor of $A$ which does not vanish at $x$. Thus the set of points where the rank is $r$ is a constructible locally closed set. Arguing similarly for the second arrow and putting everything together we obtain the desired result.
By Cohomology, Lemma \ref{cohomology-lemma-perfect-on-locally-ringed} we see that we can, locally on $X$, represent $E$ by a finite complex $\mathcal{E}^\bullet$ of finite free $\mathcal{O}_X$-modules. On such an open the function $\chi_E$ is constant with value $\sum (-1)^i \text{rank}(\mathcal{E}^i)$.
Let $\beta_j : X \to \{0, 1, 2, \ldots\}$ for $j \in \mathbf{Z}$ be the functions of Lemma \ref{lemma-jump-loci}. Then the set $$ W = \{x \in X \mid \beta_j(x) \leq 0\text{ for all }j \not = i\} $$ is open in $X$ and its formation commutes with pullback to any $Y$ over $X$. This follows from the lemma using that apriori in a neighbourhood of any point only a finite number of the $\beta_j$ are nonzero. Thus we may replace $X$ by $W$ and assume that $\beta_j(x) = 0$ for all $x \in X$ and all $j \not = i$. In this case $H^i(E)$ is a finite locally free module and $E \cong H^i(E)[-i]$, see for example  More on Algebra, Lemma \ref{more-algebra-lemma-lift-perfect-from-residue-field}. Thus $X$ is the disjoint union of the open subschemes where the rank of $H^i(E)$ is fixed and we win.
First, let $U \subset X$ be the locally constructible open subscheme where the function $\beta_a$ of Lemma \ref{lemma-jump-loci} has values $\leq r$. Let $f : Y \to X$ be as in (2). Then for any $y \in Y$ we have $\beta_a(Lf^*E) = r$ hence $y$ maps into $U$ by Lemma \ref{lemma-jump-loci}. Hence $f$ as in (2) factors through $U$. Thus we may replace $X$ by $U$ and assume that $\beta_a(x) \in \{0, 1, \ldots, r\}$ for all $x \in X$. We will show that in this case there is a closed subscheme $Z \subset X$ cut out by a finite type quasi-coherent ideal characterized by the equivalence of (4) (a), (b) and (4)(c) if $r = 1$ and that (3) holds. This will finish the proof because it will a fortiori show that morphisms as in (2) factor through $Z$. \medskip\noindent If $x \in X$ and $\beta_a(x) < r$, then there is an open neighbourhood of $x$ where $\beta_a < r$ (Lemma \ref{lemma-jump-loci}). In this way we see that set theoretically at least $Z$ is a closed subset. \medskip\noindent To get a scheme theoretic structure, consider a point $x \in X$ with $\beta_a(x) = r$. Set $\beta = \beta_{a + 1}(x)$. By More on Algebra, Lemma \ref{more-algebra-lemma-lift-perfect-from-residue-field} there exists an affine open neighbourhood $U$ of $x$ such that $K|_U$ is represented by a complex $$ \ldots \to 0 \to \mathcal{O}_U^{\oplus r} \xrightarrow{(f_{ij})} \mathcal{O}_U^{\oplus \beta} \to \ldots \to \mathcal{O}_U^{\oplus \beta_{b - 1}(x)} \to \mathcal{O}_U^{\oplus \beta_b(x)} \to 0 \to \ldots $$ (This also uses earlier results to turn the problem into algebra, for example Lemmas \ref{lemma-affine-compare-bounded} and \ref{lemma-perfect-affine}.) Now, if $g : Y \to U$ is any morphism of schemes such that $g^\sharp(f_{ij})$ is nonzero for some pair $i, j$, then $H^0(Lg^*E)$ is not a locally free $\mathcal{O}_Y$-module of rank $r$. See More on Algebra, Lemma \ref{more-algebra-lemma-coker-injective-free}. Trivially $H^0(Lg^*E)$ is a locally free $\mathcal{O}_Y$-module if $g^\sharp(f_{ij}) = 0$ for all $i, j$. Thus we see that over $U$ the closed subscheme cut out by all $f_{ij}$ satisfies (3) and we have the equivalence of (4)(a) and (b). The characterization of $Z$ shows that the locally constructed patches glue (details omitted). Finally, if $r = 1$ then (4)(c) is equivalent to (4)(b) because in this case locally $H^0(Lg^*E) \subset \mathcal{O}_Y$ is the annihilator of the ideal generated by the elements $g^\sharp(f_{ij})$.
By cohomology and base change (more precisely by Lemma \ref{lemma-flat-proper-perfect-direct-image-general}) the object $K = Rf_*\mathcal{F}$ is a perfect object of the derived category of $S$ whose formation commutes with arbitrary base change. In particular we have $$ H^i(X_s, \mathcal{F}_s) = H^i(K \otimes_{\mathcal{O}_S}^\mathbf{L} \kappa(s)) $$ Thus the lemma follows from Lemma \ref{lemma-jump-loci}.
By cohomology and base change (more precisely by Lemma \ref{lemma-flat-proper-perfect-direct-image-general}) the object $K = Rf_*\mathcal{F}$ is a perfect object of the derived category of $S$ whose formation commutes with arbitrary base change. Thus we have to show the map $$ s \longmapsto \sum (-1)^i \dim_{\kappa(s)} H^i(K \otimes^\mathbf{L}_{\mathcal{O}_S} \kappa(s)) $$ is locally constant on $S$. This is Lemma \ref{lemma-chi-locally-constant}.
By cohomology and base change (more precisely by Lemma \ref{lemma-flat-proper-perfect-direct-image-general}) the object $K = Rf_*\mathcal{F}$ is a perfect object of the derived category of $S$ whose formation commutes with arbitrary base change. Thus this lemma follows immediately from Lemma \ref{lemma-open-where-cohomology-in-degree-i-rank-r}.
By Lemma \ref{lemma-base-change-tensor-perfect} the object $E = Rf_*\mathcal{F}$ of $D(\mathcal{O}_S)$ is perfect and its formation commutes with arbitrary base change, in the sense that $Rf'_*(g')^*\mathcal{F} = Lg^*E$ for any cartesian diagram $$ \xymatrix{ X' \ar[r]_{g'} \ar[d]_{f'} & X \ar[d]^f \\ S' \ar[r]^g & S } $$ of schemes. Since there is never any cohomology in degrees $< 0$, we see that $E$ (locally) has tor-amplitude in $[0, b]$ for some $b$. If $H^i(E) = R^if_*\mathcal{F} = 0$ for $i > 0$, then $E$ has tor amplitude in $[0, 0]$. Whence $E = H^0(E)[0]$. We conclude $H^0(E) = f_*\mathcal{F}$ is finite locally free by More on Algebra, Lemma \ref{more-algebra-lemma-perfect} (and the characterization of finite projective modules in Algebra, Lemma \ref{algebra-lemma-finite-projective}). Commutation with base change means that $g^*f_*\mathcal{F} = f'_*(g')^*\mathcal{F}$ for a diagram as above and it follows from the already established commutation of base change for $E$.
By cohomology and base change (Lemma \ref{lemma-flat-proper-perfect-direct-image-general}) the complex $E = Rf_*\mathcal{O}_X$ is perfect and its formation commutes with arbitrary base change. This first implies that $E$ has tor aplitude in $[0, \infty)$. Second, it implies that for $s \in S$ we have $H^0(E \otimes^\mathbf{L} \kappa(s)) = H^0(X_s, \mathcal{O}_{X_s}) = \kappa(s)$. It follows that the map $\mathcal{O}_S \to Rf_*\mathcal{O}_X = E$ induces an isomorphism $\mathcal{O}_S \otimes \kappa(s) \to H^0(E \otimes^\mathbf{L} \kappa(s))$. Hence $H^0(E) \otimes \kappa(s) \to H^0(E \otimes^\mathbf{L} \kappa(s))$ is surjective and we may apply More on Algebra, Lemma \ref{more-algebra-lemma-better-cut-complex-in-two} to see that, after replacing $S$ by an affine open neighbourhood of $s$, we have a decomposition $E = H^0(E) \oplus \tau_{\geq 1}E$ with $\tau_{\geq 1}E$ perfect of tor amplitude in $[1, \infty)$. Since $E$ has tor amplitude in $[0, \infty)$ we find that $H^0(E)$ is a flat $\mathcal{O}_S$-module. It follows that $H^0(E)$ is a flat, perfect $\mathcal{O}_S$-module, hence finite locally free, see More on Algebra, Lemma \ref{more-algebra-lemma-perfect} (and the fact that finite projective modules are finite locally free by Algebra, Lemma \ref{algebra-lemma-finite-projective}). It follows that the map $\mathcal{O}_S \to H^0(E)$ is an isomorphism as we can check this after tensoring with residue fields (Algebra, Lemma \ref{algebra-lemma-cokernel-flat}).
By Lemma \ref{lemma-proper-flat-h0} it suffices to show that $\kappa(s) = H^0(X_s, \mathcal{O}_{X_s})$ for all $s \in S$. This follows from Varieties, Lemma \ref{varieties-lemma-proper-geometrically-reduced-global-sections} and the fact that $X_s$ is geometrically connected and geometrically reduced.
Let $X_s = T_1 \amalg T_2$ be the disjoint union decomposition with $T_1$ and $T_2$ nonempty and open and closed in $X_s$ corresponding to $e$, i.e., such that $e$ is identitically $1$ on $T_1$ and identically $0$ on $T_2$. \medskip\noindent Assume $S$ is Noetherian. We will use the theorem on formal functions in the form of Cohomology of Schemes, Lemma \ref{coherent-lemma-formal-functions-stalk}. It tells us that $$ (f_*\mathcal{O}_X)_s^\wedge = \lim_n H^0(X_n, \mathcal{O}_{X_n}) $$ where $X_n$ is the $n$th infinitesimal neighbourhood of $X_s$. Since the underlying topological space of $X_n$ is equal to that of $X_s$ we obtain for all $n $ a disjoint union decomposition of schemes $X_n = T_{1, n} \amalg T_{2, n}$ where the underlying topological space of $T_{i, n}$ is $T_i$ for $i = 1, 2$. This means $H^0(X_n, \mathcal{O}_{X_n})$ contains a nontrivial idempotent $e_n$, namely the function which is identically $1$ on $T_{1, n}$ and identically $0$ on $T_{2, n}$. It is clear that $e_{n + 1}$ restricts to $e_n$ on $X_n$. Hence $e_\infty = \lim e_n$ is a nontrivial idempotent of the limit. Thus $e_\infty$ is an element of the completion of $(f_*\mathcal{O}_X)_s$ mapping to $e$ in $H^0(X_s, \mathcal{O}_{X_s})$. Since the map $(f_*\mathcal{O}_X)_s^\wedge \to H^0(X_s, \mathcal{O}_{X_s})$ factors through $(f_*\mathcal{O}_X)^\wedge_s / \mathfrak m_s (f_*\mathcal{O}_X)_s^\wedge = (f_*\mathcal{O}_X)_s / \mathfrak m_s (f_*\mathcal{O}_X)_s$ (Algebra, Lemma \ref{algebra-lemma-hathat-finitely-generated}) we conclude that $e$ is in the image of the map $(f_*\mathcal{O}_X)_s \to H^0(X_s, \mathcal{O}_{X_s})$ as desired. \medskip\noindent General case: we reduce the general case to the Noetherian case by limit arguments. We urge the reader to skip the proof. We may replace $S$ by an affine open neighbourhood of $s$. Thus we may and do assume that $S$ is affine. By Limits, Lemma \ref{limits-lemma-proper-limit-of-proper-finite-presentation-noetherian} we can write $(f : X \to S) = \lim (f_i : X_i \to S_i)$ with $f_i$ proper and $S_i$ Noetherian. Denote $s_i \in S_i$ the image of $s$. Then $s = \lim s_i$, see Limits, Lemma \ref{limits-lemma-inverse-limit-irreducibles}. Then $X_s = X \times_S s = \lim X_i \times_{S_i} s_i = \lim X_{i, s_i}$ because limits commute with limits (Categories, Lemma \ref{categories-lemma-colimits-commute}). Hence $e$ is the image of some idempotent $e_i \in H^0(X_{i, s_i}, \mathcal{O}_{X_{i, s_i}})$ by Limits, Lemma \ref{limits-lemma-descend-section}. By the Noetherian case there is an element $\tilde e_i$ in the stalk $(f_{i, *}\mathcal{O}_{X_i})_{s_i}$ mapping to $e_i$. Taking the pullback of $\tilde e_i$ we get an element $\tilde e$ of $(f_*\mathcal{O}_X)_s$ mapping to $e$ and the proof is complete.
The proof of this lemma is similar to the proof of Lemma \ref{lemma-proper-flat-h0} which we suggest the reader read first. By cohomology and base change (Lemma \ref{lemma-flat-proper-perfect-direct-image-general}) the complex $E = Rf_*\mathcal{O}_X$ is perfect and its formation commutes with arbitrary base change. This first implies that $E$ has tor aplitude in $[0, \infty)$. \medskip\noindent We claim that after replacing $S$ by an open neighbourhood of $s$ we can find a direct sum decomposition $E = H^0(E) \oplus \tau_{\geq 1}E$ in $D(\mathcal{O}_S)$ with $\tau_{\geq 1}E$ of tor amplitude in $[1, \infty)$. Assume the claim is true for now and assume we've made the replacement so we have the direct sum decomposition. Since $E$ has tor amplitude in $[0, \infty)$ we find that $H^0(E)$ is a flat $\mathcal{O}_S$-module. Hence $H^0(E)$ is a flat, perfect $\mathcal{O}_S$-module, hence finite locally free, see More on Algebra, Lemma \ref{more-algebra-lemma-perfect} (and the fact that finite projective modules are finite locally free by Algebra, Lemma \ref{algebra-lemma-finite-projective}). Of course $H^0(E) = f_*\mathcal{O}_X$ is an $\mathcal{O}_S$-algebra. By cohomology and base change we obtain $H^0(E) \otimes \kappa(s) = H^0(X_s, \mathcal{O}_{X_s})$. By Varieties, Lemma \ref{varieties-lemma-proper-geometrically-reduced-global-sections} and the assumption that $X_s$ is geometrically reduced, we see that $\kappa(s) \to H^0(E) \otimes \kappa(s)$ is finite \'etale. By Morphisms, Lemma \ref{morphisms-lemma-set-points-where-fibres-etale} applied to the finite locally free morphism $\underline{\Spec}_S(H^0(E)) \to S$, we conclude that after shrinking $S$ the $\mathcal{O}_S$-algebra $H^0(E)$ is finite \'etale. \medskip\noindent It remains to prove the claim. For this it suffices to prove that the map $$ (f_*\mathcal{O}_X)_s \longrightarrow H^0(X_s, \mathcal{O}_{X_s}) = H^0(E \otimes^\mathbf{L} \kappa(s)) $$ is surjective, see More on Algebra, Lemma \ref{more-algebra-lemma-better-cut-complex-in-two}. Choose a flat local ring homomorphism $\mathcal{O}_{S, s} \to A$ such that the residue field $k$ of $A$ is algebraically closed, see Algebra, Lemma \ref{algebra-lemma-flat-local-given-residue-field}. By flat base change (Cohomology of Schemes, Lemma \ref{coherent-lemma-flat-base-change-cohomology}) we get $H^0(X_A, \mathcal{O}_{X_A}) = (f_*\mathcal{O}_X)_s \otimes_{\mathcal{O}_{S, s}} A$ and $H^0(X_k, \mathcal{O}_{X_k}) = H^0(X_s, \mathcal{O}_{X_s}) \otimes_{\kappa(s)} k$. Hence it suffices to prove that $H^0(X_A, \mathcal{O}_{X_A}) \to H^0(X_k, \mathcal{O}_{X_k})$ is surjective. Since $X_k$ is a reduced proper scheme over $k$ and since $k$ is algebraically closed, we see that $H^0(X_k, \mathcal{O}_{X_k})$ is a finite product of copies of $k$ by the already used Varieties, Lemma \ref{varieties-lemma-proper-geometrically-reduced-global-sections}. Since by Lemma \ref{lemma-proper-idempotent-on-fibre} the idempotents of this $k$-algebra are in the image of $H^0(X_A, \mathcal{O}_{X_A}) \to H^0(X_k, \mathcal{O}_{X_k})$ we conclude.