The G4Cerenkov and G4Scintillation processes have methods GetNumPhotons() that return the number of optical photons created in a step. When crossing from a material in which optical photons are produced to a material in which they are not, this value is not reset to 0. It appears that for G4Scintillation, setting fNumPhotons to 0 at the beginning of PostStepDoIt() solves the problem. It's not yet clear to me what happens with G4Cerenkov.
Fixed.