"""Grader for server_error task: 500 Internal Server Error.""" import sys from pathlib import Path _project_root = str(Path(__file__).parent.parent.parent) if _project_root not in sys.path: sys.path.insert(0, _project_root) from environment.api_triage_env import APITriageEnv from environment.incident_generator import get_incident_by_type def grade() -> float: """Grade the server_error task by simulating an optimal agent. Returns: Score strictly between 0 and 1. """ try: env = APITriageEnv(max_steps=10) env.incident = get_incident_by_type("server_error") if env.incident is None: return 0.1 env.fix_applied = False env.done = False env.step_counter = 0 env.total_reward = 0.0 # Optimal sequence: inspect → correct fix → resolve actions = ["inspect_logs", "escalate", "resolve"] for action in actions: state, reward, done, info = env.step(action) if done: if info.get("resolution") == "success": return 0.95 else: return 0.1 return 0.1 except Exception: return 0.1