Episode termination precedence when both terminal and timeout flags are set#463
Merged
takuseno merged 1 commit intotakuseno:masterfrom Sep 10, 2025
Merged
Episode termination precedence when both terminal and timeout flags are set#463takuseno merged 1 commit intotakuseno:masterfrom
takuseno merged 1 commit intotakuseno:masterfrom
Conversation
takuseno
approved these changes
Sep 10, 2025
Owner
takuseno
left a comment
There was a problem hiding this comment.
LGTM. Thank you for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, when generating episode data with
EpisodeGenerator, an assertion erroris raised if an episode terminates in the same timestep at which truncation occurs.
However, it is possible for an environment to terminate in the same timestep in which the
TimeLimitwrapper truncates an episode. In this case, the environment’sstepmethod (see, e.g., Humanoid-v5) has already returned a termination signal, which theTimeLimitwrapper simply passes through while adding its truncation flag. As a result, both termination and truncation can beTruein the same timestep.To handle this overlap, I suggest giving precedence to termination. The rationale is:
Concretely, the assertion
is replaced with:
While the practical effect of this change is limited — since the
TransitionPickerdiscards the final timestep of each episode — it prevents assertion failures when constructing datasets from trajectories that contain termination–truncation overlaps.Another option would be to remove
This way, timeout information stays in the
_timeoutsattribute of theEpisodeGenerator, keeping it consistent with the environment’s return values, but deviating from the implied intention of the assertion if it was meant to be more than just a consistency check.