Nanda Kumar Kondreddy commited on
Commit ·
8e7ae76
1
Parent(s): b43aff5
Fix: Enforce strict open interval (0.01, 0.99) for all grader rewards - validator compliance
Browse files
server/graders/compose_grader.py
CHANGED
|
@@ -106,6 +106,6 @@ def grade_task4(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 106 |
reward = 0.95
|
| 107 |
|
| 108 |
# Clamp to strict (0,1) range for validator
|
| 109 |
-
reward = max(0.
|
| 110 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 111 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 106 |
reward = 0.95
|
| 107 |
|
| 108 |
# Clamp to strict (0,1) range for validator
|
| 109 |
+
reward = max(0.01, min(0.99, reward))
|
| 110 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 111 |
return reward, error_msg, bugs_fixed
|
server/graders/dockerfile_grader.py
CHANGED
|
@@ -101,9 +101,9 @@ def grade_task3(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 101 |
reward = min(1.0, reward + 0.1)
|
| 102 |
|
| 103 |
if len(bugs_fixed) == total_bugs:
|
| 104 |
-
reward = 0.
|
| 105 |
|
| 106 |
# Clamp to strict (0,1) range for validator
|
| 107 |
-
reward = max(0.
|
| 108 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 109 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 101 |
reward = min(1.0, reward + 0.1)
|
| 102 |
|
| 103 |
if len(bugs_fixed) == total_bugs:
|
| 104 |
+
reward = 0.99
|
| 105 |
|
| 106 |
# Clamp to strict (0,1) range for validator
|
| 107 |
+
reward = max(0.01, min(0.99, reward))
|
| 108 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 109 |
return reward, error_msg, bugs_fixed
|
server/graders/github_actions_grader.py
CHANGED
|
@@ -161,6 +161,6 @@ def grade_task6(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 161 |
reward = 0.95
|
| 162 |
|
| 163 |
# Clamp to strict (0,1) range for validator
|
| 164 |
-
reward = max(0.
|
| 165 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 166 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 161 |
reward = 0.95
|
| 162 |
|
| 163 |
# Clamp to strict (0,1) range for validator
|
| 164 |
+
reward = max(0.01, min(0.99, reward))
|
| 165 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 166 |
return reward, error_msg, bugs_fixed
|
server/graders/json_grader.py
CHANGED
|
@@ -32,7 +32,7 @@ def grade_task1(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 32 |
error_messages.append(f"JSON parse error: {str(e)}")
|
| 33 |
# Return early with syntax failure
|
| 34 |
error_msg = "; ".join(error_messages) if error_messages else "JSON syntax error"
|
| 35 |
-
return max(0.
|
| 36 |
|
| 37 |
# ===== LEVEL 2: STRUCTURAL VALIDATION =====
|
| 38 |
# Check env structure
|
|
@@ -83,11 +83,11 @@ def grade_task1(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 83 |
|
| 84 |
# ===== FINAL REWARD CALCULATION =====
|
| 85 |
# Reward is emergent from actual fixes, not hard-coded
|
| 86 |
-
reward = min(0.
|
| 87 |
if len(bugs_fixed) == 5: # All bugs fixed
|
| 88 |
-
reward = 0.
|
| 89 |
|
| 90 |
-
reward = max(0.
|
| 91 |
|
| 92 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 93 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 32 |
error_messages.append(f"JSON parse error: {str(e)}")
|
| 33 |
# Return early with syntax failure
|
| 34 |
error_msg = "; ".join(error_messages) if error_messages else "JSON syntax error"
|
| 35 |
+
return max(0.01, min(0.99, reward)), error_msg, bugs_fixed
|
| 36 |
|
| 37 |
# ===== LEVEL 2: STRUCTURAL VALIDATION =====
|
| 38 |
# Check env structure
|
|
|
|
| 83 |
|
| 84 |
# ===== FINAL REWARD CALCULATION =====
|
| 85 |
# Reward is emergent from actual fixes, not hard-coded
|
| 86 |
+
reward = min(0.99, reward) # Cap at 0.99 for non-perfect
|
| 87 |
if len(bugs_fixed) == 5: # All bugs fixed
|
| 88 |
+
reward = 0.99
|
| 89 |
|
| 90 |
+
reward = max(0.01, min(0.99, reward)) # Enforce strict (0,1) interval
|
| 91 |
|
| 92 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 93 |
return reward, error_msg, bugs_fixed
|
server/graders/k8s_grader.py
CHANGED
|
@@ -55,12 +55,12 @@ def grade_task5(fixed_config: str) -> Tuple[float, str, List[str]]:
|
|
| 55 |
except Exception:
|
| 56 |
errors.append("missing or invalid cpu limit")
|
| 57 |
|
| 58 |
-
reward = round(min(reward,
|
| 59 |
|
| 60 |
-
if reward =
|
| 61 |
-
return 0.
|
| 62 |
|
| 63 |
# Clamp to strict (0,1) range for validator
|
| 64 |
-
reward = max(0.
|
| 65 |
error_msg = " ; ".join(errors) if errors else "Configuration has issues"
|
| 66 |
return reward, error_msg, fixed
|
|
|
|
| 55 |
except Exception:
|
| 56 |
errors.append("missing or invalid cpu limit")
|
| 57 |
|
| 58 |
+
reward = round(min(reward, 0.99), 2)
|
| 59 |
|
| 60 |
+
if reward >= 0.99:
|
| 61 |
+
return 0.99, "Deployment config is fully valid", fixed
|
| 62 |
|
| 63 |
# Clamp to strict (0,1) range for validator
|
| 64 |
+
reward = max(0.01, min(0.99, reward))
|
| 65 |
error_msg = " ; ".join(errors) if errors else "Configuration has issues"
|
| 66 |
return reward, error_msg, fixed
|
server/graders/nginx_grader.py
CHANGED
|
@@ -83,11 +83,11 @@ def grade_task7(fixed_config: str) -> Tuple[float, str, List[str]]:
|
|
| 83 |
)
|
| 84 |
|
| 85 |
# ===== FINAL REWARD CALCULATION =====
|
| 86 |
-
reward = min(0.
|
| 87 |
if len(bugs_fixed) == 3: # All bugs fixed
|
| 88 |
-
reward = 0.
|
| 89 |
|
| 90 |
-
reward = max(0.
|
| 91 |
|
| 92 |
error_msg = " ; ".join(errors) if errors else "All checks passed!"
|
| 93 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 83 |
)
|
| 84 |
|
| 85 |
# ===== FINAL REWARD CALCULATION =====
|
| 86 |
+
reward = min(0.99, reward)
|
| 87 |
if len(bugs_fixed) == 3: # All bugs fixed
|
| 88 |
+
reward = 0.99
|
| 89 |
|
| 90 |
+
reward = max(0.01, min(0.99, reward))
|
| 91 |
|
| 92 |
error_msg = " ; ".join(errors) if errors else "All checks passed!"
|
| 93 |
return reward, error_msg, bugs_fixed
|
server/graders/yaml_grader.py
CHANGED
|
@@ -31,10 +31,10 @@ def grade_task2(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 31 |
reward += 0.3
|
| 32 |
else:
|
| 33 |
error_messages.append("YAML parsed but result is not a mapping/dictionary")
|
| 34 |
-
return max(0.
|
| 35 |
except yaml.YAMLError as e:
|
| 36 |
error_messages.append(f"YAML parse error: {str(e)}")
|
| 37 |
-
return max(0.
|
| 38 |
|
| 39 |
# ===== LEVEL 2: STRUCTURAL VALIDATION =====
|
| 40 |
# Check env structure
|
|
@@ -77,11 +77,11 @@ def grade_task2(submitted_config: str) -> Tuple[float, str, List[str]]:
|
|
| 77 |
|
| 78 |
# ===== FINAL REWARD CALCULATION =====
|
| 79 |
# Reward is emergent from actual fixes
|
| 80 |
-
reward = min(0.
|
| 81 |
if len(bugs_fixed) == 3: # All bugs fixed
|
| 82 |
-
reward = 0.
|
| 83 |
|
| 84 |
-
reward = max(0.
|
| 85 |
|
| 86 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 87 |
return reward, error_msg, bugs_fixed
|
|
|
|
| 31 |
reward += 0.3
|
| 32 |
else:
|
| 33 |
error_messages.append("YAML parsed but result is not a mapping/dictionary")
|
| 34 |
+
return max(0.01, min(0.99, reward)), "; ".join(error_messages), bugs_fixed
|
| 35 |
except yaml.YAMLError as e:
|
| 36 |
error_messages.append(f"YAML parse error: {str(e)}")
|
| 37 |
+
return max(0.01, min(0.99, reward)), "; ".join(error_messages), bugs_fixed
|
| 38 |
|
| 39 |
# ===== LEVEL 2: STRUCTURAL VALIDATION =====
|
| 40 |
# Check env structure
|
|
|
|
| 77 |
|
| 78 |
# ===== FINAL REWARD CALCULATION =====
|
| 79 |
# Reward is emergent from actual fixes
|
| 80 |
+
reward = min(0.99, reward) # Cap at 0.99 for non-perfect
|
| 81 |
if len(bugs_fixed) == 3: # All bugs fixed
|
| 82 |
+
reward = 0.99
|
| 83 |
|
| 84 |
+
reward = max(0.01, min(0.99, reward)) # Enforce strict (0,1) interval
|
| 85 |
|
| 86 |
error_msg = "; ".join(error_messages) if error_messages else "All checks passed!"
|
| 87 |
return reward, error_msg, bugs_fixed
|
test_task_graders.py
CHANGED
|
@@ -33,9 +33,9 @@ def test_all_tasks():
|
|
| 33 |
print(f" Bugs Fixed: {len(broken_bugs)} (expected 0-1)")
|
| 34 |
print(f" Message: {broken_msg[:60]}...")
|
| 35 |
|
| 36 |
-
broken_ok = 0.
|
| 37 |
if not broken_ok:
|
| 38 |
-
print(f" [FAIL]
|
| 39 |
all_passed = False
|
| 40 |
else:
|
| 41 |
print(f" [PASS]")
|
|
@@ -43,13 +43,13 @@ def test_all_tasks():
|
|
| 43 |
# Test 2: Ground truth should score high
|
| 44 |
truth_reward, truth_msg, truth_bugs = task.grader(task.ground_truth)
|
| 45 |
print(f"\n GROUND TRUTH:")
|
| 46 |
-
print(f" Reward: {truth_reward:.2f} (expected
|
| 47 |
print(f" Bugs Fixed: {len(truth_bugs)} (expected {task.num_bugs})")
|
| 48 |
print(f" Message: {truth_msg[:60]}...")
|
| 49 |
|
| 50 |
-
truth_ok = 0.85 <= truth_reward <=
|
| 51 |
if not truth_ok:
|
| 52 |
-
print(f" [FAIL]
|
| 53 |
all_passed = False
|
| 54 |
else:
|
| 55 |
print(f" [PASS]")
|
|
|
|
| 33 |
print(f" Bugs Fixed: {len(broken_bugs)} (expected 0-1)")
|
| 34 |
print(f" Message: {broken_msg[:60]}...")
|
| 35 |
|
| 36 |
+
broken_ok = 0.01 <= broken_reward <= 0.99 # Must be strictly (0, 1)
|
| 37 |
if not broken_ok:
|
| 38 |
+
print(f" [FAIL] Broken config reward out of valid range (0.01-0.99)!")
|
| 39 |
all_passed = False
|
| 40 |
else:
|
| 41 |
print(f" [PASS]")
|
|
|
|
| 43 |
# Test 2: Ground truth should score high
|
| 44 |
truth_reward, truth_msg, truth_bugs = task.grader(task.ground_truth)
|
| 45 |
print(f"\n GROUND TRUTH:")
|
| 46 |
+
print(f" Reward: {truth_reward:.2f} (expected 0.85-0.99)")
|
| 47 |
print(f" Bugs Fixed: {len(truth_bugs)} (expected {task.num_bugs})")
|
| 48 |
print(f" Message: {truth_msg[:60]}...")
|
| 49 |
|
| 50 |
+
truth_ok = 0.85 <= truth_reward <= 0.99 # Should be in valid high range
|
| 51 |
if not truth_ok:
|
| 52 |
+
print(f" [FAIL] Ground truth reward out of expected range!")
|
| 53 |
all_passed = False
|
| 54 |
else:
|
| 55 |
print(f" [PASS]")
|