Skip to content

textarena_env: parse TEXTARENA_KW_* values as JSON - #1530

Merged
sergiopaniego merged 2 commits into
openenv:mainfrom
sergiopaniego:textarena-env-kwargs-types
Oct 30, 2026
Merged

sergiopaniego merged 2 commits into
openenv:mainfrom
sergiopaniego:textarena-env-kwargs-types

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

TEXTARENA_KW_* environment variables reached TextArena as strings, so numeric kwargs broke the game they configure. For example, TEXTARENA_ENV_ID=Sudoku-v0 with TEXTARENA_KW_CLUES=65 crashes on every reset():

textarena/envs/Sudoku/env.py:67  while len(cells) > clues:
TypeError: '>' not supported between instances of 'int' and 'str'

_parse_env_kwargs now reads each value as JSON and falls back to the raw string, so 65 is an int, true a bool, and hard stays "hard".

This is needed to serve Sudoku at an easier level than the default (30 clues, about 48 empty cells) from a Space, for the Sudoku SFT + GRPO tutorial we're preparing.

Changes

  • envs/textarena_env/server/app.py: parse TEXTARENA_KW_* values as JSON.
  • tests/envs/test_textarena_environment.py: one test for the parsing, one that starts Sudoku with TEXTARENA_KW_CLUES=65. Both fail without the fix (the second with the TypeError above).
  • README and docs: one line saying values are read as JSON.

Compatibility

Values that are not valid JSON are passed exactly as before. A value that is valid JSON but was meant as a string (for example TEXTARENA_KW_word="null") would now change type. No Space or Dockerfile in the repo sets TEXTARENA_KW_*.

Test plan

  • pytest tests/envs/test_textarena_environment.py: 30 passed.

Note

Low Risk
Small server startup change limited to optional TextArena kwargs; non-JSON values behave as before, with a minor edge case if a value was intentionally a JSON literal string.

Overview
TEXTARENA_KW_* env vars are no longer always passed to TextArena as strings. _parse_env_kwargs in server/app.py now runs each value through json.loads, with a fallback to the raw string when parsing fails, so numeric and boolean kwargs (e.g. Sudoku clues=65) reach games with the correct type instead of causing type errors on reset().

Documentation in the TextArena README and docs now notes JSON parsing and gives Sudoku/difficulty examples. Tests cover the parser mapping (65 → int, true → bool, hard → str) and starting Sudoku with TEXTARENA_KW_CLUES=65.

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

TEXTARENA_KW_CLUES=65 reached Sudoku as the string "65" and crashed on reset
(int > str in _remove_cells). Values that are not JSON stay strings.
@sergiopaniego
sergiopaniego merged commit 1e52dde into openenv:main Oct 30, 2026
13 checks passed
@sergiopaniego
sergiopaniego deleted the textarena-env-kwargs-types branch October 30, 2026 14:14
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.

1 participant