""" Test to verify if session state is preserved across step() calls. This runs ConfigDebugEnvironment directly to show if the same instance is reused or if new instances are created per step. """ from server.config_debug_environment import ConfigDebugEnvironment from server.models import ConfigDebugAction print("=" * 70) print("LOCAL SESSION PERSISTENCE TEST") print("=" * 70) print() env = ConfigDebugEnvironment() print(f"[TEST] Creating environment instance at: {id(env)}") print() print("[TEST] Calling reset()...") obs = env.reset() print() print("[TEST] Calling step() 6 times - checking if env instance ID stays the same...") print() env_ids = [id(env)] # Track object IDs for step_num in range(1, 7): print(f"--- STEP {step_num} ---") action = ConfigDebugAction(fixed_config="{}") obs = env.step(action) print(f"[TEST] After step: task_id={obs.task_id}, current_step={env.current_step}, done={obs.done}") env_ids.append(id(env)) print() print() print("=" * 70) print("SESSION PERSISTENCE CHECK") print("=" * 70) unique_ids = set(env_ids) print(f"Environment object IDs seen: {unique_ids}") print(f"Number of unique object IDs: {len(unique_ids)}") print() if len(unique_ids) == 1: print("[OK] GOOD: Same environment instance used for all steps") else: print(f"[ERROR] BAD: {len(unique_ids)} different environment instances created!") print("This means the validator is getting a new environment per request") print("Instead of operating on the same persistent session.") print() print(f"Final state: current_step={env.current_step}, current_task_id={env._current_task_id()}")