Skip to content

fix(lerobot): write official loader fields so v3 exports open in lerobot - #814

Open
Amidwestnoob wants to merge 2 commits into
Hebbian-Robotics:mainfrom
Amidwestnoob:fix/778-official-lerobot-loader
Open

Amidwestnoob wants to merge 2 commits into
Hebbian-Robotics:mainfrom
Amidwestnoob:fix/778-official-lerobot-loader

Conversation

@Amidwestnoob

Copy link
Copy Markdown
Contributor

Summary

LeRobot v3 exports now open in the official lerobot==0.4.4 loader.

  • Write codebase_version="v3.0", total_tasks, and range-form splits ("train": "0:N"), keeping the existing code marker.
  • Write meta/tasks.parquet with task strings as the pandas index. Preserve sparse source task IDs with positional padding so tasks.iloc[task_index].name resolves correctly.
  • Reject staged exports that lack the official fields or use the old split layout.
  • Bump EXPORT_VERSION to lerobot-export-v4 and document regeneration of older exports. The canonical episode format and transform behavior version are unchanged.

Closes #778

Why

On main 3d9dfb1, an export accepted by the structural validator fails in both LeRobotDatasetMetadata and LeRobotDataset with KeyError: 'codebase_version'. After that field, the official loader also requires the task count, range-form splits, and positional task lookup.

The committed opt-in round-trip test opens a typed export with two real synthetic MP4 cameras and checks all eight frames, including sparse task IDs 0 and 10. A separate independent round-trip also passed with unordered task IDs 10 and 2, nonzero source offsets, and both cameras decoded. The same independent test fails with the original missing-key error on unmodified main.

Validation

Local Linux checks on the final source:

  • uv run --locked pytest -q -rs tests/test_lerobot_export.py: 44 passed, 1 skipped.
  • HFLOW_LEROBOT_LOADER_PYTHON=<isolated lerobot 0.4.4 interpreter> HF_HUB_OFFLINE=1 HF_DATASETS_OFFLINE=1 uv run --locked pytest -q tests/test_lerobot_export.py::test_official_lerobot_loader_opens_typed_export: passed. Running that test together with the independent round-trip gave 2 passed, no skips.
  • uv run --locked pytest -q -n 4 -rs: 2657 passed, 9 skipped on Python 3.11, 3.12, and 3.14.
  • Python 3.14 minimum NumPy: installed numpy==2.3.5, then ran uv run --no-sync pytest -q -n 4 tests/test_resample_derive.py tests/test_episode_to_arrow.py tests/test_video_import.py: 93 passed. Restored the locked environment afterwards.
  • uv run --locked ruff check ., uv run --locked ruff format --check ., and uv run --locked ty check: passed, including Python 3.14. Also ran the contribution guide's fix/format commands.
  • Markdown link check: zero errors.
  • Applying the complete patch to a clean copy of the exact base produced the tested final tree.

Full-suite environment: an ephemeral loopback HTTP 404 endpoint replaced optional remote Hub lookups, keeping synthetic fixtures off production services. The suite's explicit loopback HTTP integration remained active. Test artifacts were retained outside the checkout, with a short temporary directory for Python 3.14 multiprocessing sockets. These are environment settings, not changes to production code or test assertions.

The official-loader integration remains opt-in so lerobot does not enter the lockfile. Its default skip was exercised separately. The other eight skips require MediaPipe, network FFmpeg, Docker, or a live bucket. An earlier development run encountered an intermittent failure in an untouched verification test; the reviewed baseline and final full runs passed. macOS and actual upstream GitHub Actions have not been verified locally; no upstream CI pass is claimed.

Checklist

  • I added or updated outcome-focused tests for changed business logic.
  • I updated documentation for changed behavior, flags, formats, or requirements.
  • I ran uv run ruff check --fix, uv run ruff format, and uv run ty check.
  • I ran the relevant pytest suite.
  • I did not add recordings, generated media, credentials, private URLs, or runtime artifacts.
  • I preserved stored-data compatibility or documented an explicit version change.

Apply the r002 producer patch from contribution-workshop staging 5f08f73abdfe525dd6200557a82672843d8a3b66 without source changes.
Independent review follow-up to r002: require official lerobot 0.4.4, exercise both sparse task IDs across every frame, and mark the real FFmpeg integration per contribution rules.
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect HFlow's local LeRobot exports and the tools that open them.

The PR appears safe to merge, with a non-blocking recommendation to bound sparse task padding.

Findings

  1. P2 Sparse tasks can exhaust memory ▶

Summary

Updates LeRobot exports with the fields and task layout needed by the official loader.

  • LeRobot exports now carry the metadata the official loader expects.
  • Sparse task IDs keep pointing to their names in LeRobot exports.

Reviews (1) · Last reviewed commit: "test(lerobot): verify sparse tasks acros..." · Reviewed by Greptile

Comment on lines +262 to +264
max_index = max(registry)
indices = list(range(max_index + 1))
names = [registry.get(i, "") for i in indices]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Sparse tasks can exhaust memory

_official_tasks_table allocates rows up to the largest source task ID, with no size limit. A small registry with a very large sparse ID can exhaust memory during export, even when the selected episodes never use that task. Previously, the exporter copied or wrote only the registry's actual entries.

Check the required row count before allocating and reject oversized registries with a clear error.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LeRobot v3 exports cannot be opened by the official lerobot loader (KeyError: 'codebase_version')

1 participant