diff --git a/server.py b/server.py index 67c1642..84697be 100644 --- a/server.py +++ b/server.py @@ -1787,20 +1787,33 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us # Helper to fetch from L1 without blocking event loop def fetch_l1_run(): - logger.info(f"record_run: Fetching run from L1: {l1_url}/runs/{req.run_id}") - resp = requests.get(f"{l1_url}/runs/{req.run_id}", timeout=30) + url = f"{l1_url}/runs/{req.run_id}" + logger.info(f"record_run: Fetching run from L1: {url}") + resp = requests.get(url, timeout=30) + if resp.status_code == 404: + raise ValueError(f"Run not found on L1: {req.run_id}") resp.raise_for_status() - return resp.json() + try: + return resp.json() + except Exception: + body_preview = resp.text[:200] if resp.text else "(empty)" + logger.error(f"L1 returned non-JSON for {url}: status={resp.status_code}, body={body_preview}") + raise ValueError(f"L1 returned invalid response: {body_preview[:100]}") def fetch_l1_cache(content_hash): logger.debug(f"record_run: Fetching cache {content_hash[:16]}... from L1") - resp = requests.get( - f"{l1_url}/cache/{content_hash}", - headers={"Accept": "application/json"}, - timeout=10 - ) + url = f"{l1_url}/cache/{content_hash}" + resp = requests.get(url, headers={"Accept": "application/json"}, timeout=10) + if resp.status_code == 404: + raise ValueError(f"Cache item not found on L1: {content_hash[:16]}...") resp.raise_for_status() - return resp.json() + try: + return resp.json() + except Exception as e: + # Log what we actually got back + body_preview = resp.text[:200] if resp.text else "(empty)" + logger.error(f"L1 returned non-JSON for {url}: status={resp.status_code}, body={body_preview}") + raise ValueError(f"L1 returned invalid response (status={resp.status_code}): {body_preview[:100]}") # Fetch run from L1 try: