If a morphism admits a unique one-sided inverse is it invertible? Sorry, for another question about basic category theory. This should be a standard result or at least folklore but I can't find it written down anywhere and I can't seem to prove it myself.
Let $f:X\to Y$ be a morphism in a category $C$. Suppose $f$ admits a section $s:Y\to X$ ie. $s\circ f =\operatorname{id}_{Y}.$ Moreover suppose that this section is unique. Is it true that $f$ is invertible?
This is certainly true if we are working in $Set$ or $Vect$, and I strongly suspect it is true in general. The trouble I'm having is that I don't know of any universal property that characterises isomorphisms (probably because isomorphism is itself not unique).
 A: You have the definition of a section the wrong way around. If $r \circ s = Id_Y$ for $r: X \to Y$ and $s: Y \to X$, then we call $s$ a section and $r$ a retraction. I will stick to this notation for this answer.
In the comments Captain Lama already mentions a counterexample for the case of vector spaces. Namely if $Y = 0$, then both $r$ and $s$ are the (unique) trivial function. Obviously, if we pick $X$ a non-trivial vector space, then $r$ and $s$ cannot be invertible (on the other side). This trick easily generalises to many 'nice' categories, e.g. groups and monoids.
In the case of the category of sets this is indeed true. Let $r: X \to Y$ such that there is unique $s: Y \to X$ with $rs = Id_Y$. I claim that $sr = Id_X$. Let $x \in X$, and set $x' = sr(x)$. Then $r(x) = rsr(x) = r(x')$. Define $s': Y \to X$ as follows
$$
s'(y) = \begin{cases}
x & \text{if $y = r(x)$} \\
s(y) & \text{else}
\end{cases}
$$
Then $rs' = Id_Y$, so by uniqueness of $s$ we must have $s = s'$. Hence $x' = sr(x) = s'r(x) = x$, as required.
