Skip to content

Automate browser based workflows with AI

fix: prevent MCP workflow updates from wiping credential parameters [SKY-8781] (#5398)

Marc Kelechava72c52b0055cb
diff --git a/skyvern/cli/mcp_tools/workflow.py b/skyvern/cli/mcp_tools/workflow.py
index f91b35b6f..c4977a287 100644
--- a/skyvern/cli/mcp_tools/workflow.py
+++ b/skyvern/cli/mcp_tools/workflow.py
@@ -19,6 +19,7 @@ from pydantic import Field
from skyvern.client.errors import BadRequestError, NotFoundError
from skyvern.client.types import WorkflowCreateYamlRequest
+from skyvern.forge.sdk.workflow.models.parameter import ParameterType
from skyvern.schemas.runs import ProxyLocation
from skyvern.schemas.workflows import WorkflowCreateYAMLRequest as WorkflowCreateYAMLRequestSchema
@@ -604,9 +605,28 @@ async def _inject_workflow_update_proxy_default(definition: str, fmt: str, workf
return _dump_definition_dict(raw, parsed_format)
-# Parameter types that are auto-managed (not user-visible input parameters) and should
-# be preserved during MCP updates when the caller omits them from the definition.
-_AUTO_MANAGED_PARAMETER_TYPES = frozenset({"credential"})
+# Parameter types that are auto-managed (credentials and secrets set via the UI) and should
+# always be preserved from the existing workflow during MCP updates, regardless of what the
+# caller sends. These should NEVER be modifiable via MCP — only via the UI credential picker.
+# Derived from the enum to stay in sync when new secret types are added.
+_AUTO_MANAGED_PARAMETER_TYPES = frozenset(pt.value for pt in ParameterType if pt.is_secret_or_credential())
+
+# Runtime-only fields returned by GET /api/v1/workflows/{id} that must be stripped before
+# re-injecting parameters into a YAML/JSON definition. Uses a suffix-based deny-list so
+# new parameter types with the standard *_parameter_id / workflow_id / timestamp pattern
+# are handled automatically.
+_RUNTIME_FIELD_SUFFIXES = ("_parameter_id", "_at")
+# workflow_id is the only runtime field not caught by the suffix rules above.
+_RUNTIME_EXACT_FIELDS = frozenset({"workflow_id"})
+
+
+def _strip_runtime_fields(param: dict[str, Any]) -> dict[str, Any]:
+ """Return a copy of *param* with runtime-only fields removed."""
+ return {
+ k: v
+ for k, v in param.items()
+ if k not in _RUNTIME_EXACT_FIELDS and not any(k.endswith(s) for s in _RUNTIME_FIELD_SUFFIXES)
+ }
def _iter_blocks_flat(blocks: list[dict[str, Any]]) -> list[dict[str, Any]]:
@@ -623,13 +643,15 @@ def _iter_blocks_flat(blocks: list[dict[str, Any]]) -> list[dict[str, Any]]:
async def _inject_workflow_update_parameters(definition: str, fmt: str, workflow_id: str) -> str:
- """Preserve auto-managed parameters (e.g. credential) when MCP update omits them.
-
- When an MCP client updates a workflow, it may provide blocks and workflow-level
- input parameters but omit credential parameters that were created automatically
- when the user selected a credential in the UI. This function reads the existing
- workflow's parameters and injects any auto-managed parameters whose keys are
- missing from the update definition, preventing accidental data loss.
+ """Preserve auto-managed parameters (credentials/secrets) during MCP workflow updates.
+
+ Credential parameters should NEVER be modifiable via MCP — the existing workflow's
+ values always win. This function:
+ 1. Always replaces auto-managed parameters with the existing workflow's versions
+ (even if the caller includes them — they may have stale/wrong data).
+ 2. Injects credential parameter_keys into blocks using type-based matching
+ (login blocks always get ALL credential keys) with label-based fallback
+ for non-login blocks.
"""
raw, parsed_format = _load_definition_dict(definition, fmt)
@@ -641,7 +663,6 @@ async def _inject_workflow_update_parameters(definition: str, fmt: str, workflow
return definition
update_params: list[dict[str, Any]] = wf_def.get("parameters", [])
- update_keys = {p.get("key") for p in update_params if isinstance(p, dict)}
existing_workflow = await _get_workflow_by_id(workflow_id)
existing_wf_def = existing_workflow.get("workflow_definition")
@@ -652,37 +673,51 @@ async def _inject_workflow_update_parameters(definition: str, fmt: str, workflow
modified = False
- # --- Step 1: Inject missing credential parameters into the parameters list ---
+ # --- Step 1: Always replace auto-managed parameters with existing values ---
+ # Credential/secret parameters should NEVER be modifiable via MCP — the existing
+ # workflow's values always win, even if the caller includes them with different data.
+ # This means callers cannot swap credential references or remove credential params
+ # via MCP; those operations must go through the UI credential picker.
+ auto_managed_keys: set[str] = set()
for param in existing_params:
if not isinstance(param, dict):
continue
- ptype = param.get("parameter_type")
- pkey = param.get("key")
- if ptype in _AUTO_MANAGED_PARAMETER_TYPES and pkey and pkey not in update_keys:
- # Build a minimal YAML-compatible parameter dict (strip runtime-only fields)
- injected_param: dict[str, Any] = {
- "parameter_type": ptype,
- "key": pkey,
- }
- if param.get("description"):
- injected_param["description"] = param["description"]
- if ptype == "credential" and param.get("credential_id"):
- injected_param["credential_id"] = param["credential_id"]
- update_params.append(injected_param)
- modified = True
-
- # --- Step 2: Inject missing credential parameter keys into blocks ---
- # Collect all auto-managed parameter keys from the existing workflow
+ if param.get("parameter_type") in _AUTO_MANAGED_PARAMETER_TYPES and param.get("key"):
+ auto_managed_keys.add(param["key"])
+
+ if auto_managed_keys:
+ # Remove any auto-managed params the caller may have included (may have stale data)
+ update_params = [p for p in update_params if not (isinstance(p, dict) and p.get("key") in auto_managed_keys)]
+ # Inject all auto-managed params from the existing workflow, stripping runtime-only
+ # fields that come from the GET API response (e.g. *_parameter_id, workflow_id,
+ # created_at, modified_at, deleted_at) to keep the definition YAML-clean.
+ for param in existing_params:
+ if not isinstance(param, dict):
+ continue
+ if param.get("parameter_type") in _AUTO_MANAGED_PARAMETER_TYPES and param.get("key"):
+ update_params.append(_strip_runtime_fields(param))
+ modified = True
+ wf_def["parameters"] = update_params
+
+ # --- Step 2: Inject credential parameter keys into blocks ---
+ # Login blocks get credential-type keys via type-based matching (resilient to label
+ # renames by Claude). Non-login blocks fall back to label-based matching — so if Claude
+ # renames a non-login block that references aws_secret/bitwarden/etc., the key reference
+ # is lost. This asymmetry is accepted because login blocks are the critical path for
+ # credential injection; non-login secret refs are rare and still work when labels match.
all_cred_keys: set[str] = set()
+ login_cred_keys: set[str] = set()
for p in existing_params:
if isinstance(p, dict) and p.get("parameter_type") in _AUTO_MANAGED_PARAMETER_TYPES and p.get("key"):
all_cred_keys.add(p["key"])
+ if p.get("parameter_type") == "credential":
+ login_cred_keys.add(p["key"])
if all_cred_keys:
existing_blocks: list[dict[str, Any]] = existing_wf_def.get("blocks", [])
update_blocks: list[dict[str, Any]] = wf_def.get("blocks", [])
- # Map existing block labels to the credential parameter keys they reference
+ # Build label-based map for fallback (non-login blocks)
existing_block_cred_keys: dict[str, list[str]] = {}
for block in _iter_blocks_flat(existing_blocks):
label = block.get("label")
@@ -693,15 +728,20 @@ async def _inject_workflow_update_parameters(definition: str, fmt: str, workflow
if cred_keys:
existing_block_cred_keys[label] = cred_keys
- # Inject credential parameter keys into matching update blocks
- if existing_block_cred_keys:
- for block in _iter_blocks_flat(update_blocks):
- label = block.get("label")
- if not label or label not in existing_block_cred_keys:
- continue
+ for block in _iter_blocks_flat(update_blocks):
+ block_type = block.get("block_type")
+ label = block.get("label")
+
+ keys_to_inject: list[str] = []
+ if block_type == "login":
+ keys_to_inject = sorted(login_cred_keys)
+ elif label and label in existing_block_cred_keys:
+ keys_to_inject = sorted(existing_block_cred_keys[label])
+
+ if keys_to_inject:
block_pkeys: list[str] = list(block.get("parameter_keys") or [])
current_keys = set(block_pkeys)
- for cred_key in existing_block_cred_keys[label]:
+ for cred_key in keys_to_inject:
if cred_key not in current_keys:
block_pkeys.append(cred_key)
modified = True
@@ -710,7 +750,6 @@ async def _inject_workflow_update_parameters(definition: str, fmt: str, workflow
if not modified:
return definition
- wf_def["parameters"] = update_params
return _dump_definition_dict(raw, parsed_format)
diff --git a/tests/unit/test_mcp_workflow_tools.py b/tests/unit/test_mcp_workflow_tools.py
index 776b2df1b..d1aa3d856 100644
--- a/tests/unit/test_mcp_workflow_tools.py
+++ b/tests/unit/test_mcp_workflow_tools.py
@@ -1021,3 +1021,595 @@ async def test_workflow_update_does_not_duplicate_existing_credential_parameter(
cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
# Should still be exactly 1, not duplicated
assert len(cred_params) == 1
+
+
+async def test_workflow_update_credential_keys_injected_when_login_block_label_renamed(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When Claude renames a login block label (e.g. 'login_block' -> 'login'),
+ credential parameter_keys should still be injected via type-based matching."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ "navigation_goal": "Login",
+ }
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude renamed the login block from "login_block" to "login"
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login",
+ "parameter_keys": [],
+ "navigation_goal": "Log in to the site",
+ }
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+
+ # Credential parameter must be injected
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ assert len(cred_params) == 1
+ assert cred_params[0].credential_id == "cred_abc123"
+
+ # Login block must have credential key despite label mismatch
+ blocks = sent_def.workflow_definition.blocks
+ login_block = next(b for b in blocks if getattr(b, "block_type", None) == "login")
+ pkeys = getattr(login_block, "parameter_keys", [])
+ assert "credentials" in pkeys
+
+
+async def test_workflow_update_always_replaces_wrong_credential_id(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When Claude includes a credential parameter with the wrong credential_id,
+ the existing workflow's credential_id should always win."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_CORRECT",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ }
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude includes credential param but with a WRONG credential_id
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_WRONG_STALE",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ "navigation_goal": "Login",
+ }
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ assert len(cred_params) == 1
+ # The existing (correct) credential_id must win
+ assert cred_params[0].credential_id == "cred_CORRECT"
+
+
+async def test_workflow_update_correct_credential_still_works(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When Claude includes the credential parameter correctly, the always-replace
+ strategy should still work (idempotent, no regression)."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ {
+ "parameter_type": "workflow",
+ "key": "url_input",
+ "workflow_parameter_type": "string",
+ "default_value": "https://example.com",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ }
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude includes credential param correctly AND the block references it
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ {
+ "parameter_type": "workflow",
+ "key": "url_input",
+ "workflow_parameter_type": "string",
+ "default_value": "https://new-url.com",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ "navigation_goal": "Login to the site",
+ }
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ assert len(cred_params) == 1
+ assert cred_params[0].credential_id == "cred_abc123"
+
+ # Non-credential params should be preserved from the update
+ wf_params = [p for p in params if getattr(p, "parameter_type", None) == "workflow"]
+ assert len(wf_params) == 1
+ assert wf_params[0].default_value == "https://new-url.com"
+
+ # Login block should have the credential key
+ blocks = sent_def.workflow_definition.blocks
+ login_block = next(b for b in blocks if getattr(b, "block_type", None) == "login")
+ pkeys = getattr(login_block, "parameter_keys", [])
+ assert "credentials" in pkeys
+
+
+async def test_workflow_update_multiple_login_blocks_all_get_credential_keys(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When the update has multiple login blocks, ALL of them should get credential
+ parameter_keys injected (even if labels don't match existing blocks)."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ }
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude split the workflow into two login blocks with new labels
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "initial_login",
+ "navigation_goal": "Login to the site",
+ },
+ {
+ "block_type": "task",
+ "label": "do_work",
+ "navigation_goal": "Do some work",
+ },
+ {
+ "block_type": "login",
+ "label": "reauth_login",
+ "navigation_goal": "Re-authenticate",
+ },
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+ blocks = sent_def.workflow_definition.blocks
+
+ # Both login blocks should have credential keys
+ login_blocks = [b for b in blocks if getattr(b, "block_type", None) == "login"]
+ assert len(login_blocks) == 2
+ for lb in login_blocks:
+ pkeys = getattr(lb, "parameter_keys", [])
+ assert "credentials" in pkeys, f"Login block {getattr(lb, 'label', '?')} missing credential key"
+
+ # Task block should NOT have credential keys (no label match, not a login block)
+ task_block = next(b for b in blocks if getattr(b, "block_type", None) == "task")
+ task_pkeys = getattr(task_block, "parameter_keys", None) or []
+ assert "credentials" not in task_pkeys
+
+
+async def test_workflow_update_credential_keys_injected_into_login_block_nested_in_for_loop(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When a login block is nested inside a for_loop block, credential parameter_keys
+ should still be injected via type-based matching."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "for_loop",
+ "label": "loop_block",
+ "loop_blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ "navigation_goal": "Login",
+ }
+ ],
+ }
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude renamed the nested login block inside the for_loop
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [],
+ "blocks": [
+ {
+ "block_type": "for_loop",
+ "label": "loop_block",
+ "loop_blocks": [
+ {
+ "block_type": "login",
+ "label": "login",
+ "navigation_goal": "Log in to the site",
+ }
+ ],
+ }
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+
+ # Credential parameter must be injected
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ assert len(cred_params) == 1
+ assert cred_params[0].credential_id == "cred_abc123"
+
+ # The nested login block inside for_loop must have credential keys
+ blocks = sent_def.workflow_definition.blocks
+ loop_block = next(b for b in blocks if getattr(b, "block_type", None) == "for_loop")
+ nested_blocks = getattr(loop_block, "loop_blocks", [])
+ login_block = next(b for b in nested_blocks if getattr(b, "block_type", None) == "login")
+ pkeys = getattr(login_block, "parameter_keys", [])
+ assert "credentials" in pkeys
+
+
+async def test_workflow_update_login_block_only_gets_credential_type_keys_not_aws_secret(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When a workflow has both a credential param and an aws_secret param,
+ login blocks should only get the credential key, not the aws_secret key."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ },
+ {
+ "parameter_type": "aws_secret",
+ "key": "api_secret",
+ "aws_key": "my-secret-key",
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ },
+ {
+ "block_type": "task",
+ "label": "api_call",
+ "parameter_keys": ["api_secret"],
+ "navigation_goal": "Make API call",
+ },
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ # Claude renamed login block and dropped all parameter info
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login",
+ "navigation_goal": "Login",
+ },
+ {
+ "block_type": "task",
+ "label": "api_call",
+ "navigation_goal": "Make API call",
+ },
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+
+ # Both params should be preserved
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ aws_params = [p for p in params if getattr(p, "parameter_type", None) == "aws_secret"]
+ assert len(cred_params) == 1
+ assert len(aws_params) == 1
+
+ blocks = sent_def.workflow_definition.blocks
+
+ # Login block should ONLY get credential key, NOT aws_secret
+ login_block = next(b for b in blocks if getattr(b, "block_type", None) == "login")
+ login_pkeys = getattr(login_block, "parameter_keys", [])
+ assert "credentials" in login_pkeys
+ assert "api_secret" not in login_pkeys
+
+ # Task block should get aws_secret via label fallback (label unchanged)
+ task_block = next(b for b in blocks if getattr(b, "block_type", None) == "task")
+ task_pkeys = getattr(task_block, "parameter_keys", [])
+ assert "api_secret" in task_pkeys
+
+
+async def test_workflow_update_strips_runtime_fields_from_credential_params(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When the existing workflow returns credential params with runtime fields
+ (credential_parameter_id, workflow_id, created_at, modified_at, deleted_at),
+ those fields must be stripped before re-injecting into the update definition."""
+
+ fake_client = SimpleNamespace(update_workflow=AsyncMock(return_value=_fake_workflow_response()))
+ monkeypatch.setattr(workflow_tools, "get_skyvern", lambda: fake_client)
+
+ async def fake_get_workflow_by_id(workflow_id: str, version: int | None = None) -> dict[str, object]:
+ return {
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [
+ {
+ "parameter_type": "credential",
+ "key": "credentials",
+ "credential_id": "cred_abc123",
+ "description": "Login credentials",
+ # Runtime fields from GET API response
+ "credential_parameter_id": "cp_runtime_123",
+ "workflow_id": "wpid_runtime_456",
+ "created_at": "2025-01-01T00:00:00Z",
+ "modified_at": "2025-06-15T12:00:00Z",
+ "deleted_at": None,
+ },
+ ],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login_block",
+ "parameter_keys": ["credentials"],
+ },
+ ],
+ },
+ }
+
+ monkeypatch.setattr(workflow_tools, "_get_workflow_by_id", fake_get_workflow_by_id)
+
+ definition = {
+ "title": "Updated workflow",
+ "proxy_location": "RESIDENTIAL",
+ "workflow_definition": {
+ "parameters": [],
+ "blocks": [
+ {
+ "block_type": "login",
+ "label": "login",
+ "navigation_goal": "Login",
+ },
+ ],
+ },
+ }
+
+ result = await workflow_tools.skyvern_workflow_update(
+ workflow_id="wpid_test",
+ definition=json.dumps(definition),
+ format="json",
+ )
+
+ assert result["ok"] is True
+
+ sent_def = fake_client.update_workflow.await_args.kwargs["json_definition"]
+
+ params = sent_def.workflow_definition.parameters
+ cred_params = [p for p in params if getattr(p, "parameter_type", None) == "credential"]
+ assert len(cred_params) == 1
+
+ cred = cred_params[0]
+ # Business fields should be preserved
+ assert getattr(cred, "key", None) == "credentials"
+ assert getattr(cred, "credential_id", None) == "cred_abc123"
+ assert getattr(cred, "description", None) == "Login credentials"
+
+ # Runtime fields must NOT be present — Fern SDK types use extra="allow"
+ # so extra fields survive as attributes if passed through
+ cred_dict = cred.dict() if hasattr(cred, "dict") else cred.__dict__
+ assert "credential_parameter_id" not in cred_dict
+ assert "workflow_id" not in cred_dict
+ assert "created_at" not in cred_dict
+ assert "modified_at" not in cred_dict
+ assert "deleted_at" not in cred_dict