Skip to content

Commit 41e53bc

Browse files
vezhnickcopybara-github
authored andcommitted
Fixing scene serialisation error that was crashing jobs after restoration from a checkpoint.
Root cause: _make_json_serializable() silently drops SceneSpec dataclass objects from the checkpoint, so the 'scene' key vanishes. Fix: Made get_state()/set_state() no-ops — _round_idx_to_scene is derived from the constructor's scenes arg, which is re-supplied when the prefab rebuilds on restore. No dynamic state needs persisting. PiperOrigin-RevId: 878400465 Change-Id: I976ecddfcced1dbf84d37a00003c43252cb280fd
1 parent 326d918 commit 41e53bc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

concordia/components/game_master/scene_tracker.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,8 @@ def pre_act(
267267

268268
def get_state(self) -> entity_component.ComponentState:
269269
"""Returns the state of the component."""
270-
return {
271-
'round_idx_to_scene': self._round_idx_to_scene,
272-
'max_rounds': self._max_rounds,
273-
}
270+
return {}
274271

275272
def set_state(self, state: entity_component.ComponentState) -> None:
276273
"""Sets the state of the component."""
277-
self._round_idx_to_scene = state['round_idx_to_scene']
278-
self._max_rounds = state['max_rounds']
274+
pass

concordia/components/game_master/scene_tracker_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ def test_premises_not_queued_twice_for_same_scene(self):
140140
# Verify no premises were queued (marker exists) - no add_to_queue calls
141141
self.assertEqual(self.mock_observation.add_to_queue.call_count, 0)
142142

143+
def test_state_round_trip_preserves_scene_data(self):
144+
tracker = self._create_tracker_with_mocks(existing_markers=[])
145+
state = tracker.get_state()
146+
tracker2 = self._create_tracker_with_mocks(existing_markers=[])
147+
tracker2.set_state(state)
148+
self.assertEqual(tracker2._max_rounds, tracker._max_rounds)
149+
for idx in range(tracker._max_rounds):
150+
self.assertEqual(
151+
tracker2._round_idx_to_scene[idx]["step_within_scene"],
152+
tracker._round_idx_to_scene[idx]["step_within_scene"],
153+
)
154+
self.assertEqual(
155+
tracker2._round_idx_to_scene[idx]["scene"],
156+
tracker._round_idx_to_scene[idx]["scene"],
157+
)
158+
143159

144160
if __name__ == "__main__":
145161
absltest.main()

0 commit comments

Comments
 (0)