Is any morphism with at most one right inverse a mono? My question is the following:

Let $f\colon B \to C$ and suppose that $f$ has at most one right inverse, i.e. if $f\, g = \mathrm{id}_C$ and $f\, h = \mathrm{id}_C$, then $g = h$. Prove that $f$ is mono or find a counterexample.

In $\mathrm{Sets}$ this is true: if $f$ is not injective, then there are at least two distinct elements of $B$ with equal images, from which one can construct two distinct right inverses.
Since I couldn't find any counterexample in other categories, I've been trying to prove it assuming that the category has pullbacks (in fact, lex categories are the ones I'm interested in). My attempt is the following. Let $g,\, h\colon A \to B$, suppose that $f\, g = f\, h$, and call such composition $t$. Draw a pullback square of $f$ and $t$, and call $f'$ and $t'$ the corresponding morphisms. Then there exists a unique $g' \colon A \to A \times_C B$ such that $t'\, g' = g$ and $f'\, g' = \mathrm{id}_A$, and similarly a unique $h'\colon A \to A \times_C B$ such that $t' \, h' = h$ and $f' \, h' = \mathrm{id}_A$. So, if the property of having at most one right inverse were preserved by pullbacks, it would follow that $g' = h'$ and hence $g = h$. But I guess this isn't true in general, so I'm stuck.
Thank you in advance for all your help.
 A: Note that "at most one right inverse" does not exclude the possibility that $f$ has no right inverse.
Consider the category $\mathsf{CRing}$ of commutative unital rings, and let $f:\mathbb{Z}\to\mathbb{Z}/2\mathbb{Z}$ be the quotient map. This has no right inverse. It is not a monomorphism because, for example, $f\circ g_1=f\circ g_2$ where
$$g_1:\mathbb{Z}[x]\to\mathbb{Z}\text{ sends }x\mapsto 1,\qquad g_2:\mathbb{Z}[x]\to\mathbb{Z}\text{ sends }x\mapsto 3$$
while $g_1\neq g_2$.
A: The terms "left inverse" and "right inverse" confuse me a lot. If $fg = 1$, then $f$ is split epi and I call it a retract of $g$, while $g$ is split mono and I call it a section of $f$. Since $(gf)^2 = gf$, I call the pair $(f,g)$ a split idempotent. The geometric terminology is the only way I can keep things straight.
As I pointed out in a comment, it's hard to tell what you're trying to show. If you're really trying to show "$f$ has at most one section implies $f$ is mono" then any function $f$ which is neither injective nor surjective is a counterexample in $\mathsf{Set}$.
If you're really trying to show "$f$ has exactly one section implies $f$ is mono", then you should note that if $f$ is split epi and mono, then $f$ is iso (this is a standard exercise) so it's equivalent to prove "$f$ has exactly one section implies $f$ is iso". Anyway, this is also false. One counterexample would be the category freely generated by a split idempotent (this is a category with two objects $B,C$, and three nonidentity morphisms $f: B \to C$, $g: C \to B$, $gf: B \to B$ subject to $fg = 1$). For a counterexample in $\mathsf{Top}$, let $B = \mathbb{R} \sqcup \{0\}$ be the disjoint union of a point and a line, let $C = \mathbb{R}$, and let $f: B \to C$ be the identity on $\mathbb{R}$ and send the point to the origin of the line, say. This map is not iso (or mono!), but it has exactly one section.
Actually, this is is an interesting question: fix an object $X$ in a category $\mathcal{C}$. When is it the case that any split epimorphism $Y \to X$ which is not an isomorphism has multiple sections?


*

*We've seen that it's false when $X = \mathbb{R}$ in $\mathsf{Top}$. The same example should work in any reasonable geometric category. This follows from the fact that $X$ is a connected object, the existence of a morphism into $X$ which is not split epi, and the existence of binary coproducts.

*The OP's argument shows that it's true in $\mathsf{Set}$: if a surjection is not a bijection, then we have a choice of which fiber to choose for a section over at least one point. I wonder if this continues to hold in the absence of the axiom of choice?

*It's false if $X$ is a zero object: every map $Y \to 0$ has a unique section.

*In an additive category, any split epi is a projection $\pi: X \oplus Z \to X$. Sections are of the form $x \mapsto (x, \lambda(x))$, so they are in bijection with morphisms $X \to Z$. So the property holds for $X$ unless there exists a nonzero $Z$ such that the only morphism $X \to Z$ is the zero morphism. So for instance,


*

*It's true (except when $X =0$) in the $\mathsf{Vect}$, the category of vector spaces over your favorite field $k$. More generally, it's true whenever $X$ is a free $R$-module in $R-\mathrm{Mod}$.

*It's false when $X$ is a torsion abelian group in $\mathsf{Ab}$ because there are no nonzero morphisms from $X$ to any torsion-free group.

*It's false in the category of representations of a finite group unless $X$ contains every irrep as a summand.
