{"record":{"id":"accc138764b51a50","repo":"Unity-Technologies/ml-agents","slug":"previous-data-from-this-run-id-was-found-either-s","errorCode":null,"errorMessage":"Previous data from this run ID was found. Either specify a new run ID, use --resume to resume this run, or use the --force parameter to overwrite existing data.","messagePattern":"Previous data from this run ID was found\\. Either specify a new run ID, use --resume to resume this run, or use the --force parameter to overwrite existing data\\.","errorType":"exception","errorClass":"UnityTrainerException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/directory_utils.py","lineNumber":26,"sourceCode":"def validate_existing_directories(\n    output_path: str, resume: bool, force: bool, init_path: Optional[str] = None\n) -> None:\n    \"\"\"\n    Validates that if the run_id model exists, we do not overwrite it unless --force is specified.\n    Throws an exception if resume isn't specified and run_id exists. Throws an exception\n    if --resume is specified and run-id was not found.\n    :param model_path: The model path specified.\n    :param summary_path: The summary path to be used.\n    :param resume: Whether or not the --resume flag was passed.\n    :param force: Whether or not the --force flag was passed.\n    :param init_path: Path to run-id dir to initialize from\n    \"\"\"\n\n    output_path_exists = os.path.isdir(output_path)\n\n    if output_path_exists:\n        if not resume and not force:\n            raise UnityTrainerException(\n                \"Previous data from this run ID was found. \"\n                \"Either specify a new run ID, use --resume to resume this run, \"\n                \"or use the --force parameter to overwrite existing data.\"\n            )\n    else:\n        if resume:\n            raise UnityTrainerException(\n                \"Previous data from this run ID was not found. \"\n                \"Train a new run by removing the --resume flag.\"\n            )\n\n    # Verify init path if specified.\n    if init_path is not None:\n        if not os.path.isdir(init_path):\n            raise UnityTrainerException(\n                \"Could not initialize from {}. \"\n                \"Make sure models have already been saved with that run ID.\".format(\n                    init_path","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/directory_utils.py#L8-L44","documentation":"validate_existing_directories checks whether the run's output directory already exists. If it does and neither --resume nor --force was passed, ML-Agents raises UnityTrainerException to prevent silently overwriting previous training artifacts (models, summaries, checkpoints) for the same run ID.","triggerScenarios":"Running mlagents-learn with a run_id whose results/<run_id> directory already exists, without --resume or --force — e.g. re-running the same command after a previous training session.","commonSituations":"Re-running an interrupted training without deciding whether to resume or start fresh; two team members using the default run_id; automated scripts re-invoking training with a fixed run_id.","solutions":["Pass --resume to continue the existing run, or --force to delete/overwrite previous data.","Choose a new --run-id to start a fresh training run in a new directory.","Manually move or delete the existing results/<run_id> directory if the old data is no longer needed."],"exampleFix":"// before\nmlagents-learn config.yaml --run-id=ppo1\n// after (overwrite previous data)\nmlagents-learn config.yaml --run-id=ppo1 --force","handlingStrategy":"validation","validationCode":"import os\nrun_id, results_dir = \"ppo1\", \"results\"\nexists = os.path.isdir(os.path.join(results_dir, run_id))\nif exists and not (resume or force):\n    # decide: resume, force, or new run-id before launching\n    pass","typeGuard":"def launch_is_safe(run_id: str, results_dir: str, resume: bool, force: bool) -> bool:\n    import os\n    return (not os.path.isdir(os.path.join(results_dir, run_id))) or resume or force","tryCatchPattern":"try:\n    validate_existing_directories(model_path, summary_path, run_id, resume, force, init_path)\nexcept UnityTrainerException as e:\n    if \"Previous data from this run ID was found\" in str(e):\n        logger.info(\"Existing run found; rerun with --resume or --force\")\n        raise SystemExit(1)\n    raise","preventionTips":["Use unique run IDs per experiment (timestamped run ids)","Always pass --resume or --force explicitly when re-running a known run ID","Archive old results/<run_id> directories before reusing an ID"],"tags":["ml-agents","trainer","output-directory","run-id"],"backgroundTag":"output-directory-conflict","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}