feat: add hermes web console cockpit and browser self-healing (#394)
Some checks failed
Contributor Attribution Check / check-attribution (pull_request) Failing after 36s
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 31s
Tests / e2e (pull_request) Successful in 3m37s
Tests / test (pull_request) Failing after 38m26s
Some checks failed
Contributor Attribution Check / check-attribution (pull_request) Failing after 36s
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 31s
Tests / e2e (pull_request) Successful in 3m37s
Tests / test (pull_request) Failing after 38m26s
This commit is contained in:
@@ -2218,6 +2218,70 @@ def cleanup_all_browsers() -> None:
|
||||
_command_timeout_resolved = False
|
||||
|
||||
|
||||
def browser_runtime_status() -> Dict[str, Any]:
|
||||
"""Return a machine-readable snapshot of the current browser runtime."""
|
||||
cdp_override = _get_cdp_override()
|
||||
provider = _get_cloud_provider()
|
||||
mode = "cdp" if cdp_override else ("cloud" if provider is not None else "local")
|
||||
|
||||
browser_cmd = None
|
||||
browser_error = None
|
||||
try:
|
||||
browser_cmd = _find_agent_browser()
|
||||
except FileNotFoundError as exc:
|
||||
browser_error = str(exc)
|
||||
|
||||
with _cleanup_lock:
|
||||
sessions = []
|
||||
for task_id, info in _active_sessions.items():
|
||||
sessions.append({
|
||||
"task_id": task_id,
|
||||
"session_name": info.get("session_name"),
|
||||
"cloud_session_id": info.get("bb_session_id"),
|
||||
"cdp_url": info.get("cdp_url"),
|
||||
"last_activity": _session_last_activity.get(task_id),
|
||||
})
|
||||
sessions.sort(key=lambda item: item["task_id"])
|
||||
recording_count = len(_recording_sessions)
|
||||
cleanup_thread_running = bool(_cleanup_running)
|
||||
|
||||
return {
|
||||
"mode": mode,
|
||||
"available": check_browser_requirements(),
|
||||
"cloud_provider": provider.provider_name() if provider is not None else None,
|
||||
"cdp_override": cdp_override or None,
|
||||
"agent_browser": {
|
||||
"available": browser_cmd is not None,
|
||||
"command": browser_cmd,
|
||||
"error": browser_error,
|
||||
},
|
||||
"session_count": len(sessions),
|
||||
"active_sessions": sessions,
|
||||
"recording_count": recording_count,
|
||||
"cleanup_thread_running": cleanup_thread_running,
|
||||
"inactivity_timeout_seconds": BROWSER_SESSION_INACTIVITY_TIMEOUT,
|
||||
"self_healing": {
|
||||
"inactivity_cleanup": True,
|
||||
"orphan_reaper": True,
|
||||
"emergency_cleanup": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def browser_runtime_heal() -> Dict[str, Any]:
|
||||
"""Run the browser layer's self-healing cleanup sequence."""
|
||||
before = browser_runtime_status()
|
||||
cleanup_all_browsers()
|
||||
_reap_orphaned_browser_sessions()
|
||||
after = browser_runtime_status()
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Browser runtime cleanup completed.",
|
||||
"before": before,
|
||||
"after": after,
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Requirements Check
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user