Elena Rybakina stunned Iga Swiatek to confirm her place in the knockout stages of the WTA Finals, while Amanda Anisimova produced a comeback victory to stay in contention in Riyadh.