Skip to content

Automate browser based workflows with AI

Name the typeahead row-listing refusals on the error_class facet (SKY-16149) (#8515)

pedrohsdb5e9a25365373
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.py
index 572ca063e..5fa236690 100644
--- a/skyvern/forge/taskv3/loop.py
+++ b/skyvern/forge/taskv3/loop.py
@@ -38,9 +38,13 @@ ToolStatus = Literal["ok", "error"]
FinishStatus = Literal["completed", "failed", "terminated"]
# Why a failing tool call failed, as one closed vocabulary. Spelled as a `Literal` rather than `str`
-# because the whole value of the facet is that it is closed: it is written at ~28 sites across two
-# modules, and a typo or a near-synonym added later would split a cohort silently. mypy runs on both
-# modules, so a value not listed here is rejected at the call site rather than discovered in a chart.
+# because the whole value of the facet is that it is closed: it is written at ~33 literal sites in
+# tools.py, and a typo or a near-synonym added later would split a cohort silently. Enforcement is
+# invocation-shaped: `mypy.ini` sets `follow_imports = skip`, so the annotation binds in tools.py only
+# while THIS module is in the same mypy run. CI's `pre-commit run mypy --all-files` includes it and
+# rejects an undeclared value; checking tools.py alone does not. The AST source census in
+# tests/unit/test_taskv3_loop.py backstops the runs that miss it, and it can only read a value spelled
+# as a literal at the write site.
ToolErrorClass = Literal[
# The address did not resolve to what it named.
"stale_selector",
@@ -58,6 +62,13 @@ ToolErrorClass = Literal[
"covered",
"inert",
"unreachable",
+ # The field resolved and the page cooperated, but the requested VALUE named no single option.
+ # Each of these names only what was READ: an absence claim holds solely over a list read in full,
+ # which is why a declared-but-truncated list gets `rows_unread` rather than `no_matching_row`.
+ "ambiguous_rows",
+ "identical_rows",
+ "no_matching_row",
+ "rows_unread",
# The handler raised instead of returning; classified by `_raised_error_class`.
"driver_timeout",
"timeout_other",
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.py
index 67ced08ca..6cc10658a 100644
--- a/skyvern/forge/taskv3/tools.py
+++ b/skyvern/forge/taskv3/tools.py
@@ -383,6 +383,9 @@ class _TypeaheadPick(NamedTuple):
clicked: bool
declared: bool
note: str | None = None
+ # How many rows the widget DECLARED beyond the ones it rendered, so a refusal can tell "nothing on
+ # this list is it" from "nothing on the part of it we could read".
+ overflow: int = 0
# Whether the commit surface already vouched for the chosen label BEFORE the pick click — such a
# surface proves nothing about the commit and must not vouch for it downstream either.
pre_surface_hit: bool = False
@@ -555,7 +558,13 @@ def _match_menu_option(value: str, options: list[dict[str, Any]], *, collapse_du
def _ambiguous_rows_error(
- selector: str, value: str, rows: list[dict[str, Any]], *, next_step: str, note: str | None = None
+ selector: str,
+ value: str,
+ rows: list[dict[str, Any]],
+ *,
+ next_step: str,
+ note: str | None = None,
+ rows_unread: bool = False,
) -> ToolResult:
"""The refusal owed a caller when rows reacted and none of them IS the requested value.
@@ -566,16 +575,24 @@ def _ambiguous_rows_error(
shown = rows[:15]
listing = "; ".join(repr(str(o.get("text") or "")[:60]) for o in shown)
more = len(rows) - len(shown)
+ # One row that is not the value is a different refusal from several the value cannot choose between:
+ # nothing on the list is it, so there is no pick to make. Same wording fork, same facet fork -- a
+ # single class over both would merge two cohorts the code already tells apart in prose.
+ several = len(rows) > 1
lead = (
f"{value!r} matches several rows in {selector}: "
- if len(rows) > 1
+ if several
else f"{value!r} is not the one row showing in {selector}: "
)
tail = f" ({note})" if note else ""
- return ToolResult.error(
- f"{lead}{listing}{f'; +{more} more' if more > 0 else ''}{tail} — {next_step}; the field is NOT filled",
- data={"release_own_list": True},
- )
+ message = f"{lead}{listing}{f'; +{more} more' if more > 0 else ''}{tail} — {next_step}; the field is NOT filled"
+ # Spelled as literal writes rather than one computed error_class: the source census can only read a
+ # literal, and a single-file mypy run does not bind the annotation across the import either.
+ if several:
+ return ToolResult.error(message, data={"release_own_list": True}, error_class="ambiguous_rows")
+ if rows_unread:
+ return ToolResult.error(message, data={"release_own_list": True}, error_class="rows_unread")
+ return ToolResult.error(message, data={"release_own_list": True}, error_class="no_matching_row")
def _row_value_suffix(o: dict[str, Any], rows: list[dict[str, Any]]) -> str:
@@ -653,6 +670,7 @@ def _identical_text_rows_error(
f"apart by text: {listing}{f'; +{more} more' if more > 0 else ''}{tail} — {next_step} — the field "
"is NOT filled",
data=None if tags_live else {"release_own_list": True},
+ error_class="identical_rows",
)
@@ -9564,6 +9582,7 @@ def build_browser_tools(
clicked=False,
declared=declared_rows,
note=note,
+ overflow=overflow,
)
best_txt = next((str(o.get("text") or "") for o in rows if o.get("n") == idx), value)
info = await _row_info(idx)
@@ -10023,6 +10042,7 @@ def build_browser_tools(
pick.candidates,
next_step="call select_combobox with the option's full text",
note=pick.note,
+ rows_unread=bool(pick.overflow),
)
if pick.suggestion:
verdict, matches = await _typeahead_commit_verdict(page, selector, pick.committed, pick.readable)
@@ -10839,7 +10859,12 @@ def build_browser_tools(
return _identical_text_rows_error(selector, value, same_text, tags_live=False, note=pick.note)
await _restore_pre_type_value(page, selector, pre_value, typed_queries)
return _ambiguous_rows_error(
- selector, value, pick.candidates, next_step="pass the option's full text", note=pick.note
+ selector,
+ value,
+ pick.candidates,
+ next_step="pass the option's full text",
+ note=pick.note,
+ rows_unread=bool(pick.overflow),
)
# No suggestion reacted at all -- but that alone does not say a list never rendered: a
# searchable typeahead that filtered to zero and a non-searchable widget that never filters
diff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.py
index 089b4ffe5..0a26a7e1a 100644
--- a/tests/unit/test_taskv3_tools.py
+++ b/tests/unit/test_taskv3_tools.py
@@ -23254,3 +23254,39 @@ def test_a_code_tool_the_submit_guard_cannot_recognise_is_refused() -> None:
# stripped in favour of a tool that was refused.
assert {t.name for t in kept} == _SURFACE_OFF_TOOL_NAMES
assert misnamed.billable is False
+
+
+def test_the_two_shared_row_refusals_carry_their_own_error_class() -> None:
+ """Asserted on the builders, the single site each label is written at, not at the six call sites."""
+ rows = [{"n": 1, "text": "Nevada", "val": "NV"}, {"n": 2, "text": "Nevada", "val": "NB"}]
+
+ ambiguous = taskv3_tools._ambiguous_rows_error("#state", "Nevada", rows, next_step="pass the option's full text")
+ assert ambiguous.status == "error"
+ assert ambiguous.error_class == "ambiguous_rows"
+ assert "the field is NOT filled" in ambiguous.content
+
+ # The same builder's other arm is a different refusal: one row showing and it is not the value asked
+ # for is "nothing here is it", not "choose among these", and the two have different remedies.
+ lone = taskv3_tools._ambiguous_rows_error("#state", "NV", rows[:1], next_step="pass the option's full text")
+ assert lone.error_class == "no_matching_row"
+ assert "is not the one row showing" in lone.content
+
+ # ... but only when the whole list was read. A widget that declares more rows than it rendered has not
+ # shown that nothing matches, and the message says so in the same breath, so the facet must not claim it.
+ truncated = taskv3_tools._ambiguous_rows_error(
+ "#country",
+ "Nevada",
+ rows[:1],
+ next_step="pass the option's full text",
+ note="the list declares 195 rows and only 1 are rendered — type the option's full label",
+ rows_unread=True,
+ )
+ assert truncated.error_class == "rows_unread"
+ assert "195 rows" in truncated.content
+
+ for tags_live in (True, False):
+ identical = taskv3_tools._identical_text_rows_error("#state", "Nevada", rows, tags_live=tags_live)
+ assert identical.status == "error"
+ assert identical.error_class == "identical_rows", tags_live
+ # Both wordings are one branch: the facet must not fork on which remedy the page allowed.
+ assert "the field is NOT filled" in identical.content