dotnet/runtime · error · RuntimeError

Final mch file failed to be generated.

Error message

Final mch file failed to be generated.

What it means

Raised in `__create_clean_mch_file__` (superpmi.py:1419-1420), taken when `--clean` is set. After running `superpmi -p` to find failing contexts and either `mcs -strip` or a `shutil.copy2` of base to final, it verifies final_mch_file exists; absence means the clean/strip step did not produce the final MCH. This is the 'clean' branch counterpart of the copy branch.

Source

Thrown at src/coreclr/scripts/superpmi.py:1420

            else
                # copy/move base file to final file
            del <s_baseFailMclFile>
        """

        logging.info("Cleaning MCH file")

        command = [self.superpmi_path, "-p", "-f", self.base_fail_mcl_file, self.base_mch_file, self.jit_path]
        run_and_log(command)

        if is_nonzero_length_file(self.base_fail_mcl_file):
            command = [self.mcs_path, "-strip", self.base_fail_mcl_file, self.base_mch_file, self.final_mch_file]
            run_and_log(command)
        else:
            # Ideally we could just rename this file instead of copying it.
            shutil.copy2(self.base_mch_file, self.final_mch_file)

        if not os.path.isfile(self.final_mch_file):
            raise RuntimeError("Final mch file failed to be generated.")

        if not self.coreclr_args.skip_cleanup:
            if os.path.isfile(self.base_fail_mcl_file):
                os.remove(self.base_fail_mcl_file)
                self.base_fail_mcl_file = None
            if os.path.isfile(self.base_mch_file):
                os.remove(self.base_mch_file)
                self.base_mch_file = None

    def __copy_to_final_mch_file__(self):
        """ When not cleaning the MCH file, copy the base MCH file to the final MCH file location.

        Notes:
            # copy/move base file to final file
            del <s_baseFailMclFile>
        """

        logging.info("Copy base MCH file to final MCH file")

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Confirm the merge step (error 164) succeeded and base_mch_file exists before the clean step runs.
  2. Inspect the `superpmi -p` and `mcs -strip` command output logged just before this error.
  3. Re-run without `--clean` first to isolate whether the failure is in strip vs. plain copy.
Defensive patterns

Strategy: try-catch

Validate before calling

# Verify base_mch_file exists before the clean step runs
if not os.path.isfile(base_mch_file):
    raise SystemExit('base MCH missing; merge step must succeed before --clean.')

Try / catch

try:
    collection.__create_clean_mch_file__()
except RuntimeError as e:
    if 'Final mch file failed' in str(e):
        logging.error('clean/strip did not produce final MCH; check superpmi -p / mcs -strip output.')
    raise

Prevention

When it happens

Trigger: Running collection with `--clean` where the strip (mcs -strip) or the base-to-final copy failed. Typical when base_mch_file itself is missing (merge failed earlier) or the strip command errored on the failing-context list.

Common situations: A prior merge step (error 164) silently left no base MCH, so the clean step has nothing to strip/copy; the base_fail_mcl_file path is invalid; disk/permission problems during copy2.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/b24642666e7dd750. Report an issue: GitHub.