Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
refactor: remove broken effective_browser_session_id suppression (SKY-8465) (#5166)
Celal Zamanoğlu42755ce6cd83
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex 8f3e67b87..f2f8e4bc1 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -6085,10 +6085,15 @@ class ConditionalBlock(Block):}# Step 4: Create and execute single ExtractionBlock.- # When all expressions have been Jinja-rendered successfully, omit- # browser_session_id so the LLM won't reinterpret resolved literal- # values as on-screen references (SKY-7985).- effective_browser_session_id = browser_session_id if has_any_pure_natlang else None+ # Always pass the browser_session_id so page-referencing conditions+ # (e.g. "the date on the page matches X") can see the screenshot.+ # The prompt template instructs the LLM to only use page content+ # when the condition explicitly references the page, and to evaluate+ # self-contained conditions purely from the expression text.+ # NOTE: The previous approach of setting browser_session_id=None for+ # Jinja-rendered expressions (SKY-7985) was ineffective because+ # BaseTaskBlock.execute() finds the browser via workflow_run_id cache+ # regardless of browser_session_id.output_param = OutputParameter(output_parameter_id=str(uuid.uuid4()),@@ -6111,7 +6116,7 @@ class ConditionalBlock(Block):block_label=self.label,num_conditions=len(branches),extraction_goal_preview=extraction_goal[:500] if extraction_goal else None,- has_browser_session=effective_browser_session_id is not None,+ has_browser_session=browser_session_id is not None,has_any_pure_natlang=has_any_pure_natlang,has_context=context_json is not None,)@@ -6121,7 +6126,7 @@ class ConditionalBlock(Block):workflow_run_id=workflow_run_id,workflow_run_block_id=workflow_run_block_id,organization_id=organization_id,- browser_session_id=effective_browser_session_id,+ browser_session_id=browser_session_id,)if not extraction_result.success:diff --git a/tests/unit/workflow/test_conditional_branch_evaluation.py b/tests/unit/workflow/test_conditional_branch_evaluation.pyindex 4a89582e1..1a1c653cf 100644--- a/tests/unit/workflow/test_conditional_branch_evaluation.py+++ b/tests/unit/workflow/test_conditional_branch_evaluation.py@@ -49,10 +49,12 @@ def _extraction_result(output_parameter: OutputParameter, evaluations: list[dict@pytest.mark.asyncio-async def test_jinja_rendered_prompt_condition_omits_browser_session() -> None:- """When all expressions are fully Jinja-rendered, ExtractionBlock should be used- but with browser_session_id=None to prevent the LLM from reinterpreting resolved- literal values as on-screen references (SKY-7985)."""+async def test_jinja_rendered_prompt_condition_keeps_browser_session() -> None:+ """When all expressions are fully Jinja-rendered, ExtractionBlock should still+ receive the browser_session_id so that page-referencing conditions (e.g.+ "the date on the page matches {{date}}") can see the screenshot. The prompt+ template instructs the LLM to only use page content when the condition+ explicitly references the page (SKY-8465)."""block = _conditional_block()branch = BranchCondition(criteria=PromptBranchCriteria(expression='{{Single_or_Joint__c}} == "Joint"'),@@ -89,9 +91,9 @@ async def test_jinja_rendered_prompt_condition_omits_browser_session() -> None:assert results == [True]assert rendered_expressions == ['Joint == "Joint"']- # ExtractionBlock should be called with browser_session_id=None (not "bs_test")+ # ExtractionBlock should be called with the real browser_session_idmock_extraction.execute.assert_awaited_once()- assert mock_extraction.execute.call_args.kwargs["browser_session_id"] is None+ assert mock_extraction.execute.call_args.kwargs["browser_session_id"] == "bs_test"# No context should be passed when all expressions are Jinja-renderedevaluation_context.build_llm_safe_context_snapshot.assert_not_called() # type: ignore[attr-defined]assert mock_prompt.call_args.kwargs["context_json"] is None