I have already solved this issue. The KSP automatically deleting code is due to a bug in KSP's incremental compilation, not a problem with my configuration. Disabling KSP's incremental compilation will resolve the problem.