Skip to content

Fixes CI errors where the PresetCfg is never resolved when running tests - #4801

Merged
kellyguo11 merged 3 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/fix/CI_preset_errors
Mar 3, 2026
Merged

kellyguo11 merged 3 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/fix/CI_preset_errors

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Description

Some task configs like CartpolePhysicsCfg are PresetCfg that wrap multiple physics backends (physx, newton). It gets resolved to its default field when going through the Hydra pipeline (_resolve_preset_defaults), but when creating environments directly via gym.make() (as the test does), the PresetCfg is never resolved — so SimulationContext sees a PresetCfg object instead of an actual PhysxCfg with a class_type attribute.

Type of change

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

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
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Mar 3, 2026
@greptile-apps

greptile-apps Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes an AttributeError that occurs when environments with PresetCfg-based configs (e.g., CartpolePhysicsCfg) are created directly via gym.make() outside the Hydra pipeline. It makes _resolve_preset_defaults public as resolve_preset_defaults, exports it from the utils package, and adds a call to it inside parse_env_cfg so that preset fields are resolved to their default concrete configs before cfg.sim.device is accessed.

Key changes:

  • _resolve_preset_defaults → resolve_preset_defaults: renamed to a public API and added to __init__.pyi exports and __all__
  • parse_env_cfg in parse_cfg.py now calls resolve_preset_defaults(cfg) (with correctly captured return value) before accessing cfg.sim attributes, fixing the described AttributeError
  • Tests in test_hydra.py updated to use the renamed public function
  • The resolve_preset_defaults function has a latent logic bug in its recursive case: when a nested PresetCfg field's default is itself a PresetCfg, the return value of the recursive call is discarded (line 274), leaving the field as an unresolved PresetCfg. Existing test fixtures do not cover this doubly-nested case, so the bug is latent but real.

Confidence Score: 3/5

  • The core fix for root-level PresetCfg resolution is correct, but a latent recursive resolution bug could surface with doubly-nested PresetCfg defaults.
  • The PR correctly fixes the primary issue: parse_env_cfg now resolves root-level PresetCfg before accessing cfg.sim attributes. However, the resolve_preset_defaults function has a latent logic bug on line 274 where the return value of the recursive call is discarded when a nested PresetCfg field's default is itself a PresetCfg. This means doubly-nested presets would not be fully resolved. Current tests do not cover this case, so the bug is real but latent. The fix to the primary issue is solid and addresses the immediate CI test failures described in the PR.
  • source/isaaclab_tasks/isaaclab_tasks/utils/hydra.py (lines 270-276: recursive return value should be captured)

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["gym.make() / parse_env_cfg()"] --> B["load_cfg_from_registry()"]
    B --> C{"Is cfg a dict?"}
    C -- Yes --> D["raise RuntimeError"]
    C -- No --> E["resolve_preset_defaults(cfg)"]
    E --> F{"cfg is PresetCfg?"}
    F -- Yes --> G["get cfg.default"]
    G --> H{"default is not None?"}
    H -- Yes --> I["return resolve_preset_defaults(default)\n(recurse until non-PresetCfg)"]
    H -- No --> J["return cfg as-is"]
    F -- No --> K["Iterate __dataclass_fields__"]
    K --> L{"field is PresetCfg?"}
    L -- Yes --> M["setattr(cfg, name, default)\nresolve_preset_defaults(default)\n⚠️ return value discarded"]
    L -- No --> N["resolve_preset_defaults(value)\n(recurse into nested configclass)"]
    M --> O["return cfg"]
    N --> O
    I --> P["Resolved concrete cfg"]
    J --> P
    O --> P
    P --> Q["cfg.sim.device = device\ncfg.scene.num_envs = num_envs\n..."]
    Q --> R["Return cfg to caller"]
Loading

Last reviewed commit: afaffee

@greptile-apps greptile-apps 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.

8 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

# resolve PresetCfg fields (e.g. physics) to their default values
from isaaclab_tasks.utils.hydra import _resolve_preset_defaults

