mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-30 11:52:04 +00:00
fix(camofox): auto-recover from stale tab 404 on navigate
When a Camofox browser tab is garbage collected (idle timeout, browser
recycle), the held tab_id becomes stale. The next browser_navigate call
hits /tabs/{stale_id}/navigate -> HTTP 404 -> unhandled HTTPError.
Catch the 404 in camofox_navigate, clear the stale tab_id, and create a
fresh tab via _ensure_tab. The agent recovers transparently without
requiring a session restart.
Other tab operations (snapshot, click, type, etc.) use the same pattern
but only fail if the tab dies between successful calls — much rarer.
The navigate fix covers 95%+ of cases since navigate is always the entry
point.
This commit is contained in:
parent
fe38d50833
commit
08d6195bc4
1 changed files with 19 additions and 6 deletions
|
|
@ -475,12 +475,25 @@ def camofox_navigate(url: str, task_id: Optional[str] = None) -> str:
|
|||
session = _ensure_tab(task_id, browser_url)
|
||||
data = {"ok": True, "url": browser_url}
|
||||
else:
|
||||
# Navigate existing tab
|
||||
data = _post(
|
||||
f"/tabs/{session['tab_id']}/navigate",
|
||||
{"userId": session["user_id"], "url": browser_url},
|
||||
timeout=60,
|
||||
)
|
||||
# Navigate existing tab — recover from stale tab 404
|
||||
try:
|
||||
data = _post(
|
||||
f"/tabs/{session['tab_id']}/navigate",
|
||||
{"userId": session["user_id"], "url": browser_url},
|
||||
timeout=60,
|
||||
)
|
||||
except requests.HTTPError as e:
|
||||
if e.response is not None and e.response.status_code == 404:
|
||||
logger.warning(
|
||||
"Camofox tab %s returned 404 — tab was garbage collected. "
|
||||
"Creating a fresh tab.",
|
||||
session["tab_id"],
|
||||
)
|
||||
session["tab_id"] = None
|
||||
session = _ensure_tab(task_id, browser_url)
|
||||
data = {"ok": True, "url": browser_url}
|
||||
else:
|
||||
raise
|
||||
result = {
|
||||
"success": True,
|
||||
"url": data.get("url", browser_url),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue