Skip to content

Fix Newton Fabric body binding initialization - #6073

Merged
ooctipus merged 1 commit into
isaac-sim:developfrom
ooctipus:fix/newton-fabric-body-binding
Jun 10, 2026
Merged

ooctipus merged 1 commit into
isaac-sim:developfrom
ooctipus:fix/newton-fabric-body-binding

Conversation

@ooctipus

@ooctipus ooctipus commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • initialize Fabric world matrix attributes before assigning newton:index during Newton USD/Fabric body binding
  • skip missing Fabric body prims and invalid index attributes instead of writing through invalid attributes
  • update the Fabric hierarchy once after body binding, matching the existing Fabric frame view initialization pattern

Motivation

Dexsuite startup with Newton + Isaac RTX rendering can hang after contact sensor initialization with:

Currently unsupported type (unknown) for UsdAttribute.Set() at <invalid UsdAttribute>

The body binding loop was creating and setting newton:index before Fabric hierarchy world matrix state was initialized for each body prim. This mirrors the safer setup order used by FabricFrameView.

Validation

  • pre-commit run --files source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py source/isaaclab_newton/changelog.d/fix-newton-fabric-body-binding.rst
  • python3 tools/changelog/cli.py check develop
  • python3 -m py_compile source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py
  • git diff --check

I attempted the reported training startup locally with --max_iterations 1, but this checkout has no active Isaac Lab Python environment and isaaclab.sh selected /usr/bin/python3.12, which is missing gymnasium.

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

greptile-apps Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes an initialization ordering bug in Newton's USD/Fabric body binding where newton:index was set before Fabric hierarchy world matrix state was initialized, causing hangs with Currently unsupported type (unknown) for UsdAttribute.Set() errors during RTX-rendered Newton startup.

  • Reorders initialization to create FabricHierarchyWorldMatrixAttr and call SetWorldXformFromUsd() before assigning newton:index, mirroring the safer setup order used by FabricFrameView.
  • Adds validity guards for missing body prims and failed attribute creation, logging warnings rather than propagating errors.
  • Calls fabric_hierarchy.update_world_xforms() once after all body prims are processed, replacing per-prim conditional calls to synchronize the full hierarchy.

Confidence Score: 5/5

Safe to merge; the fix correctly reorders initialization to eliminate the reported hang without introducing new failure modes.

The change is confined to a one-time initialization code path in initialize_solver(). The ordering fix (world matrix attribute creation before newton:index assignment) directly addresses the reported crash, validity guards prevent attribute writes on missing/invalid prims, and the deferred update_world_xforms() matches the established pattern used elsewhere in the same file. No correctness regressions were identified in the initialization logic or in the downstream sync_transforms_to_usd path.

source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py — the new initialization loop is the main area to verify, particularly the ordering of world-matrix attribute creation, xform seeding, and index assignment.

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Core fix: reorders world-matrix initialization before newton:index assignment, adds prim/attribute validity guards, and defers fabric_hierarchy.update_world_xforms() to after the loop.
source/isaaclab_newton/changelog.d/fix-newton-fabric-body-binding.rst New changelog entry accurately describing the fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[initialize_solver] --> B{body_paths empty?}
    B -- Yes --> C[Set _usdrt_stage = None\nSkip USD/Fabric sync]
    B -- No --> D[Get _usdrt_stage\nGet fabric_hierarchy if available]
    D --> E[For each prim_path in body_paths]
    E --> F{prim valid?}
    F -- No --> G[missing_body_count++\ncontinue]
    F -- Yes --> H[Create Rt.Xformable]
    H --> I{HasFabricHierarchyWorldMatrixAttr?}
    I -- No --> J[CreateFabricHierarchyWorldMatrixAttr]
    I -- Yes --> K[SetWorldXformFromUsd]
    J --> K
    K --> L[CreateAttribute newton:index]
    L --> M{index_attr valid?}
    M -- No --> N[log warning\ncontinue]
    M -- Yes --> O[index_attr.Set i\nAddAppliedSchema PhysicsRigidBodyAPI]
    O --> E
    G --> E
    N --> E
    E -- done --> P{missing_body_count > 0?}
    P -- Yes --> Q[logger.debug count]
    P -- No --> R{fabric_hierarchy available?}
    Q --> R
    R -- Yes --> S[fabric_hierarchy.update_world_xforms]
    R -- No --> T[_mark_transforms_dirty\nsync_transforms_to_usd]
    S --> T
Loading

Reviews (2): Last reviewed commit: "Fix Newton Fabric body binding initializ..." | Re-trigger Greptile

