Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Give each code-block engine its own failure reason when it cannot open a tab (SKY-13338) (#8036)
Aaron Perez447462078637
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex 8815e9b44..906d7ea44 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -3736,6 +3736,8 @@ class CodeBlockCaptchaError(Exception):"""Sanitized CAPTCHA-primitive error with no site, selector, vendor, or token details."""+CODE_BLOCK_TAB_OPEN_FAILURE_REASON = "Code block could not open a tab in the browser session; the session's browser may be held by another Playwright client"+_CODE_BLOCK_CAPTCHA_CHECKBOX_SELECTOR = ", ".join(('input[type="checkbox"][id*="captcha" i]',@@ -5539,8 +5541,10 @@ async def wrapper({default_args}):page = await browser_state.get_working_page()if page is None:- # A session can arrive holding a context with no tab, leaving nothing to adopt. Only a- # raise here means the session is genuinely unusable.+ # A session can arrive holding a context with no tab, leaving nothing to adopt. Opening+ # one can raise even on a live context: when another Playwright client enabled autoAttach+ # first, it owns target announcements and this connection stays blind to pages+ # (SKY-13338) — no reconnect or retry from here can fix that.try:page = await browser_state.get_or_create_page()except Exception:@@ -5552,16 +5556,14 @@ async def wrapper({default_args}):browser_session_id=browser_session_id,block_label=self.label,)- page = None- if not page:- return await self.build_block_result(- success=False,- failure_reason="No page found to run the code block",- output_parameter_value=None,- status=BlockStatus.failed,- workflow_run_block_id=workflow_run_block_id,- organization_id=organization_id,- )+ return await self.build_block_result(+ success=False,+ failure_reason=CODE_BLOCK_TAB_OPEN_FAILURE_REASON,+ output_parameter_value=None,+ status=BlockStatus.failed,+ workflow_run_block_id=workflow_run_block_id,+ organization_id=organization_id,+ )await self._ensure_run_recording_artifact(browser_state=browser_state,diff --git a/tests/unit/test_code_block_sandbox.py b/tests/unit/test_code_block_sandbox.pyindex 893faa0d7..420317179 100644--- a/tests/unit/test_code_block_sandbox.py+++ b/tests/unit/test_code_block_sandbox.py@@ -15,7 +15,7 @@ import pytestfrom skyvern.config import settingsfrom skyvern.forge.sdk.workflow.exceptions import InsecureCodeDetected-from skyvern.forge.sdk.workflow.models.block import CodeBlock+from skyvern.forge.sdk.workflow.models.block import CODE_BLOCK_TAB_OPEN_FAILURE_REASON, CodeBlockfrom skyvern.forge.sdk.workflow.models.parameter import OutputParameter, ParameterTypefrom skyvern.schemas.workflows import BlockStatusfrom skyvern.webeye.browser_artifacts import BrowserArtifacts@@ -927,7 +927,8 @@ async def wrapper({default_args}):assert (open_attempts, created_pages) == (1, 0)assert result.success is Falseassert result.status == BlockStatus.failed- assert result.failure_reason == "No page found to run the code block"+ assert result.failure_reason == CODE_BLOCK_TAB_OPEN_FAILURE_REASON+ assert result.failure_reason != "No page found to run the code block"def test_poc_blocked_at_is_safe_code_gate(self) -> None:"""The PoC payload is rejected before exec() is ever called."""