From 34c48743d0cfbee09dd9939feec6ae61376311cd Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Nov 2025 19:58:29 +0000 Subject: [PATCH] Fix execute_processing_script to support list comprehensions The exec() function was using empty globals dict which prevented list comprehensions from accessing variables in the local scope. Changed to use the same dict for both globals and locals to properly support comprehensions in processing scripts. Fixes battleship game flow tests that use list comprehensions. --- activity.py | 10 ++++++---- research/guarded_ai.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/activity.py b/activity.py index 25fd64d..8ce5786 100644 --- a/activity.py +++ b/activity.py @@ -372,17 +372,19 @@ def display_activity_metadata(room_name, username): def execute_processing_script(metadata, script): - # Prepare the local environment for the script - local_env = { + # Prepare the environment for the script + # Use the same dict for both globals and locals to support comprehensions + script_env = { + "__builtins__": __builtins__, "metadata": metadata, "script_result": None, } # Execute the script - exec(script, {}, local_env) + exec(script, script_env, script_env) # Return the result from the script - return local_env["script_result"] + return script_env["script_result"] def handle_activity_response(room_name, user_response, username, model="MODEL_0"): diff --git a/research/guarded_ai.py b/research/guarded_ai.py index b0526ad..8b85c22 100644 --- a/research/guarded_ai.py +++ b/research/guarded_ai.py @@ -297,14 +297,19 @@ def provide_feedback_prompts( def execute_processing_script(metadata, script): - # Prepare the local environment for the script - local_env = {"metadata": metadata, "script_result": None} + # Prepare the environment for the script + # Use the same dict for both globals and locals to support comprehensions + script_env = { + "__builtins__": __builtins__, + "metadata": metadata, + "script_result": None, + } # Execute the script - exec(script, {}, local_env) + exec(script, script_env, script_env) # Return the result from the script - return local_env["script_result"] + return script_env["script_result"] def get_next_section_and_step(activity_content, current_section_id, current_step_id):