A hidden Markov model (HMM) solved recursively by the Viterbi algorithm can be configured to search for persistent, quasimonochromatic gravitational radiation from an isolated or accreting neutron star, whose rotational frequency is unknown and wanders stochastically. Here an existing HMM analysis pipeline is generalized to track rotational phase and frequency simultaneously, by modeling the intra-step rotational evolution according to a phase-wrapped Ornstein-Uhlenbeck process, and by calculating the emission probability using a phase-sensitive version of the Bayesian matched filter known as the $mathcal{B}$-statistic. The generalized algorithm tracks signals from isolated and binary sources with characteristic wave strain $h_0 geq 1.3times 10^{-26}$ in Gaussian noise with amplitude spectral density $4times 10^{-24},{rm Hz^{-1/2}}$, for a simulated observation composed of $N_T=37$ data segments, each $T_{rm drift}=10,{rm days}$ long, the typical duration of a search for the low-mass X-ray binary (LMXB) Sco X$-$1 with the Laser Interferometer Gravitational Wave Observatory (LIGO). It is equally sensitive to isolated and binary sources and $approx 1.5$ times more sensitive than the previous pipeline. Receiver operating characteristic curves and errors in the recovered parameters are presented for a range of practical $h_0$ and $N_T$ values. The generalized algorithm successfully detects every available synthetic signal in Stage I of the Sco X$-$1 Mock Data Challenge convened by the LIGO Scientific Collaboration, recovering the frequency and orbital semimajor axis with accuracies of better than $9.5times 10^{-7},{rm Hz}$ and $1.6times 10^{-3},{rm lt,s}$ respectively. The Viterbi solver runs in $approx 2times 10^3$ CPU-hr for an isolated source and $sim 10^5$ CPU-hr for a LMXB source in a typical, broadband ($0.5$-${rm kHz}$) search.