  Quantum Error Correction (QEC) codes are vital for protecting quantum
computers from noise by encoding quantum information redundantly in physical
qubits. However, dynamic defects pose a significant challenge, potentially
rendering physical qubits faulty during computation across various quantum
platforms. Current defect mitigation strategies focus on surface codes, but
often fail to fully restore QEC capability or disrupt logical operations. In
our paper, we introduce FlexiSCD, a code deformation framework that integrates
adaptive defect mitigation into surface code workflows. It strategically crafts
basic deformation instructions based on gauge transformations, enabling
optimized processes tailored to specific defects, restoring QEC capability
efficiently with fewer qubit resources. We also design an adaptive code layout
for efficient logical operations. Our evaluation demonstrates that FlexiSCD
reduces failure rates by $35\times\sim70\times$ and requires only half the
qubit resources compared to previous methods. It surpasses previous defect
removal techniques, preserving QEC capability and improving surface code
communication.
