Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 29, 2025

This PR addresses issue #666 by documenting the confusing behavior of env.reset() in Atari environments when using the default terminal_on_life_loss=True setting.

closes #666

Problem

When using make_atari_env() with default settings, the EpisodicLifeEnv wrapper causes env.reset() to perform a no-op step instead of truly resetting the environment when the episode ends due to a life loss (not game over). This leads to unexpected behavior where consecutive calls to reset() return the same observation:

from stable_baselines3.common.env_util import make_atari_env

env = make_atari_env('BreakoutNoFrameskip-v4', n_envs=1, seed=0)

# These two calls may return different observations
obs1 = env.reset()  # First reset
obs2 = env.reset()  # Second reset - same obs

Solution

This PR adds comprehensive documentation to explain:

  1. Root cause: The EpisodicLifeEnv wrapper's reset() method only performs a true reset when self.was_real_done is True (game over), otherwise it executes a no-op step.

  2. Workaround: Users can avoid this behavior by setting terminal_on_life_loss=False:

env = make_atari_env(
    "BreakoutNoFrameskip-v4",
    n_envs=1,
    wrapper_kwargs=dict(terminal_on_life_loss=False)
)

Changes Made

  • Added detailed documentation to EpisodicLifeEnv class and reset() method docstrings
  • Updated make_atari_env() docstring with a note about this behavior
  • Added a note in the RL Tips documentation with a practical example
  • Updated changelog to record this documentation improvement

This is purely a documentation change with no code behavior modifications, ensuring existing functionality remains intact while helping users understand and work around this potentially confusing behavior.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: araffin <1973948+araffin@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Update the documentation to document the behavior described in #666 and mention how to avoid such behavior (by passing terminal_on_life_loss=False). Don't forget to update the changelog. Document Atari wrapper reset behavior and workaround for issue #666 Aug 29, 2025
@Copilot Copilot AI requested a review from araffin August 29, 2025 09:59
Copilot finished work on behalf of araffin August 29, 2025 09:59
@araffin araffin changed the title Document Atari wrapper reset behavior and workaround for issue #666 Document Atari wrapper reset behavior Aug 29, 2025
@araffin araffin marked this pull request as ready for review September 1, 2025 13:53
@araffin araffin merged commit 8cd8c62 into master Sep 1, 2025
4 checks passed
@araffin araffin deleted the copilot/fix-b1975246-02f5-4774-8cf1-737731887c11 branch September 1, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] env.reset() does not reset an environment for Atari

2 participants