Skip to content

Automate browser based workflows with AI

fix(SKY-11690): rewire wait_utils killswitch through app.AGENT_FUNCTION; delete cloud import (#7353)

Aaron Perez7792f9e54c95
diff --git a/skyvern/experimentation/wait_utils.py b/skyvern/experimentation/wait_utils.py
index 1e119a1ec..a896e5ae8 100644
--- a/skyvern/experimentation/wait_utils.py
+++ b/skyvern/experimentation/wait_utils.py
@@ -10,6 +10,7 @@ import structlog
from cachetools import TTLCache
from skyvern.experimentation.wait_config import WaitConfig, get_wait_config_from_experiment
+from skyvern.forge import app
LOG = structlog.get_logger()
@@ -35,18 +36,13 @@ async def get_or_create_wait_config(
organization_id: Organization ID for experiment properties
Returns None if:
- - ENABLE_WAIT_TIME_OPTIMIZATION_EXPERIMENT is False (killswitch activated)
+ - the wait-time optimization killswitch is off (cloud setting; always off in OSS)
- organization_id is None
- No experiment is active for this task/workflow
"""
- # KILLSWITCH: Check if experiment is disabled globally (lazy import to avoid circular dependency)
- try:
- from cloud.config import settings as cloud_settings # noqa: PLC0415
-
- if not cloud_settings.ENABLE_WAIT_TIME_OPTIMIZATION_EXPERIMENT:
- return None
- except ImportError:
- # If cloud.config isn't available (OSS), experiment is disabled by default
+ # KILLSWITCH: consult the cloud setting through the AgentFunction seam so
+ # skyvern/ never imports cloud.* (OSS default is disabled).
+ if not app.AGENT_FUNCTION.is_wait_time_optimization_enabled():
return None
if not organization_id:
diff --git a/tests/unit/test_wait_config_inter_action.py b/tests/unit/test_wait_config_inter_action.py
index b592c2003..dcb49ef88 100644
--- a/tests/unit/test_wait_config_inter_action.py
+++ b/tests/unit/test_wait_config_inter_action.py
@@ -1,7 +1,11 @@
"""Tests for inter_action_delay in the wait config experiment framework."""
+import pytest
+
+from skyvern.experimentation import wait_utils
from skyvern.experimentation.wait_config import WAIT_VARIANTS, WaitConfig
from skyvern.experimentation.wait_utils import get_wait_time
+from skyvern.forge import app
def test_inter_action_delay_in_all_variants() -> None:
@@ -44,3 +48,31 @@ def test_wait_config_global_multiplier() -> None:
def test_wait_config_default_fallback() -> None:
result = get_wait_time(None, "inter_action_delay", default=0.5)
assert result == 0.5
+
+
+async def test_wait_config_is_none_when_killswitch_off(monkeypatch: pytest.MonkeyPatch) -> None:
+ # Patch the seam on the live app.AGENT_FUNCTION instance so this pins wait_utils'
+ # branch on it, independent of which AgentFunction (or test stub) the app holds.
+ monkeypatch.setattr(app.AGENT_FUNCTION, "is_wait_time_optimization_enabled", lambda: False, raising=False)
+
+ async def _must_not_run(cache_key: str, organization_id: str) -> None:
+ raise AssertionError("experiment lookup must not run when the killswitch is off")
+
+ monkeypatch.setattr(wait_utils, "get_wait_config_from_experiment", _must_not_run)
+ assert await wait_utils.get_or_create_wait_config("tsk_kill_1", None, "org_1") is None
+
+
+async def test_wait_config_lookup_runs_when_enabled(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(app.AGENT_FUNCTION, "is_wait_time_optimization_enabled", lambda: True, raising=False)
+ calls: list[str] = []
+
+ async def _fake_lookup(cache_key: str, organization_id: str) -> None:
+ calls.append(cache_key)
+ return None
+
+ monkeypatch.setattr(wait_utils, "get_wait_config_from_experiment", _fake_lookup)
+ wait_utils._wait_config_cache.clear()
+ await wait_utils.get_or_create_wait_config("tsk_enabled_1", None, "org_1")
+ assert calls == ["tsk_enabled_1"]