How to create a sine wave that transitions through frequencies and returns to phase
For the first continuous $f_0=300\mbox{Hz}$ signal, after $2N$ samples (for a duration of $2N/f_s$ at a sampling rate $f_s$) the phase will have changed by:
$$
\begin{align}
 \Delta \phi_1
   &amp;= 2\pi \frac{f_0}{f_s} (2N-1)
\end{align}
$$

On the other hand, as the second signal ramps up linearly (in small quantized steps as per your phasor implementation) from $f_0=300\mbox{Hz}$ to $f_1=305\mbox{Hz}$ then down from 305Hz to 300Hz over the same $2N$ samples, the phase will have changed by:
$$
\begin{align}
 \Delta \phi_2
   &amp;= \sum_{n=1}^{N} 2\pi \left(\frac{f_0}{f_s} + \left(\frac{f_1}{f_s}-\frac{f_0}{f_s}\right)\frac{n}{N}\right)
      + \sum_{n=1}^{N-1} 2\pi \left(\frac{f_1}{f_s} + \left(\frac{f_0}{f_s}-\frac{f_1}{f_s}\right)\frac{n}{N}\right) \\
%   &amp;= 2\pi \frac{f_1}{f_s} 
%      + 2\pi \sum_{n=1}^{N-1} \left(\frac{f_0}{f_s} + \left(\frac{f_1}{f_s}-\frac{f_0}{f_s}\right)\frac{n}{N} + \frac{f_1}{f_s} + \left(\frac{f_0}{f_s}-\frac{f_1}{f_s}\right)\frac{n}{N}\right) \\
%   &amp;= 2\pi \frac{f_1}{f_s} 
%      + 2\pi \sum_{n=1}^{N-1} \left(\frac{f_0}{f_s} + \frac{f_1}{f_s}\right) \\
   &amp;= 2\pi \frac{f_1}{f_s} + 2\pi \left(\frac{f_0}{f_s}+\frac{f_1}{f_s}\right) \left(N - 1\right)
\end{align}
$$

For those two signals to be in phase after $2N$ samples, their phase difference must be a multiple of $2\pi$. Thus the constraint is that
$$
\begin{align}
  \Delta \phi_2 
    &amp;= \Delta \phi_1 + 2\pi k \\
  2\pi \frac{f_1}{f_s} + 2\pi \left(\frac{f_0}{f_s}+\frac{f_1}{f_s}\right) \left(N - 1\right)
    &amp;= 2\pi \frac{f_0}{f_s} \left(2N-1\right) + 2\pi k
\end{align}
$$
for some arbitrary integer $k$, or equivalently:
$$
\begin{align}
  N &amp;= k \frac{f_s}{f_1-f_0} 
\end{align}
$$
Which, provided that $kf_s/(f_1-f_0)$ is an integer greater than 0, yields a signal duration of
\begin{align}
  \frac{2k}{f_1-f_0}
\end{align}

In your specific case for a frequency excursion of $5\mbox{Hz}$, the signals will return in phase for modulation durations of 0.4, 0.8, 1.2, ... seconds.

Note that if you need to sustain the signal for some $M$ samples at $f_1$ (instead of immediately going back down after the rise), then the constraint becomes:
$$
\begin{align}
  N+M &amp;= k \frac{f_s}{f_1-f_0} 
\end{align}
$$
In other words the duration of the rise and plateau together would, in your case, need to be a multiple of 0.2 seconds. So for example if you want to have a plateau of 1 second at 305Hz, you might choose a rise + plateau of 1.2 seconds, giving 0.2 seconds for the ramp up and another 0.2 seconds for the ramp down (for a total signal duration of 1.4 seconds)