coderMayank69 commited on
Commit
a8a9661
·
1 Parent(s): b213994

debugged the task validation error

Browse files
app/__pycache__/main.cpython-313.pyc CHANGED
Binary files a/app/__pycache__/main.cpython-313.pyc and b/app/__pycache__/main.cpython-313.pyc differ
 
app/__pycache__/models.cpython-313.pyc CHANGED
Binary files a/app/__pycache__/models.cpython-313.pyc and b/app/__pycache__/models.cpython-313.pyc differ
 
app/main.py CHANGED
@@ -20,6 +20,7 @@ from app.tasks import TASKS
20
  # Repo root (contains openenv.yaml) — /app in Docker, project dir locally.
21
  _ENV_ROOT = Path(__file__).resolve().parent.parent
22
  _OPENENV_PATH = _ENV_ROOT / "openenv.yaml"
 
23
 
24
  app = FastAPI(
25
  title="Synapse Code Auditor",
@@ -56,8 +57,8 @@ def metadata() -> dict[str, Any]:
56
  {
57
  "task_id": task.id,
58
  "task_type": task.task_type.value,
59
- "has_grader": True,
60
- "grader_enabled": True,
61
  "criteria_count": len(task.criteria),
62
  }
63
  for task in TASKS.values()
@@ -80,7 +81,7 @@ def list_tasks() -> dict[str, Any]:
80
  "task_id": task.id,
81
  "task_type": task.task_type.value,
82
  "title": task.title,
83
- "has_grader": True,
84
  "grader": {"type": "deterministic", "enabled": True},
85
  # Use numeric bounds strictly inside (0, 1); some validators reject
86
  # any 0.0/1.0 floats anywhere under task payloads.
@@ -91,6 +92,18 @@ def list_tasks() -> dict[str, Any]:
91
  }
92
 
93
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  @app.get("/openenv.yaml")
95
  def openenv_manifest() -> FileResponse:
96
  """Serve the OpenEnv manifest so validators can read it from the running Space."""
 
20
  # Repo root (contains openenv.yaml) — /app in Docker, project dir locally.
21
  _ENV_ROOT = Path(__file__).resolve().parent.parent
22
  _OPENENV_PATH = _ENV_ROOT / "openenv.yaml"
23
+ _GRADERS_JSON_PATH = _ENV_ROOT / "graders.json"
24
 
25
  app = FastAPI(
26
  title="Synapse Code Auditor",
 
57
  {
58
  "task_id": task.id,
59
  "task_type": task.task_type.value,
60
+ "has_grader": task.has_grader,
61
+ "grader_enabled": task.has_grader,
62
  "criteria_count": len(task.criteria),
63
  }
64
  for task in TASKS.values()
 
81
  "task_id": task.id,
82
  "task_type": task.task_type.value,
83
  "title": task.title,
84
+ "has_grader": task.has_grader,
85
  "grader": {"type": "deterministic", "enabled": True},
86
  # Use numeric bounds strictly inside (0, 1); some validators reject
87
  # any 0.0/1.0 floats anywhere under task payloads.
 
92
  }
93
 
94
 
95
+ @app.get("/graders.json")
96
+ def graders_manifest() -> FileResponse:
97
+ """Static grader manifest for hub validators that fetch JSON from the running Space."""
98
+ if not _GRADERS_JSON_PATH.is_file():
99
+ raise HTTPException(status_code=404, detail="graders.json not found in environment root")
100
+ return FileResponse(
101
+ _GRADERS_JSON_PATH,
102
+ media_type="application/json",
103
+ filename="graders.json",
104
+ )
105
+
106
+
107
  @app.get("/openenv.yaml")
108
  def openenv_manifest() -> FileResponse:
109
  """Serve the OpenEnv manifest so validators can read it from the running Space."""
app/models.py CHANGED
@@ -75,6 +75,8 @@ class TaskDefinition(BaseModel):
75
  code: str
76
  instructions: str
77
  criteria: list[list[str]]
 
 
78
 
