4. Let $x \in\left(-\frac{1}{2}, 0\right)$, among the following three numbers: $a_{1}=\cos (\sin x \pi), a_{2}=\sin (\cos x \pi), a_{3}=\cos (x+1) \pi$, the size relationship is
A. $a_{3}<a_{2}<a_{1}$
B. $a_{1}<a_{3}<a_{2}$
C. $a_{3}<a_{1}<a_{2}$
D. $a_{2}<a_{3}<a_{1}$
$$
\begin{array}{l}
x \in\left(-\frac{1}{2}, 0\right) \Rightarrow (x+1) \pi \in\left(\frac{\pi}{2}, \pi\right) \Rightarrow a_{3}=\cos (x+1) \pi < 0, \sin x \pi < 0, \cos x \pi + \sin x \pi = \sqrt{2} \sin \left(x \pi + \frac{\pi}{4}\right) \leqslant \sqrt{2} < \frac{\pi}{2} \\
\Rightarrow a_{2}=\sin (\cos x \pi) = \cos \left(\frac{\pi}{2} - \cos x \pi\right) < \cos (\sin x \pi) = a_{1} .
\end{array}
$$

Thus $a_{3} < a_{2} < a_{1}$, so the answer is $A$.