hcju/stacksqa huggingface dataset:
Say $X = \Spec(A)$. Write $T = V(f_1, \ldots, f_r)$. (The case $r = 0$, i.e., $T = X$ follows immediately from Lemma \ref{lemma-pseudo-coherent-affine} and the definitions.) Let $(T, E, m)$ be a triple as in the lemma. Let $t$ be the largest integer such that $H^t(E)$ is nonzero. We will proceed by induction on $t$. The base case is $t < m$; in this case the result is trivial. Now suppose that $t \geq m$. By Cohomology, Lemma \ref{cohomology-lemma-finite-cohomology} the sheaf $H^t(E)$ is of finite type. Since it is quasi-coherent it is generated by finitely many sections (Properties, Lemma \ref{properties-lemma-finite-type-module}). For every $s \in \Gamma(X, H^t(E)) = H^t(X, E)$ (see proof of Lemma \ref{lemma-affine-compare-bounded}) we can find an $e > 0$ and a morphism $K_e[-t] \to E$ such that $s$ is in the image of $H^0(K_e) = H^t(K_e[-t]) \to H^t(E)$, see Lemma \ref{lemma-represent-cohomology-class-on-closed}. Taking a finite direct sum of these maps we obtain a map $P \to E$ where $P$ is a perfect complex supported on $T$, where $H^i(P) = 0$ for $i > t$, and where $H^t(P) \to E$ is surjective. Choose a distinguished triangle $$ P \to E \to E' \to P[1] $$ Then $E'$ is $m$-pseudo-coherent (Cohomology, Lemma \ref{cohomology-lemma-cone-pseudo-coherent}), $H^i(E') = 0$ for $i \geq t$, and $H^i(E')$ is supported on $T$ for $i \geq m - r + 1$. By induction we find an approximation $P' \to E'$ of $(T, E', m)$. Fit the composition $P' \to E' \to P[1]$ into a distinguished triangle $P \to P'' \to P' \to P[1]$ and extend the morphisms $P' \to E'$ and $P[1] \to P[1]$ into a morphism of distinguished triangles $$ \xymatrix{ P \ar[r] \ar[d] & P'' \ar[d] \ar[r] & P' \ar[d] \ar[r] & P[1] \ar[d] \\ P \ar[r] &  E \ar[r] & E' \ar[r] & P[1] } $$ using TR3. Then $P''$ is a perfect complex (Cohomology, Lemma \ref{cohomology-lemma-two-out-of-three-perfect}) supported on $T$. An easy diagram chase shows that $P'' \to E$ is the desired approximation.
Let $T \subset X$ be a closed subset with $X \setminus T$ retro-compact in $X$. Let $r_U$ be the integer of Definition \ref{definition-approximation} adapted to the pair $(U, T \cap U)$. Set $T' = T \setminus U$. Note that $T' \subset V$ and that $V \setminus T' = (X \setminus T) \cap U \cap V$ is quasi-compact by our assumption on $T$. Let $r'$ be the number of affines needed to cover $V \setminus T'$. We claim that $r = \max(r_U, r')$ works for the pair $(X, T)$. \medskip\noindent To see this choose a triple $(T, E, m)$ such that $E$ is $(m - r)$-pseudo-coherent and $H^i(E)$ is supported on $T$ for $i \geq m - r$. Let $t$ be the largest integer such that $H^t(E)|_U$ is nonzero. (Such an integer exists as $U$ is quasi-compact and $E|_U$ is $(m - r)$-pseudo-coherent.) We will prove that $E$ can be approximated by induction on $t$. \medskip\noindent Base case: $t \leq m - r'$. This means that $H^i(E)$ is supported on $T'$ for $i \geq m - r'$. Hence Lemma \ref{lemma-approximation-affine} guarantees the existence of an approximation $P \to E|_V$ of $(T', E|_V, m)$ on $V$. Applying Lemma \ref{lemma-open} we see that $(T', E, m)$ can be approximated. Such an approximation is also an approximation of $(T, E, m)$. \medskip\noindent Induction step. Choose an approximation $P \to E|_U$ of $(T \cap U, E|_U, m)$. This in particular gives a surjection $H^t(P) \to H^t(E|_U)$. By Lemma \ref{lemma-lift-perfect-complex-plus-shift-support} we can choose a perfect object $Q$ in $D(\mathcal{O}_V)$ supported on $T \cap V$ and an isomorphism $Q|_{U \cap V} \to (P \oplus P[1])|_{U \cap V}$. By Lemma \ref{lemma-lift-map} we can replace $Q$ by $Q \otimes^\mathbf{L} I$ and assume that the map $$ Q|_{U \cap V} \to (P \oplus P[1])|_{U \cap V} \longrightarrow P|_{U \cap V} \longrightarrow E|_{U \cap V} $$ lifts to $Q \to E|_V$. By Cohomology, Lemma \ref{cohomology-lemma-glue} we find an morphism $a : R \to E$ of $D(\mathcal{O}_X)$ such that $a|_U$ is isomorphic to $P \oplus P[1] \to E|_U$ and $a|_V$ isomorphic to $Q \to E|_V$. Thus $R$ is perfect and supported on $T$ and the map $H^t(R) \to H^t(E)$ is surjective on restriction to $U$. Choose a distinguished triangle $$ R \to E \to E' \to R[1] $$ Then $E'$ is $(m - r)$-pseudo-coherent (Cohomology, Lemma \ref{cohomology-lemma-cone-pseudo-coherent}), $H^i(E')|_U = 0$ for $i \geq t$, and $H^i(E')$ is supported on $T$ for $i \geq m - r$. By induction we find an approximation $R' \to E'$ of $(T, E', m)$. Fit the composition $R' \to E' \to R[1]$ into a distinguished triangle $R \to R'' \to R' \to R[1]$ and extend the morphisms $R' \to E'$ and $R[1] \to R[1]$ into a morphism of distinguished triangles $$ \xymatrix{ R \ar[r] \ar[d] & R'' \ar[d] \ar[r] & R' \ar[d] \ar[r] & R[1] \ar[d] \\ R \ar[r] &  E \ar[r] & E' \ar[r] & R[1] } $$ using TR3. Then $R''$ is a perfect complex (Cohomology, Lemma \ref{cohomology-lemma-two-out-of-three-perfect}) supported on $T$. An easy diagram chase shows that $R'' \to E$ is the desired approximation.
Choose a distinguished triangle $E \to Rj_*(E|_U) \to N \to E[1]$. Observe that $$ \Hom_{D(\mathcal{O}_X)}(K[n], Rj_*(E|_U)) = \Hom_{D(\mathcal{O}_U)}(K|_U[n], E) = 0 $$ for all $n$ as $K|_U = 0$. Thus it suffices to prove the result for $N$. In other words, we may assume that $E$ restricts to zero on $U$. Observe that there are distinguished triangles $$ K^\bullet(f_1^{e_1}, \ldots, f_i^{e'_i}, \ldots, f_r^{e_r}) \to K^\bullet(f_1^{e_1}, \ldots, f_i^{e'_i + e''_i}, \ldots, f_r^{e_r}) \to K^\bullet(f_1^{e_1}, \ldots, f_i^{e''_i}, \ldots, f_r^{e_r}) \to \ldots $$ of Koszul complexes, see More on Algebra, Lemma \ref{more-algebra-lemma-koszul-mult}. Hence if $\Hom_{D(\mathcal{O}_X)}(K[n], E) = 0$ for all $n \in \mathbf{Z}$ then the same thing is true for the $K$ replaced by $K_e$ as in Lemma \ref{lemma-represent-cohomology-class-on-closed}. Thus our lemma follows immediately from that one and the fact that $E$ is determined by the complex of $A$-modules $R\Gamma(X, E)$, see Lemma \ref{lemma-affine-compare-bounded}.
Recall that as $X$ has an ample invertible sheaf, it is quasi-compact and separated (Properties, Definition \ref{properties-definition-ample} and Lemma \ref{properties-lemma-affine-s-opens-cover-quasi-separated}). Thus we may apply Proposition \ref{proposition-quasi-compact-affine-diagonal} and represent $K$ by a complex $\mathcal{F}^\bullet$ of quasi-coherent modules. Pick any $p$ such that $\mathcal{H}^p = \Ker(\mathcal{F}^p \to \mathcal{F}^{p + 1})/ \Im(\mathcal{F}^{p - 1} \to \mathcal{F}^p)$ is nonzero. Choose a point $x \in X$ such that the stalk $\mathcal{H}^p_x$ is nonzero. Choose an $n \geq 0$ and $s \in \Gamma(X, \mathcal{L}^{\otimes n})$ such that $X_s$ is an affine open neighbourhood of $x$. Choose $\tau \in \mathcal{H}^p(X_s)$ which maps to a nonzero element of the stalk $\mathcal{H}^p_x$; this is possible as $\mathcal{H}^p$ is quasi-coherent and $X_s$ is affine. Since taking sections over $X_s$ is an exact functor on quasi-coherent modules, we can find a section $\tau' \in \mathcal{F}^p(X_s)$ mapping to zero in $\mathcal{F}^{p + 1}(X_s)$ and mapping to $\tau$ in $\mathcal{H}^p(X_s)$. By Properties, Lemma \ref{properties-lemma-invert-s-sections} there exists an $m$ such that $\tau' \otimes s^{\otimes m}$ is the image of a section $\tau'' \in \Gamma(X, \mathcal{F}^p \otimes \mathcal{L}^{\otimes mn})$. Applying the same lemma once more, we find $l \geq 0$ such that $\tau'' \otimes s^{\otimes l}$ maps to zero in $\mathcal{F}^{p + 1} \otimes \mathcal{L}^{\otimes (m + l)n}$. Then $\tau''$ gives a nonzero class in $H^p(X, K \otimes^\mathbf{L}_{\mathcal{O}_X} \mathcal{L}^{(m + l)n})$ as desired.
Recall that $\mathbf{P}^n_A$ is $\text{Proj}(A[X_0, \ldots, X_n])$, see Constructions, Definition \ref{constructions-definition-projective-space}. Consider the Koszul complex $$ K_\bullet = K_\bullet(A[X_0, \ldots, X_n], X_0, \ldots, X_n) $$ over $S = A[X_0, \ldots, X_n]$ on $X_0, \ldots, X_n$. Since $X_0, \ldots, X_n$ is clearly a regular sequence in the polynomial ring $S$, we see that (More on Algebra, Lemma \ref{more-algebra-lemma-regular-koszul-regular}) that the Koszul complex $K_\bullet$ is exact, except in degree $0$ where the cohomology is $S/(X_0, \ldots, X_n)$. Note that $K_\bullet$ becomes a complex of graded modules if we put the generators of $K_i$ in degree $+i$. In other words an exact complex $$ 0 \to S(-n - 1) \to \ldots \to S(-n - 1 + i)^{\oplus {n \choose i}} \to \ldots \to S \to S/(X_0, \ldots, X_n) \to 0 $$ Applying the exact functor $\tilde{\ }$ functor of Constructions,  Lemma \ref{constructions-lemma-proj-sheaves} and using that the last term is in the kernel of this functor, we obtain the exact complex $$ 0 \to \mathcal{O}_X(-n - 1) \to \ldots \to \mathcal{O}_X(-n - 1 + i)^{\oplus {n + 1 \choose i}} \to \ldots \to \mathcal{O}_X \to 0 $$ Twisting by the invertible sheaves $\mathcal{O}_X(n + a)$ we get the exact complexes of the lemma.
Let $K \in D_\QCoh(\mathcal{O}_X)$. Assume $\Hom(E, K[p]) = 0$ for all $p \in \mathbf{Z}$. We have to show that $K = 0$. By Derived Categories, Lemma \ref{derived-lemma-right-orthogonal} we see that $\Hom(E', K[p])$ is zero for all $E' \in \langle E \rangle$ and $p \in \mathbf{Z}$. By Lemma \ref{lemma-construct-the-next-one} applied with $a = -n - 1$ we see that $\mathcal{O}_X(-n - 1) \in \langle E \rangle$ because it is quasi-isomorphic to a finite complex whose terms are finite direct sums of summands of $E$. Repeating the argument with $a = -n - 2$ we see that $\mathcal{O}_X(-n - 2) \in \langle E \rangle$. Arguing by induction we find that $\mathcal{O}_X(-m) \in \langle E \rangle$ for all $m \geq 0$. Since $$ \Hom(\mathcal{O}_X(-m), K[p]) = H^p(X, K \otimes_{\mathcal{O}_X}^\mathbf{L} \mathcal{O}_X(m)) = H^p(X, K \otimes_{\mathcal{O}_X}^\mathbf{L} \mathcal{O}_X(1)^{\otimes m}) $$ we conclude that $K = 0$ by Lemma \ref{lemma-nonzero-some-cohomology}. (This also uses that $\mathcal{O}_X(1)$ is an ample invertible sheaf on $X$ which follows from Properties, Lemma \ref{properties-lemma-open-in-proj-ample}.)
Part (2) follows from (1) as $\Ext^n_{D(\mathcal{O}_X)}(K, L) = \Hom_{D(\mathcal{O}_X)}(K, L[n])$. We prove (1). Since $K$ is perfect we have $$ \Hom_{D(\mathcal{O}_X)}(K, L) = H^0(X, K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L) $$ where $K^\vee$ is the ``dual'' perfect complex to $K$, see Cohomology, Lemma \ref{cohomology-lemma-dual-perfect-complex}. Note that $K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L$ is in $D_\QCoh(X)$ by Lemmas \ref{lemma-quasi-coherence-tensor-product} and \ref{lemma-pseudo-coherent} (to see that a perfect complex has quasi-coherent cohomology sheaves). Say $K^\vee$ has tor amplitude in $[a, b]$. Then the spectral sequence $$ E_1^{p, q} = H^p(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} H^q(L)) \Rightarrow H^{p + q}(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L) $$ shows that $H^j(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L)$ is zero if $H^q(L) = 0$ for $q \in [j - b, j - a]$. Let $N$ be the integer $d$ of Cohomology of Schemes, Lemma \ref{coherent-lemma-vanishing-nr-affines-quasi-separated}. Then $H^0(X, K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L)$ vanishes if the cohomology sheaves $$ H^{-N}(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L), \ H^{-N + 1}(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L), \ \ldots, \ H^0(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L) $$ are zero. Namely, by the lemma cited and Lemma \ref{lemma-application-nice-K-injective}, we have $$ H^0(X, K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L) = H^0(X, \tau_{\geq -N}(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L)) $$ and by the vanishing of cohomology sheaves, this is equal to $H^0(X, \tau_{\geq 1}(K^\vee \otimes_{\mathcal{O}_X}^\mathbf{L} L))$ which is zero by Derived Categories, Lemma \ref{derived-lemma-negative-vanishing}. It follows that $\Hom_{D(\mathcal{O}_X)}(K, L)$ is zero if $H^i(L) = 0$ for $i \in [-b - N, -a]$.
The implication (2) $\Rightarrow$ (1) is true on any ringed space. Namely, assume (2) holds. Recall that a perfect object of the derived category is pseudo-coherent, see Cohomology, Lemma \ref{cohomology-lemma-perfect}. Then it follows from the definitions that $\tau_{\geq -n}K_n$ is $(-n + 1)$-pseudo-coherent and hence $\tau_{\geq -n}K$ is $(-n + 1)$-pseudo-coherent, hence $K$ is $(-n + 1)$-pseudo-coherent. This is true for all $n$, hence $K$ is pseudo-coherent, see Cohomology, Definition \ref{cohomology-definition-pseudo-coherent}. \medskip\noindent Assume (1). We start by choosing an approximation $K_1 \to K$ of $(X, K, -2)$ by a perfect complex $K_1$, see Definitions \ref{definition-approximation-holds} and \ref{definition-approximation} and Theorem \ref{theorem-approximation}. Suppose by induction we have $$ K_1 \to K_2 \to \ldots \to K_n \to K $$ with $K_i$ perfect such that such that $\tau_{\geq -i}K_i \to \tau_{\geq -i}K$ is an isomorphism for all $1 \leq i \leq n$. Then we pick $a \leq b$ as in Lemma \ref{lemma-ext-from-perfect-into-bounded-QCoh} for the perfect object $K_n$. Choose an approximation $K_{n + 1} \to K$ of $(X, K, \min(a - 1, -n - 1))$. Choose a distinguished triangle $$ K_{n + 1} \to K \to C \to K_{n + 1}[1] $$ Then we see that $C \in D_\QCoh(\mathcal{O}_X)$ has $H^i(C) = 0$ for $i \geq a$. Thus by our choice of $a, b$ we see that $\Hom_{D(\mathcal{O}_X)}(K_n, C) = 0$. Hence the composition $K_n \to K \to C$ is zero. Hence by Derived Categories, Lemma \ref{derived-lemma-representable-homological} we can factor $K_n \to K$ through $K_{n + 1}$ proving the induction step. \medskip\noindent We still have to prove that $K = \text{hocolim} K_n$. This follows by an application of Derived Categories, Lemma \ref{derived-lemma-cohomology-of-hocolim} to the functors $H^i( - ) : D(\mathcal{O}_X) \to \textit{Mod}(\mathcal{O}_X)$ and our choice of $K_n$.
To prove that our functor is fully faithful it suffices to prove that $\Ext^i_X(P, P)$ is zero for $i \not = 0$ and equal to $R$ for $i = 0$, see Differential Graded Algebra, Lemma \ref{dga-lemma-fully-faithful-in-compact-case}. As in the proof of Lemma \ref{lemma-ext-from-perfect-into-bounded-QCoh} we see that $$ \Ext^i_X(P, P) = H^i(X, P^\wedge \otimes P) = \bigoplus\nolimits_{0 \leq a, b \leq n} H^i(X, \mathcal{O}_X(a - b)) $$ By the computation of cohomology of projective space (Cohomology of Schemes, Lemma \ref{coherent-lemma-cohomology-projective-space-over-ring}) we find that these $\Ext$-groups are zero unless $i = 0$. For $i = 0$ we recover $R$ because this is how we defined $R$ in (\ref{equation-algebra-for-Pn}). By Differential Graded Algebra, Lemma \ref{dga-lemma-tensor-with-complex-hom-adjoint} our functor has a right adjoint, namely $R\Hom(P, -) : D_\QCoh(\mathcal{O}_X) \to D(R)$. Since $P$ is a generator for $D_\QCoh(\mathcal{O}_X)$ by Lemma \ref{lemma-generator-P1} we see that the kernel of $R\Hom(P, -)$ is zero. Hence our functor is an equivalence of triangulated categories by Derived Categories, Lemma \ref{derived-lemma-fully-faithful-adjoint-kernel-zero}.
[First proof] We will use the induction principle as in Cohomology of Schemes, Lemma \ref{coherent-lemma-induction-principle} to prove this. If $D(\QCoh(\mathcal{O}_X)) \to D_\QCoh(\mathcal{O}_X)$ is an equivalence, then the lemma is true because the functor $RQ_X$ of Section \ref{section-coherator} is a right adjoint to the functor $D(\QCoh(\mathcal{O}_X)) \to D(\mathcal{O}_X)$. In particular, our lemma is true for affine schemes, see Lemma \ref{lemma-affine-coherator}. Thus we see that it suffices to show: if $X = U \cup V$ is a union of two quasi-compact opens and the lemma holds for $U$, $V$, and $U \cap V$, then the lemma holds for $X$. \medskip\noindent The adjoint exists if and only if for every object $K$ of $D(\mathcal{O}_X)$ we can find a distinguished triangle $$ E' \to E \to K \to E'[1] $$ in $D(\mathcal{O}_X)$ such that $E'$ is in $D_\QCoh(\mathcal{O}_X)$ and such that $\Hom(M, K) = 0$ for all $M$ in $D_\QCoh(\mathcal{O}_X)$. See Derived Categories, Lemma \ref{derived-lemma-right-adjoint}. Consider the distinguished triangle $$ E \to Rj_{U, *}E|_U \oplus Rj_{V, *}E|_V \to Rj_{U \cap V, *}E|_{U \cap V} \to E[1] $$ in $D(\mathcal{O}_X)$ of Cohomology, Lemma \ref{cohomology-lemma-exact-sequence-j-star}. By Derived Categories, Lemma \ref{derived-lemma-prepare-adjoint} it suffices to construct the desired distinguished triangles for $Rj_{U, *}E|_U$, $Rj_{V, *}E|_V$, and $Rj_{U \cap V, *}E|_{U \cap V}$. This reduces us to the statement discussed in the next paragraph. \medskip\noindent Let $j : U \to X$ be an open immersion corresponding with $U$ a quasi-compact open for which the lemma is true. Let $L$ be an object of $D(\mathcal{O}_U)$. Then there exists a distinguished triangle $$ E' \to Rj_*L \to K \to E'[1] $$ in $D(\mathcal{O}_X)$ such that $E'$ is in $D_\QCoh(\mathcal{O}_X)$ and such that $\Hom(M, K) = 0$ for all $M$ in $D_\QCoh(\mathcal{O}_X)$. To see this we choose a distinguished triangle $$ L' \to L \to Q \to L'[1] $$ in $D(\mathcal{O}_U)$ such that $L'$ is in $D_\QCoh(\mathcal{O}_U)$ and such that $\Hom(N, Q) = 0$ for all $N$ in $D_\QCoh(\mathcal{O}_U)$. This is possible because the statement in Derived Categories, Lemma \ref{derived-lemma-right-adjoint} is an if and only if. We obtain a distinguished triangle $$ Rj_*L' \to Rj_*L \to Rj_*Q \to Rj_*L'[1] $$ in $D(\mathcal{O}_X)$. Observe that $Rj_*L'$ is in $D_\QCoh(\mathcal{O}_X)$ by Lemma \ref{lemma-quasi-coherence-direct-image}. On the other hand, if $M$ in $D_\QCoh(\mathcal{O}_X)$, then $$ \Hom(M, Rj_*Q) = \Hom(Lj^*M, Q) = 0 $$ because $Lj^*M$ is in $D_\QCoh(\mathcal{O}_U)$ by Lemma \ref{lemma-quasi-coherence-pullback}. This finishes the proof.
We will prove this using the induction principle of Cohomology of Schemes, Lemma \ref{coherent-lemma-induction-principle}. \medskip\noindent If $X$ is affine, then the lemma is true with $N = 0$ because then $RQ_X = DQ_X$ is given by taking the complex of quasi-coherent sheaves associated to $R\Gamma(X, K)$. See Lemmas \ref{lemma-affine-compare-bounded} and \ref{lemma-affine-coherator}. \medskip\noindent Asssume $U, V$ are quasi-compact open in $X$ and the lemma holds for $U$, $V$, and $U \cap V$. Say with integers $N(U)$, $N(V)$, and $N(U \cap V)$. Now suppose $K$ is in $D(\mathcal{O}_X)$ with $H^i(W, K) = 0$ for all affine open $W \subset X$ and all $i \not \in [a, b]$. Then $K|_U$, $K|_V$, $K|_{U \cap V}$ have the same property. Hence we see that $RQ_U(K|_U)$ and $RQ_V(K|_V)$ and $RQ_{U \cap V}(K|_{U \cap V})$ have vanishing cohomology sheaves outside the inverval $[a, b + \max(N(U), N(V), N(U \cap V))$. Since the functors $Rj_{U, *}$, $Rj_{V, *}$, $Rj_{U \cap V, *}$ have finite cohomological dimension on $D_\QCoh$ by Lemma \ref{lemma-quasi-coherence-direct-image} we see that there exists an $N$ such that $Rj_{U, *}DQ_U(K|_U)$, $Rj_{V, *}DQ_V(K|_V)$, and $Rj_{U \cap V, *}DQ_{U \cap V}(K|_{U \cap V})$ have vanishing cohomology sheaves outside the interval $[a, b + N]$. Then finally we conclude by the distinguished triangle of Remark \ref{remark-explain-consequence}.
To check the map is an isomorphism we may work locally on $Y$. Hence we reduce to the case that $Y$ is affine. \medskip\noindent Suppose that $K = \bigoplus K_i$ is a direct sum of some complexes $K_i \in D_\QCoh(\mathcal{O}_Y)$. If the statement holds for each $K_i$, then it holds for $K$. Namely, the functors $Lf^*$ and $\otimes^\mathbf{L}$ preserve direct sums by construction and $Rf_*$ commutes with direct sums (for complexes with quasi-coherent cohomology sheaves) by Lemma \ref{lemma-quasi-coherence-pushforward-direct-sums}. Moreover, suppose that $K \to L \to M \to K[1]$ is a distinguished triangle in $D_\QCoh(Y)$. Then if the statement of the lemma holds for two of $K, L, M$, then it holds for the third (as the functors involved are exact functors of triangulated categories). \medskip\noindent Assume $Y$ affine, say $Y = \Spec(A)$. The functor $\widetilde{\ } : D(A) \to D_\QCoh(\mathcal{O}_Y)$ is an equivalence (Lemma \ref{lemma-affine-compare-bounded}). Let $T$ be the property for $K \in D(A)$ that the statement of the lemma holds for $\widetilde{K}$. The discussion above and More on Algebra, Remark \ref{more-algebra-remark-P-resolution} shows that it suffices to prove $T$ holds for $A[k]$. This finishes the proof, as the statement of the lemma is clear for shifts of the structure sheaf.
For any object $E$ of $D(\mathcal{O}_X)$ we can use Cohomology, Remark \ref{cohomology-remark-base-change} to get a canonical base change map $Lg^*Rf_*E \to Rf'_*L(g')^*E$. To check this is an isomorphism we may work locally on $S'$. Hence we may assume $g : S' \to S$ is a morphism of affine schemes. In particular, $g$ is affine and it suffices to show that $$ Rg_*Lg^*Rf_*E \to Rg_*Rf'_*L(g')^*E = Rf_*(Rg'_* L(g')^* E) $$ is an isomorphism, see Lemma \ref{lemma-affine-morphism} (and use Lemmas \ref{lemma-quasi-coherence-pullback}, \ref{lemma-quasi-coherence-tensor-product}, and \ref{lemma-quasi-coherence-direct-image} to see that the objects $Rf'_*L(g')^*E$ and $Lg^*Rf_*E$ have quasi-coherent cohomology sheaves). Note that $g'$ is affine as well (Morphisms, Lemma \ref{morphisms-lemma-base-change-affine}). By Lemma \ref{lemma-affine-morphism-pull-push} the map becomes a map $$ Rf_*E \otimes_{\mathcal{O}_S}^\mathbf{L} g_*\mathcal{O}_{S'} \longrightarrow Rf_*(E \otimes_{\mathcal{O}_X}^\mathbf{L} g'_*\mathcal{O}_{X'}) $$ Observe that $g'_*\mathcal{O}_{X'} = f^*g_*\mathcal{O}_{S'}$. Thus by Lemma \ref{lemma-cohomology-base-change} it suffices to prove that $Lf^*g_*\mathcal{O}_{S'} = f^*g_*\mathcal{O}_{S'}$. This follows from our assumption that $X$ and $S'$ are Tor independent over $S$. Namely, to check it we may work locally on $X$, hence we may also assume $X$ is affine. Say $X = \Spec(A)$, $S = \Spec(R)$ and $S' = \Spec(R')$. Our assumption implies that $A$ and $R'$ are Tor independent over $R$ (More on Algebra, Lemma \ref{more-algebra-lemma-tor-independent}), i.e., $\text{Tor}_i^R(A, R') = 0$ for $i > 0$. In other words $A \otimes_R^\mathbf{L} R' = A \otimes_R R'$ which exactly means that $Lf^*g_*\mathcal{O}_{S'} = f^*g_*\mathcal{O}_{S'}$ (use Lemma \ref{lemma-quasi-coherence-pullback}).
There is a canonical map $R\Hom_X(M, K) \to R\Hom_{X'}(L(g')^*M, L(g')^*K)$ in $D(\Gamma(X, \mathcal{O}_X))$ of global hom complexes, see Cohomology, Section \ref{cohomology-section-global-RHom}. Restricting scalars we can view this as a map in $D(R)$. Then we can use the adjointness of restriction and $- \otimes_R^\mathbf{L} R'$ to get the displayed map of the lemma. Having defined the map it suffices to prove it is an isomorphism in the derived category of abelian groups. \medskip\noindent The right hand side is equal to $$ R\Hom_X(M, R(g')_*L(g')^*K) = R\Hom_X(M, K \otimes_{\mathcal{O}_X}^\mathbf{L} g'_*\mathcal{O}_{X'}) $$ by Lemma \ref{lemma-affine-morphism-pull-push}. In both cases the complex $R\SheafHom(M, K)$ is an object of $D_\QCoh(\mathcal{O}_X)$ by Lemma \ref{lemma-quasi-coherence-internal-hom}. There is a natural map $$ R\SheafHom(M, K) \otimes_{\mathcal{O}_X}^\mathbf{L} g'_*\mathcal{O}_{X'} \longrightarrow R\SheafHom(M, K \otimes_{\mathcal{O}_X}^\mathbf{L} g'_*\mathcal{O}_{X'}) $$ which is an isomorphism in both cases by Lemma \ref{lemma-internal-hom-evaluate-tensor-isomorphism}. To see that this lemma applies in case (2) we note that $g'_*\mathcal{O}_{X'} = Rg'_*\mathcal{O}_{X'} = Lf^*g_*\mathcal{O}_X$ the second equality by Lemma \ref{lemma-compare-base-change}. Using Lemma \ref{lemma-tor-dimension-affine} and Cohomology, Lemma \ref{cohomology-lemma-tor-amplitude-pullback} we conclude that $g'_*\mathcal{O}_{X'}$ has finite Tor dimension. Hence, in both cases by replacing $K$ by $R\SheafHom(M, K)$ we reduce to proving $$ R\Gamma(X, K) \otimes^\mathbf{L}_A A' \longrightarrow R\Gamma(X, K \otimes^\mathbf{L}_{\mathcal{O}_X} g'_*\mathcal{O}_{X'}) $$ is an isomorphism. Note that the left hand side is equal to $R\Gamma(X', L(g')^*K)$ by Lemma \ref{lemma-affine-morphism-pull-push}. Hence the result follows from Lemma \ref{lemma-compare-base-change}.