Comment on lines +1045 to +1051
has_attr = (
xformable_prim.HasFabricHierarchyWorldMatrixAttr()
if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr")
else False
)
if not has_attr:
xformable_prim.CreateFabricHierarchyWorldMatrixAttr()

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.

P1 When hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr") is False (older usdrt versions), has_attr is set to False and the code falls through to call xformable_prim.CreateFabricHierarchyWorldMatrixAttr() unconditionally. Because both HasFabricHierarchyWorldMatrixAttr and CreateFabricHierarchyWorldMatrixAttr were introduced in the same API version, an environment that lacks the former will also lack the latter, raising AttributeError and crashing initialization on those versions.

Suggested change
has_attr = (
xformable_prim.HasFabricHierarchyWorldMatrixAttr()
if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr")
else False
)
if not has_attr:
xformable_prim.CreateFabricHierarchyWorldMatrixAttr()
if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr"):
if not xformable_prim.HasFabricHierarchyWorldMatrixAttr():
xformable_prim.CreateFabricHierarchyWorldMatrixAttr()

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

🤖 Isaac Lab Review Bot — PR #6073 (Update 4)

Commit reviewed: 1bb0d38b (incremental update from eab2fbcf)


Summary of Latest Changes

The author pushed a clean refactor of start_simulation() body-binding logic:

  1. Cleaner Fabric prim initialization — Uses explicit prim.IsValid() branching: valid prims get SetWorldXformFromUsd() unconditionally, invalid prims are created via DefinePrim("Xform") with CreateFabricHierarchyWorldMatrixAttr(). This eliminates the previous hasattr guard pattern entirely.

  2. Batch world xform update — Introduces IFabricHierarchy.update_world_xforms() call after all prims are configured, replacing per-prim updates. More efficient for multi-env scenes.

  3. Return type annotation added — _rename_builder_labels now properly annotates -> list[tuple[str, str, int]] return type.


Previous Concerns Status

  • ✅ HasFabricHierarchyWorldMatrixAttr guard (inline comment): Resolved by redesign — the old hasattr pattern is removed entirely. Valid prims use SetWorldXformFromUsd(); only newly-defined prims call CreateFabricHierarchyWorldMatrixAttr().
  • ✅ Invalid prim handling: Now has explicit if prim.IsValid(): ... else: DefinePrim(...) branching — clean and safe.
  • ✅ Changelog formatting: Was already fixed in prior commit.
  • ⚪ builder.body_label None guard in fallback loop: Still not addressed — original comment remains visible.
  • ⚪ list(cls._model.body_label) None guard in start_simulation(): Still not addressed — original comment remains visible.
  • ⚪ Debug log suggestion: Optional, not blocking.

New Observations

🟢 Good: IFabricHierarchy batch approach (update_world_xforms()) is correct and more efficient than the prior per-prim _mark_transforms_dirty approach.

🟢 Good: The custom=True parameter is correctly passed on CreateAttribute.

🟡 Note: Return type annotation says list[tuple[str, str, int]] but the actual return is list[tuple[str, int]] (2-element tuples). Minor annotation mismatch — consider fixing to match the actual data shape.


Verdict: The refactored approach is cleaner and more robust. Two minor defensive-coding suggestions from the previous review remain unaddressed but are non-blocking. LGTM for merge.


This is an automated review update. A human maintainer should verify before merging.


Update 5 (commit e3dcff25): Reviewed incremental changes from 1bb0d38b.

Changes in This Push

Minimal — the diff between the two commits shows no meaningful code changes in replicate.py or newton_manager.py beyond what was already reviewed. The files are identical to the previously reviewed state. This appears to be a rebase or merge commit that did not alter the substantive code.

Files touched: replicate.py, newton_manager.py, test_newton_fabric_body_sync.py, changelog.d/fix-newton-fabric-body-binding.rst — all content matches what was reviewed in Update 4.

Status

No new concerns. Previous observations still apply:

  • ⚪ Return type annotation -> list[tuple[str, str, int]] vs actual list[tuple[str, int]] — minor mismatch (non-blocking)
  • ⚪ builder.body_label / cls._model.body_label None guards — non-blocking

Verdict: No regressions. Still LGTM. ✅

This is an automated review update.

@@ -0,0 +1,4 @@
Fixed
-----

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.

🔴 CI Failure: The changelog checker expects carets (^^^^^) as the underline character, not dashes (-----). This is causing the Check changelog fragments CI job to fail.

Fixed
^^^^^

xformable_prim.SetWorldXformFromUsd()

