Skip to content

Commit 8db4a93

Browse files
committed
Compress round logs after every round rather than at the end
1 parent 4c72959 commit 8db4a93

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

aws/docker_and_sync.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cleanup() {
2222
if [ -n "$(ls -A logs/ 2>/dev/null)" ]; then
2323
echo "Compressing rounds..."
2424
# Tar.gz all subfolders of any 'rounds' directory if we haven't done so.
25+
# This python in bash is not pretty, but it's still more readable than a bash script.
26+
# Also we do `|| true` to ignore failures, because we still want to sync the logs to s3 anyway.
2527
python3 - <<'PY' || true
2628
import subprocess
2729
from pathlib import Path
@@ -50,7 +52,7 @@ PY
5052
echo "Syncing codeclash logs to S3..."
5153
aws s3 sync logs/ s3://codeclash/logs/ || echo "Warning: Failed to sync logs to S3"
5254
else
53-
echo "No codeclashlogs to sync"
55+
echo "No codeclash logs to sync"
5456
fi
5557
echo "docker ps:"
5658
docker ps
@@ -60,7 +62,7 @@ PY
6062
docker system df
6163
echo "--------------------------------"
6264
echo "Last 100 lines of Docker logs"
63-
docker ps -aq | xargs -I {} sh -c 'logs=$(docker logs --tail 100 {} 2>&1); [ -n "$logs" ] && echo "=== {} ===" && echo "$logs"'Retry
65+
docker ps -aq | xargs -I {} sh -c 'logs=$(docker logs --tail 100 {} 2>&1); [ -n "$logs" ] && echo "=== {} ===" && echo "$logs"'
6466
echo "--------------------------------"
6567
echo "Docker cleanup"
6668
docker system prune -af

codeclash/tournaments/pvp.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ def get_agent(self, agent_config: dict, prompts: dict, push: bool) -> Player:
7575
def run(self) -> None:
7676
"""Main execution function that runs all rounds."""
7777
try:
78-
self.run_competition_phase(0) # Warm up (doesn't count)
78+
self.run_competition_phase(0) # Initial round with identical codebases
7979
for round_num in range(1, self.rounds + 1):
8080
self.run_edit_phase(round_num)
8181
self.run_competition_phase(round_num)
82+
# Need to separately compress the last round, because
83+
# in run_edit_phase we always only compress the previous round
84+
self._compress_round_folder(self.rounds)
8285
finally:
8386
self.end()
8487

@@ -108,6 +111,7 @@ def run_edit_phase(self, round_num: int) -> None:
108111
self.game.log_local / "rounds" / str(round_num - 1),
109112
DIR_LOGS / "rounds" / str(round_num - 1),
110113
)
114+
self._compress_round_folder(round_num - 1)
111115

112116
with ThreadPoolExecutor() as executor:
113117
futures = [executor.submit(self.run_agent, agent, round_num) for agent in self.agents]
@@ -156,8 +160,31 @@ def _compress_round_logs(self) -> None:
156160
shutil.rmtree(self.game.log_local / "rounds")
157161
self.logger.info("Round logs compressed successfully")
158162

163+
def _compress_round_folder(self, round_num_zero_indexed: int) -> None:
164+
round_dir = self.game.log_local / "rounds" / str(round_num_zero_indexed)
165+
if not round_dir.exists():
166+
return
167+
168+
archive = self.game.log_local / "rounds" / f"round_{round_num_zero_indexed}.tar.gz"
169+
cmd = [
170+
"tar",
171+
"-zcf",
172+
str(archive),
173+
"-C",
174+
str(round_dir.parent),
175+
str(round_num_zero_indexed),
176+
]
177+
self.logger.info(
178+
f"Compressing round {round_num_zero_indexed} logs, this might take a while... ({' '.join(cmd)})"
179+
)
180+
result = subprocess.run(cmd, capture_output=True, text=True)
181+
if result.returncode != 0:
182+
raise RuntimeError(f"Command failed with exit code {result.returncode}:\n{result.stderr}")
183+
self.logger.debug("Removing %s", round_dir)
184+
shutil.rmtree(round_dir)
185+
self.logger.info(f"Round {round_num_zero_indexed} logs compressed successfully")
186+
159187
def end(self) -> None:
160188
"""Save output files, clean up game resources and push agents if requested."""
161189
self._save()
162190
self.game.end(self.cleanup_on_end)
163-
self._compress_round_logs()

0 commit comments

Comments
 (0)