﻿# Gymnasium vector autoreset: keep the final transition separate from the reset observation

Build Gymnasium vector replay data around the configured autoreset mode, preserving final_obs masks and excluding reset-only returns from action transitions.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/simulation-gymnasium-vector-autoreset-final-observation/
Language: en

## A valid array can describe the wrong episode

A parallel robot collector appends every returned vector observation as the successor of the action it just submitted. At an episode boundary, an automatic reset can replace that observation with the next episode’s initial state. Shape and type remain valid while the replay transition becomes impossible. Determine the configured autoreset mode before defining the collector’s transition rule. The observation used for the next policy call need not be the observation that belongs in the preceding transition.

## Same-step mode returns a new beginning

Farama’s [autoreset explanation](https://farama.org/Vector-Autoreset-Mode) states that same-step mode resets an ended sub-environment within that step call. The ordinary returned observation is then the reset observation; the actual final observation is supplied separately. The inspected [synchronous implementation](https://raw.githubusercontent.com/Farama-Foundation/Gymnasium/v1.4.0/gymnasium/vector/sync_vector_env.py) in Gymnasium 1.4.0 uses final_obs and final_info for this path. Keep the final successor for the stored transition and the reset observation for the following policy input. Do not swap those distinct roles merely to simplify buffer assignment.

## Next-step mode includes a reset-only return

In next-step mode, the ending transition returns its final observation normally. The following step call resets that sub-environment instead of applying its submitted action. The inspected implementation emits a reset observation with a zero reward and false ending flags for that reset path. Exclude that reset-only entry from action-transition collection or mask it appropriately. The action array can contain an entry for the sub-environment without proving that this particular action was executed there.

## Preserve per-environment information validity

The [information aggregation implementation](https://raw.githubusercontent.com/Farama-Foundation/Gymnasium/v1.4.0/gymnasium/vector/vector_env.py) pairs fields with per-environment masks. For final_obs, inspect the corresponding validity mask rather than assume every vector position contains a final observation. Some sub-environments continue while others reset. Preserve episode identity per position and retain the configured mode with the artifact. Do not generalize one wrapper’s historical final-observation field name to every release, vectorizer and mode; inspect the implementation and wrapper chain used by the actual collector.

## Propose staggered episode endings

A proposed fixture should make sub-environments end on different calls and use unmistakably different final and reset observations. Check same-step final-observation recovery, next-step reset-entry exclusion and manual reset behavior when autoreset is disabled. Inspect both recorded transitions and subsequent policy inputs. No Gymnasium vector rollout was executed here. Acceptance should show that no stored action crosses an episode boundary and that every successor belongs to the action actually executed in that sub-environment.

## Separate collection integrity from policy performance

The [LeRobot episode guide](/journal/fg2-lerobot-v3-episode-boundaries-not-shared-file-boundaries/) covers stored trajectory boundaries; [stack reproducibility](/journal/software-stack-reproducibility/) supports retaining vectorizer and wrapper revisions. Here acceptance establishes valid live transition assembly. It does not establish reward quality, learning convergence or real robot performance. Those evaluations become interpretable only after automatic reset no longer substitutes another episode’s state or an unapplied action into the training examples.
