Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a fresh game where nothing has been researched (for example
open_play),Observation.from_dict()crashes on the observation thatFactorioGymEnv.reset()returns:Observation.to_dict()writes the string"None"for an emptyresearch.progress(and for a missingcurrent_research).from_dict()then iterates over that string character by character.GymTrajectoryRunneravoids this for the first observation by callingget_observation(), but any external agent loop that round-trips the dict fromreset()(or from astep()before any research has started) hits it.Fix
from_dict()now treats a non-listprogressas empty and mapscurrent_research == "None"back toNone.to_dict()is left unchanged so its output format stays the same for existing consumers.Testing
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.open_playserver: the dict fromreset()hasresearch.progress == "None", andfrom_dict()now returnsprogress == {}andcurrent_research is None.pre-commit(ruff check and format) passes on the changed files.🤖 Generated with Claude Code