Let $W$ be a Brownian motion and $z,\kappa>0$. Let $X_t(z)$ be a solution to the SDE
$$dX_t(z)=dW_t+2/(\kappa X_t(z))dt.\quad X_0(z)=z.$$
The solution is well-defined on $t<\tau(z)$ where $\tau(z)$ is a stopping time . Moreover, $X_t(z)\rightarrow 0$ for $t\uparrow\tau$. Hence $X_t(z):=0$ for $t\geq \tau$ makes $X(z)$ a continuous semimartingale. Consider now $y>x>0$. Then $P(\tau(x)\leq\tau(y))=1$, and almost surely $X_t(x)<X_t(y)$ for all $t<\tau$. Define also
$$\vartheta_t=\frac{X_t(y)-X_t(x)}{X_t(y)}.$$
The notes that i am reading applies Itos formula with $f(x,y)=\frac{x-y}{y}$ to conclude that
$$\vartheta_t-\vartheta_0=\int_0^t (\frac{\vartheta_s}{X_s(y)})^2(-\frac{2/k}{1-\vartheta_s}+\frac{1-1/\kappa}{\vartheta_s})ds-\int_0^t \frac{\vartheta_s}{X_s(y)}dW_s,\quad t<\tau.$$
My question is how Itos formula can be applied, since $f$ is not $C_2$ on the line $y=0$. Moreover, is the process a semimartingale?
I can't see how this is done. I have tried approximating by using stopping times for when $X_t(x)$ hits small r, but then i don't know how to remove them for the integral again.
While it is true that you can't directly apply Ito's formula as it is stated in most textbooks, it is nonetheless true that Ito's Formula is valid in this case when $t<\tau$. Indeed we will prove a more general fact.
Suppose $U \subset \Bbb R^d$ is an open set, and $f: U \to \Bbb R$ is a $C^2$ function. Suppose $X=(X^1,...,X^d)$ is a continuous semimartingale with $X_0\in U$ a.s., and let $\tau_U$ denote the first exit time of $X$ from $U$.
Claim: Ito's formula for $f(X_t)$ holds whenever $t< \tau_U$.
Proof: For $n \in \Bbb N$, let $\tau_U^{(n)}$ denote the first time $t$ such that $dist(X_t, U^c)<\frac{1}{n}$. Then the stopped process $X^{\tau^{(n)}_U}$ is a semimartingale taking values in $U$ for all time, hence Ito's formula for $f(X^{\tau_U^{(n)}})$ is valid in the usual sense of the theorem (that you cited in your comment). This implies that for all $n$ the events $E_n:=\{ $Ito's formula for $f(X_t)$ holds when $t<\tau^{(n)}_U\}$ have probability $1$, therefore so does their intersection $E$. But $\tau^{(n)}_U \uparrow \tau_U$ as $n \to \infty$, so it follows that $E$ is the event that Ito's formula for $f(X_t)$ holds when $t<\tau_U$. $\Box$
Note that Ito's formula itself is a justification that $f(X)$ has a semimartingale decomposition, but which is valid only for times $t<\tau_U$ in this case.