Global regular functions and restriction to the fiber Let $S$ be a local scheme (spectrum of a local ring) with closed point $s$ and $f:X \to S$ a morphism of schemes.
Under which conditions on $f$ and $S$ is the natural map
$$
H^0(X,\mathcal{O})\otimes k(s) \to H^0(X_s,\mathcal{O})
$$
an isomorphism?
For instance, is this always true if $S$ is Artinian or does one need to impose something on $f$?
 A: Here's an interesting example very similar to one I described in my dissertation (in a discussion of Stein factorisation and base change). In particular, it shows that assuming $f$ is flat and projective with geometrically connected fibres is not sufficient, both in the case where $S$ is integral and the case $S$ Artinian. (You can even show that the source and target are regular in the integral case, cf. §2.3 of my dissertation.)
(On the other hand, flat proper with connected and reduced geometric fibres is certainly enough, for then $f_*\mathcal O_X = \mathcal O_S$ holds universally.)
(I suspect there might be more elementary examples, but at least this one is somewhat conceptual.)
Example. Let $k = \bar{\mathbf F}_p(x)$ and $S = \mathbf A^1_k = \operatorname{Spec} k[t]$. Let $E$ be a supersingular elliptic curve over $\bar {\mathbf F}_p$, and let
$$\mathcal E = E \underset{\operatorname{Spec}\bar{\mathbf F}_p}\times S = E_ k \underset{\operatorname{Spec} k}\times S.$$
Construct an $\pmb\alpha_p$-torsor $X \to \mathcal E$ that is geometrically nontrivial in all fibres over $S \setminus 0$, and in the special fibre is the purely inseparable map $E_{\bar{\mathbf F}_p(x^{1/p})} \to E_k$: the short exact sequence
$$0 \to \pmb\alpha_p \to \mathcal O_{\mathcal E} \stackrel{F}\to \mathcal O_{\mathcal E} \to 0$$
on the flat site of $\mathcal E$ gives a long exact sequence
$$\ldots \to H^0(E,\mathcal O_E) \underset{\bar{\mathbf F}_p}\otimes k[t] \stackrel\delta\to H^1(\mathcal E,\pmb\alpha_p) \to H^1(E,\mathcal O_E) \underset{\bar{\mathbf F}_p}\otimes k[t] \stackrel{F}\to H^1(E,\mathcal O_E) \underset{\bar{\mathbf F}_p}\otimes k[t] \to \ldots.$$
Since $E$ is supersingular, the Frobenius action on $H^1(E,\mathcal O_E)$ is $0$, so a nonzero class $\eta \in H^1(E,\mathcal O_E)$ gives $\eta t \in H^1(E,\mathcal O_E) \otimes_{\bar{\mathbf F}_p} k[t]$ mapping to $0$ under $F$. If $\beta \in H^1(\mathcal E,\pmb\alpha_p)$ is an element mapping to $\eta t$, then $\beta|_{\mathcal E_0}$ maps to $0$ in $H^1(\mathcal E_0,\mathcal O_{\mathcal E_0}) = H^1(E,\mathcal O_E) \otimes_{\bar{\mathbf F}_p} k$, hence comes from an element $f \in H^0(\mathcal E_0,\mathcal O_{\mathcal E_0}) = H^0(E,\mathcal O_E) \otimes_{\bar{\mathbf F}_p} k$. Replacing $\beta$ by $\beta + \delta(x-f)$ we may assume that $\beta|_{\mathcal E_0} = \delta(x)$.
Letting $X \to \mathcal E$ be the $\pmb\alpha_p$-torsor given by the class $\beta$, we see that $X_0 = E_{\bar{\mathbf F}_p(x^{1/p})}$ (corresponding to the class $\delta(x) \in H^1(\mathcal E_0,\pmb\alpha_p)$). It is clear that $X \to \mathcal E$ and $\mathcal E \to S$ are flat and proper, so the same goes for $f \colon X \to S$.

Claim. With $X$ as above, we have $H^0(X,\mathcal O_X) = k[t]$, i.e. $f_*\mathcal O_X = \mathcal O_S$.

Indeed, note that the fibres at $s \neq 0$ are smooth since the $\pmb\alpha_p$-torsors $X_s \to \mathcal E_s$ are geometrically nontrivial, hence $X_{\bar s} \to \mathcal E_{\bar s}$ is a degree $p$ inseparable cover of elliptic curves. Thus the geometric fibres of $f|_{S \setminus 0}$ are reduced and connected, so $f_* \mathcal O_{X|_{S\setminus 0}} = \mathcal O_{S \setminus 0}$. Since $S$ is normal, $f_* \mathcal O_X$ is the normalisation of $\mathcal O_S$ in $f_* \mathcal O_{X|_{S \setminus 0}}$, hence equals $\mathcal O_S$. $\square$
Since $f_* \mathcal O_X = \mathcal O_S$ but $H^0(X_0,\mathcal O_{X_0}) = \bar{\mathbf F}_p(x^{1/p}) \supsetneq k$, we already have a counterexample over an integral base (which can be made local by localising at $0$).
To get an Artinian counterexample, restrict the above to $\operatorname{Spec} k[t]/t^n \subseteq S$ for $n \gg 0$. By the theorem of formal functions, if the maps $H^0(X|_{\operatorname{Spec} k[t]/t^n},\mathcal O) \to H^0(X_0,\mathcal O_{X_0})$ are surjective for all $n$, then so is $H^0(X,\mathcal O_X) \to H^0(X_0,\mathcal O_{X_0})$, which we saw is not the case.
Remark. A slightly easier example has as special fibre the trivial $\pmb\alpha_p$-torsor $k \to k[y]/y^p$. The above example is a twisted version of this, with the extra property that all fibres are regular (but the special fibre is not smooth, i.e. geometrically regular).
A: Assume that $S$ is Artinian local and $f$ is proper and flat. If $H^0(X, \mathcal{O}_X)\otimes k(s)\to H^0(X_s, \mathcal{O}_{X_s})$ is surjective then standard cohomology and base change results imply that $H^0(X, \mathcal{O}_X)$ is a flat module over $H^0(S, \mathcal{O}_S)$. However that is not always true https://mathoverflow.net/a/107603/158636
