Quantum state protection using all-optical feedback