Fixed: mlflow gc Leaves traces.json Files Behind
mlflow gc told me an experiment had been permanently deleted, but one of its traces was still on disk, as a traces.json file under mlartifacts. MLflow had saved a spare copy of that trace as a file, and neither deleting the trace nor gc removes it. Deleting the experiment's folder myself, after gc, cleaned it up.
What I Was Doing
I was cleaning up my MLflow 3.18.0 tracking server after writing a set of tracing how-to posts. The server runs in its own folder, started there with uv run mlflow server --port 8080, so its data lives in that folder: experiments, runs and traces in the database mlflow.db, and files in mlartifacts. Seven experiments from the posts' examples had to go. Their traces came from small Python scripts that used @mlflow.trace, with MLflow's default settings.
Six of the experiments were still active, so I deleted them first with mlflow experiments delete -x <ID>. The seventh, experiment 8, I had deleted earlier. Then I removed all seven for good with mlflow gc, in the server's folder. The server hands out its files itself (artifact proxying), so gc needs MLFLOW_TRACKING_URI set to the server, as its help says:
- macOS / Linux
- Windows (PowerShell)
export MLFLOW_TRACKING_URI=http://127.0.0.1:8080
uv run mlflow gc --backend-store-uri sqlite:///mlflow.db --experiment-ids 2,3,4,5,6,7,8
$env:MLFLOW_TRACKING_URI = "http://127.0.0.1:8080"
uv run mlflow gc --backend-store-uri sqlite:///mlflow.db --experiment-ids 2,3,4,5,6,7,8
--backend-store-uri sqlite:///mlflow.dbis the server's database, in this folder.--experiment-idslists the deleted experiments to remove for good, with everythinggcdeletes along with them.
Experiment with ID 4 has been permanently deleted.
Experiment with ID 5 has been permanently deleted.
Experiment with ID 6 has been permanently deleted.
Experiment with ID 7 has been permanently deleted.
Experiment with ID 8 has been permanently deleted.
What I Expected
The mlflow gc documentation says that when it deletes experiments, it "removes the experiment record and all associated data". I expected nothing left of experiment 8 in mlartifacts/8.
What I Got
I looked for trace files in mlartifacts:
- macOS / Linux
- Windows (PowerShell)
find mlartifacts -name traces.json
Get-ChildItem mlartifacts -Recurse -Filter traces.json | Resolve-Path -Relative
find lists every file named traces.json inside mlartifacts, at any depth. In PowerShell, Get-ChildItem -Recurse -Filter finds the same files, and Resolve-Path -Relative prints their paths from the current folder; PowerShell 7.6 on my Mac printed the same list, each path starting with ./.
mlartifacts/1/traces/tr-259b95fb327152e8b6bf089997c3fea9/artifacts/traces.json
mlartifacts/1/traces/tr-0b187f6a78766fe305f2165684b9e6b5/artifacts/traces.json
mlartifacts/1/traces/tr-489f48a7df80c7cd613448fc53d665f1/artifacts/traces.json
mlartifacts/1/traces/tr-af60cbc38c91ce09454dd34e2f602681/artifacts/traces.json
mlartifacts/8/traces/tr-4364dea12925bad740c36e6ccb5104bd/artifacts/traces.json

gc had removed experiment 8, yet mlartifacts/8 still held one trace's traces.json. The other four files are in experiment 1, which I kept: it holds the traces of a Claude-powered agent, eight in all.
What I Checked
Whether MLflow still knows these traces. Each file sits in a folder named after its trace's ID, so a short script can ask MLflow about each one. mlflow.get_trace() loads a trace by its ID, and returns None when there's no such trace. Every trace also carries the tag mlflow.trace.spansLocation, which says where its spans, the steps the trace recorded, are stored. I saved this as check_traces.py in the server's folder:
"""For each traces.json under mlartifacts: does MLflow still have that trace, and where are its spans?"""
from pathlib import Path
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:8080")
for file in sorted(Path("mlartifacts").rglob("traces.json")):
trace_id = file.parts[3] # mlartifacts/<experiment ID>/traces/<trace ID>/artifacts/traces.json
trace = mlflow.get_trace(trace_id)
if trace is None:
print(f"{trace_id}: no such trace")
else:
print(f"{trace_id}: spans in {trace.info.tags['mlflow.trace.spansLocation']}")

Path("mlartifacts").rglob("traces.json")finds everytraces.jsoninsidemlartifacts, likefinddid.file.parts[3]is the fourth part of the file's path, the folder named after the trace's ID.trace.info.tagsholds the trace's tags,mlflow.trace.spansLocationamong them.
With the server running, I ran it in the server's folder; the command is the same in every shell:
uv run python check_traces.py
/Users/you/source/mlflow-server/.venv/lib/python3.15/site-packages/google/protobuf/json_format.py:1065: FutureWarning: invalid character '+' in URL-safe Base64 data will be discarded in future Python versions
return base64.urlsafe_b64decode(padded_value)
/Users/you/source/mlflow-server/.venv/lib/python3.15/site-packages/google/protobuf/json_format.py:1065: FutureWarning: invalid character '/' in URL-safe Base64 data will be discarded in future Python versions
return base64.urlsafe_b64decode(padded_value)
tr-0b187f6a78766fe305f2165684b9e6b5: spans in TRACKING_STORE
tr-259b95fb327152e8b6bf089997c3fea9: spans in TRACKING_STORE
tr-489f48a7df80c7cd613448fc53d665f1: spans in TRACKING_STORE
tr-af60cbc38c91ce09454dd34e2f602681: spans in TRACKING_STORE
2026/12/03 10:52:01 WARNING mlflow.tracing.fluent: Failed to get trace from the tracking store: RESOURCE_DOES_NOT_EXIST: Trace with ID 'tr-4364dea12925bad740c36e6ccb5104bd' not found.. If using async trace logging, pass flush=True to wait for pending writes. For full traceback, set logging level to debug.
tr-4364dea12925bad740c36e6ccb5104bd: no such trace

