Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-11087 Default unset runtime proxy to none (#6634)
Andrew Neilsonb6cd2cf47265
diff --git a/skyvern/config.py b/skyvern/config.pyindex ffd91607e..7852198ec 100644--- a/skyvern/config.py+++ b/skyvern/config.py@@ -180,6 +180,9 @@ class Settings(BaseSettings):# one with no scout_interaction this turn, and the evaluate tool is framed as the scout-act# path for interaction-gated affordances. Off (default) restores today's inspect-then-author.COPILOT_DOWNLOAD_SCOUT_ACT_REQUIRED_ENABLED: bool = False+ # Staged rollout for treating omitted runtime workflow proxy values as direct/no-proxy.+ # Off preserves the historical implicit residential default for anti-bot-sensitive traffic.+ RUNTIME_PROXY_DEFAULT_NONE_ENABLED: bool = False# Dispatch flag for the workflow copilot v2 (openai-agents-SDK rewrite).# Off = existing direct-LLM copilot at workflow_copilot_chat_post.# On = new agent-SDK path under skyvern.forge.sdk.copilot.diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.pyindex 443f2fb47..214df7ef1 100644--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py@@ -56,7 +56,7 @@ from skyvern.forge.sdk.workflow.exceptions import BaseWorkflowHTTPException, Insfrom skyvern.forge.sdk.workflow.models.block import CodeBlockfrom skyvern.forge.sdk.workflow.models.parameter import RESERVED_PARAMETER_KEYS, is_sensitive_workflow_parameterfrom skyvern.forge.sdk.workflow.models.workflow import Workflow-from skyvern.schemas.proxy_location import ProxyLocation+from skyvern.schemas.proxy_location import runtime_proxy_locationfrom skyvern.schemas.workflows import BlockTypefrom ._shared import (@@ -2180,7 +2180,7 @@ async def _update_workflow(def _record_workflow_proxy_location_span(workflow_yaml: str, workflow: Workflow) -> None:input_present, input_proxy_location = _raw_yaml_proxy_location(workflow_yaml)- effective_proxy_location = _proxy_location_trace_value(workflow.proxy_location)+ effective_proxy_location = _proxy_location_trace_value(runtime_proxy_location(workflow.proxy_location))with copilot_span("workflow_proxy_location_normalized",data={@@ -2218,7 +2218,7 @@ def _record_workflow_update_result(copilot_ctx.last_workflow = wf_clear_resolved_per_tool_budget_problem_labels(copilot_ctx, wf)copilot_ctx.last_workflow_yaml = copilot_ctx.workflow_yaml or None- copilot_ctx.effective_workflow_proxy_location = getattr(wf, "proxy_location", None) or ProxyLocation.RESIDENTIAL+ copilot_ctx.effective_workflow_proxy_location = runtime_proxy_location(getattr(wf, "proxy_location", None))data = result.get("data")if isinstance(data, dict):block_count = data.get("block_count")diff --git a/skyvern/forge/sdk/routes/debug_sessions.py b/skyvern/forge/sdk/routes/debug_sessions.pyindex 6fc10b4a6..a4210863b 100644--- a/skyvern/forge/sdk/routes/debug_sessions.py+++ b/skyvern/forge/sdk/routes/debug_sessions.py@@ -24,7 +24,7 @@ from skyvern.forge.sdk.workflow.service import (DEBUG_SESSION_PROFILE_REASON_DIFFERENT,DEBUG_SESSION_PROFILE_REASON_NO_PROFILE,)-from skyvern.schemas.runs import ProxyLocation+from skyvern.schemas.proxy_location import runtime_proxy_locationLOG = structlog.get_logger()@@ -285,7 +285,7 @@ async def new_debug_session(workflow_permanent_id=workflow_permanent_id,organization_id=current_org.organization_id,)- proxy_location = workflow.proxy_location or ProxyLocation.RESIDENTIAL+ proxy_location = runtime_proxy_location(workflow.proxy_location)new_browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(organization_id=current_org.organization_id,diff --git a/skyvern/forge/sdk/routes/run_blocks.py b/skyvern/forge/sdk/routes/run_blocks.pyindex 7ccbd2175..69481aa38 100644--- a/skyvern/forge/sdk/routes/run_blocks.py+++ b/skyvern/forge/sdk/routes/run_blocks.py@@ -24,8 +24,9 @@ from skyvern.forge.sdk.schemas.organizations import Organizationfrom skyvern.forge.sdk.services import org_auth_servicefrom skyvern.forge.sdk.workflow.models.parameter import WorkflowParameterTypefrom skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRequestBody+from skyvern.schemas.proxy_location import runtime_proxy_locationfrom skyvern.schemas.run_blocks import BaseRunBlockRequest, CredentialType, DownloadFilesRequest, LoginRequest-from skyvern.schemas.runs import ProxyLocation, RunType, WorkflowRunRequest, WorkflowRunResponse+from skyvern.schemas.runs import RunType, WorkflowRunRequest, WorkflowRunResponsefrom skyvern.schemas.workflows import (AzureVaultCredentialParameterYAML,BitwardenLoginCredentialParameterYAML,@@ -259,7 +260,7 @@ async def login(workflow_create_request = WorkflowCreateYAMLRequest(title=new_workflow.title,description=new_workflow.description,- proxy_location=login_request.proxy_location or ProxyLocation.RESIDENTIAL,+ proxy_location=runtime_proxy_location(login_request.proxy_location),workflow_definition=workflow_definition_yaml,status=new_workflow.status,max_screenshot_scrolls=login_request.max_screenshot_scrolling_times,@@ -352,7 +353,7 @@ async def download_files(workflow_create_request = WorkflowCreateYAMLRequest(title=new_workflow.title,description=new_workflow.description,- proxy_location=download_files_request.proxy_location or ProxyLocation.RESIDENTIAL,+ proxy_location=runtime_proxy_location(download_files_request.proxy_location),workflow_definition=workflow_definition_yaml,status=new_workflow.status,max_screenshot_scrolls=download_files_request.max_screenshot_scrolling_times,diff --git a/skyvern/schemas/proxy_location.py b/skyvern/schemas/proxy_location.pyindex b0d6ac87f..05ce9dabd 100644--- a/skyvern/schemas/proxy_location.py+++ b/skyvern/schemas/proxy_location.py@@ -6,6 +6,8 @@ from zoneinfo import ZoneInfofrom pydantic import BaseModel, Field, field_validator+from skyvern.config import settings+class ProxyLocation(StrEnum):RESIDENTIAL = "RESIDENTIAL"@@ -207,7 +209,16 @@ class GeoTarget(BaseModel):return v-ProxyLocationInput = ProxyLocation | GeoTarget | dict[str, Any] | None+ResolvedProxyLocationInput = ProxyLocation | GeoTarget | dict[str, Any]+ProxyLocationInput = ResolvedProxyLocationInput | None+++def runtime_proxy_location(proxy_location: ProxyLocationInput) -> ResolvedProxyLocationInput:+ if proxy_location is None:+ if not settings.RUNTIME_PROXY_DEFAULT_NONE_ENABLED:+ return ProxyLocation.RESIDENTIAL+ return ProxyLocation.NONE+ return proxy_locationdef proxy_location_to_request(proxy_location: ProxyLocationInput) -> ProxyLocation | dict[str, Any] | None:diff --git a/skyvern/services/task_v2_service.py b/skyvern/services/task_v2_service.pyindex dae24cabd..181a85785 100644--- a/skyvern/services/task_v2_service.py+++ b/skyvern/services/task_v2_service.py@@ -41,8 +41,8 @@ from skyvern.forge.sdk.workflow.models.block import ()from skyvern.forge.sdk.workflow.models.parameter import PARAMETER_TYPE, ContextParameterfrom skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRequestBody, WorkflowRun, WorkflowRunStatus+from skyvern.schemas.proxy_location import runtime_proxy_locationfrom skyvern.schemas.runs import (- ProxyLocation,ProxyLocationInput,RunEngine,RunStatus,@@ -1020,7 +1020,7 @@ async def run_task_v2_helper(workflow_create_request = WorkflowCreateYAMLRequest(title=workflow.title,description=workflow.description,- proxy_location=task_v2.proxy_location or ProxyLocation.RESIDENTIAL,+ proxy_location=runtime_proxy_location(task_v2.proxy_location),workflow_definition=workflow_definition_yaml,status=workflow.status,max_screenshot_scrolls=task_v2.max_screenshot_scrolls,diff --git a/tests/unit/forge/sdk/routes/test_debug_sessions.py b/tests/unit/forge/sdk/routes/test_debug_sessions.pyindex 2b44508ec..7e643f826 100644--- a/tests/unit/forge/sdk/routes/test_debug_sessions.py+++ b/tests/unit/forge/sdk/routes/test_debug_sessions.py@@ -3,11 +3,28 @@ from unittest.mock import AsyncMock, MagicMock, patchimport pytest+from skyvern.config import settingsfrom skyvern.forge.sdk.routes import debug_sessions as debug_sessions_mod--+from skyvern.schemas.runs import ProxyLocation+++ ("rollout_enabled", "workflow_proxy_location", "expected_proxy_location"),+ [+ (False, None, ProxyLocation.RESIDENTIAL),+ (True, None, ProxyLocation.NONE),+ (False, ProxyLocation.RESIDENTIAL_GB, ProxyLocation.RESIDENTIAL_GB),+ (False, ProxyLocation.NONE, ProxyLocation.NONE),+ ],+)@pytest.mark.asyncio-async def test_new_debug_session_skips_redundant_local_close_before_create() -> None:+async def test_new_debug_session_uses_workflow_proxy_default_for_created_browser(+ monkeypatch: pytest.MonkeyPatch,+ rollout_enabled: bool,+ workflow_proxy_location: ProxyLocation | None,+ expected_proxy_location: ProxyLocation,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", rollout_enabled)created_debug_session = SimpleNamespace(debug_session_id="ds_new", pbs_browser_profile_id=None)new_browser_session = SimpleNamespace(persistent_browser_session_id="pbs_new",@@ -24,7 +41,7 @@ async def test_new_debug_session_skips_redundant_local_close_before_create() ->app_mock.DATABASE.debug.create_debug_session = AsyncMock(return_value=created_debug_session)app_mock.DATABASE.browser_sessions.get_persistent_browser_session = AsyncMock()app_mock.WORKFLOW_SERVICE.get_workflow_by_permanent_id = AsyncMock(- return_value=SimpleNamespace(proxy_location=None)+ return_value=SimpleNamespace(proxy_location=workflow_proxy_location))app_mock.PERSISTENT_SESSIONS_MANAGER.close_session = AsyncMock()app_mock.PERSISTENT_SESSIONS_MANAGER.create_session = AsyncMock(return_value=new_browser_session)@@ -45,7 +62,7 @@ async def test_new_debug_session_skips_redundant_local_close_before_create() ->app_mock.PERSISTENT_SESSIONS_MANAGER.create_session.assert_awaited_once_with(organization_id="org_123",timeout_minutes=debug_sessions_mod.settings.DEBUG_SESSION_TIMEOUT_MINUTES,- proxy_location=debug_sessions_mod.ProxyLocation.RESIDENTIAL,+ proxy_location=expected_proxy_location,wait_for_startup=False,)app_mock.DATABASE.debug.create_debug_session.assert_awaited_once_with(diff --git a/tests/unit/forge/sdk/routes/test_run_blocks_proxy_location.py b/tests/unit/forge/sdk/routes/test_run_blocks_proxy_location.pynew file mode 100644index 000000000..1af37ad3b--- /dev/null+++ b/tests/unit/forge/sdk/routes/test_run_blocks_proxy_location.py@@ -0,0 +1,112 @@+from types import SimpleNamespace+from unittest.mock import AsyncMock, MagicMock, patch++import pytest+from fastapi import BackgroundTasks++from skyvern.config import settings+from skyvern.forge.sdk.routes import run_blocks as run_blocks_mod+from skyvern.schemas.credential_type import CredentialType+from skyvern.schemas.run_blocks import DownloadFilesRequest, LoginRequest+from skyvern.schemas.runs import ProxyLocation+++def _workflow_stub() -> SimpleNamespace:+ return SimpleNamespace(+ title="Generated workflow",+ description=None,+ status="auto_generated",+ workflow_permanent_id="wpid_test",+ workflow_id="wf_test",+ )+++def _app_mock() -> MagicMock:+ app_mock = MagicMock()+ app_mock.WORKFLOW_SERVICE.create_empty_workflow = AsyncMock(return_value=_workflow_stub())+ app_mock.WORKFLOW_SERVICE.create_workflow_from_request = AsyncMock(return_value=_workflow_stub())+ app_mock.DATABASE.credentials.get_credential = AsyncMock(return_value=SimpleNamespace(totp_identifier=None))+ return app_mock+++ ("rollout_enabled", "input_proxy_location", "expected_proxy_location"),+ [+ (False, None, ProxyLocation.RESIDENTIAL),+ (True, None, ProxyLocation.NONE),+ (False, ProxyLocation.RESIDENTIAL_GB, ProxyLocation.RESIDENTIAL_GB),+ (False, ProxyLocation.NONE, ProxyLocation.NONE),+ ],+)+async def test_login_generated_workflow_uses_runtime_proxy_default(+ monkeypatch: pytest.MonkeyPatch,+ rollout_enabled: bool,+ input_proxy_location: ProxyLocation | None,+ expected_proxy_location: ProxyLocation,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", rollout_enabled)+ app_mock = _app_mock()+ response = SimpleNamespace(run_id="wr_test")+ run_response = AsyncMock(return_value=response)++ with (+ patch.object(run_blocks_mod, "app", app_mock),+ patch.object(run_blocks_mod, "_run_workflow_and_build_response", run_response),+ ):+ result = await run_blocks_mod.login(+ request=MagicMock(),+ background_tasks=BackgroundTasks(),+ login_request=LoginRequest(+ url="https://example.com",+ credential_type=CredentialType.skyvern,+ credential_id="cred_test",+ proxy_location=input_proxy_location,+ ),+ organization=SimpleNamespace(organization_id="org_test"),+ )++ assert result is response+ workflow_request = app_mock.WORKFLOW_SERVICE.create_workflow_from_request.await_args.kwargs["request"]+ assert workflow_request.proxy_location == expected_proxy_location+++ ("rollout_enabled", "input_proxy_location", "expected_proxy_location"),+ [+ (False, None, ProxyLocation.RESIDENTIAL),+ (True, None, ProxyLocation.NONE),+ (False, ProxyLocation.RESIDENTIAL_GB, ProxyLocation.RESIDENTIAL_GB),+ (False, ProxyLocation.NONE, ProxyLocation.NONE),+ ],+)+async def test_download_files_generated_workflow_uses_runtime_proxy_default(+ monkeypatch: pytest.MonkeyPatch,+ rollout_enabled: bool,+ input_proxy_location: ProxyLocation | None,+ expected_proxy_location: ProxyLocation,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", rollout_enabled)+ app_mock = _app_mock()+ response = SimpleNamespace(run_id="wr_test")+ run_response = AsyncMock(return_value=response)++ with (+ patch.object(run_blocks_mod, "app", app_mock),+ patch.object(run_blocks_mod, "_run_workflow_and_build_response", run_response),+ ):+ result = await run_blocks_mod.download_files(+ request=MagicMock(),+ background_tasks=BackgroundTasks(),+ download_files_request=DownloadFilesRequest(+ url="https://example.com",+ navigation_goal="Download the statement.",+ proxy_location=input_proxy_location,+ ),+ organization=SimpleNamespace(organization_id="org_test"),+ )++ assert result is response+ workflow_request = app_mock.WORKFLOW_SERVICE.create_workflow_from_request.await_args.kwargs["request"]+ assert workflow_request.proxy_location == expected_proxy_locationdiff --git a/tests/unit/test_copilot_non_retriable_nav.py b/tests/unit/test_copilot_non_retriable_nav.pyindex 8bdf63952..54484227f 100644--- a/tests/unit/test_copilot_non_retriable_nav.py+++ b/tests/unit/test_copilot_non_retriable_nav.py@@ -13,6 +13,7 @@ from types import SimpleNamespaceimport pytest+from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.context import CopilotContextfrom skyvern.forge.sdk.copilot.enforcement import (POST_NON_RETRIABLE_NAV_ERROR_STOP_NUDGE,@@ -32,6 +33,7 @@ from skyvern.forge.sdk.copilot.tools import (_record_workflow_update_result,_tool_loop_error,)+from skyvern.schemas.runs import ProxyLocation_DNS_FAILURE_REASON = ("Failed to navigate to url https://www.example.invalid/path. Error message: net::ERR_NAME_NOT_RESOLVED"@@ -184,6 +186,36 @@ def test_workflow_update_clears_non_retriable_flag_and_signature_latch() -> Noneassert ctx.last_test_failure_reason is None+ ("rollout_enabled", "workflow_proxy_location", "expected_proxy_location"),+ [+ (False, None, ProxyLocation.RESIDENTIAL),+ (True, None, ProxyLocation.NONE),+ (False, ProxyLocation.RESIDENTIAL_GB, ProxyLocation.RESIDENTIAL_GB),+ (False, ProxyLocation.NONE, ProxyLocation.NONE),+ ],+)+def test_workflow_update_records_runtime_proxy_default(+ monkeypatch: pytest.MonkeyPatch,+ rollout_enabled: bool,+ workflow_proxy_location: ProxyLocation | None,+ expected_proxy_location: ProxyLocation,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", rollout_enabled)+ ctx = _fresh_context()++ _record_workflow_update_result(+ ctx,+ {+ "ok": True,+ "data": {"block_count": 1},+ "_workflow": SimpleNamespace(workflow_id="wf_new", proxy_location=workflow_proxy_location),+ },+ )++ assert ctx.effective_workflow_proxy_location == expected_proxy_location++def test_workflow_update_does_not_clear_flag_on_failed_update() -> None:# Only a SUCCESSFUL update invalidates prior test state — a failed# validation attempt leaves the existing flags alone.diff --git a/tests/unit/test_proxy_location_defaults.py b/tests/unit/test_proxy_location_defaults.pynew file mode 100644index 000000000..758ebfc0b--- /dev/null+++ b/tests/unit/test_proxy_location_defaults.py@@ -0,0 +1,33 @@+import pytest++from skyvern.config import settings+from skyvern.schemas.proxy_location import GeoTarget, ProxyLocation, runtime_proxy_location+++def test_runtime_proxy_location_preserves_legacy_default_when_rollout_disabled(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", False)++ assert runtime_proxy_location(None) == ProxyLocation.RESIDENTIAL+++def test_runtime_proxy_location_defaults_missing_value_to_no_proxy_when_rollout_enabled(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(settings, "RUNTIME_PROXY_DEFAULT_NONE_ENABLED", True)++ assert runtime_proxy_location(None) == ProxyLocation.NONE+++def test_runtime_proxy_location_preserves_explicit_proxy_values() -> None:+ assert runtime_proxy_location(ProxyLocation.RESIDENTIAL) == ProxyLocation.RESIDENTIAL+ assert runtime_proxy_location(ProxyLocation.NONE) == ProxyLocation.NONE+++def test_runtime_proxy_location_preserves_geotarget_and_custom_proxy_values() -> None:+ geo_target = GeoTarget(country="GB", city="London")+ custom_proxy = {"url": "http://proxy.example.com:8080"}++ assert runtime_proxy_location(geo_target) is geo_target+ assert runtime_proxy_location(custom_proxy) is custom_proxy