Skip to content

Fix duplicate source-prim resolution for overlapping wildcard subtrees - #7526

Merged
kellyguo11 merged 4 commits into
isaac-sim:developfrom
diegoferigo-rai:diegoferigo/ovphysx-contact-sensor-dedup
Sep 26, 2026
Merged

kellyguo11 merged 4 commits into
isaac-sim:developfrom
diegoferigo-rai:diegoferigo/ovphysx-contact-sensor-dedup

Conversation

@diegoferigo-rai

@diegoferigo-rai diegoferigo-rai commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Nested body paths such as Robot/.*/left_knee can resolve the same physical body several times. This inflates the OVPhysX contact sensor's per-environment body count: one environment fails initialization, while three environments can pass the divisibility guard with an incorrect body count.

The shared resolver now returns each source prim once before validating expected_num_matches. It preserves first-match order, the first destination expression, and distinct bodies with the same leaf name. Assets and sensors consume that guarantee directly; no contact-sensor-specific deduplication is needed.

Root cause

#6841 made prim queries consistently use whole-path regular expressions. This correctly allows .* to cross /, but resolve_matching_prims_from_source still concatenated descendant results as though its matched roots were disjoint.

For Robot/pelvis/left_hip/left_knee, the contact sensor resolves the parent expression Robot/.* and filters descendants named left_knee. The matching roots include pelvis, left_hip, and left_knee itself. Expanding all three produces the same leaf three times. Flat hierarchies and expressions selecting disjoint roots do not expose that assumption.

The resolver owns this correction because other callers, including articulation discovery, validate match counts there. Fixing only the contact sensor leaves those callers exposed. The existing resolver test checked regex discovery without descendant filtering; it now exercises the composition with and without a clone plan.

Validation

  • Before the shared fix, both resolver cases fail with Expected 2 prims ... found 4, even with the original sensor-local patch present.
  • With the sensor-local patch removed and the shared resolver still unfixed, the consolidated contact test reproduces the CPU initialization failure with one environment and the incorrect CUDA body count with three environments.
  • After the shared fix: 19 cloner tests, 11 query tests, and 4 nested-contact cases pass (34 total).
  • The contact regression extends the existing nested-hierarchy test, sharing scene setup and retaining CPU/CUDA binding coverage, single/cloned environments, body names, counts, and force-buffer shapes.
  • uv run isaaclab -f and the package changelog gate pass. Documentation builds are left to CI.

Type of change

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

Release backport

  • Backport this pull request to the active release branch after it merges into develop

Checklist

Docker and GPU tests run on demand. Push the commits you want tested, then
comment run-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the formatting and lint checks with uv run isaaclab -f
  • 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 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

@diegoferigo-rai
diegoferigo-rai requested a review from a team September 3, 2026 08:40
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Sep 3, 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.

Isaac Lab Review Bot

The change deduplicates OVPhysX contact-sensor discovery results by concrete prim path while preserving first-match order. It directly addresses duplicate leaf registration from mid-path wildcards and includes focused regression coverage plus the required package changelog fragment.

  • Design and architecture: Deduplication occurs at the discovery boundary before body names, sensor counts, sensor patterns, and filter patterns are derived. This keeps all downstream consumers consistent and limits the change to the OVPhysX contact-sensor path without affecting the classic backend.
  • API: No public symbols or configuration fields change. The observable correction is that num_sensors, body_names, and force-buffer dimensions now represent unique resolved bodies for mid-path wildcard expressions. Existing ordering is preserved by retaining the first occurrence, and the behavior change is documented in the isaaclab_ov changelog.
  • Implementation: The implementation keys uniqueness on prim.GetPath().pathString and retains the corresponding expression used to construct each sensor glob. The regression test exercises one and multiple cloned environments on CPU and CUDA, checking the unique sensor count, body name, initialization path, and resulting force-buffer shape. The broad object annotation for the retained prim is less precise than the concrete USD type but does not create a material correctness or API issue.

No blocking issues. No inline issue met the actionable-evidence threshold; the assessment above records the review feedback.

Automated review; human maintainers own approval decisions.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes duplicate OVPhysX contact-sensor body discovery for mid-path wildcards by preserving only the first match for each USD prim path.

  • Deduplicates resolved contact bodies before sensor patterns and counts are constructed.
  • Adds CPU and CUDA regression coverage for nested bodies across one and multiple cloned environments.
  • Documents the correction in an isaaclab_ov changelog fragment.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable correctness, security, or maintainability issues identified.

The deduplication collapses only repeated references to the same uniquely identified USD prim, preserves the valid traversal order, and is covered across CPU, CUDA, and cloned-environment configurations.

Important Files Changed

Filename Overview
source/isaaclab_ov/isaaclab_ov/sensors/contact_sensor/contact_sensor.py Deduplicates repeated resolver results by unique USD prim path while preserving traversal order and the valid first expression.
source/isaaclab_ov/test/sensors/test_contact_sensor.py Adds focused regression coverage proving a nested wildcard leaf produces one sensor and the expected batched force shape.
source/isaaclab_ov/changelog.d/ovphysx-contact-sensor-dedup.rst Accurately documents the duplicate-discovery failure and its correction.

