Skip to content

Fix KeyError when 'add' mode not present in observation_manager.active_functors#200

Merged
yuecideng merged 1 commit intomainfrom
fix/datasets-observation-manager-add-mode-safety
Mar 25, 2026
Merged

Fix KeyError when 'add' mode not present in observation_manager.active_functors#200
yuecideng merged 1 commit intomainfrom
fix/datasets-observation-manager-add-mode-safety

Conversation

@yuecideng
Copy link
Contributor

Description

This PR fixes a KeyError that occurs in LeRobotRecorder when the active_functors dictionary does not contain an 'add' key.

Previously, the code assumed that active_functors["add"] always existed, which caused a runtime error in configurations where observation functors are not registered in 'add' mode. The fix adds a conditional check (if "add" in self._env.observation_manager.active_functors:) before iterating over the add-mode functors.

This is a non-breaking change that makes the code more robust for different observation manager configurations.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

🤖 Generated with Claude Code

…e_functors

The code previously assumed 'add' always existed in active_functors,
which caused KeyError in configurations without observation functors
in 'add' mode. Added a conditional check before iterating over 'add'
functors to prevent this error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 15:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a runtime KeyError in LeRobotRecorder when the environment’s ObservationManager.active_functors does not define an 'add' mode, making dataset feature generation robust across different observation-manager configurations.

Changes:

  • Guard iteration over add-mode observation functors with an 'add' in active_functors check.
  • Add a clarifying inline comment for the add-mode functor handling block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +419 to +421
# Add extra observation in `add` mode based on functor config
if "add" in self._env.observation_manager.active_functors:
for functor_name in self._env.observation_manager.active_functors["add"]:
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This change adds a new behavior path when observation_manager.active_functors does not contain an 'add' key, but the existing LeRobotRecorder tests appear to always set active_functors={"add": []} in the mock env. Please add a unit test that exercises _build_features() / _modify_feature_names() with active_functors missing 'add' to prevent regressions of the original KeyError.

Copilot uses AI. Check for mistakes.
logger.log_warning(
f"Asset with UID '{asset_uid}' is not RigidObject, Articulation or Robot. Cannot assign feature names based on asset properties."
)
# Add extra observation in `add` mode based on functor config
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The inline comment says "Add extra observation in add mode", but this block doesn’t add observations; it only updates features[obs_key]["names"] for observations created via add-mode functors. Consider rewording to avoid misleading readers.

Suggested change
# Add extra observation in `add` mode based on functor config
# Update feature names for observations created via `add` mode functors

Copilot uses AI. Check for mistakes.
@yuecideng yuecideng merged commit a781294 into main Mar 25, 2026
9 checks passed
@yuecideng yuecideng deleted the fix/datasets-observation-manager-add-mode-safety branch March 25, 2026 16:03
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.

2 participants