From 164ebf7f2f80a2f436fc3676c585e842523c5766 Mon Sep 17 00:00:00 2001 From: w286554018 Date: Mon, 25 May 2026 23:10:27 +0800 Subject: [PATCH] fix: wrap _turn_end_hooks iteration with list() to prevent RuntimeError When a hook modifies _turn_end_hooks dict during iteration in turn_end_callback, Python raises RuntimeError: dictionary changed size during iteration. Wrapping .values() with list() creates a snapshot copy, preventing this error. --- ga.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ga.py b/ga.py index 4ccd84f42..9347d3eca 100644 --- a/ga.py +++ b/ga.py @@ -573,7 +573,7 @@ def turn_end_callback(self, response, tool_calls, tool_results, turn, next_promp injprompt = consume_file(self.parent.task_dir, '_intervene') if injkeyinfo: self.working['key_info'] = self.working.get('key_info', '') + f"\n[MASTER] {injkeyinfo}" if injprompt: next_prompt += f"\n\n[MASTER] {injprompt}\n" - for hook in getattr(self.parent, '_turn_end_hooks', {}).values(): hook(locals()) # current readonly + for hook in list(getattr(self.parent, '_turn_end_hooks', {}).values()): hook(locals()) # current readonly return next_prompt def get_global_memory():