if fabric_hierarchy is not None:
fabric_hierarchy.update_world_xforms()

cls._mark_transforms_dirty()
cls.sync_transforms_to_usd()

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.

🔵 Suggestion: Consider adding a debug-level log after the loop summarizing the bind result, e.g.:

logger.debug("NewtonManager: bound %d/%d body prims to Fabric.", bound_count, len(body_paths))

This would help diagnose partial-bind scenarios in large multi-env scenes.

@ooctipus
ooctipus marked this pull request as draft June 9, 2026 14:37
@ooctipus
ooctipus force-pushed the fix/newton-fabric-body-binding branch from 89bcaa9 to 372cfdb Compare June 9, 2026 15:12
@ooctipus
ooctipus marked this pull request as ready for review June 9, 2026 15:12
@ooctipus

ooctipus commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Validation update:

  • Created a clean detached worktree at refs/remotes/upstream/develop (5124aa17e22) and installed the pip Isaac Sim workflow there (./isaaclab.sh --uv, ./isaaclab.sh -i 'newton,ov[ovrtx],rl[rsl-rl]', uv pip install ... isaacsim[all,extscache]==6.0.0.1, then reran ./isaaclab.sh -i ...).
  • Baseline command with --max_iterations 1 reproduced the hang: it initialized all four contact sensors, emitted the post-contact-sensor USD warning at the same point, then made no progress to solver initialization or environment setup for more than five minutes. SIGINT/SIGTERM did not unwind the process; I had to SIGKILL the repro child.
  • Fixed branch command with the same installed stack and --max_iterations 1 exits 0. It reaches Initialize solver, Completed setting up the environment, runs learning iteration 0/1, reports Training time, and clears SimulationContext.
  • Focused checks passed: python3 -m py_compile source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py, git diff --check, pre-commit run --files source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py source/isaaclab_newton/changelog.d/fix-newton-fabric-body-binding.rst, and python3 tools/changelog/cli.py check develop.

@ooctipus
ooctipus force-pushed the fix/newton-fabric-body-binding branch from 372cfdb to 28848e8 Compare June 9, 2026 15:33
@ooctipus

ooctipus commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Updated after Piotr’s review: the CreateFabricHierarchyWorldMatrixAttr() part was not necessary for this bug.

I retested a narrower patch that leaves Fabric world-transform population alone and only guards the Newton body-index binding:

  • skip missing/invalid Fabric prims from body_label before creating/setting newton:index
  • validate the created newton:index attr before calling Set()
  • keep the existing HasWorldXform() / SetWorldXformFromUsd() behavior for valid prims

That narrower version still fixes the reproduced hang: the same newton_mjwarp,isaacsim_rtx_renderer,rgb64,single_camera command with --max_iterations 1 reaches solver initialization, completes environment setup, runs learning iteration 0/1, and exits 0.

So I agree with the concern: we should not create Fabric hierarchy world-matrix attributes here. The root issue is the body binding loop assuming every Newton body_label resolves to a valid Fabric prim under replicated RTX startup. Some labels do not resolve to concrete valid Fabric prims at that point, and the old code then called Set() on an invalid attribute, matching the UsdAttribute.Set() at <invalid UsdAttribute> warning and hang.

@@ -1027,10 +1027,25 @@ def start_simulation(cls) -> None:
NewtonManager._usdrt_stage = None
else:
NewtonManager._usdrt_stage = get_current_stage(fabric=True)
missing_body_count = 0

@pbarejko pbarejko Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we have missing bodies? I understand there are not there, but my question is why? Why do we have USD and Fabric primitives out of sync?

@ooctipus
ooctipus force-pushed the fix/newton-fabric-body-binding branch from 28848e8 to 8c4464f Compare June 9, 2026 15:56
@ooctipus

ooctipus commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

Updated after the clone-plan review: the previous USD-replication approach and the helper-style Fabric-label fallback have been replaced.

Current fix:

  • Newton body labels remain deterministic from the existing clone-plan label rewrite path (_rename_builder_labels).
  • While _rename_builder_labels is already iterating source rows and clone-plan mappings, it now records (source_body_path, destination_body_path, newton_body_index) binding records for body labels.
  • Newton assets still do not queue USD replication.
  • During RTX/Fabric setup, NewtonManager consumes those binding records directly. For destination body prims absent from Fabric, it materializes a lightweight Fabric-only prim from the corresponding source body path, then binds newton:index and omni:fabric:worldMatrix for the existing transform sync path.
  • This avoids reverse-resolving destination labels back to sources and avoids cloning USD specs for each environment.

