TITLE: Does Zariski's Main Theorem come with a canonical factorization?
QUESTION [22 upvotes]: Zariski's Main Theorem (EGA IV, Thm 8.12.6): Suppose $Y$ is a quasi-compact and quasi-separated scheme, and $f:X\to Y$ is quasi-finite, separated, and finitely presented. Then $f$ factors as $X\xrightarrow{g} Z\xrightarrow{h} Y$, where $g$ is an open immersion and $h$ is finite.

Is there a canonical choice for the factorization $f=h\circ g$, at least under some circumstances? 

For example, suppose $f$ factors as $X\to U\to Y$, where $X\to U$ is finite étale and $U\to Y$ is a Stein open immersion (i.e. the pushforward of $\mathcal O_U$ is $\mathcal O_Y$). Then I'm pretty sure the Stein factorization $X\to \mathit{Spec}_Y(f_*\mathcal O_X)\to Y$ witnesses Zariksi's Main Theorem (i.e. is an open immersion followed by a finite map).

In general, when does the Stein factorization witness ZMT? In the cases where it fails to witness ZMT (e.g. $X$ finite over an affine open in $Y$), is there some other canonical witness?

REPLY [5 votes]: I realized that I completely missed the second part of the question (the example). Note that ZMT implies that $f$ is a quasi-affine morphism. Then $X\to \mathit{Spec}(f_*\mathcal O_X)$ is always an open immersion (see stack project, chapter 21, Lemma 12.3). So the Stein factorization witness ZMT if and only if $f_*\mathcal O_X$ is finite over $\mathcal O_Y$.
Some comments: one should note that in general, the quasi-coherent algebra $f_*\mathcal O_X$ is not finite over $\mathcal O_Y$ and even worse, the morphism $\mathit{Spec}(f_*\mathcal O_X)\to Y$ may not be of finite type (take $Y$ an algebraic variety and $f$ an open immersion. Then $\mathcal O(X)$ is or not finitely generated is related to Hilbert's 14th problem). Now consider a ZMT factorisation $X\to Z\to Y$. If the complementary of $X$ in $Z$ only consists in points of depth at least 2 (see discussions here), then $f_*\mathcal O_X=h_*\mathcal O_Z$ is finite and we are happy. This happens when $X$ is normal (or with non-normal locus finite over $Y$) and surjective to $Y$ with complementary in $Z$ of codimension at least 2. But I don't have a general criterion.