OpenEnv icon indicating copy to clipboard operation
OpenEnv copied to clipboard

reset() drops seed and episode_id in 14 environments

Open Aafimalek opened this issue 2 weeks ago • 1 comments

Environment.reset takes seed and episode_id, and INVARIANTS.md lists reset(seed?, episode_id?) -> Observation as an API invariant. These 14 environments override reset without either parameter:

Environment Class Signature on main
atari_env AtariEnvironment reset()
calendar_env MCPEnvironment reset()
carla_env CarlaEnvironment reset(scenario_name, scenario_config)
chess_env ChessEnvironment reset(fen)
coding_env PythonCodeActEnv reset()
connect4_env Connect4Environment reset()
finrl_env FinRLEnvironment reset()
git_env GitTaskEnvironment reset(task_id)
grid_world_env GridWorldEnvironment reset()
openapp_env OpenAppEnvironment reset()
openspiel_env OpenSpielEnvironment reset()
snake_env SnakeEnvironment reset()
sumo_rl_env SumoEnvironment reset()
websearch_env WebSearchEnvironment reset()

The HTTP server filters reset arguments by the method's signature (_get_valid_kwargs in http_server.py), so over the wire a seed is dropped without an error and a given episode_id is replaced by a generated one. Called directly, reset(seed=1) raises TypeError.

Where the environment has randomness, episodes can't be reproduced. In chess_env, for example, the random opponent uses the process-wide random and the agent's colour comes from hash(uuid4()); in two runs of 20 resets, the random opponent gave 13 and 15 different replies to e2e4.

This is the same gap #1443, #1250 and #1102 described for other environments, fixed in #1444, #1252 and #1127 by giving each environment its own random.Random that reset(seed=...) replaces, and keeping episode_id when one is given. I'll send a PR for chess_env and can follow up on others. coding_env is being reworked in #1644, so it may be better handled there.

Aafimalek avatar Nov 18 '26 18:11 Aafimalek

Status of the fixes, one PR per group of environments:

  • chess_env: #1648 (merged)
  • connect4_env, grid_world_env: #1649
  • finrl_env, git_env: #1650
  • openspiel_env: #1651
  • atari_env: #1654
  • snake_env: #1655
  • maze_env: #1656
  • openapp_env, sumo_rl_env, websearch_env: #1670
  • coding_env, calendar_env: #1671
  • carla_env: #1672

Environments with no random state (finrl, git, websearch, coding, calendar) accept the seed and ignore it. carla_env seeds Python's random only, since the CARLA simulator itself is not seeded.

Aafimalek avatar Nov 20 '26 10:11 Aafimalek