From 4c41c83085b2e9aedfad1e6765e8800c4e22bcf1 Mon Sep 17 00:00:00 2001 From: Xinyu Guan Date: Wed, 2 Dec 2026 13:48:27 -0800 Subject: [PATCH] Fix matrix evaluation deadlock and completion reporting --- codeclash/analysis/matrix.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/codeclash/analysis/matrix.py b/codeclash/analysis/matrix.py index 9de30edf..e89398b2 100644 --- a/codeclash/analysis/matrix.py +++ b/codeclash/analysis/matrix.py @@ -4,7 +4,7 @@ import uuid from pathlib import Path from queue import Queue -from threading import Lock, Thread +from threading import Event, Lock, Thread from codeclash.agents.dummy_agent import Dummy from codeclash.agents.utils import GameContext @@ -213,13 +213,13 @@ def _evaluate_matrix_cell_parallel( self.logger.info(f"Evaluating {player1_name} round {i} vs {player2_name} round {j}") round_id = str(uuid.uuid4().hex) - stats = game_worker.run_round([agent1, agent2], round_id, copy_logs=False) + stats = game_worker.run_round([agent1, agent2], round_id, copy_logs=True) result = stats.to_dict() self.logger.debug(f"Result: {result}") with self._save_lock: self.matrices[matrix_id][str(i)][str(j)] = result - self._save() + self._save() return (i, j, result) @@ -238,6 +238,7 @@ def _worker_thread(self, worker_id: int, task_queue: Queue): try: self._evaluate_matrix_cell_parallel(game_worker, **task) except Exception as e: + self._evaluation_failed.set() self.logger.error(f"Worker {worker_id} failed on task {task}: {e}") finally: task_queue.task_done() @@ -293,14 +294,19 @@ def _evaluate_matrix(self, player1_name: str, player2_name: str): for worker in workers: worker.join() - self.logger.info(f"Completed matrix evaluation for {matrix_id}") + self.logger.info(f"Finished processing matrix {matrix_id}") def evaluate_all_matrices(self) -> dict: """Evaluate vs matrix between the two players.""" self.logger.info("Starting matrix evaluation") + self._evaluation_failed = Event() + self._metadata.pop("evaluation_completed_timestamp", None) self._evaluate_matrix(self.players[0], self.players[0]) self._evaluate_matrix(self.players[1], self.players[1]) - self._metadata["evaluation_completed_timestamp"] = int(time.time()) + if self._evaluation_failed.is_set(): + self.logger.error("Matrix evaluation incomplete: one or more cells failed") + else: + self._metadata["evaluation_completed_timestamp"] = int(time.time()) self.end() return self.matrices