skip to content

Why do a scheduled job's MLflow runs land in a local mlflow.db instead of the team's shared tracking server, and how do you fix it?

level: middleimportance: should knowfreq 13%

answer

  1. the client never discovers a server
  2. code first, then environment
  3. MLFLOW_TRACKING_URI in the job definition
  4. SQLite default since 3.7
  5. ./mlruns reused only if data exists

basics

~20 s

The MLflow client uses mlflow.set_tracking_uri, else MLFLOW_TRACKING_URI, else a default — sqlite:///mlflow.db in the working directory since MLflow 3.7. A scheduler that doesn't pass the variable gets that default; set it in the job's environment or code.

solid answer

~40 s

The MLflow client never looks for a server. It uses the URI given to `mlflow.set_tracking_uri`, otherwise the `MLFLOW_TRACKING_URI` environment variable, otherwise a default. Since MLflow 3.7 that default is `sqlite:///mlflow.db` in the current working directory — unless an existing `./mlruns` file store with experiment data is found there, which is reused — and the run's artifacts go to a local `./mlruns` directory. A cron or orchestrator job that doesn't inherit the shell's exports therefore writes a private database nobody else sees, and a different working directory means a different `mlflow.db`. Fix it by setting `MLFLOW_TRACKING_URI=http://mlflow.internal.example:5000` in the job definition, or calling `set_tracking_uri` before the run starts; call `mlflow.set_experiment("store-demand")`, which creates the experiment on the server if it is missing; and log `mlflow.get_tracking_uri()` at startup so the job's output says where its runs went.

go deeper

for a junior

Recall the resolution order — set_tracking_uri, then MLFLOW_TRACKING_URI, then the default — and that the 3.x default is a local sqlite:///mlflow.db.

for a middle

Explain why scheduled and containerised jobs miss the variable, how the working directory decides which local database is used, and how set_experiment creates the experiment.

for a senior

Show how you would make the destination part of the job's definition, verify it from the job's output, inject credentials safely and decide what to do with runs already written locally.

for a principal

Weigh how a platform team hands every job its tracking address and credentials, so that a missing setting fails visibly instead of logging silently to a disk nobody reads.

## The client decides where runs go MLflow's **tracking URI** tells the client library where to send run metadata. It can be a database URI, a local path, or the HTTP address of a **tracking server** — a process started with `mlflow server` that a whole team logs to. The client never searches the network for a server; it resolves the URI in a fixed order: 1. A value passed to `mlflow.set_tracking_uri(...)` earlier in the process. 2. The `MLFLOW_TRACKING_URI` environment variable. 3. A built-in default. `mlflow.get_tracking_uri()` returns whatever that resolution produced, which makes it the first thing to print when runs are missing. ## What the default is in MLflow 3.x Before MLflow 3.7 the default was a file store: YAML files under `./mlruns`. MLflow 3.7 made a **SQLite database** the default, keeping the old store only when it already holds data. | Situation when no URI is set | Where metadata goes | Where artifacts go | |---|---|---| | No `./mlruns` with experiment data in the working directory | `sqlite:///mlflow.db` in the working directory | `./mlruns` | | An existing `./mlruns` file store with experiment data | That `./mlruns` file store | `./mlruns` | Both are resolved against the **current working directory**, so the same script run from two directories creates two unrelated `mlflow.db` files. Some older pages in MLflow's documentation still describe `./mlruns` as the default for everything; the 3.7 changelog and the backend-store page describe the current behaviour. ## Why scheduled jobs hit the default - **Cron and orchestrators** start jobs with a minimal environment. A variable exported in an engineer's shell profile does not reach them. - **Containers** see only the environment their spec declares; an image that works locally because of a `.env` file loses it in the scheduler. - **Working directories differ** between a laptop and a job runner, so even the local fallback ends up somewhere unexpected. - `set_tracking_uri` writes its value into `MLFLOW_TRACKING_URI` for the current process, so subprocesses it launches inherit the setting. A job whose parent never set either has nothing to inherit. None of this raises an error: logging to a local SQLite file succeeds, which is why the symptom is silence on the shared server rather than a failure in the job. ## Fixing and verifying - Put `MLFLOW_TRACKING_URI=http://mlflow.internal.example:5000` in the **job definition** — the scheduler's environment block or the container spec — rather than in a shell profile. - Or call `mlflow.set_tracking_uri(...)` at the top of the script, **before** any run starts, if the address is not meant to vary by environment. - Call `mlflow.set_experiment("store-demand")`. It activates the experiment by name and creates it on the server if it does not exist, so the job does not depend on someone creating it in the UI first. - Log `mlflow.get_tracking_uri()` at startup so the job's own output shows the destination. - If the server requires authentication, the client reads credentials from `MLFLOW_TRACKING_USERNAME` and `MLFLOW_TRACKING_PASSWORD`, or a token from `MLFLOW_TRACKING_TOKEN`; inject them from the scheduler's secret store, never from the code. ## A worked diagnosis 1. Print `mlflow.get_tracking_uri()` from inside the job, not from a laptop shell; the two environments differ. 2. Inspect the job's environment block or container spec for `MLFLOW_TRACKING_URI`. 3. Look for a fresh `mlflow.db` (and a `./mlruns` artifact folder) in the job's working directory — that is where the missing runs are. 4. Set the variable in the job definition, rerun, and confirm the run appears in the server's UI under the expected experiment. A URI set in a notebook cell is the other common cause: it lives in that kernel's process only, so the scheduled script built from the notebook starts without it. ## What about the runs already written locally - `mlflow migrate-filestore` (MLflow 3.10 and later) moves a `./mlruns` **file store** into a SQLite database, preserving IDs. Its target must be SQLite and empty, and artifacts stay where they were. - Copying runs from one tracking store to another server is the job of the separate `mlflow-export-import` tool, which does not preserve original IDs or timestamps. For a nightly job, re-running against the server is often simpler than recovering a stray `mlflow.db`. The lasting fix is making the URI part of the job's definition, so the next run cannot fall back silently.

  • A script calls mlflow.set_tracking_uri() while MLFLOW_TRACKING_URI also points somewhere. Which one wins?
    The value set in code. The client checks the URI set by `set_tracking_uri` first and reads `MLFLOW_TRACKING_URI` only when nothing was set in the process. Because `set_tracking_uri` also writes the environment variable, subprocesses launched afterwards inherit the code's choice.
  • An old laptop project has years of runs in a ./mlruns file store. How do you bring them onto MLflow 3's database backend?
    `mlflow migrate-filestore --source ./mlruns --target sqlite:///mlflow.db` (MLflow 3.10 or later) copies the metadata losslessly, IDs and timestamps included. The target must be an empty SQLite database, and artifacts are not moved — the database keeps pointing at the original files. Copying to a different server is what `mlflow-export-import` is for.

  • MLflow finds the team's tracking server automatically on the network
  • MLflow 3 still writes runs to ./mlruns YAML files by default
  • MLFLOW_TRACKING_URI overrides a URI set in code with set_tracking_uri
  • A missing tracking URI makes log calls fail, so the job would have crashed
  • mlflow migrate-filestore copies runs from one tracking server to another

Assumes MLflow 3.16; since 3.7 the default tracking URI is sqlite:///mlflow.db, where 2.x defaulted to a ./mlruns file store.