Nanda Kumar Kondreddy commited on
Commit ·
5bc98e9
1
Parent(s): 9f8c7b6
FIX: Add middleware to correct /reset response schema - add 'info' field, remove reward/done
Browse files- server/app.py +36 -1
server/app.py
CHANGED
|
@@ -5,6 +5,8 @@ Uses OpenEnv's create_fastapi_app() for standard framework compatibility
|
|
| 5 |
"""
|
| 6 |
import json
|
| 7 |
import gradio as gr
|
|
|
|
|
|
|
| 8 |
|
| 9 |
from openenv.core.env_server import create_fastapi_app
|
| 10 |
from server.models import ConfigDebugAction, ConfigDebugObservation, ConfigDebugState
|
|
@@ -27,6 +29,39 @@ for i, route in enumerate(app.router.routes):
|
|
| 27 |
print("[APP_INIT] Removed default /metadata route for override")
|
| 28 |
break
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# ---- Startup Diagnostics ----
|
| 31 |
print("[APP_INIT] ConfigDebugEnvironment initialization started")
|
| 32 |
print(f"[APP_INIT] Loaded {len(TASK_ORDER)} tasks: {TASK_ORDER}")
|
|
@@ -153,7 +188,7 @@ def metadata():
|
|
| 153 |
print("[VALIDATOR] GET /metadata called")
|
| 154 |
return {
|
| 155 |
"name": "ConfigDebugEnvironment",
|
| 156 |
-
"description": "An
|
| 157 |
"version": "1.0.0",
|
| 158 |
"tasks": [
|
| 159 |
{
|
|
|
|
| 5 |
"""
|
| 6 |
import json
|
| 7 |
import gradio as gr
|
| 8 |
+
from starlette.middleware.base import BaseHTTPMiddleware
|
| 9 |
+
from starlette.responses import JSONResponse
|
| 10 |
|
| 11 |
from openenv.core.env_server import create_fastapi_app
|
| 12 |
from server.models import ConfigDebugAction, ConfigDebugObservation, ConfigDebugState
|
|
|
|
| 29 |
print("[APP_INIT] Removed default /metadata route for override")
|
| 30 |
break
|
| 31 |
|
| 32 |
+
# ---- Middleware to fix /reset response schema ----
|
| 33 |
+
# OpenEnv returns {"observation": {...}, "reward": 0.0, "done": false}
|
| 34 |
+
# but validator expects {"observation": {...}, "info": {}}
|
| 35 |
+
class ResetSchemaFixMiddleware(BaseHTTPMiddleware):
|
| 36 |
+
async def dispatch(self, request, call_next):
|
| 37 |
+
response = await call_next(request)
|
| 38 |
+
|
| 39 |
+
# Only fix /reset responses
|
| 40 |
+
if request.url.path == "/reset" and request.method == "POST":
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
try:
|
| 43 |
+
# Get response body
|
| 44 |
+
body = b""
|
| 45 |
+
async for chunk in response.body_iterator:
|
| 46 |
+
body += chunk
|
| 47 |
+
|
| 48 |
+
data = json.loads(body)
|
| 49 |
+
|
| 50 |
+
# Fix schema: keep only observation and add info
|
| 51 |
+
if isinstance(data, dict) and "observation" in data:
|
| 52 |
+
fixed_data = {
|
| 53 |
+
"observation": data["observation"],
|
| 54 |
+
"info": {}
|
| 55 |
+
}
|
| 56 |
+
print("[MIDDLEWARE] Fixed /reset response schema")
|
| 57 |
+
return JSONResponse(fixed_data, status_code=200)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"[MIDDLEWARE] Error fixing reset response: {e}")
|
| 60 |
+
|
| 61 |
+
return response
|
| 62 |
+
|
| 63 |
+
app.add_middleware(ResetSchemaFixMiddleware)
|
| 64 |
+
|
| 65 |
# ---- Startup Diagnostics ----
|
| 66 |
print("[APP_INIT] ConfigDebugEnvironment initialization started")
|
| 67 |
print(f"[APP_INIT] Loaded {len(TASK_ORDER)} tasks: {TASK_ORDER}")
|
|
|
|
| 188 |
print("[VALIDATOR] GET /metadata called")
|
| 189 |
return {
|
| 190 |
"name": "ConfigDebugEnvironment",
|
| 191 |
+
"description": "An environment for training AI agents to debug broken configuration files",
|
| 192 |
"version": "1.0.0",
|
| 193 |
"tasks": [
|
| 194 |
{
|