Skip to content

Automate browser based workflows with AI

feat(tagging): gate workflow tagging behind WORKFLOW_TAGGING flag (backend) (SKY-10683) (#6643)

Aaron Perez49b0fe928cd7
diff --git a/skyvern-frontend/src/routes/root/SideNav.tsx b/skyvern-frontend/src/routes/root/SideNav.tsx
index 16d923502..c9ae11fd2 100644
--- a/skyvern-frontend/src/routes/root/SideNav.tsx
+++ b/skyvern-frontend/src/routes/root/SideNav.tsx
@@ -264,9 +264,9 @@ function SideNav({ collapsed }: Props = {}) {
icon: <GearIcon className="size-4" />,
children: [
{
- label: "API Keys",
- to: "/settings?section=api-keys",
- icon: <KeyIcon className="size-3.5" />,
+ label: "General",
+ to: "/settings",
+ icon: <GearIcon className="size-3.5" />,
},
],
},
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index 0b914033a..d87d010a9 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -514,6 +514,10 @@ class AgentFunction:
) -> bool:
return True
+ async def is_workflow_tagging_enabled(self, organization_id: str) -> bool:
+ """OSS always-on; cloud overrides to gate per-org for staged rollout."""
+ return True
+
async def get_analytics_warmable_organization_ids(self, statement_timeout_seconds: int = 10) -> list[str]:
"""Return org IDs whose analytics summary cache should be kept warm.
diff --git a/skyvern/forge/sdk/experimentation/providers.py b/skyvern/forge/sdk/experimentation/providers.py
index f9d2dcd1c..c2e0ee25b 100644
--- a/skyvern/forge/sdk/experimentation/providers.py
+++ b/skyvern/forge/sdk/experimentation/providers.py
@@ -169,6 +169,7 @@ class BaseExperimentationProvider(ABC):
self.result_map: TTLCache = TTLCache(maxsize=EXPERIMENTATION_CACHE_MAX_SIZE, ttl=EXPERIMENTATION_CACHE_TTL)
self.variant_map: TTLCache = TTLCache(maxsize=EXPERIMENTATION_CACHE_MAX_SIZE, ttl=EXPERIMENTATION_CACHE_TTL)
self.payload_map: TTLCache = TTLCache(maxsize=EXPERIMENTATION_CACHE_MAX_SIZE, ttl=EXPERIMENTATION_CACHE_TTL)
+ self.tri_state_map: TTLCache = TTLCache(maxsize=EXPERIMENTATION_CACHE_MAX_SIZE, ttl=EXPERIMENTATION_CACHE_TTL)
@abstractmethod
async def _is_feature_enabled(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> bool:
@@ -207,6 +208,36 @@ class BaseExperimentationProvider(ABC):
)
return feature_flag_value
+ async def _resolve_feature_flag(
+ self, feature_name: str, distinct_id: str, properties: dict | None = None
+ ) -> bool | None:
+ """Tri-state flag resolution: True/False, or None when the flag is undefined/unknown.
+
+ Base implementation collapses to the boolean resolver; providers that can tell an
+ undefined flag apart from an explicit ``False`` override this to surface ``None``.
+ """
+ return await self._is_feature_enabled(feature_name, distinct_id, properties)
+
+ async def resolve_feature_flag_cached(
+ self, feature_name: str, distinct_id: str, properties: dict | None = None
+ ) -> bool | None:
+ cache_key = _make_cache_key(feature_name, distinct_id, properties)
+ if should_bypass_feature_flag_cache(feature_name):
+ await self._prepare_feature_flag_resolution(feature_name, cached=False)
+ resolved = await self._resolve_feature_flag(feature_name, distinct_id, properties)
+ elif cache_key in self.tri_state_map:
+ resolved = self.tri_state_map[cache_key]
+ else:
+ await self._prepare_feature_flag_resolution(feature_name, cached=True)
+ resolved = await self._resolve_feature_flag(feature_name, distinct_id, properties)
+ self.tri_state_map[cache_key] = resolved
+ record_feature_flag_resolution(
+ feature_name=feature_name,
+ resolution_kind="enabled",
+ resolved_value=resolved,
+ )
+ return resolved
+
@abstractmethod
async def _get_value(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> str | None:
"""Get the value of a feature."""
diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.py
index ddf8943ac..be29a4cc1 100644
--- a/skyvern/forge/sdk/routes/agent_protocol.py
+++ b/skyvern/forge/sdk/routes/agent_protocol.py
@@ -1591,6 +1591,16 @@ async def _apply_tag_changes_with_retry(
)
+async def require_workflow_tagging(
+ current_org: Organization = Depends(org_auth_service.get_current_org),
+) -> None:
+ if not await app.AGENT_FUNCTION.is_workflow_tagging_enabled(current_org.organization_id):
+ raise HTTPException(
+ status_code=http_status.HTTP_403_FORBIDDEN,
+ detail="Workflow tagging is not enabled for this organization.",
+ )
+
+
@legacy_base_router.post(
"/workflows/{workflow_permanent_id}/tags",
response_model=TagsResponse,
@@ -1619,6 +1629,7 @@ async def apply_workflow_tags(
workflow_permanent_id: str = Path(..., description="Workflow permanent ID", examples=["wpid_123"]),
data: TagApplyRequest = Body(...),
caller: org_auth_service.CallerContext = Depends(org_auth_service.get_current_caller_context),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagsResponse:
analytics.capture("skyvern-oss-workflow-tags-apply")
organization_id = caller.organization.organization_id
@@ -1677,6 +1688,7 @@ async def delete_workflow_tag(
workflow_permanent_id: str = Path(..., description="Workflow permanent ID", examples=["wpid_123"]),
key: str = Path(..., description="Tag key to delete", examples=["env"]),
caller: org_auth_service.CallerContext = Depends(org_auth_service.get_current_caller_context),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagsResponse:
analytics.capture("skyvern-oss-workflow-tags-delete")
organization_id = caller.organization.organization_id
@@ -1723,6 +1735,7 @@ async def delete_workflow_tag(
async def get_workflow_tags(
workflow_permanent_id: str = Path(..., description="Workflow permanent ID", examples=["wpid_123"]),
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagsResponse:
organization_id = current_org.organization_id
await _assert_workflow_in_org(workflow_permanent_id, organization_id)
@@ -1776,6 +1789,7 @@ async def get_workflow_tag_history(
since: datetime | None = Query(None, description="Only return events at or after this timestamp"),
key: str | None = Query(None, description="Filter to events for a single tag key"),
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagHistoryResponse:
organization_id = current_org.organization_id
await _assert_workflow_in_org(workflow_permanent_id, organization_id)
@@ -1806,6 +1820,7 @@ async def get_workflow_tag_history(
@base_router.get("/tag-keys/", response_model=list[TagKey], include_in_schema=False)
async def list_tag_keys(
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> list[TagKey]:
organization_id = current_org.organization_id
rows = await app.DATABASE.tags.list_tag_keys(organization_id=organization_id)
@@ -1833,6 +1848,7 @@ async def update_tag_key(
key: str = Path(..., description="Tag key to update"),
data: TagKeyUpdate = Body(...),
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagKey:
_validate_path_key(key)
organization_id = current_org.organization_id
@@ -1868,6 +1884,7 @@ async def update_tag_key(
async def delete_tag_key(
key: str = Path(..., description="Tag key to delete", examples=["env"]),
caller: org_auth_service.CallerContext = Depends(org_auth_service.get_current_caller_context),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> TagKeyDeleteResponse:
analytics.capture("skyvern-oss-tag-key-delete")
_validate_path_key(key)
@@ -1971,6 +1988,7 @@ async def batch_get_workflow_tags(
examples=["wpid_123,wpid_456"],
),
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> WorkflowTagsBatchResponse:
wpids = _parse_batch_wpids(workflow_permanent_ids)
if len(wpids) > _BATCH_TAGS_MAX_WPIDS:
@@ -2002,6 +2020,7 @@ async def batch_get_workflow_tags(
async def batch_get_workflow_tags_post(
data: WorkflowTagsBatchRequest = Body(...),
current_org: Organization = Depends(org_auth_service.get_current_org),
+ _tagging_gate: None = Depends(require_workflow_tagging),
) -> WorkflowTagsBatchResponse:
wpids = [wpid.strip() for wpid in data.workflow_permanent_ids if wpid and wpid.strip()]
if len(wpids) > _BATCH_TAGS_MAX_WPIDS:
diff --git a/tests/unit/test_tag_endpoints.py b/tests/unit/test_tag_endpoints.py
index 769cf7efe..a6b1eea06 100644
--- a/tests/unit/test_tag_endpoints.py
+++ b/tests/unit/test_tag_endpoints.py
@@ -114,6 +114,7 @@ def app_with_routes(repo: TagsRepository, monkeypatch: pytest.MonkeyPatch) -> Fa
app_mock = MagicMock()
app_mock.DATABASE = database_mock
+ app_mock.AGENT_FUNCTION.is_workflow_tagging_enabled = AsyncMock(return_value=True)
monkeypatch.setattr(ap, "app", app_mock)
@@ -294,6 +295,21 @@ def test_get_tags_404_when_workflow_not_in_org(client: TestClient) -> None:
assert resp.status_code == 404
+def test_tagging_gate_returns_403_when_disabled(client: TestClient) -> None:
+ from skyvern.forge.sdk.routes import agent_protocol as ap
+
+ ap.app.AGENT_FUNCTION.is_workflow_tagging_enabled = AsyncMock(return_value=False)
+ assert client.get(f"/v1/workflows/{WPID}/tags").status_code == 403
+ assert client.get("/v1/tag-keys").status_code == 403
+ assert (
+ client.post(
+ f"/v1/workflows/{WPID}/tags",
+ json={"tags": [{"key": "env", "value": "prod"}]},
+ ).status_code
+ == 403
+ )
+
+
# ----------------------------- GET /workflows/{wpid}/tags/history --------------------