[Tune] A trial stopped while PAUSED is TERMINATED in memory but PAUSED in experiment_state (_schedule_trial_stop returns before _mark_trial_to_checkpoint)
What happened + What you expected to happen
A trial that is stopped while it is PAUSED ends up TERMINATED in memory, but it is written to experiment_state-*.json as PAUSED. I expected the persisted status to be TERMINATED as well.
HyperBand reaches this on its normal path. When a bracket finishes, _process_bracket → cleanup_full calls tune_controller.stop_trial(t) for the bracket's paused trials, so every halving that leaves a trial paused persists it this way.
Why. In python/ray/tune/execution/tune_controller.py (TuneController._schedule_trial_stop, lines 1367-1395 on master e70ad5f77a), the status is set first, and then the method returns early for a trial that has no live actor. The early return comes before _mark_trial_to_checkpoint(trial), which is what queues the trial's state for the next experiment_state write:
self._set_trial_status(trial, Trial.ERROR if exception else Trial.TERMINATED)
trial.set_location(_Location())
if trial not in self._trial_to_actor:
logger.debug(f"Will not STOP trial actor as it is not live: {trial}")
return
...
self._mark_trial_to_checkpoint(trial)A PAUSED trial has no actor, because pausing already released or cached it. So the early return is always taken, and the TERMINATED status is never persisted.
Consequence (from reading the code, not measured): Tuner.restore(..., resume_unfinished=True) treats a PAUSED trial as unfinished, so on restore it would re-run a trial that the finished run had already stopped.
Output of the script below (PyPI ray[tune]==2.58.0, clean container):
ray 2.58.0 cec0a091b12675bbf101cf8a350c8706107baee1
INMEMORY role=a status=TERMINATED
INMEMORY role=b status=TERMINATED
PERSISTED role=a status=PAUSED
PERSISTED role=b status=TERMINATEDTrial a reaches the rung first and is paused while b sleeps. When b finishes, the bracket completes, and cleanup_full stops a from PAUSED.
A possible fix: call self._mark_trial_to_checkpoint(trial) before the early return, since the status has already been set by then. With that one line added to the same PyPI package, the script below prints PERSISTED role=a status=TERMINATED.
A second gap on the same path, from reading only (not reproduced): with the legacy export_formats set, _schedule_graceful_trial_stop → _schedule_trial_export → _schedule_trial_task indexes self._trial_to_actor[trial] (line 1206 on master). For an actorless PAUSED trial, that raises KeyError. stop_trial's except hands the error to _process_trial_failure, which acts only on RUNNING or PENDING trials, so the trial stays PAUSED, even though on_trial_remove has already dropped it from its bracket.
Versions / Dependencies
ray[tune]==2.58.0from PyPI (ray.__commit__cec0a091b1).- Python 3.12.14,
python:3.12-slim, aarch64. - The code path is unchanged on
mastere70ad5f77a(2026-09-29).
Reproduction script
import glob, json, os, tempfile, time
import ray
from ray import tune
from ray.tune import RunConfig, TuneConfig, Tuner
from ray.tune.schedulers import HyperBandScheduler
def trainable(config):
if config["role"] == "b":
time.sleep(config["sleep"]) # "a" reaches the milestone first and is PAUSED
for i in range(5):
tune.report({"loss": (0.1 if config["role"] == "a" else 1.0) / (i + 1)})
storage = tempfile.mkdtemp()
ray.init(num_cpus=4, include_dashboard=False, log_to_driver=False)
print(f"ray {ray.__version__} {ray.__commit__}")
grid = Tuner(
trainable,
param_space={"role": tune.grid_search(["a", "b"]), "sleep": 20},
tune_config=TuneConfig(metric="loss", mode="min",
scheduler=HyperBandScheduler(time_attr="training_iteration", max_t=5, reduction_factor=2)),
run_config=RunConfig(verbose=0, storage_path=storage, name="stop_from_paused"),
).fit()
for t in grid._experiment_analysis.trials:
print(f"INMEMORY role={t.config['role']} status={t.status}")
newest = sorted(glob.glob(os.path.join(storage, "stop_from_paused", "experiment_state-*.json")))[-1]
for entry in json.load(open(newest))["trial_data"]:
d = json.loads(entry[0]) if isinstance(entry[0], str) else entry[0]
print(f"PERSISTED role={d['config']['role']} status={d['status']}")Issue Severity
Low: it causes friction when restoring an experiment. Suggested labels: bug, tune.
This report was prepared with AI assistance and reviewed by a human before posting.
Source: ray-project/ray