_resolve_preset_defaults(cfg)

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.

_resolve_preset_defaults is documented to return "the (possibly replaced) cfg if the root itself is a PresetCfg." Every other call site in hydra.py captures this return value:

env_cfg = _resolve_preset_defaults(env_cfg)
if agent_cfg is not None:
    agent_cfg = _resolve_preset_defaults(agent_cfg)

Here the return value is discarded. If the root config itself is a PresetCfg (e.g., CartpolePhysicsCfg as described in the PR), the resolved default will be returned but cfg will remain the raw PresetCfg object. Then cfg.sim.device = device on the next line will fail because PresetCfg does not have a .sim attribute. The fix is to capture the return value:

Suggested change
_resolve_preset_defaults(cfg)
cfg = _resolve_preset_defaults(cfg)

@@ -149,6 +149,11 @@ def parse_env_cfg(
if isinstance(cfg, dict):
raise RuntimeError(f"Configuration for the task: '{task_name}' is not a class. Please provide a class.")

# resolve PresetCfg fields (e.g. physics) to their default values
from isaaclab_tasks.utils.hydra import _resolve_preset_defaults

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.

This in-function import creates a circular dependency: hydra.py already imports from parse_cfg.py at module level (line 41). While the lazy import defers the ImportError until parse_env_cfg is called, it introduces fragile coupling.

More critically, hydra.py unconditionally raises an ImportError at module load if hydra-core is not installed (lines 31–36). This means parse_env_cfg — a general-purpose utility function — will now fail with a Hydra-specific error in any environment where hydra-core is absent, even if the caller never intended to use Hydra.

Consider refactoring _resolve_preset_defaults into a shared utility module (e.g., preset_utils.py) that neither parse_cfg.py nor hydra.py depends on, to break the circular dependency and remove the Hydra installation requirement from parse_env_cfg.

@AntoineRichard
AntoineRichard force-pushed the antoiner/fix/CI_preset_errors branch from 4374e59 to afaffee Compare March 3, 2026 15:09
@AntoineRichard

Copy link
Copy Markdown
Collaborator Author

@greptile

@AntoineRichard AntoineRichard changed the title Fix CI errors where the PresetCfg is never resolved when running tests Fixes CI errors where the PresetCfg is never resolved when running tests Mar 3, 2026
@greptile-apps

greptile-apps Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

source/isaaclab_tasks/isaaclab_tasks/utils/hydra.py, line 276
Discarded return value in recursive PresetCfg resolution

When a nested PresetCfg field's default is itself a PresetCfg, the return value of the recursive resolve_preset_defaults(default) call on line 274 is discarded. This leaves the field pointing to the intermediate PresetCfg object rather than the fully-resolved concrete config.

Consider a doubly-nested case:

EnvCfg
  └── sim: OuterPreset(PresetCfg)
              └── default: InnerPreset(PresetCfg)
                            └── default: ActualSimCfg

After execution:

  1. Line 273 sets cfg.sim to InnerPreset
  2. Line 274 calls resolve_preset_defaults(InnerPreset) which returns ActualSimCfg, but this return value is discarded
  3. cfg.sim remains InnerPreset instead of ActualSimCfg

The fix is to capture and apply the return value:

        if default is not None:
            setattr(cfg, name, resolve_preset_defaults(default))

Current tests only cover non-PresetCfg default fields, so this latent bug would surface once a PresetCfg with a nested PresetCfg default is introduced.

@kellyguo11
kellyguo11 merged commit a17e501 into isaac-sim:develop Mar 3, 2026
5 of 12 checks passed
kellyguo11 added a commit to kellyguo11/IsaacLab-public that referenced this pull request Mar 4, 2026
…aac-sim#4803)

Conflict in parse_cfg.py: kept HEAD's hydra-import-free PresetCfg
resolution (_is_preset_cfg / _resolve_presets_to_default) to avoid
the circular-import that would arise from importing resolve_preset_defaults
from hydra.py (which itself imports load_cfg_from_registry from parse_cfg).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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