Epitaxial Fe3O4 thin films grown on single crystal MgO(001) present well-defined model systems to study fundamental multivalent ion diffusion and associated phase transition processes in transition-metal-oxide-based cathodes. In this work, we show at an atomic scale the Mg2+ diffusion pathways, kinetics, and reaction products at the Fe3O4/MgO heterostructures under different oxygen partial pressures but with the same thermal annealing conditions. Combining microscopic, optical, and spectroscopic techniques, we demonstrate that an oxygen-rich environment promotes facile Mg2+ incorporation into the Fe2+ sites, leading to the formation of Mg1-xFe2+xO4 spinel structures, where the corresponding portion of the Fe2+ ions are oxidized to Fe3+. Conversely, annealing in vacuum results in the formation of a thin interfacial rocksalt layer (Mg1-yFeyO), which serves as a blocking layer leading to significantly reduced Mg2+ diffusion to the bulk Fe3O4. The observed changes in transport and optical properties as a result of Mg diffusion are interpreted in light of the electronic structures determined by X-ray photoelectron spectroscopy and X-ray absorption spectroscopy. Our results reveal the critical role of available anions in governing cation diffusion in the spinel structures and the need to prevent formation of unwanted reaction intermediates for the promotion of facile cation diffusion.