When does the Cas9 nuclease stop?
Regarding the loss of Cas9 activity, you are already touching on the answer in your question. Cas9 as a nuclease/enzyme is always active, and will continue to cleave double-stranded DNA as long as there are complementary target sites and guide RNAs to guide it there. If the target site is not mutated or completely removed after cleavage, Cas9 can indeed cleave the same site again.

However, even if the target gene is mutated, there is likely to remain complementary sequence to the guide RNA, at least upstream of the mutation.

I'm not sure if I misunderstand the point you are trying to make here, but the introduction of mutations is usually enough to prevent recurrent cleavage of the same site (although studies of off-target effects clearly show that this is not always the case):
Both Streptococcus pyogenes and Staphylococcus aureus Cas9 cleave their target sites between positions -3 and -4, counting from the end of the 20-nt guide sequence (see attached figure below). The double-stranded break can then be repaired either via non-homologous end joining (NHEJ), or via template-driven homologous recombination (HR).

In the former case (NHEJ), double-stranded breaks are sometimes repaired with small errors. These errors usually accumulate near the break site (read about NHEJ to understand why), and such mutations will typically destroy the gRNA recognition site. Note, however, that not all (in fact, very few) NHEJ repair events will result in the introduction of mutations, and &quot;perfectly repaired&quot; breaks both can and will be re-cleaved by Cas9. But since repeated cleavage is lethal to the cell, there is a selective advantage for mutations that prevent re-cleavage of a target site. Also note that the introduction of mutations (and thereby gene editing) via NHEJ is a random process, with no direct control by the researcher.
In the latter case (HR), the DNA template used for repairing the double-stranded break can typically be chosen by the researcher. It can for example be a chemically synthesized DNA fragment or PCR product with at least some sequence homology to regions flanking the cleavage site. But since there is no specific sequence requirement for the region in between the homology regions, this interspacing region can be designed such that it partly or completely replaces the original recognition and/or PAM sequence (violet region in figure below).