I have the following stochastic optimal control problem, where
$$dx = u(t)dt + \sqrt{2\nu}dW(t)$$
and $x(t_0) = x_0$ and where $W(t)$ is the Wiener process/Brownian motion, and the cost function is,
$$J(x_0,t_0,u) = \mathbb{E}\left[\int_{t_0}^T \frac{1}{2}\|u(\tau)\|^2 + \frac{1}{2}\|x(\tau)\|^2\, d\tau + g(x(T)) \right]$$
with $g(x) = \frac{1}{2}\|x\|^2$. The value function is,
$$\phi(x,t) = \inf_u J(x,t,u)$$
and we have that $\phi$ solves the HJB equation,
$$ -\partial_t \phi - \nu \Delta \phi + \frac{1}{2} \|\nabla_x \phi\|^2 - \frac{1}{2}\|x\|^2 = 0$$
A solution to the above HJB equation is $\phi(x,t) = \frac{1}{2}\|x\|^2 + \nu(T-t)$. From this, the optimal control should then be $u(t) = -\nabla_x \phi$, so we should have,
$$ x(t) = x(t_0)e^{-(t-t_0)} + \sqrt{2\nu} W(t - t_0)$$
But if I insert the $u(t)$ and the $x(t)$ into the cost function $J(x_0, t_0, u)$, I do NOT get $\phi(x,t) = \frac{1}{2} \|x\|^2 + \nu(T-t)$. Rather, I get $\phi(x,t) = \frac{1}{2}\|x\|^2 + \frac{\nu}{2}(T-t)^2 + \nu(T-t)$, but this doesn't solve the HJB equation.
What am I doing wrong? Thank you in advance.
Edit: The above is when $x$ is 1 dimension. If $x$ is of dimension $d$ then all that needs to be changed is in $\phi(x,t)$, where instead of $\nu$ we should change to $\nu d$.
Edit2, What I did: For simplicity, assume $t_0=0$, and let $X(0)=x_0$. In 1 dimension, if $dX_t = -X_tdt + \sqrt{2\nu}dW_t$ then the solution for $X_t$ should be,
$$ X(t) = x_0 e^{-t} + \sqrt{2\nu} W_{t}$$
is that right? Then using that $u(t) = -x_0e^{-t}$, if I plug this into $J(x_0, t_0, u)$, I get:
\begin{align} J(x_0, 0, u) &= \mathbb{E} \left[ \int_{0}^T \frac{1}{2} x_0^2e^{-2t} + \frac{1}{2}\left(x_0 e^{-t} + \sqrt{2\nu} W_t \right)^2 \, dt + \frac{1}{2}\left(x_0 e^{-T} + \sqrt{2\nu} W_T \right)^2 \right] \\ &= \mathbb{E} \left[ \int_{0}^T x_0^2 e^{-2t} + x_0e^{-t}\sqrt{2\nu}W_t + \nu W_t^2\,dt \right] \\ &\qquad +\mathbb{E}\left[\frac{1}{2}x_0^2 e^{-2T} + x_0 e^{-T}\sqrt{2\nu}W_T + \nu W_T^2 \right] \\ &= \int_0^T x_0^2 e^{-2t} + x_0 e^{-t} \sqrt{2\nu}\mathbb{E}[W_t] + \nu \mathbb{E}[W_t^2]\,dt \\ &\qquad + \frac{1}{2}x_0^2 e^{-2T} + x_0 e^{-T}\sqrt{2\nu}\mathbb{E}[W_T] + \nu \mathbb{E}[W_T^2] \end{align}
At this point since $\mathbb{E}[W_t] = 0$ and $\mathbb{E}[W_t^2] = t$ for all $t$, then,
\begin{align} J(x_0, 0, u) &= -\frac{1}{2}x_0^2 e^{-2T} + \frac{1}{2}x_0^2 + \frac{\nu}{2}T^2 + \frac{1}{2}x_0^2 e^{-2T} + vT \\ &= \frac{1}{2}x_0^2 + \frac{\nu}{2}T^2 + \nu T \end{align}
So I get an extra $\frac{\nu}{2}T^2$ term. Where did I go wrong?
Well I found the error in my calculation. Basically, I got the solution of the SDE incorrect. If
$$ dX_t = -X_tdt + \sqrt{2\nu}dW_t$$
then the solution is
$$X(t) = X(0)e^{-t} + \sqrt{2\nu} \int_0^t e^{s-t}\,dW(s).$$
In my original question, I got the solution of the SDE wrong.