Skip to content

Add direct environment reset hook - #6510

Merged
AntoineRichard merged 2 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/direct-env-reset-hook
Jul 15, 2026
Merged

AntoineRichard merged 2 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/direct-env-reset-hook

Conversation

@AntoineRichard

Copy link
Copy Markdown
Collaborator

Description

Adds a protected DirectRLEnv reset hook that preserves the existing indexed reset behavior by default while allowing backend-native task implementations to complete reset processing from a device mask without materializing dynamic reset indices on the host.

CUDA torch.nonzero compaction requires determining a dynamic output size and can synchronize the stream. The hook isolates that policy decision without changing existing DirectRLEnv task semantics.

ManagerBasedRLEnv is intentionally not included. Its scene, event, recorder, curriculum, observation, action, reward, command, and termination reset contracts currently require compact environment IDs, so adding the same hook there would not yet provide a synchronization-free path.

This is one focused slice of superseded Draft PR #6509 and is independent of benchmark PR #6474.

Type of change

  • New feature (non-breaking protected extension point)

Validation

  • ./isaaclab.sh -p tools/changelog/cli.py check develop
  • ./isaaclab.sh -f before commit
  • ./isaaclab.sh -f after commit and before push
  • The source change was exercised by the original focused CPU/CUDA validation before the PR split; new test files are intentionally omitted from this slice.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • Documentation changes are not required for this protected hook
  • 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 for the touched package
  • My name already exists in CONTRIBUTORS.md

Allow direct tasks with backend-native mask reset support to bypass dynamic reset-index compaction while preserving the existing indexed reset behavior by default.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jul 14, 2026
@AntoineRichard AntoineRichard mentioned this pull request Jul 14, 2026
14 of 17 tasks
@AntoineRichard
AntoineRichard marked this pull request as ready for review July 14, 2026 08:59
@AntoineRichard
AntoineRichard requested a review from ooctipus July 14, 2026 09:00
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a direct-environment reset hook for mask-native reset implementations. The main changes are:

  • Adds _reset_envs_from_buffer() to DirectRLEnv.
  • Moves reset-index compaction and default reset handling into the hook.
  • Allows overrides to finish reset processing without returning compact indices.
  • Adds a changelog fragment for the new protected hook.

Confidence Score: 4/5

The new override path needs fixes before merging. A None return after a real reset can skip required same-step autoreset side effects.

  • Default behavior stays close to the old inline reset path.
  • Native mask reset overrides can skip RTX reset rerenders, which can produce stale sensor observations.
  • Native mask reset overrides can skip terminal-observation capture when compute_final_obs is enabled.

source/isaaclab/isaaclab/envs/direct_rl_env.py

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/envs/direct_rl_env.py Adds the reset hook and rewires step() to use it; the intended None return path can skip reset side effects.
source/isaaclab/changelog.d/ant-direct-device-mask-reset.rst Adds the changelog entry for the protected direct-environment reset hook.

Reviews (1): Last reviewed commit: "Add direct environment reset hook" | Re-trigger Greptile

self.extras["final_obs"] = terminal_obs
self._reset_idx(reset_env_ids)
reset_env_ids = self._reset_envs_from_buffer()
if reset_env_ids is not None and len(reset_env_ids) > 0:

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 Mask Reset Skips Rerender

When a mask-native override resets environments and returns None, this branch skips the post-reset rerender loop even if RTX sensors and reset rerenders are enabled. The later _get_observations() call can then read stale pre-reset sensor buffers for same-step autoreset observations.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in b5c94d0. A mask-native override that returns None now raises when RTX reset rerenders are required, preventing the step from returning stale sensor observations. Such overrides must delegate to the default indexed path for this configuration, and the hook docstring now states that restriction.

Comment on lines +665 to +676
def _reset_envs_from_buffer(self) -> torch.Tensor | None:
"""Reset environments marked in the reset buffer.

The default implementation compacts the reset mask into environment indices. CUDA
environments synchronize while determining the dynamic output size of
``torch.Tensor.nonzero``. Tasks with backend-native mask reset support may
override this hook and return None to avoid that synchronization.

Returns:
Reset environment indices, or None when an override completed reset
processing without materializing host-visible indices.
"""

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 Final Observation Becomes Optional

The hook contract allows an override to complete reset processing and return None, but the default hook also owns the compute_final_obs side effect. A native reset override that only performs the mask reset can therefore skip self.extras["final_obs"], so same-step autoreset consumers receive a missing or stale terminal observation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in b5c94d0. A mask-native override that returns None now raises when compute_final_obs is enabled, so terminal-observation capture cannot be silently skipped. Such overrides must delegate to the default indexed path for this configuration, and the hook docstring now states that restriction.

Reject synchronization-free reset overrides when terminal observations or RTX reset rerenders require compact reset indices. This prevents overrides from silently skipping same-step autoreset behavior.
@AntoineRichard
AntoineRichard merged commit fece607 into isaac-sim:develop Jul 15, 2026
38 checks passed
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
# Description

Adds a protected DirectRLEnv reset hook that preserves the existing
indexed reset behavior by default while allowing backend-native task
implementations to complete reset processing from a device mask without
materializing dynamic reset indices on the host.

CUDA torch.nonzero compaction requires determining a dynamic output size
and can synchronize the stream. The hook isolates that policy decision
without changing existing DirectRLEnv task semantics.

ManagerBasedRLEnv is intentionally not included. Its scene, event,
recorder, curriculum, observation, action, reward, command, and
termination reset contracts currently require compact environment IDs,
so adding the same hook there would not yet provide a
synchronization-free path.

This is one focused slice of superseded Draft PR isaac-sim#6509 and is
independent of benchmark PR isaac-sim#6474.

## Type of change

- New feature (non-breaking protected extension point)

## Validation

- ./isaaclab.sh -p tools/changelog/cli.py check develop
- ./isaaclab.sh -f before commit
- ./isaaclab.sh -f after commit and before push
- The source change was exercised by the original focused CPU/CUDA
validation before the PR split; new test files are intentionally omitted
from this slice.

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks with ./isaaclab.sh --format
- [x] Documentation changes are not required for this protected hook
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment for the touched package
- [x] My name already exists in CONTRIBUTORS.md
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.

2 participants