﻿# Gymnasium time limits: episode closure and terminal value are different decisions

Preserve terminated and truncated separately in Gymnasium learning data, and distinguish an external rollout limit from a finite horizon defined by the task.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/simulation-gymnasium-time-limit-termination-bootstrap/
Language: en

## A collector can stop without the task becoming terminal

A robot-learning collector stops a simulated rollout at its data budget and stores a single ended flag. The learner later treats every stopped transition as having no future value. That changes the learning target when the budget was an external collection limit rather than a terminal condition of the task. Preserve why collection stopped. Resetting the simulator and deciding whether to bootstrap are related operations, but they answer different questions about the transition.

## Read the task definition before classifying a timeout

The [time-limit tutorial](https://gymnasium.farama.org/tutorials/gymnasium_basics/handling_time_limits/) separates termination inside the task’s decision process from truncation imposed outside it. An inherent finite horizon can itself terminate a task; the remaining time then belongs in the observation to preserve the intended Markov description. Therefore, not every condition described informally as a timeout is automatically truncation. Record whether the horizon is part of the environment definition or an external practical limit on collecting experience.

## The wrapper preserves independent signals

The inspected [TimeLimit implementation](https://raw.githubusercontent.com/Farama-Foundation/Gymnasium/v1.4.0/gymnasium/wrappers/common.py) calls the underlying environment, preserves its termination signal and independently sets truncation when the elapsed-step limit is reached. Do not assume the flags are mutually exclusive. For a bootstrapped value target, terminal task state removes the continuation term; an external truncation alone does not. Closing an episode record on either flag remains compatible with preserving this distinction in the learner’s target construction and subsequent reset scheduling.

## Keep the actual last observation with the target

A truncated transition still needs the observation reached by that transition if its target uses a continuation estimate. Do not substitute a fresh reset observation from another episode. Preserve reward, both flags and the correct successor together. This is separate from choosing the value estimator or discounting rule. A perfectly preserved truncation flag cannot repair a target that evaluates the next episode’s initial state because an observation buffer was overwritten during reset.

## Propose a target-level acceptance fixture

A proposed fixture should include genuine task termination, external truncation and a case where both flags are true. Inspect the continuation mask and successor observation used by the target, separately from the collector’s reset decision. Include a finite-horizon task with an explicitly represented time budget if that is the intended environment. No Gymnasium rollout or learning experiment was executed here. The evidence should explain the target rather than claim a measured improvement in learning.

## Separate transition semantics from controller quality

The [CALVIN carryover guide](/journal/fg2-calvin-chain-prefix-success-environment-state-carryover/) discusses another episode boundary; [stack reproducibility](/journal/software-stack-reproducibility/) supports retaining environment and wrapper versions. Correct flags establish what a stopped transition means to the learner. They do not establish reward suitability, physical fidelity or policy success. Evaluate those claims after collection limits no longer silently convert continuing task states into terminal learning targets.
