Repository navigation
Fix sensor ancestor suffix trimming - #6068
AntoineRichard merged 1 commit into
Conversation
Trim only the terminal sensor-relative path when building rigid-body ancestor expressions so repeated child suffixes earlier in the prim path are preserved. Add a regression covering a repeated link/link sensor path.
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot — PR #6068
Summary
This PR fixes a bug in SensorBase._resolve_rigid_body_ancestor_expr() where str.replace() was used to strip the sensor-relative suffix from a target expression. Since str.replace() replaces the first occurrence (not the last), paths like /World/envs/env_.*/Robot/link/link would incorrectly strip the earlier /link segment, yielding /World/envs/env_.*/Robot instead of /World/envs/env_.*/Robot/link. The fix uses str.endswith() validation followed by slice-based suffix removal.
Design Assessment
✅ Correct approach. The fix replaces unbounded str.replace() with explicit suffix validation and slice removal — a well-known Python idiom that is both safe and efficient. The endswith() guard converts a silent data corruption into a loud RuntimeError, following Isaac Lab's fail-fast conventions for path resolution.
✅ Error message quality. The RuntimeError includes both the target expression and the relative path, providing sufficient context for debugging.
✅ Minimal blast radius. Only the final 3 lines of the method are changed. The ancestor traversal, early-return path (sensor == body), and pose resolution are untouched.
Findings
🟢 No critical or warning-level issues found.
🔵 Suggestion — consider removesuffix (Python 3.9+):
Since Isaac Lab requires Python ≥3.10, the implementation could use target_expr.removesuffix(suffix) after the endswith() check. This is purely stylistic — the current slice is equally correct and arguably more explicit given the guard clause.
🔵 Suggestion — test the negative path:
The test exercises the happy path (suffix is correctly terminal), but does not assert that the new RuntimeError is raised for the previously-buggy scenario (e.g., a malformed target_expr that doesn't end with the expected suffix). Adding a pytest.raises(RuntimeError) case would lock in the guard behavior.
Test Coverage
✅ Regression test included. test_rigid_body_ancestor_expr_trims_only_terminal_suffix creates the exact pathological topology (/Robot/link/link) and asserts the ancestor expression preserves the intermediate /link segment. This directly exercises the fixed code path.
RuntimeError guard. Low risk since the guard is straightforward, but worth considering for completeness.
CI Status
| Check | Status |
|---|---|
| pre-commit | ✅ pass |
| Build Wheel | ✅ pass |
| Broken Links | ✅ pass |
| Installation Tests | ⏳ pending |
| Changelog check | ⏳ pending |
| Docs build | ⏳ pending |
Core quality gates (pre-commit, wheel build) pass. Infrastructure checks still pending but unlikely to be affected by this change.
Verdict
✅ LGTM — Approve-worthy. Clean, minimal, well-tested bug fix with proper error handling. The suffix-slice approach is correct and robust. No blocking issues found.
Greptile SummaryThis PR fixes a path-trimming bug in
Confidence Score: 4/5Safe to merge; the fix is narrowly scoped and the new behavior is strictly better than silent string corruption. The core fix is correct and well-tested for the reported case. One minor gap: when target_expr equals suffix exactly, the slice returns an empty string that is passed downstream as a physics-view expression with no validation, which could produce a confusing failure. This is an extremely unlikely path in practice but would benefit from an explicit guard. The slice in sensor_base.py line 481 could produce an empty rigid_parent_expr; the new RuntimeError branch in the same function has no test coverage. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["_resolve_rigid_body_ancestor_expr()"] --> B["resolve first matching prim\ntarget_expr"]
B --> C["get_first_matching_ancestor_prim\nHasAPI RigidBodyAPI"]
C --> D{ancestor found?}
D -- No --> E["raise RuntimeError"]
D -- Yes --> F{ancestor == prim?}
F -- Yes --> G["return target_expr, None, None"]
F -- No --> H["MakeRelativePath\nsuffix = '/' + relative_path"]
H --> I{target_expr ends with suffix?}
I -- No --> J["raise RuntimeError\nnew: was silent corruption"]
I -- Yes --> K["rigid_parent_expr = target_expr at negative len suffix"]
K --> L["resolve_prim_pose"]
L --> M["return rigid_parent_expr, pos, quat"]
Reviews (1): Last reviewed commit: "Fix sensor ancestor suffix trimming" | Re-trigger Greptile |
| f"Failed to build rigid body ancestor expression: target expression {target_expr!r} does not end " | ||
| f"with relative path {relative_path!r}." | ||
| ) | ||
| rigid_parent_expr = target_expr[: -len(suffix)] |
There was a problem hiding this comment.
Empty
rigid_parent_expr when sensor is at path root
If target_expr equals suffix exactly (e.g. target_expr = "/link" with relative_path = "link"), target_expr[:-len(suffix)] evaluates to "". The empty string is then returned as rigid_parent_expr and used downstream as a physics-view expression, which would likely produce a silent failure or an unhelpful error at the call site. An explicit guard here would make the failure mode clearer, even though this degenerate case (sensor mounted at the USD stage root) is extremely unlikely in practice.
mmichelis
left a comment
There was a problem hiding this comment.
Nice fix! I added a quick point that could be nice to discuss.
Description
Fixes rigid-body ancestor expression resolution for sensors mounted under a
non-rigid child when the terminal child suffix also appears earlier in the path.
The old implementation used an unbounded
str.replace(), which could removemore than the sensor-relative suffix.
Simple example:
The fix verifies that the relative path is a terminal suffix and slices only that
end segment.
No issue filed.
Validation:
./isaaclab.sh -p -m pytest source/isaaclab/test/sensors/test_sensor_base.py::test_rigid_body_ancestor_expr_trims_only_terminal_suffix -qPATH=/tmp/git-lfs-v3.7.1:$PATH ./isaaclab.sh -fType of change
Screenshots
Not applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatsource/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bumpextension.toml— CI handles that)CONTRIBUTORS.mdor my name already exists there