Q: When is $V=U\oplus U^{\perp}$? Let $V$ be a (infinite dimensional) vector space with inner product $(,)$ and $V$ may not be complete with the metric induced from the norm. Let $U$ be a subspace of $V$. What is the necessary and sufficient condition that can guarantee
$$
U\oplus U^{\perp}=V?
$$
Is the hypothesis $U$ has finite codimension enough?
Update:
As others pointed out, $U$ is closed or $U$ has finite codimension is not enough. I `know' that the following condition is enough: If there exist a finite dimensional subspace $W\subseteq V$ such that $W^{\perp}\subseteq U$, then $V=U\oplus U^{\perp}$. But neither can I prove it, nor do I know a better condition to replace it or show the criterion is wrong. So I ask at here. 

A: Construction
Here's a recipe to construct "bad" incomplete spaces:


*

*Start with a Hilbert space $\dim\mathcal{H}=\infty$.

*Choose a normalized vector $e_0$.

*Extend it to an ONB $\mathcal{E}\owns e_0$.

*Fix the independent vector $b_0:=e_0+\sum_{k=1}^\infty\frac{1}{k}e_k$.

*Extend this to a Hamel basis $\mathcal{B}\supseteq\mathcal{E}$ with $\mathcal{B}\owns e_0,b_0$.

*Rip it off to get an orthonormal system $\mathcal{S}:=\mathcal{E}\setminus\{e_0\}$.

*Rip it off to get a linear independent system $\mathcal{L}:=\mathcal{B}\setminus\{e_0\}$.

*Span your incomplete space $X:=\langle\mathcal{L}\rangle$.


Then the orthonormal system is maximal $\mathcal{S}^\perp=(0)$ but not an ONB $\overline{\langle\mathcal{S}\rangle}\neq X$.
Example
For your query then you can split $\mathcal{S}=\mathcal{S}_1\sqcup\mathcal{S}_2$ to get subspaces $U_1:=\overline{\langle\mathcal{S}_1\rangle}$ and $U_2:=\overline{\langle\mathcal{S}_1\rangle}$. These are orthogonal complements to each other but don't reduce the space $X\neq U_1\oplus U_2$.
Moreover you see that any combination of dimension and codimension can appear to be bad in an incomplete space.

A: I'm adding another answer, now that you've changed the question.
Assume that $W$ is finite-dimensional with $W^{\perp} \subseteq U$. The goal is to show that $U\oplus U^{\perp} = V$. All '$\oplus$' decompositions are orthogonal in what follows.
Because $W$ is finite-dimensional then $V=W\oplus W^{\perp}$ which can be seen by choosing any basis of $W$ and using Gram-Schmidt to find an orthonormal basis $\{ e_{1},\cdots,e_{n}\}$ of $W$. Then every $v\in V$ can be written as
$$
            v = \left(v-\sum_{j=1}^{n}(v,e_{j})e_{j}\right)+\sum_{j=1}^{n}(v,e_{j})e_{j}.
$$
So $W^{\perp}\oplus W=V$. Assuming that $W^{\perp}\subseteq U$, it follows that every $u \in U$ can be written as $u=w_{\perp}+w$ where $w_{\perp}\in W^{\perp}$ and $w\in W$. Because $w_{\perp} \in W^{\perp}\subseteq U$, then $u-w_{\perp}=w \in U$, which gives the decomposition
$$
                    U = W^{\perp}\oplus(U\cap W).
$$
Because $U\cap W$ is a finite-dimensional subspace of $W$, then it follows that there exists a finite-dimensional subspace $U'$ such that $(U\cap W)\oplus U'=W$; $U'$ is found by completing an orthonormal basis of $U\cap W$ to one for $W$. Therefore $(U\cap W)\oplus U'=W$. Finally,
$$
\begin{align}
       U\oplus U' & = (W^{\perp}\oplus (U\cap W))\oplus U' \\
                  & = W^{\perp}\oplus((U\cap W)\oplus U') \\
                  & = W^{\perp}\oplus W = V.
\end{align}
$$
This is enough to give $U'=U^{\perp}$ and $U\oplus U^{\perp}=V$.

A: The hypothesis that $U$ has finite co-dimension is not enough. The hypothesis that $U$ is closed is not enough. I'll give you an example where both hold and it's still not true that $V=U\oplus U^{\perp}$.
Let $V$ the be the linear space  generated by finite linear combinations of standard basis elements $\{ e_{j}\}_{j=1}^{\infty}$ of $l^{2}$. Define a linear functional $\Phi$ on $V$ by 
$$\Phi(x)=\sum_{j=1}^{\infty}\frac{1}{j}(x,e_{j}).$$
$\Phi$ is a bounded linear function on $V$ and, therefore, $U=\mathcal{N}(\Phi)$ is closed in $V$; and $U$ is of co-dimension $1$ in $V$ because $\Phi$ is not the $0$ functional on $V$. Therefore $V \ne U$. However, $U^{\perp}=\{ x \in V : (x,u)=0 \mbox{ for all } u \in U\}=\{0\}$ which means that $V \ne U = U\oplus U^{\perp}$.
