Skip to content

Open a new OpenEnv client per game in the Wordle and multi-env examples - #8129

Merged
sergiopaniego merged 8 commits into
mainfrom
wordle-client-per-game
Nov 19, 2026
Merged

sergiopaniego merged 8 commits into
mainfrom
wordle-client-per-game

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

grpo_wordle.py and its notebook keep one OpenEnv client for the whole run. A Space closes WebSockets that stay open for hours (about every 2 hours in our runs), and the Wordle run takes about 2 hours 15 minutes. If the drop hits a game in progress, the clients up to OpenEnv 0.11.0 reconnect to a new session and the next step() plays on a board that was never reset, with no error. Since 0.12.0 they raise SessionLostError instead, so the game fails and counts as a loss.

This PR opens a new client at the start of every game, as the Sudoku example does (#8097), so no connection lives long enough to be dropped. The client is .sync(), so close() really closes the previous one. Without it, close() on the async client returns a result that is never run and each game leaves a connection and an event-loop thread open (4 resets leave 5 threads on 0.10.0, 1 with .sync()).

grpo_multi_env.py (and its snippet in openenv.md) already opened a new client per game, but without .sync(), so its close() left the event-loop thread behind. It now uses .sync() as well.

Follow-up from Albert's review of #8097. The same change for the OpenEnv Wordle tutorial script is in openenv/OpenEnv#1560.

Before submitting


Note

Low Risk
Example and documentation changes for remote client lifecycle; no changes to TRL training core or auth flows.

Overview
OpenEnv Wordle and multi-environment GRPO examples now close and recreate a synchronous client on every reset(), matching the Sudoku pattern and the documented “long runs against a Space” guidance so WebSocket idle drops don’t break games mid-episode.

TextArenaEnv and OpenSpielEnv clients use .sync() so close() actually tears down connections and event-loop threads instead of leaking them when cycling clients between games.

Docs and run instructions recommend MAX_CONCURRENT_ENVS=96 (up from 64) to cover 64 parallel games plus sessions that are still closing asynchronously.

Reviewed by Cursor Bugbot for commit 00bec7f. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

bot-ci-comment Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this matches the Sudoku pattern and the .sync() change is right for multi-env too. A few nits:

  • docs/source/openenv.md: the WordleEnv snippet in the Wordle section (~L270) still keeps one client for the whole run. Could it get the same reset() change, so it matches the script?
  • grpo_wordle.py/notebook reset(): Sudoku has a one-line comment linking to https://huggingface.co/docs/trl/openenv#long-runs-against-a-space. Could Wordle use the same comment, so the copies stay aligned?
  • Notebook and openenv.md say MAX_CONCURRENT_ENVS=96 with no reason. The script, plus the Sudoku notebook and README, explain it (64 games plus the sessions being closed). Worth the same short note?

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the comment! Two points from my previous review are still open:

  • docs/source/openenv.md: the WordleEnv snippet (L258) still keeps one client for the whole run, so it doesn't match the script.
  • Notebook and openenv.md: MAX_CONCURRENT_ENVS=96 still has no reason (64 games plus the sessions being closed).

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all addressed!

# Conflicts:
#	examples/grpo_wordle/grpo_wordle.ipynb
@sergiopaniego
sergiopaniego merged commit 77d2dcc into main Nov 19, 2026
12 checks passed
@sergiopaniego
sergiopaniego deleted the wordle-client-per-game branch November 19, 2026 11:13
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.

2 participants