4. In the sequence $\left\{a_{n}\right\}$, it is known that $a_{1}=1, a_{n+1}>a_{n}$, and $a_{n+1}^{2}+a_{n}^{2}+1=2\left(a_{n+1} a_{n}+a_{n+1}+a_{n}\right)$. Then $\lim _{n \rightarrow \infty} \frac{S_{n}}{n a_{n}}=$ $\qquad$ .
4. $\frac{1}{3}$.

From the given, we have
$$
\begin{array}{l}
1+a_{n+1}^{2}+a_{n}^{2}+2 a_{n+1} a_{n}-2 a_{n+1}-2 a_{n} \\
=4 a_{n+1} a_{n},
\end{array}
$$

which simplifies to
$$
\begin{array}{l}
\left(a_{n+1}+a_{n}-1\right)^{2}=4 a_{n} a_{n+1} . \\
\because a_{1}=1, a_{n+1}>a_{n}, \\
\therefore a_{n+1}+a_{n}-1>0 .
\end{array}
$$

Thus, $a_{n+1}+a_{n}-1=2 \sqrt{a_{n} a_{n+1}}$
or $\left(\sqrt{a_{n+1}}-\sqrt{a_{n}}\right)^{2}=1$,
which means $\sqrt{a_{n+1}}-\sqrt{a_{n}}=1$.
Given $a_{1}=1$, the general term of the arithmetic sequence $\left\{\sqrt{a_{n}}\right\}$ is $\sqrt{a_{n}}=n$. Therefore, $a_{n}=n^{2}$. Consequently,
$$
S_{n}=1^{2}+2^{2}+\cdots+n^{2}=\frac{1}{6} n(n+1)(2 n+1) \text {. }
$$

Hence, $\lim _{n \rightarrow \infty} \frac{S_{n}}{n a_{n}}=\lim _{n \rightarrow \infty} \frac{2 n^{2}+3 n+1}{6 n^{2}}=\frac{1}{3}$.