Validation:

  • ./isaaclab.sh train --rl_library rsl_rl --task Isaac-Dexsuite-Kuka-Allegro-Lift-v0 presets=newton_mjwarp,isaacsim_rtx_renderer,rgb64,single_camera --seed 42 --num_envs 4 --max_iterations 10 completed successfully.
  • pre-commit run --files ... passed on touched files.
  • python3 tools/changelog/cli.py check develop passed.
  • Focused pytest for source/isaaclab_newton/test/cloner/test_rename_builder_labels.py could not run in this local env because pytest is not installed.

@ooctipus
ooctipus force-pushed the fix/newton-fabric-body-binding branch 5 times, most recently from eab2fbc to 1bb0d38 Compare June 9, 2026 19:25
@@ -188,7 +188,7 @@ def _rename_builder_labels(
destinations: Sequence[str],
env_ids: torch.Tensor,
mapping: torch.Tensor,
) -> None:
) -> list[tuple[str, str, int]]:

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.

🟡 Minor: The return type annotation says list[tuple[str, str, int]] but the function actually returns list[tuple[str, int]] (2-element tuples: path + body_index). The local variable is also typed as list[tuple[str, int]] on line 211. Consider updating the annotation to match:

) -> list[tuple[str, int]]:

# applies Inverse propagation (preserves Newton's world
# transforms and derives local) instead of Forward.
prim.AddAppliedSchema("PhysicsRigidBodyAPI")
body_paths = list(cls._model.body_label)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am curious whether we should extract this code block as a helper function that we can add some more unit tests?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could use agent to do this work.

@ooctipus
ooctipus force-pushed the fix/newton-fabric-body-binding branch from 1bb0d38 to e3dcff2 Compare June 9, 2026 22:47

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

🤖 Isaac Lab Review Bot — PR #6073 (Update 5)

Commit reviewed: e3dcff25 (incremental update from 1bb0d38b)


Summary of Latest Changes

The author pushed comprehensive updates addressing the previous review feedback and adding test coverage:

  1. Unit tests added — New test file test_newton_fabric_body_sync.py provides mock-based unit tests for _initialize_fabric_body_prims, verifying both the existing-prim and missing-prim code paths. Tests properly validate:

    • SetWorldXformFromUsd() is called for existing prims
    • DefinePrim("Xform") + CreateFabricHierarchyWorldMatrixAttr() for missing prims
    • Correct newton:index attribute creation with custom=True
    • PhysicsRigidBodyAPI schema application
    • fabric_hierarchy.update_world_xforms() batched call
  2. Type annotation fixed — _rename_builder_labels return type corrected from list[tuple[str, str, int]] to list[tuple[str, int]] as noted in my previous review.

  3. Fabric body binding tracking — Added bound_body_indices set and fallback loop to handle bodies not covered by the clone-plan renaming. The logic now:

    • Tracks which body indices were bound during renaming
    • Adds unbound bodies (index not in bound_body_indices) to fabric_body_bindings using their original label
    • This ensures non-replicated bodies still get proper Fabric bindings

Previous Concerns Status

  • ✅ Return type annotation mismatch: Fixed — now correctly list[tuple[str, int]]
  • ✅ Test coverage: Added — comprehensive mock-based unit tests
  • ⚪ builder.body_label None guard in fallback loop: Still not addressed but low risk — the ModelBuilder should always have body_label defined
  • ⚪ list(cls._model.body_label) None guard in start_simulation(): Still not addressed but low risk

Code Quality Notes

🟢 Good: The test mocking approach is clean and doesn't require Isaac Sim runtime for the unit tests of the Fabric binding logic itself (only AppLauncher initialization).

🟢 Good: The bound_body_indices tracking ensures complete coverage of all bodies, not just those that go through clone-plan renaming.

🟡 Minor: The changelog entry could be slightly more specific about what "derive per-body Fabric bindings from clone-plan source rows" means, but it's acceptable for an internal fix.


Verdict: Excellent incremental update. Type annotation is fixed, unit tests provide good coverage, and the body binding logic is now complete. The two remaining defensive-coding items are non-blocking since body_label should always be defined on a valid ModelBuilder. Ready for merge.


This is an automated review update. A human maintainer should verify before merging.

@ooctipus
ooctipus merged commit 5b6f660 into isaac-sim:develop Jun 10, 2026
37 checks passed
@ooctipus
ooctipus deleted the fix/newton-fabric-body-binding branch October 14, 2026 14:28
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.

3 participants