Skip to content

Automate browser based workflows with AI

Document who owns a customer issue once it reaches Follow-up (SKY-17954) (#8847)

Aaron Perez669a15940fbe
diff --git a/skyvern/cli/mcp_tools/argument_validation.py b/skyvern/cli/mcp_tools/argument_validation.py
index dd0385660..73a70ec8b 100644
--- a/skyvern/cli/mcp_tools/argument_validation.py
+++ b/skyvern/cli/mcp_tools/argument_validation.py
@@ -18,9 +18,9 @@ model receives a clear message naming the unsupported and expected arguments
with no ``arguments`` at all also falls through: pydantic handles it,
rejecting only when the tool has required parameters.
-Type-level mismatches the repair step doesn't cover (an out-of-range int, a
-still-malformed list) still reach FastMCP's own pydantic validation inside
-``call_next``. Those are deliberately not silently coerced — an ambiguous
+Type-level mismatches the repair step doesn't cover (an out-of-range number with
+no unit to infer, a still-malformed list) still reach FastMCP's own pydantic
+validation inside ``call_next``. Those are deliberately not silently coerced — an ambiguous
shape should fail rather than be guessed at — but the resulting
``fastmcp.exceptions.ValidationError`` is caught here too and wrapped in the
same structured envelope, so the model always gets an actionable message
@@ -46,6 +46,7 @@ _MAX_REPAIR_LIST_ITEMS = 100
# Repair only production-observed fields whose comma-delimited meaning is known;
# the schema check below prevents this policy from outliving a signature change.
_COMMA_SEPARATED_LIST_ARGUMENTS = frozenset({("skyvern_workflow_run_list", "status")})
+_MILLISECOND_FLOOR = 1000
# Same policy for production-observed fields documented as a JSON string that callers send as
# the object that string is supposed to encode.
_JSON_STRING_OBJECT_ARGUMENTS = frozenset({("skyvern_workflow_run", "parameters")})
@@ -77,6 +78,63 @@ def _split_comma_separated_list(value: Any) -> Any:
return items
+def _millisecond_bounds(schema: Any, *, minimum_floor: float) -> tuple[float, float | None] | None:
+ """Return ``(minimum, maximum)`` when ``schema`` describes a millisecond duration.
+
+ The floor is 1000 for ambiguous ``timeout`` names; an explicit ``_ms`` suffix can use
+ the schema's lower bound directly. This avoids inferring units from unrelated parameters.
+ """
+ if not isinstance(schema, dict):
+ return None
+ for alternatives in (schema.get("anyOf"), schema.get("oneOf")):
+ if isinstance(alternatives, list):
+ for option in alternatives:
+ bounds = _millisecond_bounds(option, minimum_floor=minimum_floor)
+ if bounds is not None:
+ return bounds
+ schema_type = schema.get("type")
+ types = schema_type if isinstance(schema_type, list) else [schema_type]
+ if not any(entry in ("integer", "number") for entry in types):
+ return None
+ minimum = schema.get("minimum")
+ if not isinstance(minimum, (int, float)) or isinstance(minimum, bool) or minimum < minimum_floor:
+ return None
+ maximum = schema.get("maximum")
+ if not isinstance(maximum, (int, float)) or isinstance(maximum, bool):
+ return minimum, None
+ return minimum, maximum
+
+
+def _rescale_seconds_to_milliseconds(name: str, schema: Any, value: Any) -> Any:
+ """Scale a sub-floor value on a millisecond parameter, which callers undershoot in seconds.
+
+ The name gate matters as much as the bound: a non-duration parameter could legitimately
+ carry a 1000 minimum, and multiplying its value by 1000 would be silent corruption.
+ """
+ if name == "timeout":
+ minimum_floor = _MILLISECOND_FLOOR
+ elif name.endswith("_ms"):
+ # An explicit unit suffix identifies milliseconds even when the schema floor is < 1s.
+ minimum_floor = 0
+ else:
+ return value
+ if not isinstance(value, (int, float)) or isinstance(value, bool):
+ return value
+ bounds = _millisecond_bounds(schema, minimum_floor=minimum_floor)
+ if bounds is None:
+ return value
+ minimum, maximum = bounds
+ if not 0 < value < minimum:
+ return value
+ rescaled = value * 1000
+ if rescaled < minimum:
+ return value
+ # Rescaling past the ceiling would swap one validation failure for a less recognizable one.
+ if maximum is not None and rescaled > maximum:
+ return value
+ return int(rescaled) if isinstance(rescaled, float) and rescaled.is_integer() else rescaled
+
+
def _encode_json_object(value: Any) -> Any:
if not isinstance(value, dict):
return value
@@ -108,18 +166,8 @@ def _repair_argument_types(tool_name: str, tool: Any, arguments: dict[str, Any])
and not _schema_accepts_type(schema, "object")
):
arguments[name] = _encode_json_object(value)
-
- timeout = arguments.get("timeout")
- if (
- tool_name == "skyvern_navigate"
- and isinstance(timeout, (int, float))
- and not isinstance(timeout, bool)
- and 0 < timeout < 1000
- ):
- timeout_ms = timeout * 1000
- arguments["timeout"] = (
- int(timeout_ms) if isinstance(timeout_ms, float) and timeout_ms.is_integer() else timeout_ms
- )
+ else:
+ arguments[name] = _rescale_seconds_to_milliseconds(name, schema, value)
def _argument_contract(tool: Any) -> tuple[set[str], set[str]] | None:
diff --git a/tests/unit/test_mcp_argument_validation.py b/tests/unit/test_mcp_argument_validation.py
index 71e7bb88d..203661d87 100644
--- a/tests/unit/test_mcp_argument_validation.py
+++ b/tests/unit/test_mcp_argument_validation.py
@@ -219,7 +219,7 @@ async def test_navigate_sub_1000_timeout_is_treated_as_seconds_and_converted_to_
@pytest.mark.asyncio
[email protected](("timeout_seconds", "timeout_ms"), [(1.5, 1500), (0.5, 500)])
[email protected](("timeout_seconds", "timeout_ms"), [(1.5, 1500)])
async def test_navigate_fractional_seconds_with_whole_milliseconds_are_converted_to_int(
timeout_seconds: float,
timeout_ms: int,
@@ -233,6 +233,16 @@ async def test_navigate_fractional_seconds_with_whole_milliseconds_are_converted
assert type(arguments["timeout"]) is int
+async def test_navigate_fractional_seconds_stay_unchanged_when_rescaling_is_still_below_minimum() -> None:
+ tool = await mcp.get_tool("skyvern_navigate")
+ arguments = {"timeout": 0.5}
+
+ _repair_argument_types("skyvern_navigate", tool, arguments)
+
+ assert arguments["timeout"] == 0.5
+
+
@pytest.mark.asyncio
async def test_navigate_timeout_at_millisecond_threshold_is_not_scaled(monkeypatch: pytest.MonkeyPatch) -> None:
navigate = _mock_navigation(monkeypatch)
@@ -243,6 +253,54 @@ async def test_navigate_timeout_at_millisecond_threshold_is_not_scaled(monkeypat
assert _awaited_kwargs(navigate)["timeout"] == 1000
+async def test_composite_navigate_sub_1000_timeout_reaches_the_navigate_step_as_milliseconds(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ paired_capture = AsyncMock(return_value={"ok": True, "action": "navigate_extract_and_screenshot"})
+ monkeypatch.setattr(mcp_browser, "_run_paired_capture", paired_capture)
+
+ payload = await _call(
+ "skyvern_navigate_extract_and_screenshot",
+ {"url": "https://example.com", "prompt": "read the page", "timeout": 45},
+ )
+
+ assert payload["ok"] is True
+ operations = dict(paired_capture.await_args.args[1])
+ assert operations["navigate"]["timeout"] == 45000
+
+
+ ("tool_name", "argument", "sent", "expected"),
+ [
+ # Sub-floor values on millisecond-named parameters are interpreted as seconds.
+ ("skyvern_navigate_extract_and_screenshot", "timeout", 45, 45000),
+ ("skyvern_navigate_and_screenshot", "timeout", 30, 30000),
+ ("skyvern_click", "timeout", 10, 10000),
+ ("skyvern_wait", "poll_interval_ms", 5, 5000),
+ ("skyvern_tab_wait_for_new", "timeout_ms", 20, 20000),
+ ("skyvern_open_tabs", "per_tab_timeout_ms", 15, 15000),
+ # Second- and minute-denominated parameters mean what they say and must survive untouched.
+ ("skyvern_browser_session_create", "timeout", 5, 5),
+ ("skyvern_run_task", "timeout_seconds", 45, 45),
+ ("skyvern_workflow_run", "timeout_seconds", 30, 30),
+ ("skyvern_login", "timeout_seconds", 60, 60),
+ # Rescaling past the published ceiling would trade one validation failure for another.
+ ("skyvern_click", "timeout", 90, 90),
+ ],
+)
+async def test_timeout_repair_rescales_millisecond_parameters_only(
+ tool_name: str, argument: str, sent: int, expected: int
+) -> None:
+ tool = await mcp.get_tool(tool_name)
+ arguments = {argument: sent}
+
+ _repair_argument_types(tool_name, tool, arguments)
+
+ assert arguments[argument] == expected
+
+
@pytest.mark.asyncio
async def test_type_repair_preserves_structured_missing_key_rejection() -> None:
payload = await _call("skyvern_workflow_run_list", {"status": "terminated,failed"})