  We investigate the collective spin dynamics of a self-rephasing bosonic
ensemble of $^{87}$Rb trapped in a 1D vertical optical lattice. We show that
the combination of the frequency shifts induced by atomic interactions and
inhomogeneous dephasing, together with the spin self-rephasing mechanism leads
to the existence of a `magic density': \textit{i.e} a singular operating point
where the clock transition is first-order insensitive to density fluctuations.
This feature is very appealing for improving the stability of quantum sensors
based on trapped pseudo-spin-1/2 ensembles. Ramsey spectroscopy of the
$|F=1,m_{F}=0\rangle\rightarrow|F=2,m_{F}=0\rangle$ hyperfine transition is in
qualitative agreement with a numerical model based on coupled Bloch equations
of motion for energy dependent spin vectors.
