{"record":{"id":"05662c1b6742f931","repo":"mlflow/mlflow","slug":"run-with-uuid-is-already-active-to-start-a-new","errorCode":null,"errorMessage":"Run with UUID {} is already active. To start a new run, first end the current run with mlflow.end_run(). To start a nested run, call start_run with nested=True","messagePattern":"Run with UUID (.+?) is already active\\. To start a new run, first end the current run with mlflow\\.end_run\\(\\)\\. To start a nested run, call start_run with nested=True","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"mlflow/tracking/fluent.py","lineNumber":567,"sourceCode":"    .. code-block:: text\n        :caption: Output\n\n        parent run:\n        run_id: 8979459433a24a52ab3be87a229a9cdf\n        description: starting a parent for experiment 7\n        version tag value: v1\n        priority tag value: P1\n        --\n        child runs:\n                                     run_id params.child tags.mlflow.runName\n        0  7d175204675e40328e46d9a6a5a7ee6a          yes           CHILD_RUN\n    \"\"\"\n    active_run_stack = _active_run_stack.get()\n    _validate_experiment_id_type(experiment_id)\n    # back compat for int experiment_id\n    experiment_id = str(experiment_id) if isinstance(experiment_id, int) else experiment_id\n    if len(active_run_stack) > 0 and not nested:\n        raise Exception(\n            (\n                \"Run with UUID {} is already active. To start a new run, first end the \"\n                + \"current run with mlflow.end_run(). To start a nested \"\n                + \"run, call start_run with nested=True\"\n            ).format(active_run_stack[0].info.run_id)\n        )\n    client = MlflowClient()\n    sgc_job_run_id_tag_key: str | None = None\n    if run_id:\n        existing_run_id = run_id\n    elif run_id := MLFLOW_RUN_ID.get():\n        existing_run_id = run_id\n        del os.environ[MLFLOW_RUN_ID.name]\n    # Get SGC job run ID tag key for run resumption if applicable\n    elif sgc_job_run_id_tag_key := _get_sgc_job_run_id_tag_key():\n        existing_run_id = _get_sgc_mlflow_run_id_for_resumption(\n            client, experiment_id, sgc_job_run_id_tag_key\n        )","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/tracking/fluent.py#L549-L585","documentation":"mlflow.start_run() maintains an active-run stack; a plain (non-nested) start_run while a run is already active on the stack is ambiguous and rejected. The error names the currently active run UUID and points to end_run() or nested=True.","triggerScenarios":"Calling mlflow.start_run() (or the context manager) while _active_run_stack is non-empty and nested is not True — e.g., nested start_run calls in a loop, or re-entering start_run inside an active `with mlflow.start_run():` block.","commonSituations":"Calling start_run twice in the same script without ending the first run; wrapping training steps in start_run inside an outer start_run without nested=True; a callback (e.g., on_evaluate_start) starting a run while the framework already has one active.","solutions":["Use `with mlflow.start_run(nested=True):` for the inner run.","Call mlflow.end_run() before starting a new top-level run, or use separate `with mlflow.start_run():` blocks.","Restructure so each run is properly closed (e.g., don't call start_run in a callback that runs inside an active run).","If a stale run is stuck from a crashed process, it no longer affects a new process; just ensure this process's stack is clean."],"exampleFix":"// before\nwith mlflow.start_run():\n    with mlflow.start_run():  # raises\n        train()\n// after\nwith mlflow.start_run():\n    with mlflow.start_run(nested=True):\n        train()","handlingStrategy":"validation","validationCode":"if mlflow.active_run() is not None:\n    mlflow.end_run()  # or use nested=True","typeGuard":"def has_active_run() -> bool:\n    return mlflow.active_run() is not None","tryCatchPattern":"try:\n    mlflow.start_run()\nexcept Exception as e:\n    if \"already active\" in str(e):\n        mlflow.end_run()\n        run = mlflow.start_run()\n    else:\n        raise","preventionTips":["Always use context managers (with mlflow.start_run():) so runs auto-close","Use nested=True for inner runs","Don't call start_run inside callbacks that run within an active run"],"tags":["mlflow","run-lifecycle","nested-runs","fluent-api"],"backgroundTag":"active-run-conflict","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}