PROTHAM commited on
Commit
41120b8
·
1 Parent(s): d3623ef

Enhance episode state isolation and realistic grader hints for max scoring

Browse files
graders/grader.py CHANGED
@@ -28,13 +28,13 @@ class APIGrader:
28
  if status == expected_status:
29
  return "Correct status code. Verify response schema matches expected."
30
  hints = {
31
- 401: "Authentication failed. Check Authorization header format and token value.",
32
- 403: "Forbidden. Token valid but lacks permission.",
33
- 404: "Endpoint not found. Check the URL path.",
34
- 405: "Wrong HTTP method. Check if endpoint needs GET POST PUT or DELETE.",
35
- 415: "Wrong Content-Type. Send application/json.",
36
- 422: "Body validation failed. Check field names types and required fields.",
37
- 429: "Rate limited. Add header X-Retry-After: 2 on next request.",
38
- 500: "Server error. Your payload caused an exception.",
39
  }
40
- return hints.get(status, f"Got {status} expected {expected_status}. Re-read task description carefully.")
 
28
  if status == expected_status:
29
  return "Correct status code. Verify response schema matches expected."
30
  hints = {
31
+ 401: "Authentication failed. The server could not verify your identity. Check your tokens or auth headers in the response.",
32
+ 403: "Forbidden. You authenticated successfully but lack permission for this explicit resource.",
33
+ 404: "Endpoint not found. Double-check the URL path and HTTP method.",
34
+ 405: "Method Not Allowed. The HTTP method used is not supported by this endpoint.",
35
+ 415: "Unsupported Media Type. The server expects a different Content-Type.",
36
+ 422: "Unprocessable Entity. The request body or query parameters failed validation. Check property names and data types.",
37
+ 429: "Too Many Requests. You have been rate limited. Look for a retry header.",
38
+ 500: "Internal Server Error. Your payload caused an unhandled exception.",
39
  }
40
+ return hints.get(status, f"Received status {status}. Read the response body/headers for clues and retry.")
server/api_debug_environment.py CHANGED
@@ -21,6 +21,13 @@ class APIDebugEnvironment(Environment):
21
  self._current_task = None
22
 
23
  def reset(self, task_id: str = "easy", **kwargs) -> APIObservation:
 
 
 
 
 
 
 
24
  if task_id not in TASK_REGISTRY:
25
  task_id = "easy"
26
  self._current_task = random.choice(TASK_REGISTRY[task_id])
 
21
  self._current_task = None
22
 
23
  def reset(self, task_id: str = "easy", **kwargs) -> APIObservation:
24
+ # Reset the mock API state to ensure strict episode isolation
25
+ try:
26
+ with httpx.Client(base_url=MOCK_BASE, timeout=2.0) as http:
27
+ http.post("/mock_api/_admin/reset")
28
+ except Exception:
29
+ pass
30
+
31
  if task_id not in TASK_REGISTRY:
32
  task_id = "easy"
33
  self._current_task = random.choice(TASK_REGISTRY[task_id])
server/mock_api.py CHANGED
@@ -14,6 +14,12 @@ LOG_PAGES = {
14
  "cur_def": {"items": list(range(20, 25)), "next_cursor": None, "has_more": False},
15
  }
16
 
 
 
 
 
 
 
17
 
18
  class TokenRequest(BaseModel):
19
  client_id: str
 
14
  "cur_def": {"items": list(range(20, 25)), "next_cursor": None, "has_more": False},
15
  }
16
 
17
+ @router.post("/_admin/reset")
18
+ async def admin_reset():
19
+ _issued_tokens.clear()
20
+ _request_log.clear()
21
+ return {"status": "reset_successful"}
22
+
23
 
24
  class TokenRequest(BaseModel):
25
  client_id: str