Problem
compute_episode_data_index() in lerobot/common/datasets/utils.py builds dataset_from_index and dataset_to_index boundaries from a cumulative sum of episode["length"] metadata values without validating that those lengths are positive or internally consistent.
If episode metadata lengths are wrong for any reason (converter bug, manual edit, partial write, corruption), the function silently returns wrong boundaries. Frames then load without error but belong to the wrong episodes during training — a silent data quality failure with no diagnostic signal.
Reproduction
from lerobot.common.datasets.utils import compute_episode_data_index
import torch
# Simulate metadata where episode 1 has a wrong length
episodes = {
0: {"length": 50},
1: {"length": 0}, # corrupted: should be 50
2: {"length": 50},
}
total_frames = 150 # actual data has 150 frames
# Returns boundaries as if episode 1 has 0 frames
# Episode 2 gets frames that belong to episode 1
result = compute_episode_data_index(episodes)
print(result)
# from_index: [0, 50, 50] <- episode 1 gets no frames
# to_index: [50, 50, 100] <- episode 2 starts where episode 1 should
Suggested fix
Add validation at the start of compute_episode_data_index that raises a clear ValueError when any episode length is <= 0, naming the episode index and declared length in the message so the caller can diagnose the source dataset.
Context
I found this while building trajlens (https://github.com/Kunal-Somani/trajlens), a dataset validation and repair tool for LeRobot datasets. The trajlens episode_reindex fixer detects this class of corruption by comparing declared boundaries against per-row episode_index values in the actual data shards. This upstream validation would provide an earlier, clearer signal at dataset load time rather than silent wrong-frame loading.
Problem
compute_episode_data_index()inlerobot/common/datasets/utils.pybuildsdataset_from_indexanddataset_to_indexboundaries from a cumulative sum ofepisode["length"]metadata values without validating that those lengths are positive or internally consistent.If episode metadata lengths are wrong for any reason (converter bug, manual edit, partial write, corruption), the function silently returns wrong boundaries. Frames then load without error but belong to the wrong episodes during training — a silent data quality failure with no diagnostic signal.
Reproduction
Suggested fix
Add validation at the start of
compute_episode_data_indexthat raises a clearValueErrorwhen any episode length is <= 0, naming the episode index and declared length in the message so the caller can diagnose the source dataset.Context
I found this while building trajlens (https://github.com/Kunal-Somani/trajlens), a dataset validation and repair tool for LeRobot datasets. The trajlens
episode_reindexfixer detects this class of corruption by comparing declared boundaries against per-rowepisode_indexvalues in the actual data shards. This upstream validation would provide an earlier, clearer signal at dataset load time rather than silent wrong-frame loading.