Skip to content

Commit 0fca875

Browse files
committed
Important fix: Guard against overwriting metadata!
1 parent 6be802f commit 0fca875

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

codeclash/tournaments/pvp.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(
3131
keep_containers: bool = False,
3232
):
3333
super().__init__(config, name="PvpTournament", output_dir=output_dir)
34+
if self.metadata_file.exists():
35+
self.logger.critical(f"Metadata file already exists: {self.metadata_file}")
36+
raise FileExistsError(f"Metadata file already exists: {self.metadata_file}")
3437
self.cleanup_on_end = cleanup
3538
self.game: CodeGame = get_game(
3639
self.config,
@@ -42,6 +45,10 @@ def __init__(
4245
for agent_conf in self.config["players"]:
4346
self.agents.append(self.get_agent(agent_conf, self.config["prompts"], push=push))
4447

48+
@property
49+
def metadata_file(self) -> Path:
50+
return self.local_output_dir / "metadata.json"
51+
4552
@property
4653
def rounds(self) -> int:
4754
return self.config["tournament"]["rounds"]
@@ -133,9 +140,8 @@ def run_agent(self, agent: Player, round_num: int) -> None:
133140

134141
def _save(self) -> None:
135142
self.local_output_dir.mkdir(parents=True, exist_ok=True)
136-
metadata_file = self.local_output_dir / "metadata.json"
137-
atomic_write(metadata_file, json.dumps(self.get_metadata(), indent=2))
138-
self.logger.debug(f"Metadata saved to {metadata_file}")
143+
atomic_write(self.metadata_file, json.dumps(self.get_metadata(), indent=2))
144+
self.logger.debug(f"Metadata saved to {self.metadata_file}")
139145
if is_running_in_aws_batch():
140146
s3_log_sync(self.local_output_dir, logger=self.logger)
141147

0 commit comments

Comments
 (0)