4. Given the sequence $\left\{a_{n}\right\}$, where $a_{1}=1, a_{2}=2, a_{n} a_{n+1} a_{n+2}=a_{n}+a_{n+1}+a_{n+2}$, and $a_{n+1} a_{n+2} \neq 1$, then $S_{1999}=\sum_{n=1}^{1999} a_{n}=$ $\qquad$.
4. 3997 Given $a_{n+2}=\frac{a_{n}+a_{n+1}}{a_{n} a_{n+1}-1}$ and $a_{1}=1, a_{2}=2$, we have
$$
\begin{array}{l}
a_{3}=\frac{a_{1}+a_{2}}{a_{1} a_{2}-1}=3, \\
a_{4}=\frac{a_{2}+a_{3}}{a_{2} a_{3}-1}=1, \\
a_{5}=\frac{a_{3}+a_{4}}{a_{3} a_{4}-1}=2, \\
a_{5}=\frac{a_{4}+a_{5}}{a_{4} a_{5}-1}=3 .
\end{array}
$$

Since $a_{n} a_{n+1} a_{n+2}=a_{n}+a_{n+1}+a_{n+2}$,
$$
a_{n+1} a_{n+2} a_{n+3}=a_{n+1}+a_{n+2}+a_{n+3} \text {. }
$$
Subtracting (1) from (2), we get

That is,
$$
\begin{array}{c}
a_{n+3}-a_{n}=a_{n+1} a_{n+2}\left(a_{n+3}-a_{n}\right), \\
\left(a_{n+3}-a_{n}\right)\left(a_{n+1} a_{n+2}-1\right)=0 . \\
a_{n+1} a_{n+2} \neq 1,
\end{array}
$$

Since
Therefore, $a_{n+3}=a_{n}$, which means $\left\{a_{n}\right\}$ is a periodic sequence with a period of 3.
Since
Also,
$$
\begin{array}{c}
a_{1}+a_{2}+a_{3}=6, \\
1999=3 \times 666+1, \\
1999=1(\bmod 3) .
\end{array}
$$

Therefore,
Thus, $S_{1999}=\sum_{n=1}^{1999} a_{n}=6 \times 666+1=3997$.