Affine hulls and base change

Let $S$ be a scheme. We consider the functor, called affine hull, from the category of quasicompact and quasiseparated $S$-schemes to the category of affine $S$-schemes, defined as a left adjoint to the inclusion functor between these two full subcategories of the category of $S$-schemes (cf. EGA I.9.1.21). This functor commutes with flat base change in an obvious sense. My question, mostly out of pure curiosity, is how much we need flatness for this to hold. More precisely I would like to ask the following two things:

A. What are examples showing that flatness cannot be omitted in the above statement?

B. Are there any other conditions on the base change morphism under which formation of affine hulls commutes with base change?

First of all, I think that the affine hull functor can be extended to the category of all $S$-schemes, that is, not only the quasicompact quasiseparated ones [EDIT this may be true but the argument given here is not correct as it stands, see below]. The assumption qcqs is useful in that it ensures that the sheaf $A$ which is the pushforward of the structure sheaf is quasicoherent and then one defines the affine hull to be relative Spec of $A$. However, in full generality, there is a largest quasi-coherent submodule of $A$, equal to the image of the canonical map $\oplus F_i\to A$ where the $F_i$ are all the quasi-coherent submodules of $A$. Call this largest submodule $A'$. It is easy to see that $A'$ has an induced multiplication, i.e. it is a subalgebra. Then one sees that the scheme $Spec(A')$ serves as an affine hull on all $S$-schemes.

[EDIT. In fact Fred points out that the image of $\oplus F_i\to A$ may not be quasi-coherent and in this case the argument breaks down. Sorry.]

A. Start from the projective line over the ring of rational integers, and let $D$ be a section of that line, i.e. a $\mathbb{Z}$-point. Remove the closed point $D_2$ from the fibre at $2$ and call the result $X$. Let $S=Spec(\mathbb{Z})$ and $S'=Spec(\mathbb{F}_2)$. A global function on $X$ restricts to the generic fibre to a function on $\mathbb{P}^1_{\mathbb{Q}}$ i.e. a rational constant, and it restricts to the affine line $\mathbb{P}^1_{\mathbb{Z}}\setminus D$ to a polynomial in $\mathbb{Z}[T]$, $T$ a coordinate. Thus the ring of global functions on $X$ is in fact $\mathbb{Z}$. On the other hand, clearly the ring of global functions on the special fibre $X_2$ is a big polynomial ring, therefore the formation of the affine hull does not commute with the base change $S'\to S$.
B. Here is one simple example: if $X$ is affine over $S$, then it is equal to its affine hull and this remains true universally, i.e. after any base change (flat or not).
• Dear Matthieu, thank you very much for your detailed answer. Do you know where the affine hull without qcqs hypothesis is treated in the literature? Concerning question B: What I am looking for is rather a condition on the base change morphism $S'\rightarrow S$ such that the affine hull commutes for every $S$-scheme. – Fred Rohrer Aug 27 '14 at 12:40
• Dear Fred, I don't know a place where you can find this explained in full without the qcqs hypothesis. But you can find the lemma on existence of largest quasicoherent submodules in the Stacks Project under Lemma Tag 01QZ and then check for yourself that 1) in the case of a sheaf of algebras this largest thing is a subalgebra and 2) the Spec of this satisfies the universal property of the affine hull. For question B, sorry I misread. But I don't quite see what kind of condition on $S'\to S$ could do. – Matthieu Romagny Aug 27 '14 at 13:06
• This example generalizes to the following very weak necessary condition: the inverse image of each closed set with empty interior in $S$ has empty interior in $S'$. – Will Sawin Aug 27 '14 at 16:18
• Damned! I had overlooked that subtlety. At the moment I don't know how to argue -- do you have an example of a sheaf of modules on a scheme that does not embed into a quasi-coherent one ? What about a sheaf of the form $f_*O_X$? – Matthieu Romagny Aug 27 '14 at 21:05