Skip to content

Fix skrl MARL observation space config keys - #5841

Merged
kellyguo11 merged 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/fix-skrl-marl-observation-spaces
May 29, 2026
Merged

kellyguo11 merged 1 commit into
isaac-sim:developfrom
AntoineRichard:antoiner/fix-skrl-marl-observation-spaces

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Description

Fixes MARL environment config space deserialization so non-serialized per-agent
space specs are preserved when Hydra resolves task configs. This keeps
cfg.observation_spaces and cfg.action_spaces populated for all agents in
cfg.possible_agents, including:

  • Isaac-Cart-Double-Pendulum-Direct-v0 (cart, pendulum)
  • Isaac-Shadow-Hand-Over-Direct-v0 (right_hand, left_hand)

Fixes: N/A (reported from local reproduction)

Type of change

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

Screenshots

N/A

Test Plan

  • ./isaaclab.sh -p -m pytest source/isaaclab/test/envs/test_spaces_utils.py::test_replace_strings_with_env_cfg_spaces_preserves_unserialized_marl_spaces -q
  • ./isaaclab.sh -p -m pytest source/isaaclab/test/envs/test_spaces_utils.py -q
  • Verified resolve_task_config() preserves observation/action spaces for Cart Double Pendulum and Shadow Hand Over with skrl_ippo_cfg_entry_point and skrl_mappo_cfg_entry_point.
  • ./isaaclab.sh -f

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation (N/A; no docs change needed)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump extension.toml — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Preserve non-serialized per-agent observation and action space entries when resolving Hydra environment configs. This keeps direct MARL task metadata complete for skrl multi-agent wrappers.
@AntoineRichard
AntoineRichard requested a review from Toni-SM as a code owner May 28, 2026 15:38
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels May 28, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

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.

Code Review Summary

This PR correctly fixes a bug in replace_strings_with_env_cfg_spaces() where non-serialized per-agent space entries were being silently dropped during Hydra config resolution.

What Changed

The Bug: The original dictionary comprehension used if isinstance(v, str) which filtered out any non-string values:

{k: deserialize_space(v) for k, v in getattr(env_cfg, attr).items() if isinstance(v, str)}

The Fix: Changed to a conditional expression that preserves non-string values:

{k: deserialize_space(v) if isinstance(v, str) else v for k, v in getattr(env_cfg, attr).items()}

Findings

✅ Correctness

  • The fix is minimal and surgical — only the necessary line is modified
  • The docstring correction (describing deserialization rather than serialization) is accurate
  • Backwards compatible with existing all-string dictionaries

✅ Test Coverage

  • New test test_replace_strings_with_env_cfg_spaces_preserves_unserialized_marl_spaces directly validates the fix
  • Test creates a realistic mixed-type scenario with both pre-resolved integers and serialized strings
  • Existing test suite remains intact

ℹ️ Observations

  • The function now correctly handles mixed dictionaries where some values are already resolved (integers/space objects) and others are still serialized strings
  • No new failure modes introduced
  • Pre-commit checks passed; CI still running installation and Docker builds

Verdict

Looks good. This is a clean, well-tested bug fix for MARL environment config deserialization. The change preserves the original contract while fixing the edge case where Hydra leaves some space specs unresolved.

@greptile-apps

greptile-apps Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent data-loss bug in replace_strings_with_env_cfg_spaces where per-agent space entries that Hydra had not serialized to strings were being dropped entirely from observation_spaces / action_spaces dicts during deserialization.

  • The original dict comprehension used if isinstance(v, str) as a filter, silently excluding non-string values (e.g., raw integer dimension specs) rather than passing them through. The fix changes this to a conditional expression (deserialize_space(v) if isinstance(v, str) else v), preserving every key regardless of its type.
  • A new focused test (test_replace_strings_with_env_cfg_spaces_preserves_unserialized_marl_spaces) validates the mixed-type dict round-trip, and a changelog fragment is added under the correct package.

Confidence Score: 5/5

Safe to merge; the change is a minimal, targeted fix that corrects the deserialization loop without altering any serialization path or public API.

The diff is a single-expression change that stops the deserialization loop from silently discarding non-string per-agent space entries. The logic is straightforward, the existing round-trip tests still pass, and the new targeted test directly validates the previously broken case with a mixed-type dict.

No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/envs/utils/spaces.py One-line fix: dict comprehension now uses a conditional expression instead of a filter, preserving non-string per-agent space entries; docstring corrected to match new behavior.
source/isaaclab/test/envs/test_spaces_utils.py New test exercises mixed serialized/unserialized per-agent space dicts and asserts both string (deserialized) and non-string (passed through) values survive the call correctly.
source/isaaclab/changelog.d/antoiner-fix-skrl-marl-observation-spaces.rst Changelog fragment correctly describes the fix under the Fixed heading; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["replace_strings_with_env_cfg_spaces(env_cfg)"] --> B["Iterate over observation_spaces / action_spaces dict"]
    B --> C{{"isinstance(v, str)?"}}
    C -- "Yes (Hydra serialized)" --> D["deserialize_space(v)\n→ gymnasium Space or Python spec"]
    C -- "No (not serialized by Hydra)" --> E["Pass through as-is\n(integer dim, Space object, …)"]
    D --> F["Rebuilt dict with all agents preserved"]
    E --> F
    F --> G["setattr(env_cfg, attr, rebuilt_dict)"]
Loading

Reviews (1): Last reviewed commit: "Fix MARL config space deserialization" | Re-trigger Greptile

@kellyguo11
kellyguo11 merged commit c4a2a9b into isaac-sim:develop May 29, 2026
37 checks passed
kellyguo11 added a commit that referenced this pull request May 29, 2026
…nt training fixes from develop (#5855)

# Description

Cherry pick fixes from the develop branch:

- #5805 
- #5786 
- #5787 
- #5793 
- #5831 
- #5853
- #5841 
- #5843

---------

Signed-off-by: sameerchavan0027 <[email protected]>
Co-authored-by: Antoine RICHARD <[email protected]>
Co-authored-by: hujc <[email protected]>
Co-authored-by: sameerchavan0027 <[email protected]>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants