Skip to content

[Fix] Separate SimulationContext construction from lookup - #7722

Merged
ooctipus merged 3 commits into
isaac-sim:developfrom
hujc7:jichuanh/simcontext-device-guard
Sep 21, 2026
Merged

ooctipus merged 3 commits into
isaac-sim:developfrom
hujc7:jichuanh/simcontext-device-guard

Conversation

@hujc7

@hujc7 hujc7 commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Separate SimulationContext construction from lookup. A second construction previously returned the live singleton and silently discarded its configuration, including a requested device change (NVBug 6677911).

  • SimulationContext(cfg) constructs a context and raises if one already exists, including no-argument construction or re-passing the same cfg.
  • SimulationContext.instance() retrieves the live context.
  • SimulationContext.clear_instance() releases it before constructing a replacement.

Removed the singleton-reusing __new__, configuration/device comparison helper, and warn-and-ignore path. Native-backend sharing remains the registry's responsibility; this change does not alter it or introduce concurrent simulation contexts.

The follow-up removes 49 production lines compared with the previous PR revision. Thirteen existing test suites now release the contexts they construct instead of accidentally borrowing a previous test's context. No production caller migration was needed.

Compatibility

Breaking: callers using repeated SimulationContext(...) as lookup must switch to SimulationContext.instance(). To apply a new configuration, tear down with clear_instance() before constructing again. The class documentation and major changelog fragment include this migration.

Validation

  • Verified the revised singleton regression test fails on the previous implementation and passes with the fix.
  • GPU 0 / CPU: test_simulation_context.py: 51 passed; test_build_simulation_context_headless.py: 15 passed, run in separate processes because each launches Kit.
  • Nine schema/fragment suites: 165 passed.
  • Four manager suites: 38 passed. Total: 269 passed.
  • uv run --no-sync isaaclab -f: passed, including changelog validation against the PR merge base.

Type of change

  • Bug fix
  • Breaking change with migration guidance

Release backport

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

Checklist

  • Read the contribution guidelines
  • Ran formatting and lint checks
  • Updated public API documentation and migration guidance
  • Added no new runtime warnings
  • Verified the regression test fails before the fix and passes afterward
  • Added a changelog fragment for the changed package
  • Contributor already listed in CONTRIBUTORS.md

SimulationContext.__new__ returns the existing singleton and __init__ returns
before storing the config, so a second construction discarded every field of
the config it was handed. A caller that set SimulationCfg(device=...) on a
second context got no exception, no warning and no log line, and the
simulation stayed on the original device. The OvPhysxManager device lock never
saw the request: it is only reached through the construction branch that a
live instance skips, which is why the drop is backend-agnostic rather than
specific to one physics manager.

Ignoring a device request is harder to diagnose than failing it, and moving a
running simulation to another device is not something the singleton can do. A
repeat construction that would need a different device now raises; one that
differs only in other fields warns and is still ignored. Reaching the existing
instance through instance() or a no-argument construction is unchanged, as is
the clear_instance() and rebuild lifecycle.

The "cuda" alias resolution moves into a shared helper so the new comparison
and the existing normalization cannot drift apart and disagree about whether
"cuda" and "cuda:0" name the same device.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Sep 10, 2026
@hujc7
hujc7 marked this pull request as ready for review September 15, 2026 21:37
@hujc7
hujc7 requested a review from a team September 15, 2026 21:37
@hujc7

hujc7 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator Author

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 15, 2026
@greptile-apps

greptile-apps Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the intended singleton-reuse behavior covered by focused regression tests.

Summary

This PR prevents repeated SimulationContext construction from silently ignoring a conflicting device request while preserving singleton reuse.

  • Expands bare cuda aliases through a shared normalization helper.
  • Raises when a repeat construction requests a different device.
  • Warns when another distinct configuration is ignored.
  • Adds regression coverage and documents the behavior change.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Construct SimulationContext] --> B{Live instance exists?}
    B -- No --> C[Initialize from configuration]
    C --> D[Normalize CUDA alias]
    D --> E[Register singleton]
    B -- Yes --> F{Configuration omitted or live object?}
    F -- Yes --> G[Return existing instance silently]
    F -- No --> H[Resolve requested device]
    H --> I{Matches running device?}
    I -- No --> J[Raise RuntimeError]
    I -- Yes --> K[Warn that configuration is ignored]
    K --> G
Loading

Reviews (1) · Last reviewed commit: "Merge remote-tracking branch 'upstream/d..."

@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 reuse guard correctly distinguishes conflicting-device requests, but the updated public class docstring inaccurately says every repeat construction returns the existing instance and ignores its configuration.

  • Design and architecture: Keeping reuse validation in SimulationContext.__init__ before the singleton early return is coherent, and sharing CUDA alias normalization avoids inconsistent device comparisons. The class-level description of that singleton behavior must reflect the guard’s exception path.
  • API: The documented contract contradicts the implementation: a repeat construction with a different device raises RuntimeError rather than returning normally and ignoring the configuration. Qualify the class docstring to distinguish same-device ignored configurations from conflicting-device requests.
  • Implementation: The changed implementation checks reuse before mutating state and consistently normalizes bare cuda aliases. The actionable issue is the inaccurate public documentation at the changed class docstring.

Minor fixes needed. Posted 1 actionable finding inline.

Automated review; human maintainers own approval decisions.

* Rendering and visualization

The singleton instance can be accessed using the ``instance()`` class method.
The singleton instance can be accessed using the ``instance()`` class method. Constructing

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.

🟡 Warning · Api — Class docstring omits new device-conflict RuntimeError

The added class-level text states that constructing the class again "returns that instance and ignores the configuration passed in", but _check_reuse_request now raises RuntimeError when the requested device differs from the running one. The primary public documentation therefore states the pre-change contract and contradicts the __init__ Raises: section and the changelog fragment. Qualify the sentence to distinguish same-device ignored configurations from conflicting-device requests.

@ooctipus ooctipus changed the title [Fix] Stop SimulationContext silently discarding a second construction's config [Fix] Separate SimulationContext construction from lookup Sep 21, 2026
@ooctipus

Copy link
Copy Markdown
Collaborator

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 21, 2026
@ooctipus
ooctipus merged commit 4cf439d into isaac-sim:develop Sep 21, 2026
53 checks passed
@ooctipus
ooctipus deleted the jichuanh/simcontext-device-guard branch September 21, 2026 06:47
ooctipus pushed a commit to ooctipus/IsaacLab that referenced this pull request Sep 23, 2026
…7722)

Separate `SimulationContext` construction from lookup. A second
construction previously returned the live singleton and silently
discarded its configuration, including a requested device change (NVBug
6677911).

- `SimulationContext(cfg)` constructs a context and raises if one
already exists, including no-argument construction or re-passing the
same cfg.
- `SimulationContext.instance()` retrieves the live context.
- `SimulationContext.clear_instance()` releases it before constructing a
replacement.

Removed the singleton-reusing `__new__`, configuration/device comparison
helper, and warn-and-ignore path. Native-backend sharing remains the
registry's responsibility; this change does not alter it or introduce
concurrent simulation contexts.

The follow-up removes 49 production lines compared with the previous PR
revision. Thirteen existing test suites now release the contexts they
construct instead of accidentally borrowing a previous test's context.
No production caller migration was needed.

**Breaking:** callers using repeated `SimulationContext(...)` as lookup
must switch to `SimulationContext.instance()`. To apply a new
configuration, tear down with `clear_instance()` before constructing
again. The class documentation and major changelog fragment include this
migration.

- Verified the revised singleton regression test fails on the previous
implementation and passes with the fix.
- GPU 0 / CPU: `test_simulation_context.py`: **51 passed**;
`test_build_simulation_context_headless.py`: **15 passed**, run in
separate processes because each launches Kit.
- Nine schema/fragment suites: **165 passed**.
- Four manager suites: **38 passed**. Total: **269 passed**.
- `uv run --no-sync isaaclab -f`: passed, including changelog validation
against the PR merge base.

- Bug fix
- Breaking change with migration guidance

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

- [x] Read the contribution guidelines
- [x] Ran formatting and lint checks
- [x] Updated public API documentation and migration guidance
- [x] Added no new runtime warnings
- [x] Verified the regression test fails before the fix and passes
afterward
- [x] Added a changelog fragment for the changed package
- [x] Contributor already listed in `CONTRIBUTORS.md`

---------

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

(cherry picked from commit 4cf439d)
ooctipus added a commit that referenced this pull request Sep 24, 2026
…ng docs (#7957)

Backports the three changes from the September 20–23 `develop` audit
that are missing from `release/3.0.0`, alongside the existing
cloning-guide backport:

- #7722 (`4cf439dfeb`): reject a second `SimulationContext` construction
instead of silently discarding its configuration. Includes the original
fixture cleanup and regression coverage.
- #7893 (`22fcd71bc4`): validate DelayBuffer lag values before mutating
its live configuration.
- #7947 (`6e9ef17f59`): make `v3.0.0-EA` the default documentation
version in deployment and local multi-version builds.
- #7129 (`354168560f`): clarify that `replicate_physics=False` skips the
active physics context while other declared replication contexts still
run.

**Compatibility:** repeated `SimulationContext(...)` calls now raise.
Retrieve the live context with `SimulationContext.instance()`, or call
`clear_instance()` before constructing a replacement. The original major
changelog fragment includes this migration.

The runtime and test files match current `develop`. The docs-default
backport adapts the release branch's existing redirect template,
validates the target page, and preserves explicit overrides. The
cloning-guide backport preserves the current release APIs; its obsolete
sections were already removed.

## Release audit

Checked all **35 PRs** merged into `develop` from **2026-09-20 16:43:18
UTC** through `cff81e8473` (September 23), against release head
`5d3e0b695e`. **32 are already covered; the remaining three are included
here.** Git history, patch equivalence, GitHub's merged PR list, and
remaining file differences were checked. Branch-specific
version/changelog compilation and existing release-only changes are
preserved.

<details>
<summary>Already covered PRs</summary>

26 have an equivalent patch in release: #7919, #7922, #7923, #7924,
#7925, #6758, #7928, #7902, #7927, #7891, #7931, #7691, #7861, #7929,
#7916, #7939, #4609, #7942, #7940, #7948, #7937, #7955, #7960, #7961,
#7970, #7958.

Six were squash-merged or adapted: #7530 and #7899 in #7926; #7637 in
#7933; #7860 in #7936; #7954 and #7950 in #7964. Their implementation
differences were checked against the current release tree.

</details>

## Validation

- **276 tests passed**: SimulationContext (51, including CPU/CUDA),
headless context construction (15), nine schema/fragment suites (165),
four manager suites (38), and DelayBuffer (7).
- Both backported regressions reproduce with the original release
implementations.
- Docs redirect recipe: local/deployment EA defaults, explicit override,
and missing-target rejection passed with a stubbed Sphinx builder.
- All 22 changed files match the intended backport scope; `uv run
isaaclab -f` and `git diff --check` passed.
- Fresh Sphinx validation (`-b dummy -W --keep-going`): passed without
warnings, excluding static assets as the HTML builder does. Full HTML
documentation CI is running.

Local runtime validation used PyTorch 2.12.0, CUDA 13.0, Isaac Sim
6.0.1.0, and an RTX 5090. Existing runtime/deprecation warnings
occurred; the CI jobs validate the pinned environments.

The previous [docs CI
failure](https://github.com/isaac-sim/IsaacLab/actions/runs/35795116307/job/106972539281)
was an external connection reset fetching the Omniverse intersphinx
inventory, producing one warning under `-W`. That URL returned HTTP 200
when rechecked. This update starts a fresh docs build.

---------

Co-authored-by: hujc <[email protected]>
Co-authored-by: Zihan Xu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants