Skip to content

Commit e8b4e69

Browse files
committed
fix(training): reserve final return storage and validate agent sequences
1 parent 18defc8 commit e8b4e69

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎python/gamesforai/trajectories.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def __init__(
4949
if position is not None:
5050
self._native.reset(seed, position)
5151
self._spec = json.loads(self._native.spec_json())
52+
if isinstance(agents, (str, bytes)):
53+
raise ValueError("agents must be a sequence of identities")
5254
self._agents = tuple(_text(agent, "agent id", 256) for agent in agents)
5355
if len(self._agents) != self._native.num_players:
5456
raise ValueError("one agent identity is required per seat")
@@ -138,8 +140,8 @@ def step(self, seat, action, *, reasoning=None, transcript=None):
138140
"next_to_act": candidate.current_players(),
139141
"terminated": terminated, "truncated": truncated,
140142
}
141-
# Include final fields at their maximum serialized size in the bound.
142-
size = len(_dump({**row, "outcome": "truncated", "episode_returns": [-1.0] * len(rewards)}).encode("utf-8")) + 1
143+
# Reserve final labels and up to 32 bytes for each finite float64 return.
144+
size = len(_dump(row).encode("utf-8")) + 128 + 32 * len(rewards)
143145
if self._bytes + size > self._max_bytes:
144146
raise ValueError("episode record byte limit reached")
145147
self._native = candidate

0 commit comments

Comments
 (0)