Skip to content

Automate browser based workflows with AI

Log when Task V3's select_combobox leaves an already-selected value as is (#8785)

pedrohsdbb66cf1a6b510
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.py
index 7ef531fd1..caf17e5b1 100644
--- a/skyvern/forge/taskv3/loop.py
+++ b/skyvern/forge/taskv3/loop.py
@@ -1990,6 +1990,7 @@ _TOOL_CALL_RECORD_FIELDS = frozenset(
"turn",
"batch_size",
"batch_index",
+ "tool_call_seq",
"action_key_hash",
"snapshot_digest",
"probe_first_time",
@@ -4619,6 +4620,8 @@ async def run_agent_tool_loop(
turn=st.turns,
batch_size=len(tool_calls),
batch_index=idx,
+ # What current_tool_call_seq() returned inside this call, so a tool's own lines join here.
+ tool_call_seq=st.total_tool_calls,
**cost_fields,
**observe_summary,
**navigate_fields,
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.py
index cd41cd462..42e21fcea 100644
--- a/skyvern/forge/taskv3/tools.py
+++ b/skyvern/forge/taskv3/tools.py
@@ -17778,6 +17778,9 @@ def build_browser_tools(
await input_dispatch.press(_current_page(), None, "Escape")
except Exception:
pass
+ same = " ".join(pre_value.split()).casefold() == " ".join(matched.split()).casefold()
+ signal = "aria-selected" if multi_select else "input value" if same else "displayed text"
+ _log_already_selected(signal, _exact_tier_key(matched) == _exact_tier_key(value))
return ToolResult.ok(f"{matched!r} was already selected for {selector}; left it as is")
chosen_values: list[str] = []
try:
@@ -17846,8 +17849,18 @@ def build_browser_tools(
return ToolResult.error(f"clicked {matched!r} but {selector} did not commit a value")
def _already_held_result(selector: str, value: str) -> ToolResult:
+ _log_already_selected("chip", True)
return ToolResult.ok(f"{value!r} was already selected for {selector}; left it as is")
+ def _log_already_selected(signal: str, matched_exact: bool) -> None:
+ # No form values and no selector, which can quote one. tool_call_seq joins this line to its tool call.
+ LOG.info(
+ "taskv3 select left an already-selected value",
+ tool_call_seq=current_tool_call_seq(),
+ signal=signal,
+ matched_exact=matched_exact,
+ )
+
def _surface_holds(matched: str, surface: str, value: str) -> bool:
def norm(t: str) -> str:
return " ".join(t.split()).casefold()
diff --git a/tests/unit/test_taskv3_loop.py b/tests/unit/test_taskv3_loop.py
index 7c8c3e5ea..33fc95b88 100644
--- a/tests/unit/test_taskv3_loop.py
+++ b/tests/unit/test_taskv3_loop.py
@@ -87,6 +87,7 @@ from skyvern.forge.taskv3.loop import (
_ProgressLedger,
_raised_error_class,
_RevisitMemory,
+ current_tool_call_seq,
make_finish_tool,
record_covered_layer,
record_hit_class,
@@ -4401,6 +4402,27 @@ async def test_every_executed_tool_call_emits_one_timing_record() -> None:
assert outcome.tool_seconds >= observe_record["duration_seconds"]
+async def test_tool_call_record_carries_the_seq_its_tool_saw() -> None:
+ # A tool's own log lines carry current_tool_call_seq(); the per-call record must carry the same value,
+ # or those lines cannot be joined to the call's tool name and selector kind.
+ seen: list[int | None] = []
+
+ async def handler(args: dict[str, Any]) -> ToolResult:
+ seen.append(current_tool_call_seq())
+ return ToolResult.ok("done")
+
+ tools = [ToolSpec(name="probe", description="p", parameters={}, handler=handler), make_finish_tool()]
+ script = [[("probe", {}), ("probe", {})], [("finish", {"status": "completed", "reason": "ok"})]]
+ with capture_logs() as logs:
+ outcome, _ = await _run(script, tools)
+
+ assert outcome.status == "completed"
+ records = [e for e in logs if e["event"] == "taskv3 tool call finished" and e["tool"] == "probe"]
+ assert [r["tool_call_seq"] for r in records] == seen
+ assert len(set(seen)) == 2 and None not in seen, seen
+
+
_OBSERVE_SUMMARY_FIELDS = (
"text_dropped",
"hidden_listed",
diff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.py
index ebd330a41..083d35ffe 100644
--- a/tests/unit/test_taskv3_tools.py
+++ b/tests/unit/test_taskv3_tools.py
@@ -30684,6 +30684,14 @@ async def test_select_combobox_offers_vocabulary_on_no_match() -> None:
assert "IL" in r.content, r.content
+def _already_selected_log(logs: list[dict[str, Any]], value: str) -> tuple[str, bool]:
+ # The one line the already-selected returns emit; the form value itself must never be in it.
+ entry = next((e for e in logs if e["event"] == "taskv3 select left an already-selected value"), None)
+ assert entry is not None, [e["event"] for e in logs]
+ assert value not in repr(entry) and "selector" not in entry, entry
+ return entry["signal"], entry["matched_exact"]
+
+
@_skip_no_browser
@pytest.mark.asyncio
async def test_select_combobox_reports_already_selected_row_as_ok() -> None:
@@ -30693,9 +30701,11 @@ async def test_select_combobox_reports_already_selected_row_as_ok() -> None:
async with _content_page(_VIRTUALIZED_BUTTON_LISTBOX_HTML) as page:
tools = build_browser_tools(_fixed_page_provider(page))
current = _CC_COUNTRIES[_CC_CURRENT_INDEX][0]
- r = await _tool(tools, "select_combobox").handler({"selector": "#cc", "value": current})
+ with capture_logs() as logs:
+ r = await _tool(tools, "select_combobox").handler({"selector": "#cc", "value": current})
assert r.status == "ok", r.content
assert "already selected" in r.content, r.content
+ assert _already_selected_log(logs, current) == ("displayed text", True)
expanded = await page.eval_on_selector("#cc", "el => el.getAttribute('aria-expanded')")
assert expanded == "false", expanded
label = await page.eval_on_selector("#cc", "el => el.getAttribute('aria-label')")
@@ -31274,13 +31284,15 @@ async def test_select_combobox_leaves_a_held_chip_only_when_its_list_is_known_cl
html = html.replace('<div id="dep">', '<div id="fld-list" role="listbox" hidden></div><div id="dep">', 1)
async with _content_page(html) as page:
tools = build_browser_tools(_fixed_page_provider(page))
- r = await _tool(tools, "select_combobox").handler({"selector": "#fld", "value": shape["target"]})
+ with capture_logs() as logs:
+ r = await _tool(tools, "select_combobox").handler({"selector": "#fld", "value": shape["target"]})
state = await page.evaluate(
"() => [document.body.getAttribute('data-committed'), window.__rowClicks,"
" Number(document.getElementById('fld').getAttribute('data-inputs'))]"
)
assert r.status == "ok" and "already selected" in r.content, r.content
assert state == [shape["target"], 0, 0], state
+ assert _already_selected_log(logs, shape["target"]) == ("chip", True)
@_skip_no_browser
@@ -31643,9 +31655,11 @@ async def test_select_combobox_trusts_aria_selected_in_a_declared_multi_select_w
assert '"2 selected"' in html
async with _content_page(html) as page:
tools = build_browser_tools(_fixed_page_provider(page))
- r = await _tool(tools, "select_combobox").handler({"selector": "#cc", "value": "Germany"})
+ with capture_logs() as logs:
+ r = await _tool(tools, "select_combobox").handler({"selector": "#cc", "value": "Germany"})
assert r.status == "ok", r.content
assert "already selected" in r.content, r.content
+ assert _already_selected_log(logs, "Germany") == ("aria-selected", True)
assert await page.eval_on_selector("#de", "el => el.getAttribute('aria-selected')") == "true"