Reviews (1): Last reviewed commit: "Deduplicate ovphysx contact-sensor bodie..." | Re-trigger Greptile

@AntoineRichard AntoineRichard left a comment

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.

LGTM thanks!

The isaaclab_ov ContactSensor discovers bodies with
resolve_matching_prims_from_source, which matches every ancestor in phase
one and then collects the leaf as a descendant of each match in phase two.
With a mid-path wildcard prim path (for example
Robot/.*/left_ankle_roll_link) the same ankle body is returned once per
link in the chain, with no dedup by prim identity. That inflates the sensor
and filter counts and makes the physics-cloned init guard
sensor_count % num_sensors fire, breaking any reward reading a
self-collision force off the sensor. The classic
isaaclab.sensors.contact_sensor does not resolve discovery this way and is
unaffected.

Deduplicate the resolved matches by prim path before they are consumed, the
minimal fix that keeps the natural mid-path wildcard prim path working on
both the Newton and the ovphysx backends. Add a regression test that
authors a nested link chain and resolves a single leaf through a mid-path
wildcard, asserting the body is registered exactly once.
@diegoferigo-rai
diegoferigo-rai force-pushed the diegoferigo/ovphysx-contact-sensor-dedup branch from e15647d to 2f05dc0 Compare September 22, 2026 09:55
@diegoferigo-rai

Copy link
Copy Markdown
Contributor Author

I rebased this PR onto the latest develop and updated the regression test to use the current ClonePlan API and net_normal_forces_w. @AntoineRichard, could you please have another look?

@kellyguo11

Copy link
Copy Markdown
Contributor

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Sep 25, 2026
@ooctipus ooctipus changed the title Deduplicate ovphysx contact-sensor bodies from mid-path wildcards Fix duplicate source-prim resolution for overlapping wildcard subtrees Sep 26, 2026
@ooctipus ooctipus added the ci:run-docker Trigger the on-demand Docker and GPU CI workflow label Sep 26, 2026
@kellyguo11
kellyguo11 merged commit c59f95d into isaac-sim:develop Sep 26, 2026
52 of 53 checks passed
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 26, 2026
#7526)

# Description

Nested body paths such as `Robot/.*/left_knee` can resolve the same
physical body several times. This inflates the OVPhysX contact sensor's
per-environment body count: one environment fails initialization, while
three environments can pass the divisibility guard with an incorrect
body count.

The shared resolver now returns each source prim once before validating
`expected_num_matches`. It preserves first-match order, the first
destination expression, and distinct bodies with the same leaf name.
Assets and sensors consume that guarantee directly; no
contact-sensor-specific deduplication is needed.

## Root cause

#6841 made prim queries consistently use whole-path regular expressions.
This correctly allows `.*` to cross `/`, but
`resolve_matching_prims_from_source` still concatenated descendant
results as though its matched roots were disjoint.

For `Robot/pelvis/left_hip/left_knee`, the contact sensor resolves the
parent expression `Robot/.*` and filters descendants named `left_knee`.
The matching roots include `pelvis`, `left_hip`, and `left_knee` itself.
Expanding all three produces the same leaf three times. Flat hierarchies
and expressions selecting disjoint roots do not expose that assumption.

The resolver owns this correction because other callers, including
articulation discovery, validate match counts there. Fixing only the
contact sensor leaves those callers exposed. The existing resolver test
checked regex discovery without descendant filtering; it now exercises
the composition with and without a clone plan.

## Validation

- Before the shared fix, both resolver cases fail with `Expected 2 prims
... found 4`, even with the original sensor-local patch present.
- With the sensor-local patch removed and the shared resolver still
unfixed, the consolidated contact test reproduces the CPU initialization
failure with one environment and the incorrect CUDA body count with
three environments.
- After the shared fix: 19 cloner tests, 11 query tests, and 4
nested-contact cases pass (34 total).
- The contact regression extends the existing nested-hierarchy test,
sharing scene setup and retaining CPU/CUDA binding coverage,
single/cloned environments, body names, counts, and force-buffer shapes.
- `uv run isaaclab -f` and the package changelog gate pass.
Documentation builds are left to CI.

## Type of change

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

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

## Checklist

Docker and GPU tests run on demand. Push the commits you want tested,
then
comment `run-ci` on the pull request.

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the formatting and lint checks with `uv run isaaclab
-f`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] 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)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Co-authored-by: Kelly Guo <[email protected]>
Co-authored-by: Octi Zhang <[email protected]>

(cherry picked from commit c59f95d)
@isaaclab-bot

isaaclab-bot Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as 4d6241e.

@ooctipus ooctipus added this to the Isaac Lab 3.0 GA milestone Sep 26, 2026
@ooctipus ooctipus self-assigned this Sep 26, 2026
@ooctipus

Copy link
Copy Markdown
Collaborator

run-ci

@diegoferigo-rai
diegoferigo-rai deleted the diegoferigo/ovphysx-contact-sensor-dedup branch September 28, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-docker Trigger the on-demand Docker and GPU CI workflow isaac-lab Related to Isaac Lab team

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants