Nanda Kumar Kondreddy commited on
Commit ·
cf3a550
1
Parent(s): a91aa82
SIMPLIFY: Override /reset to create fresh environment directly, avoiding original endpoint call
Browse files- server/app.py +18 -25
server/app.py
CHANGED
|
@@ -26,10 +26,8 @@ app = create_fastapi_app(
|
|
| 26 |
|
| 27 |
# ---- Override OpenEnv's default /metadata route ----
|
| 28 |
# Remove the built-in metadata endpoint so we can replace it with task enumeration
|
| 29 |
-
reset_endpoint = None
|
| 30 |
for i, route in enumerate(app.router.routes):
|
| 31 |
if hasattr(route, "path") and route.path == "/reset":
|
| 32 |
-
reset_endpoint = route.endpoint
|
| 33 |
app.router.routes.pop(i)
|
| 34 |
print("[APP_INIT] Removed default /reset route for schema fix")
|
| 35 |
break
|
|
@@ -223,29 +221,24 @@ async def reset_env(request: Request):
|
|
| 223 |
"""
|
| 224 |
print("[VALIDATOR] POST /reset called - CUSTOM OVERRIDE")
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
print(f"[VALIDATOR] Error in custom reset: {e}")
|
| 245 |
-
raise
|
| 246 |
-
else:
|
| 247 |
-
print("[VALIDATOR] ERROR: reset_endpoint not saved")
|
| 248 |
-
raise RuntimeError("Reset endpoint initialization failed")
|
| 249 |
|
| 250 |
|
| 251 |
@app.get("/tasks")
|
|
|
|
| 26 |
|
| 27 |
# ---- Override OpenEnv's default /metadata route ----
|
| 28 |
# Remove the built-in metadata endpoint so we can replace it with task enumeration
|
|
|
|
| 29 |
for i, route in enumerate(app.router.routes):
|
| 30 |
if hasattr(route, "path") and route.path == "/reset":
|
|
|
|
| 31 |
app.router.routes.pop(i)
|
| 32 |
print("[APP_INIT] Removed default /reset route for schema fix")
|
| 33 |
break
|
|
|
|
| 221 |
"""
|
| 222 |
print("[VALIDATOR] POST /reset called - CUSTOM OVERRIDE")
|
| 223 |
|
| 224 |
+
try:
|
| 225 |
+
# Create a fresh environment for this session
|
| 226 |
+
env = ConfigDebugEnvironment()
|
| 227 |
+
observation = env.reset()
|
| 228 |
+
|
| 229 |
+
# Format response with correct schema
|
| 230 |
+
fixed_response = {
|
| 231 |
+
"observation": observation.model_dump(),
|
| 232 |
+
"done": False,
|
| 233 |
+
"reward": None,
|
| 234 |
+
"metadata": {},
|
| 235 |
+
"info": {}
|
| 236 |
+
}
|
| 237 |
+
print("[VALIDATOR] Reset response formatted with base fields")
|
| 238 |
+
return fixed_response
|
| 239 |
+
except Exception as e:
|
| 240 |
+
print(f"[VALIDATOR] Error in custom reset: {e}")
|
| 241 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
|
| 244 |
@app.get("/tasks")
|