79
 
80
  class GradeResult(BaseModel):
 
75
  code: str
76
  instructions: str
77
  criteria: list[list[str]]
78
+ # Explicit flag for static validators / hub scanners that inspect task definitions.
79
+ has_grader: bool = True
80
 
81
 
82
  class GradeResult(BaseModel):
app/tasks.py CHANGED
@@ -5,6 +5,7 @@ TASKS: dict[str, TaskDefinition] = {
5
  "easy": TaskDefinition(
6
  id="easy",
7
  task_type=TaskType.EASY,
 
8
  title="Detect syntax errors",
9
  code=(
10
  "def add_numbers(a, b)\n"
@@ -24,6 +25,7 @@ TASKS: dict[str, TaskDefinition] = {
24
  "medium": TaskDefinition(
25
  id="medium",
26
  task_type=TaskType.MEDIUM,
 
27
  title="Suggest optimization",
28
  code=(
29
  "def squared_evens(numbers):\n"
@@ -46,6 +48,7 @@ TASKS: dict[str, TaskDefinition] = {
46
  "hard": TaskDefinition(
47
  id="hard",
48
  task_type=TaskType.HARD,
 
49
  title="Full code review with scoring",
50
  code=(
51
  "def average(values):\n"
 
5
  "easy": TaskDefinition(
6
  id="easy",
7
  task_type=TaskType.EASY,
8
+ has_grader=True,
9
  title="Detect syntax errors",
10
  code=(
11
  "def add_numbers(a, b)\n"
 
25
  "medium": TaskDefinition(
26
  id="medium",
27
  task_type=TaskType.MEDIUM,
28
+ has_grader=True,
29
  title="Suggest optimization",
30
  code=(
31
  "def squared_evens(numbers):\n"
 
48
  "hard": TaskDefinition(
49
  id="hard",
50
  task_type=TaskType.HARD,
51
+ has_grader=True,
52
  title="Full code review with scoring",
53
  code=(
54
  "def average(values):\n"
graders.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "spec_version": 1,
3
+ "environment": "synapse_code_auditor",
4
+ "tasks_with_graders": 3,
5
+ "graders": [
6
+ { "task_id": "easy", "kind": "deterministic", "enabled": true },
7
+ { "task_id": "medium", "kind": "deterministic", "enabled": true },
8
+ { "task_id": "hard", "kind": "deterministic", "enabled": true }
9
+ ],
10
+ "score_policy": {
11
+ "min": 0.01,
12
+ "max": 0.99,
13
+ "strictly_between_zero_and_one": true
14
+ }
15
+ }
inference.py CHANGED
@@ -263,7 +263,7 @@ def main() -> None:
263
  "event": "task_completed",
264
  "index": index,
265
  "task_id": result.task_id,
266
- "score": result.score,
267
  "rationale": result.rationale,
268
  "latency_s": result.latency_s,
269
  },
@@ -280,7 +280,9 @@ def main() -> None:
280
  "timestamp": int(time.time()),
281
  "average_score": avg_score,
282
  "total_latency_s": total_latency,
283
- "tasks": [{"task_id": r.task_id, "score": r.score} for r in results],
 
 
284
  "status": status,
285
  },
286
  )
 
263
  "event": "task_completed",
264
  "index": index,
265
  "task_id": result.task_id,
266
+ "score": round(float(result.score), 4),
267
  "rationale": result.rationale,
268
  "latency_s": result.latency_s,
269
  },
 
280
  "timestamp": int(time.time()),
281
  "average_score": avg_score,
282
  "total_latency_s": total_latency,
283
+ "tasks": [
284
+ {"task_id": r.task_id, "score": round(float(r.score), 4)} for r in results
285
+ ],
286
  "status": status,
287
  },
288
  )
openenv.yaml CHANGED
@@ -38,6 +38,7 @@ endpoints:
38
  metadata: GET /metadata
39
  tasks: GET /tasks
40
  manifest: GET /openenv.yaml
 
41
  reset: POST /reset
42
  step: POST /step
43
  state: GET /state
 
38
  metadata: GET /metadata
39
  tasks: GET /tasks
40
  manifest: GET /openenv.yaml
41
+ graders_manifest: GET /graders.json
42
  reset: POST /reset
43
  step: POST /step
44
  state: GET /state
validate_submission.py CHANGED
@@ -62,11 +62,31 @@ def _check_openapi_reward_schema() -> None:
62
  client = TestClient(app)
63
  r = client.get("/openapi.json")
64
  assert r.status_code == 200
 
 
 
 
 
65
  data = r.json()
66
  reward = data["components"]["schemas"]["Reward"]["properties"]["score"]
67
  assert reward.get("minimum") == 0.01 and reward.get("maximum") == 0.99
68
 
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def _check_metadata_graders() -> None:
71
  client = TestClient(app)
72
  response = client.get("/metadata")
@@ -121,6 +141,11 @@ def _check_tasks_endpoint() -> None:
121
  f"/tasks task payload must not contain 0.0 or 1.0 floats (strict grader rules): {t}"
122
  )
123
 
 
 
 
 
 
124
 
125
  def _check_api_contracts() -> None:
126
  client = TestClient(app)
@@ -229,6 +254,8 @@ def main() -> None:
229
  root = Path(__file__).resolve().parent
230
 
231
  _check_openenv_yaml(root / "openenv.yaml")
 
 
232
  _check_openapi_reward_schema()
233
  _check_metadata_graders()
234
  _check_tasks_endpoint()
 
62
  client = TestClient(app)
63
  r = client.get("/openapi.json")
64
  assert r.status_code == 200
65
+ raw = json.dumps(r.json())
66
+ # Reject the old Pydantic pattern that embeds 0.0/1.0 as exclusive bounds on score.
67
+ assert '"exclusiveMinimum": 0.0' not in raw and '"exclusiveMaximum": 1.0' not in raw, (
68
+ "OpenAPI must not expose exclusive bounds 0.0/1.0 on scores (hub static validation)"
69
+ )
70
  data = r.json()
71
  reward = data["components"]["schemas"]["Reward"]["properties"]["score"]
72
  assert reward.get("minimum") == 0.01 and reward.get("maximum") == 0.99
73
 
74
 
75
+ def _check_graders_json(path: Path) -> None:
76
+ assert path.is_file(), "graders.json is required at repository root for hub scanners"
77
+ data = json.loads(path.read_text(encoding="utf-8"))
78
+ assert data.get("tasks_with_graders", 0) >= 3
79
+ graders = data.get("graders")
80
+ assert isinstance(graders, list) and len(graders) >= 3
81
+ enabled = sum(1 for g in graders if isinstance(g, dict) and g.get("enabled") is True)
82
+ assert enabled >= 3, "graders.json must list at least 3 enabled graders"
83
+
84
+
85
+ def _check_task_definitions_have_grader() -> None:
86
+ for task_id, task in TASKS.items():
87
+ assert task.has_grader is True, f"task {task_id} must have has_grader=True"
88
+
89
+
90
  def _check_metadata_graders() -> None:
91
  client = TestClient(app)
92
  response = client.get("/metadata")
 
141
  f"/tasks task payload must not contain 0.0 or 1.0 floats (strict grader rules): {t}"
142
  )
143
 
144
+ gm = client.get("/graders.json")
145
+ assert gm.status_code == 200, f"/graders.json returned {gm.status_code}"
146
+ gdata = gm.json()
147
+ assert len(gdata.get("graders", [])) >= 3
148
+
149
 
150
  def _check_api_contracts() -> None:
151
  client = TestClient(app)
 
254
  root = Path(__file__).resolve().parent
255
 
256
  _check_openenv_yaml(root / "openenv.yaml")
257
+ _check_graders_json(root / "graders.json")
258
+ _check_task_definitions_have_grader()
259
  _check_openapi_reward_schema()
260
  _check_metadata_graders()
261
  _check_tasks_endpoint()