TITLE: When is fiber dimension upper semi-continuous?
QUESTION [28 upvotes]: Suppose $f\colon X \to Y $ is a morphism of schemes. We can define a function on the topological space $Y$ by sending $y\in Y$ to the dimension of the fiber of $f$ over $y$.

When is this function upper semi-continuous?

I have the following "concrete" application in mind. If an algebraic group $G$ acts on a scheme $X$, I'm pretty sure the stabilizer dimension is an upper semi-continuous function on $X$ (i.e. it can jump up on closed sub-schemes), but I don't know a proof. The stabilizers of points are the fibers of the map $\text{Stab}\to X$ in the following Cartesian square:
\begin{equation}
\require{AMScd}
\begin{CD}
\text{Stab} @>>> G \times X \\
@VVV @VV{\alpha}V \\
X @>{\Delta}>> X \times X.
\end{CD}
\end{equation}
where $\alpha\colon G\times X\to X\times X $ is given by $(g,x) \mapsto (g\cdot x,x)$, and $\Delta\colon X\to X\times X $ is the diagonal map $x\mapsto (x,x)$. It would be nice to have a condition satisfied by $\alpha\colon G\times X \to X\times X$ that would guarantee the upper semi-continuity of fiber dimension.

REPLY [21 votes]: I just discovered that Shavarevich (second edition) has a wrong answer to this question. In Section I.6.3, after Theorem 7 (which is correct), he gives the following Corollary. This quotation combines the Theorem and the Corollary.

Let $f: X \to Y$ be a regular map between irreducible varieties. Suppose that $f$ is surjective ... The sets $Y_k := \{ y \in Y: \dim f^{-1}(y) \geq k \}$ are closed in $Y$.

Note that this differs from the true EGA IV 13.1.5 by replacing "closed" with "surjective". I figured I'd record a counterexample here, which is slightly more public than just creating a handout for my class.
Our map is a composition $X \subset \mathbb{A}^3 \to \mathbb{A}^3 \to Y \subset \mathbb{A}^4$. We'll call the two $\mathbb{A}^3$'s $A$ and $B$ respectively.
$X$ is the quasi-affine variety $A \setminus \{ (0,\ast,0) \}$. We map $A \to B$ by $(x,y,z) \mapsto (x, xy, z)$. We map the $B$ to $\mathbb{A}^4$ by $(p,q,r) \mapsto (p(p-1), p^2(p-1), q,r)$. $Y$ is the affine variety $\{ (a,b,c,d) : a^3 = b(b-a) \}$. In other words, $Y$ is the product of a nodal cubic with $\mathbb{A}^2$.
To see surjectivity, note that $X$ hits every point of $B$ where $p$ is nonzero. The points of $B$ where $p \neq 0$ map to the points of $Y$ where $(a,b) \neq (0,0)$. The points $(0,0,c,d)$ in $Y$ are the images of $(1,c,d) \in B$, which are in turn the images of $(1,c,d)$ in $X$.
Now, let's look at $\dim f^{-1}(0,0,0,r)$. When $r \neq 0$, this is the union of $(1,0,r)$ and $(0, \ast, r)$, so one dimensional. When $r = 0$, the line $(0, \ast, 0)$ is deleted, so the preimage is only a point.
This suggests that something nicer may happen if we insist that fibers are irreducible, or that $Y$ is normal (perhaps Zariski's Main Theorem gets involved?) but I don't have a proposed statement to make.