Skip to content

fix(observation): map the "None" research sentinel back in from_dict - #439

Open
JimmyL83 wants to merge 1 commit into
JackHopkins:mainfrom
JimmyL83:fix/observation-from-dict-empty-research
Open

JimmyL83 wants to merge 1 commit into
JackHopkins:mainfrom
JimmyL83:fix/observation-from-dict-empty-research

Conversation

@JimmyL83

Copy link
Copy Markdown

Problem

In a fresh game where nothing has been researched (for example open_play), Observation.from_dict() crashes on the observation that FactorioGymEnv.reset() returns:

obs, _ = env.reset(options={"game_state": task.starting_game_state})
Observation.from_dict(obs)
File "fle/env/gym_env/observation.py", line 101, in from_dict
    item["name"]: item["value"]
TypeError: string indices must be integers, not 'str'

Observation.to_dict() writes the string "None" for an empty research.progress (and for a missing current_research). from_dict() then iterates over that string character by character. GymTrajectoryRunner avoids this for the first observation by calling get_observation(), but any external agent loop that round-trips the dict from reset() (or from a step() before any research has started) hits it.

Fix

from_dict() now treats a non-list progress as empty and maps current_research == "None" back to None. to_dict() is left unchanged so its output format stays the same for existing consumers.

Testing

  • New tests/unit/test_observation_roundtrip.py (no server needed). It round-trips an observation with nothing researched, which failed before this change, and one with research in progress.
  • Checked against a live open_play server: the dict from reset() has research.progress == "None", and from_dict() now returns progress == {} and current_research is None.
  • pre-commit (ruff check and format) passes on the changed files.

🤖 Generated with Claude Code

Observation.to_dict() writes the string "None" for an empty research
`progress` and for a missing `current_research`. from_dict() iterated that
string and raised `TypeError: string indices must be integers`, so
`Observation.from_dict(env.reset(...)[0])` crashed in any fresh game where
nothing has been researched yet (e.g. open_play).

from_dict() now treats a non-list `progress` as empty and maps
`current_research == "None"` back to None. to_dict() is unchanged.

Adds server-free round-trip tests in tests/unit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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