The two FutureWarning lines come from protobuf on Python 3.15, while MLflow reads the traces, and have nothing to do with this problem: Fixed: "FutureWarning: invalid character '+' in URL-safe Base64 data will be discarded in future Python versions" When You Read MLflow Traces.
MLflow no longer has trace tr-4364…: its record went with experiment 8, and only the file is left. The four traces of experiment 1 still exist, and their spans are in TRACKING_STORE, the tracking server's database. So their traces.json files are spare copies: the spans they hold are in mlflow.db too.
Why only some traces have a file. Experiment 1 holds eight traces, and only four of them have a traces.json. MLflow issue #27258 explains it. With async trace logging, which is on by default, the client hands a finished trace to the server in two background tasks: one sends its spans to the database, the other records the trace and uploads traces.json, unless the server already says the spans are in the database. When the trace is recorded before the spans are saved, the client doesn't see that yet, and uploads the file as well. The issue adds that reads of these traces use the database, so nothing reads the file. Whether it happens depends on timing: four of the eight agent traces in experiment 1 got a file, and one of the two traces in experiment 8 did, while in a test on a fresh server, 20 traces of a tiny function got none.
What gc and trace deletion remove. In MLflow's code, on 3.18.0 and on the main branch, mlflow gc removes an experiment by deleting its records from the database, without touching its folder in mlartifacts (mlflow/cli/__init__.py). Deleting a trace whose spans are in the database removes only its database rows as well (sqlalchemy_store.py). I added this to the issue, with the output above, in a comment on #27258.
Why It Happens
Two things meet. Async trace logging sometimes uploads a traces.json for a trace whose spans are already in the database, and neither deleting the trace nor mlflow gc deletes trace files from mlartifacts. So the file outlives its trace, and then its experiment, with nothing in MLflow pointing at it.
The Fix
Once gc has removed an experiment for good, delete the experiment's folder under mlartifacts yourself. Its name is the ID in gc's line Experiment with ID 8 has been permanently deleted., 8 here. In the server's folder:
- macOS / Linux
- Windows (PowerShell)
rm -r mlartifacts/8
Remove-Item -Recurse mlartifacts/8
rm -r deletes the folder and everything in it, and prints nothing when it succeeds. Remove-Item -Recurse does the same in PowerShell.
Only delete the folder of an experiment that gc has removed for good. An experiment that's only deleted can still be restored with mlflow experiments restore, and its folder holds its runs' files.
Leave the traces.json files of traces that still exist, such as the four in experiment 1. They're spare copies, and they go when their experiment is removed and its folder deleted.
After the Fix
The folder deleted, the same search again:
mlartifacts/1/traces/tr-259b95fb327152e8b6bf089997c3fea9/artifacts/traces.json
mlartifacts/1/traces/tr-0b187f6a78766fe305f2165684b9e6b5/artifacts/traces.json
mlartifacts/1/traces/tr-489f48a7df80c7cd613448fc53d665f1/artifacts/traces.json
mlartifacts/1/traces/tr-af60cbc38c91ce09454dd34e2f602681/artifacts/traces.json

Experiment 8's file is gone, and the only traces.json files left belong to traces that still exist.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting mlflow gc --experiment-ids to remove the experiment's files | A trace's traces.json stayed in mlartifacts/8 | After gc, look in the experiment's folder and delete it yourself |
Assuming every trace writes a traces.json | Only four of experiment 1's eight traces had one | Search the whole folder with find after gc |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
find: mlartifacts: No such file or directory | You're not in the server's folder, or the server hasn't stored any files yet | Run it in the folder where you start mlflow server |
RESOURCE_DOES_NOT_EXIST: Trace with ID '...' not found.. from mlflow.get_trace() | The trace was deleted, and only its file is left | Once its experiment is removed with gc, delete the experiment's folder |
FutureWarning: invalid character '+' in URL-safe Base64 data will be discarded in future Python versions | protobuf on Python 3.15, while MLflow reads traces | It's unrelated to the leftover files |
FAQ
Is it safe to delete the folder?
For an experiment that gc has removed, yes. MLflow has no record of its traces anymore, as check_traces.py showed with no such trace, so nothing points at the files.
Will an MLflow update fix this?
On MLflow 3.18.0, #27258 is open. A fix for it stops new spare copies, but files written before it stay until you delete them.
Does deleting a single trace remove its file?
Not according to MLflow's code. For a trace whose spans are in the database, deleting it removes only its database rows, as the code linked under What I Checked shows. The file stays in the experiment's folder until you remove the experiment and delete its folder.
Conclusion
mlflow gc removed experiment 8, but a traces.json that async trace logging had saved for one of its traces stayed in mlartifacts/8. MLflow no longer knew that trace, so deleting the experiment's folder myself, after gc, removed the last of it.
Additional Resources
mlflow gc— what the command deletes.- mlflow/mlflow#27258 — the async export race that uploads the spare
traces.json. - Delete Traces — deleting traces from Python and the CLI.
