Spaces:
Paused
Paused
fix: fetch runtime logs in check_health when RUNNING but API unresponsive
Browse filesAgents were blind-guessing why Cain's API wasn't responding because
check_health only returned "Running but API not responding" with no logs.
Now fetches last 10 lines of runtime logs, giving agents concrete errors.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- scripts/conversation-loop.py +26 -1
scripts/conversation-loop.py
CHANGED
|
@@ -311,7 +311,32 @@ def action_check_health():
|
|
| 311 |
f"or config with [ACTION: write_file:dataset:.openclaw/openclaw.json]")
|
| 312 |
if stage in ("BUILDING", "STARTING", "APP_STARTING"):
|
| 313 |
return f"{CHILD_NAME} is starting up (stage: {stage}). Be patient."
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
except Exception as e:
|
| 316 |
return f"Cannot reach {CHILD_NAME}: {e}"
|
| 317 |
|
|
|
|
| 311 |
f"or config with [ACTION: write_file:dataset:.openclaw/openclaw.json]")
|
| 312 |
if stage in ("BUILDING", "STARTING", "APP_STARTING"):
|
| 313 |
return f"{CHILD_NAME} is starting up (stage: {stage}). Be patient."
|
| 314 |
+
if stage == "RUNNING":
|
| 315 |
+
# API not responding — fetch runtime logs to help agents diagnose
|
| 316 |
+
log_snippet = ""
|
| 317 |
+
try:
|
| 318 |
+
log_resp = requests.get(
|
| 319 |
+
f"https://api.hf.space/v1/{CHILD_SPACE_ID}/logs/run",
|
| 320 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}"}, timeout=10,
|
| 321 |
+
stream=True)
|
| 322 |
+
if log_resp.ok:
|
| 323 |
+
log_lines = []
|
| 324 |
+
for line in log_resp.iter_lines(decode_unicode=True):
|
| 325 |
+
if line and line.startswith("data:"):
|
| 326 |
+
try:
|
| 327 |
+
entry = json.loads(line[5:])
|
| 328 |
+
log_lines.append(entry.get("data", "").strip())
|
| 329 |
+
except:
|
| 330 |
+
pass
|
| 331 |
+
if len(log_lines) >= 30:
|
| 332 |
+
break
|
| 333 |
+
meaningful = [l for l in log_lines if l and len(l) > 5]
|
| 334 |
+
if meaningful:
|
| 335 |
+
log_snippet = "\nRUNTIME LOGS (last 10 lines):\n" + "\n".join(meaningful[-10:])
|
| 336 |
+
except:
|
| 337 |
+
pass
|
| 338 |
+
return f"{CHILD_NAME} stage: RUNNING. Running but API not responding.{log_snippet}"
|
| 339 |
+
return f"{CHILD_NAME} stage: {stage}."
|
| 340 |
except Exception as e:
|
| 341 |
return f"Cannot reach {CHILD_NAME}: {e}"
|
| 342 |
|