Skip to content

Automate browser based workflows with AI

Scale the prod API out earlier and keep the reason every task stopped (SKY-14682) (#8248)

Aaron Perezf32549fde77c
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 09d863d19..2b6cbe71d 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -65,7 +65,15 @@ if TYPE_CHECKING:
LOG = structlog.get_logger()
_SESSION_CLEANUP_TIMEOUT_SECONDS = 5.0
-_BROWSER_PROBE_WAIT_SECONDS = 5.0
+# Sized to cover the manager's COMMON recovery so this deadline stops cancelling it midway and
+# reporting a session unverified that was about to be handed back: a 2s cached-handle probe, a
+# stale teardown the manager documents as additive (5s close + 5s driver stop), then a CDP
+# re-attach — roughly 12s of the 15s. It does NOT dominate the worst case, and is not meant to: a
+# cached wrapper that fails ``is_connected()`` routes to an unbounded close budgeted at
+# ``BROWSER_INTERCEPTOR_DISABLE_TIMEOUT + 3 * BROWSER_CLOSE_TIMEOUT`` (~9.5 min), which needs
+# bounding in cloud/ rather than a larger number here. ``ensure_browser_session`` applies this
+# twice in sequence — probe, then attach-verify — so the worst-case turn stall is double.
+_BROWSER_PROBE_WAIT_SECONDS = 15.0
# Browser contexts can lag the persistent-session row under load; this keeps
# Copilot from handing a not-yet-attachable session to the next MCP tool.
_BROWSER_BOOT_WAIT_SECONDS = 30.0
diff --git a/skyvern/webeye/utils/dom.py b/skyvern/webeye/utils/dom.py
index 31f774bd6..6a142636e 100644
--- a/skyvern/webeye/utils/dom.py
+++ b/skyvern/webeye/utils/dom.py
@@ -62,11 +62,13 @@ def is_incompatible_text_input_error(exc: BaseException) -> bool:
def is_element_detached_error(exc: BaseException) -> bool:
- # "Element is not attached to the DOM" (ElementHandle ops on a replaced node) and
- # "Frame was detached" (ops routed through a frame that navigated or was removed)
- # both mean the resolved target no longer exists in the live page.
+ # "Element is not attached to the DOM" (ElementHandle ops on a replaced node), "Frame was
+ # detached" (ops routed through a frame that navigated or was removed) and "Frame has been
+ # detached" (frame_element() on such a frame) all mean the target no longer exists in the live page.
message = str(exc).lower()
- return "not attached to the dom" in message or "frame was detached" in message
+ return (
+ "not attached to the dom" in message or "frame was detached" in message or "frame has been detached" in message
+ )
def is_engine_error(exc: BaseException, engine_selection: BrowserEngineSelection | None = None) -> bool:
diff --git a/tests/unit/test_stale_context_guards.py b/tests/unit/test_stale_context_guards.py
index 828c11819..c510b2711 100644
--- a/tests/unit/test_stale_context_guards.py
+++ b/tests/unit/test_stale_context_guards.py
@@ -11,12 +11,14 @@ from skyvern.webeye.utils.dom import SkyvernElement, is_element_detached_error,
_DETACHED_ERROR = "ElementHandle.content_frame: Element is not attached to the DOM"
_FRAME_DETACHED_ERROR = "Locator.count: Frame was detached"
+_FRAME_HAS_BEEN_DETACHED_ERROR = "Frame.frame_element: Frame has been detached."
_TYPE_TIMEOUT_ERROR = "Locator.type: Timeout 10000ms exceeded."
def test_predicate_matches_detached_errors() -> None:
assert is_element_detached_error(PlaywrightError(_DETACHED_ERROR)) is True
assert is_element_detached_error(PlaywrightError(_FRAME_DETACHED_ERROR)) is True
+ assert is_element_detached_error(PlaywrightError(_FRAME_HAS_BEEN_DETACHED_ERROR)) is True
assert is_element_detached_error(PlaywrightTimeoutError(_TYPE_TIMEOUT_ERROR)) is False