Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Route API workflow runs (#8667)
Shuchang Zheng68a2dfe1a4b1
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/healStatus.ts b/skyvern-frontend/src/routes/workflows/workflowRun/healStatus.tsindex 34d9df0b8..9204c357a 100644--- a/skyvern-frontend/src/routes/workflows/workflowRun/healStatus.ts+++ b/skyvern-frontend/src/routes/workflows/workflowRun/healStatus.ts@@ -53,6 +53,7 @@ const healSkipReasonLabels: Record<string, string> = {insecure_code: "Unsafe code blocked",unclassifiable: "Unclassified",user_defined_error: "Error raised by the block",+ proxy_transport: "Proxy connection failed",};function healSkipReasonLabel(reason: string | null): string {diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.pyindex 25df3a29d..512f5b6d4 100644--- a/skyvern/forge/agent.py+++ b/skyvern/forge/agent.py@@ -575,7 +575,7 @@ _PAGE_FINGERPRINT_PROBE_JS = (# page change and resets the stall counter -- on a frozen page the model works through# mark after mark, which is precisely the run the stall detector exists to catch.# OTP bookkeeping attributes must also be ignored after masking so stamps do not count as page progress.- ' const scrub = (s) => s.replace(/ data-(?:tv3-act|tv3-cover|skyvern-otp-[^\\s=]+)="[^"]*"/gi, \'\');'+ ' const scrub = (s) => s.replace(/ data-(?:tv3-act|tv3-cover|tv3-pick|skyvern-otp-[^\\s=]+)="[^"]*"/gi, \'\');'" const walk = (root) => { h = mix(scrub(otpSafeHtml(root, true)), h);"" const all = root.querySelectorAll('*'); elems += all.length;"" for (const el of root.querySelectorAll('input, textarea, select'))"@@ -1238,11 +1238,42 @@ async def _resolve_task_v3_llm_key(task: Task) -> str:return override or settings.TASK_V3_LLM_KEY or settings.LLM_KEY+async def _read_goal_check_judge_key(distinct_id: str, organization_id: str) -> str | None:+ """The judge llm_key named by the TASK_V3_GOAL_CHECK payload for this run's variant, or None to use the+ configured key. A payload that is set but is not a key name is returned as-is so the registry rejects it."""+ try:+ payload = await app.EXPERIMENTATION_PROVIDER.get_payload_cached(+ GOAL_CHECK_FLAG, distinct_id, properties={"organization_id": organization_id}, record=False+ )+ except Exception:+ LOG.warning("Failed to read the goal check payload; using the configured judge model", exc_info=True)+ return None+ if isinstance(payload, str):+ # Production providers deliver a payload as a JSON string; a bare key name is not JSON.+ try:+ payload = json.loads(payload)+ except ValueError:+ pass+ if payload is None or payload == "":+ return None+ return payload.strip() if isinstance(payload, str) else str(payload)++def _task_v3_goal_judge_skip_reason(task: Task, context: SkyvernContext | None) -> str | None:- """Why the goal judge must not run for this task, or None. The judge never overrides a model choice- the task or its org pinned, runs only on a registered, non-BYO vision key, and never sends an image- to a run whose screenshot policy withholds them (the handler would drop it silently)."""- judge_key = settings.TASK_V3_GOAL_CHECK_LLM_KEY+ """Why the goal judge must not run for this task whatever its model, or None. The judge never overrides a+ model choice the task or its org pinned, and never sends an image to a run whose screenshot policy+ withholds them (the handler would drop it silently)."""+ if task.llm_key:+ return "task_model_pinned"+ if context is not None and (context.org_default_llm_key or context.org_default_secondary_llm_key):+ return "org_model_pinned"+ if context is not None and not context.llm_screenshots_enabled_for_prompt():+ return "screenshots_disabled"+ return None+++def _goal_judge_key_skip_reason(judge_key: str | None) -> str | None:+ """Why ``judge_key`` cannot run the judge, or None: it must be a registered, non-BYO vision key."""if not judge_key:return "no_judge_model"if is_custom_llm_key(judge_key):@@ -1256,12 +1287,6 @@ def _task_v3_goal_judge_skip_reason(task: Task, context: SkyvernContext | None)return "judge_key_unregistered"if not supports_vision:return "judge_model_no_vision"- if task.llm_key:- return "task_model_pinned"- if context is not None and (context.org_default_llm_key or context.org_default_secondary_llm_key):- return "org_model_pinned"- if context is not None and not context.llm_screenshots_enabled_for_prompt():- return "screenshots_disabled"return None@@ -1340,14 +1365,14 @@ def _task_v3_goal_check_redactor(task: Task, context: SkyvernContext | None) ->def _build_task_v3_goal_judge(*,+ judge_key: str,task: Task,step: Step,browser_state: BrowserState,peek_page: Callable[[], Awaitable[Any]],shot_holder: list[bytes],) -> GoalJudge:- assert settings.TASK_V3_GOAL_CHECK_LLM_KEY- handler = LLMAPIHandlerFactory.get_llm_api_handler(settings.TASK_V3_GOAL_CHECK_LLM_KEY)+ handler = LLMAPIHandlerFactory.get_llm_api_handler(judge_key)async def _goal_judge(prompt: str) -> dict[str, Any] | None:del shot_holder[:]@@ -2383,7 +2408,7 @@ class ForgeAgent:goal = _compose_goal(goal_fields)# The precedence arm grants the goal and criteria the user's authority; a value a page produced must- # not share it. The judge keeps the plain goal so the guard metric reads the same text in both arms.+ # not share it. The goal judge reads this same goal, so it too sees page values as quoted data.customer_precedence_on = not page_free_validation and run_arm_enabled(CUSTOMER_PRECEDENCE_FLAG, settings.TASK_V3_CUSTOMER_PRECEDENCE)@@ -2404,9 +2429,7 @@ class ForgeAgent:if workflow_run_context is not None and task.workflow_system_promptelse {})- judge_goal: str | None = Noneif customer_precedence_on and presented_fields:- judge_goal = goalgoal = _compose_goal({name: shown.text if (shown := presented_fields.get(name)) else value@@ -2998,9 +3021,8 @@ class ForgeAgent:extraction_requested = bool(task.data_extraction_goal or task.extracted_information_schema)goal_judge: GoalJudge | None = Nonegoal_check_enforce = False- # An unset judge key means the check is not deployed: nothing to resolve and nothing to log.goal_judge_skip: str | None = "ineligible"- if settings.TASK_V3_GOAL_CHECK_LLM_KEY and goal_check_eligible(+ if goal_check_eligible(page_free=page_free_validation,completion_blocker_present=completion_blocker is not None,extraction_requested=extraction_requested,@@ -3009,31 +3031,59 @@ class ForgeAgent:if goal_judge_skip is not None:LOG.info("taskv3 goal check skipped", task_id=task.task_id, reason=goal_judge_skip)if goal_judge_skip is None:+ goal_check_distinct_id = task.workflow_run_id or task.task_idif context:await resolve_run_arm(context,GOAL_CHECK_FLAG,- distinct_id=task.workflow_run_id or task.task_id,+ distinct_id=goal_check_distinct_id,organization_id=task.organization_id,forced=settings.TASK_V3_GOAL_CHECK,)if run_arm_enabled(GOAL_CHECK_FLAG, settings.TASK_V3_GOAL_CHECK):- if context:- await resolve_run_arm(- context,- GOAL_CHECK_ENFORCE_FLAG,- distinct_id=task.workflow_run_id or task.task_id,- organization_id=task.organization_id,- forced=settings.TASK_V3_GOAL_CHECK_ENFORCE,+ # The model rides on the treatment payload, so it is known only after assignment. A bad key+ # then skips every treatment run alike, which leaves the arm inert rather than selected.+ payload_key = await _read_goal_check_judge_key(goal_check_distinct_id, task.organization_id)+ judge_key = payload_key or settings.TASK_V3_GOAL_CHECK_LLM_KEY+ # The payload is re-read per block, so a mid-run payload edit can change the model between+ # blocks of one run; the key is logged per block so a read can split by it.+ judge_key_source = "payload" if payload_key else "setting"+ key_skip = _goal_judge_key_skip_reason(judge_key)+ if key_skip is not None:+ LOG.info(+ "taskv3 goal check skipped",+ task_id=task.task_id,+ reason=key_skip,+ judge_key=judge_key,+ judge_key_source=judge_key_source,+ )+ else:+ assert judge_key is not None+ LOG.info(+ "taskv3 goal check judge",+ task_id=task.task_id,+ judge_key=judge_key,+ judge_key_source=judge_key_source,+ )+ if context:+ await resolve_run_arm(+ context,+ GOAL_CHECK_ENFORCE_FLAG,+ distinct_id=goal_check_distinct_id,+ organization_id=task.organization_id,+ forced=settings.TASK_V3_GOAL_CHECK_ENFORCE,+ )+ goal_check_enforce = run_arm_enabled(+ GOAL_CHECK_ENFORCE_FLAG, settings.TASK_V3_GOAL_CHECK_ENFORCE+ )+ goal_judge = _build_task_v3_goal_judge(+ judge_key=judge_key,+ task=task,+ step=step,+ browser_state=browser_state,+ peek_page=_fingerprint_page,+ shot_holder=goal_judge_shot,)- goal_check_enforce = run_arm_enabled(GOAL_CHECK_ENFORCE_FLAG, settings.TASK_V3_GOAL_CHECK_ENFORCE)- goal_judge = _build_task_v3_goal_judge(- task=task,- step=step,- browser_state=browser_state,- peek_page=_fingerprint_page,- shot_holder=goal_judge_shot,- )outcome = await run_task_v3_agent_loop(page_provider=_page_provider,resolve_typed_text=resolve_typed_text,@@ -3081,7 +3131,6 @@ class ForgeAgent:),llm_caller=llm_caller,goal=goal,- judge_goal=judge_goal,parameters=parameters,starting_url=task.url,downloads_dir=get_download_dir(download_id),diff --git a/skyvern/forge/sdk/experimentation/providers.py b/skyvern/forge/sdk/experimentation/providers.pyindex 3e56910bc..d61134e67 100644--- a/skyvern/forge/sdk/experimentation/providers.py+++ b/skyvern/forge/sdk/experimentation/providers.py@@ -326,7 +326,11 @@ class BaseExperimentationProvider(ABC):)return variant- async def get_payload_cached(self, feature_name: str, distinct_id: str, properties: dict | None = None) -> Any:+ async def get_payload_cached(+ self, feature_name: str, distinct_id: str, properties: dict | None = None, *, record: bool = True+ ) -> Any:+ """``record=False`` keeps the run's recorded resolution for the flag, which is keyed by flag name, on the+ variant a caller already read rather than overwriting it with the payload."""cache_key = _make_cache_key(feature_name, distinct_id, properties)await self._prepare_feature_flag_resolution(feature_name, cached=True)if cache_key in self.payload_map:@@ -334,11 +338,12 @@ class BaseExperimentationProvider(ABC):else:payload = await self._get_payload(feature_name, distinct_id, properties)self.payload_map[cache_key] = payload- record_feature_flag_resolution(- feature_name=feature_name,- resolution_kind="payload",- resolved_value=payload,- )+ if record:+ record_feature_flag_resolution(+ feature_name=feature_name,+ resolution_kind="payload",+ resolved_value=payload,+ )return payloaddiff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.pyindex 72c665ad2..dee1d7131 100644--- a/skyvern/forge/sdk/workflow/models/block.py+++ b/skyvern/forge/sdk/workflow/models/block.py@@ -85,6 +85,7 @@ from skyvern.constants import (MAX_UPLOAD_FILE_COUNT,NAVIGATION_MAX_RETRY_TIME,PDF_OCR_PAGE_CONCURRENCY,+ PROXY_TRANSPORT_NAV_ERRORS,SAVE_DOWNLOADED_FILES_TIMEOUT,)from skyvern.errors.errors import UserDefinedError@@ -8003,6 +8004,13 @@ async def wrapper({default_args}):return HealSkipReason.insecure_codereturn HealSkipReason.unclassifiable+ @staticmethod+ def _skip_heal_on_proxy_transport(classification: HealClassification, nav_code: str | None) -> HealClassification:+ # The fallback reuses the same browser and proxy, so it would start on the same dead hop.+ if classification.healable and nav_code in PROXY_TRANSPORT_NAV_ERRORS:+ return HealClassification(healable=False, skip_reason=HealSkipReason.proxy_transport)+ return classification+def _classify_secure_runner_failure(self, failure: CodeBlockEngineFailure | None) -> HealClassification:if failure is None:return HealClassification(healable=False, skip_reason=HealSkipReason.unclassifiable)@@ -8554,7 +8562,7 @@ async def wrapper({default_args}):if (organization_idand not classification.healable- and classification.skip_reason is HealSkipReason.user_defined_error+ and classification.skip_reason in (HealSkipReason.user_defined_error, HealSkipReason.proxy_transport)):await self._write_heal_episode_safe(organization_id=organization_id,@@ -8565,7 +8573,7 @@ async def wrapper({default_args}):block_label=self.label,engine="harness",status="skipped",- skip_reason=HealSkipReason.user_defined_error,+ skip_reason=classification.skip_reason,parameter_binding_keys=self._heal_parameter_binding_keys(workflow_run_context),exception_class=scrub_failure_value("Exception", fallback=""),failing_line=failing_line,@@ -9194,13 +9202,22 @@ async def wrapper({default_args}):)await recorder.persist(recorded)if secure_failure is not None:+ # The runner's code is uncorroborated; the worker recorder resolved the host, so a dead+ # site behind the proxy (reported there as the sentinel) keeps healing.+ secure_nav_code = (+ secure_failure.nav_error_code+ if recording_page.last_failed_nav_error_code() in PROXY_TRANSPORT_NAV_ERRORS+ else None+ )secure_classification = (HealClassification(healable=False,skip_reason=HealSkipReason.user_defined_error,)if secure_failure.accepted_user_defined_error is not None- else self._classify_secure_runner_failure(secure_failure)+ else self._skip_heal_on_proxy_transport(+ self._classify_secure_runner_failure(secure_failure), secure_nav_code+ ))def scrub_secure_failure_fact(raw_value: str | None) -> str | None:@@ -9740,28 +9757,30 @@ async def wrapper({default_args}):if browser_state and inspect.getattr_static(browser_state, "engine_selection", None) is not Noneelse None)+ # ``e`` is unbound once the except block exits, so the driver's code is captured here+ # rather than read inside the deferred closure below. It comes from the recorder, never+ # from ``e``: authored code can rewrite the exception, or raise a fresh one, before it lands.+ inline_nav_code = recording_page.failure_nav_error_code(e)legacy_healable = self._is_healable_page_failure(e,recording_page,engine_selection,)- legacy_classification = HealClassification(- healable=legacy_healable,- skip_reason=(- None- if legacy_healable- else (- HealSkipReason.credential_off_site- if isinstance(e, CodeBlockCredentialReleaseError)- else HealSkipReason.unclassifiable- )+ legacy_classification = self._skip_heal_on_proxy_transport(+ HealClassification(+ healable=legacy_healable,+ skip_reason=(+ None+ if legacy_healable+ else (+ HealSkipReason.credential_off_site+ if isinstance(e, CodeBlockCredentialReleaseError)+ else HealSkipReason.unclassifiable+ )+ ),),+ inline_nav_code,)-- # ``e`` is unbound once the except block exits, so the driver's code is captured here- # rather than read inside the deferred closure below. It comes from the recorder, never- # from ``e``: authored code can rewrite the exception, or raise a fresh one, before it lands.- inline_nav_code = recording_page.failure_nav_error_code(e)if inline_nav_code and is_registered_secret(inline_nav_code, workflow_run_context):inline_nav_code = Nonedriver_nav_codes = [inline_nav_code] if inline_nav_code else Nonediff --git a/skyvern/forge/sdk/workflow/models/code_block_recorder.py b/skyvern/forge/sdk/workflow/models/code_block_recorder.pyindex 90d0d9b3b..4499a47e6 100644--- a/skyvern/forge/sdk/workflow/models/code_block_recorder.py+++ b/skyvern/forge/sdk/workflow/models/code_block_recorder.py@@ -463,8 +463,8 @@ class _Recorder:self.failed_locator_exception = Noneself.failed_locator = Noneself.failed_page = None- self.failed_nav_error_code_exception = None- self.failed_nav_error_code = None+ # The nav code survives later calls: block code may click or screenshot before re-raising, and+ # failure_nav_error_code only hands it back for the exception that navigated.return self.failure_operation_generationdef _reserve_action_order(self) -> int:@@ -1034,6 +1034,9 @@ class RecordingPage:recorder = self.__recorderreturn recorder.failed_nav_error_code if recorder.failed_nav_error_code_exception is exception else None+ def last_failed_nav_error_code(self) -> str | None:+ return self.__recorder.failed_nav_error_code+async def _record_solve_captcha(self,call: Callable[[], Awaitable[bool]],diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.pyindex 3e13abf58..a3e9c4acd 100644--- a/skyvern/forge/taskv3/engine.py+++ b/skyvern/forge/taskv3/engine.py@@ -310,8 +310,6 @@ async def run_task_v3_agent_loop(# A secret may already be on the page from before this loop (an earlier block, a self-healing# script): the goal check then never captures a screenshot.secret_on_page_at_start: bool = False,- # The goal as the judge reads it when `goal` carries arm-specific presentation; defaults to `goal`.- judge_goal: str | None = None,) -> LoopOutcome:"""Run one Task V3 task to completion against `page`, returning the loop outcome.@@ -338,13 +336,11 @@ async def run_task_v3_agent_loop(else:refs = mask_opaque_urls(parameters)model_goal = refs.mint_in_text(goal)- judge_goal = refs.mint_in_text(judge_goal) if judge_goal is not None else Noneextra_system_guidance = refs.mint_in_text(extra_system_guidance)goal_instructions = refs.mint_in_text(goal_instructions)# One whole URL, not prose: the text scan would stop at a legal path character such as "'".if starting_url and is_signed_url(starting_url):model_starting_url = refs.derive(starting_url)- model_judge_goal = model_goal if judge_goal is None else judge_goal# The single model-facing masking boundary reads these off the task context (the chokepoint# hide_from_model already runs on every tool result), so a resolved ref echoed by any tool —# success or error — is rewritten to its token by membership, without each tool opting in. Set@@ -487,7 +483,7 @@ async def run_task_v3_agent_loop(verdict = GoalVerdict("achieved", "", "", "instructions_too_long", 0.0)else:verdict = await run_goal_check(- goal=model_judge_goal,+ goal=model_goal,trail=tool_trail,judge=goal_judge,timeout_seconds=timeout,diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.pyindex cba25d92e..ebf358a79 100644--- a/skyvern/forge/taskv3/loop.py+++ b/skyvern/forge/taskv3/loop.py@@ -762,13 +762,14 @@ def telemetry_hash(salt: str, *parts: str) -> str:# as is a page-authored data-tv3-ref: observe addresses by a server-held ref, never by an# attribute, so nothing in the markup with that name is a handle this engine minted._TV3_MARKER_VALUE_RE = re.compile(r'data-tv3="t\d+(?:-\d+)?"')+_TV3_PICK_VALUE_RE = re.compile(r'data-tv3-pick="[^"]*"')# get_html truncates to a fixed budget before the loop ever sees the content, so a marker the cut# leaves open at the tail has no closing quote for the pattern above and its churning digits would# be the one leak that survives canonicalization. The lookahead assumes the truncation notice itself# carries no quote character, and this sub must run AFTER closed markers are rewritten to the# quote-bearing placeholder — either broken silently brings the leak back.-_TV3_MARKER_CUT_RE = re.compile(r'data-tv3="t\d*(?:-\d*)?(?=[^"]*\Z)')+_TV3_MARKER_CUT_RE = re.compile(r'(?:data-tv3="t\d*(?:-\d*)?|data-tv3-pick="[a-f0-9]*)(?=[^"]*\Z)')# A read can now start at an offset, so a marker can be cut open at the HEAD of a window too. Same# leak, same canonicalization, opposite end — but the boundary can land at ANY of the sixteen@@ -845,7 +846,15 @@ def _canonical_perception_content(noticed = addressed[:notice_at] + "…[*]" + addressed[closing + 1 :]head_folded = '*"' + noticed[head_fragment_len:] if head_fragment_len else noticedclosed = _TV3_MARKER_VALUE_RE.sub(lambda m: m.group(0).partition("=")[0] + '="*"', head_folded)- return _TV3_MARKER_CUT_RE.sub(lambda m: m.group(0).partition("=")[0] + '="*', closed)+ closed = _TV3_PICK_VALUE_RE.sub('data-tv3-pick="*"', closed)+ return _TV3_MARKER_CUT_RE.sub(+ lambda m: (+ m.group(0)+ if notice_at is None and m.group(0).startswith("data-tv3-pick=")+ else m.group(0).partition("=")[0] + '="*'+ ),+ closed,+ )def _content_only_perception(@@ -4268,8 +4277,7 @@ async def run_agent_tool_loop(breakif result.status == "error":- # The rest of the batch is skipped only when the failed call moved the page: the tool's- # own signal, or the probe sampled before dispatch (a missing reading counts as moved).+ # A live refusal needs a new model choice, so stop_batch skips pending calls without claiming progress.poisoned = (tool_name == "navigate"or result.content == PAGE_UNAVAILABLE_ERROR@@ -4277,6 +4285,7 @@ async def run_agent_tool_loop(result_data.get("page_transitioned")or result_data.get("page_state_changed")or result_data.get("navigation_dead_end")+ or result_data.get("stop_batch")))# Whether the page moved is independent of the tool's kind: a wait that timed out becausediff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.pyindex f9e845373..a46ba0d98 100644--- a/skyvern/forge/taskv3/tools.py+++ b/skyvern/forge/taskv3/tools.py@@ -208,7 +208,7 @@ def _past_end_error(total: int) -> ToolResult:)-_MARKER_ATTR_OPEN = 'data-tv3="'+_MARKER_ATTR_OPENS = ('data-tv3="', 'data-tv3-pick="')# The value shape this engine mints, and the same test `MINTED_MARKER_RE` applies in the observe JS# before it will trust a `data-tv3` as a selector. A page can author the attribute too, so the value# is what separates ours from theirs.@@ -232,36 +232,20 @@ _HOST_INSIDE_COVER_JS = r"""(host, limit) => {def _marker_head_fragment_len(content: str, offset: int) -> int:- """How many characters at `offset` are the tail of a marker attribute the cut opened, or 0.-- Computed from the boundary itself rather than by recognizing the fragment's SHAPE. Every prefix- of the attribute is also legal page text — `123"`, `t123"`, `="t123"` — so a pattern cannot tell- a split marker from a page that merely starts that way, and folding page text that differs makes- it read as frozen, which the perception-stall guard terminates on.- """+ # Read the complete attribute across the cut; a fragment's shape can also be ordinary page text.if offset <= 0:return 0- # The opener may STRADDLE the boundary — a window can begin `a-tv3="t123"` — so the search admits- # any occurrence starting before `offset`, not only ones ending before it. Bounded at `0, offset`- # it misses every cut that lands inside the attribute's own name, and the marker value then goes- # unfolded: an unchanged window gets a fresh digest whenever a remount re-mints it, which is how- # a frozen page evades the stall guard instead of tripping it.- opened = content.rfind(_MARKER_ATTR_OPEN, 0, offset + len(_MARKER_ATTR_OPEN) - 1)- if opened < 0 or opened >= offset:- return 0- closed = content.find('"', opened + len(_MARKER_ATTR_OPEN))- if closed < offset:- # A boundary at or past the closing quote left nothing open.- return 0- # The VALUE decides, and by here the whole of it is in hand — which is why this is not the- # shape-matching the fragment forbids. A prefix is ambiguous (`123"`, `t123"` are also legal page- # text); a complete value is not. A page may author `data-tv3` itself, and folding a- # page-authored value that is changing makes the window read as frozen, which the- # perception-stall guard terminates on. Same test the observe JS applies before it will trust one- # of these as a selector.- if not _MINTED_MARKER_VALUE_RE.match(content[opened + len(_MARKER_ATTR_OPEN) : closed]):- return 0- return closed - offset + 1+ for opener in _MARKER_ATTR_OPENS:+ opened = content.rfind(opener, 0, offset + len(opener) - 1)+ if opened < 0 or opened >= offset:+ continue+ closed = content.find('"', opened + len(opener))+ if closed < offset:+ continue+ if opener == 'data-tv3="' and not _MINTED_MARKER_VALUE_RE.match(content[opened + len(opener) : closed]):+ continue+ return closed - offset + 1+ return 0def _window(content: str, offset: int, cut: Callable[[int, int], str]) -> tuple[str, int, int | None] | ToolResult:@@ -371,7 +355,9 @@ def _escape_tags_in_text(text: str) -> str:# kept for the life of the document, so the submit watch can still resolve it turns later). Each# exists only where we set it, so one that matches nothing now cannot reappear without a fresh# observe / menu-opening click / look.-_TV3_MARKER_SELECTOR_RE = re.compile(r'^\[data-tv3(?:-menu|-act|-sugg)?="[^"\\]+"\]$')+_TV3_MARKER_SELECTOR_RE = re.compile(+ r'^\[data-tv3(?:(?:-menu|-act)?="[^"\\]+"\]|-sugg="[^"\\]+"\](?:\[data-tv3-pick="[^"\\]+"\])?)$'+)# An opaque identifier (a uuid, or a run of 12+ hex digits) does not survive a model's copy: one# transposed pair sends every later call to a selector that matches nothing. observe addresses its# own elements by ref for that reason; this is what look()'s legend refuses to use as a label.@@ -879,6 +865,8 @@ def _ambiguous_rows_error(next_step: str,note: str | None = None,rows_unread: bool = False,+ live_token: str | None = None,+ live_search: str | None = None,) -> ToolResult:"""The refusal owed a caller when rows reacted and none of them IS the requested value.@@ -886,27 +874,60 @@ def _ambiguous_rows_error(caller's. One wording for both entry points, so a refusal reported by type() and by select_comboboxcannot drift into telling a model two different stories about the same page."""+ # Preserve the telemetry facet from the original row count, before collapsing proven copies.+ several = len(rows) > 1+ if live_token is not None:+ groups: dict[str, list[dict[str, Any]]] = defaultdict(list)+ for row in rows:+ groups[_canon_label(str(row.get("text") or ""))].append(row)+ copies = {+ id(row) for group in groups.values() if _lone_duplicate_candidate(group) is not None for row in group[1:]+ }+ rows = [row for row in rows if id(row) not in copies]shown = rows[:15]- listing = "; ".join(repr(str(o.get("text") or "")[:60]) for o in shown)+ listing = "; ".join(+ (f'[data-tv3-sugg="{o.get("n")}"][data-tv3-pick="{live_token}"] ' if live_token is not None else "")+ + repr(str(o.get("text") or "")[:60])+ + (_row_value_suffix(o, groups[_canon_label(str(o.get("text") or ""))]) if live_token is not None else "")+ 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) > 1lead = (f"{value!r} matches several rows in {selector}: "if severalelse f"{value!r} is not the one row showing in {selector}: ")+ data = {"release_own_list": True}+ if live_token is not None:+ lead = (+ f"{value!r} is not exactly any of the {len(rows)} rows showing in {selector}: "+ if len(rows) > 1+ else f"{value!r} is not exactly the one row showing in {selector}: "+ )+ next_step = (+ "click the row that is the value you hold by its selector, or call select_combobox with that row's exact "+ "label as value and no search (the typed query was left in the field to keep the list open); if none of "+ "them is that value, call select_combobox with a different search, or report that the field cannot be filled"+ )+ if live_search is not None:+ next_step = (+ "click the row that is the value you hold by its selector, or call select_combobox with that row's "+ f"exact label as value and search={live_search!r}, the query that rendered them "+ "(the typed query was left in the field to keep the list open); "+ "if the label you want is not among them, a longer search narrows it"+ )+ data = {"stop_batch": True}+ if note:+ note = note.removesuffix(" — type the option's full label")tail = f" ({note})" if note else ""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")+ return ToolResult.error(message, data=data, 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")+ return ToolResult.error(message, data=data, error_class="rows_unread")+ return ToolResult.error(message, data=data, error_class="no_matching_row")def _row_value_suffix(o: dict[str, Any], rows: list[dict[str, Any]]) -> str:@@ -954,36 +975,43 @@ def _row_value_suffix(o: dict[str, Any], rows: list[dict[str, Any]]) -> str:def _identical_text_rows_error(- selector: str, value: str, rows: list[dict[str, Any]], *, tags_live: bool = True, note: str | None = None+ selector: str,+ value: str,+ rows: list[dict[str, Any]],+ *,+ note: str | None = None,+ live_token: str | None = None,) -> ToolResult:"""The refusal owed when ≥2 rows match the value at the exact tier and are not one duplicate-renderedcandidate: the exact tier folds case/apostrophes, so every row already IS the requested text and only- a direct click on a named row can choose between them. With `tags_live` the query stays typed and the- rows' [data-tv3-sugg="N"] tags stay clickable; otherwise the field's prior value is restored and the- refusal directs a re-open instead.+ a direct click on a named row can choose between them. With `live_token` the query stays typed and+ the rows' token-qualified selectors stay clickable; otherwise the field's prior value is restored+ and the refusal directs a re-open instead."""shown = rows[:15]def _sel(o: dict[str, Any]) -> str:# A selector is only named while it can be honored: after a restore the list may have closed# and the stale tags may re-land on different rows at the next scan.- return f'[data-tv3-sugg="{o.get("n")}"] ' if tags_live else ""+ return f'[data-tv3-sugg="{o.get("n")}"][data-tv3-pick="{live_token}"] ' if live_token is not None else ""listing = "; ".join(f"{_sel(o)}{str(o.get('text') or '')[:60]!r}{_row_value_suffix(o, rows)}" for o in shown)more = len(rows) - len(shown)next_step = (- 'click the intended row directly by its [data-tv3-sugg="N"] selector; the typed query was left '+ "click the intended row directly by its listed selector; the typed query was left ""in the field to keep the list open for that click"- if tags_live+ if live_token is not Noneelse "type the value to reopen the list, then click the intended row directly; the field's ""prior value was put back")+ if live_token is not None and note:+ note = note.removesuffix(" — type the option's full label")tail = f" ({note})" if note else ""return ToolResult.error(f"{value!r} matches {len(rows)} rows in {selector} whose labels the exact matcher cannot tell "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},+ data={"stop_batch": True} if live_token is not None else {"release_own_list": True},error_class="identical_rows",)@@ -1737,7 +1765,10 @@ _FIND_SUGGESTION_JS = (// IS that value can ever be committed. So the ceiling is measured from it, keeping 80 as the// allowance for the extra parts a declared row can render beside its label.const txtCap = searched ? String(args.match).replace(/\s+/g, ' ').trim().length + 80 : 80;- pQSA('[data-tv3-sugg]').forEach((e) => e.removeAttribute('data-tv3-sugg'));+ pQSA('[data-tv3-sugg], [data-tv3-pick]').forEach((e) => {+ e.removeAttribute('data-tv3-sugg');+ e.removeAttribute('data-tv3-pick');+ });if ((!searched && !want.size && !exact) || !preReady()) return null;const field = pQS(args.field) || (args.el && args.el.isConnected ? args.el : null);// No field means no geometry gate, and without it the scan below is page-wide and will happily@@ -2482,7 +2513,7 @@ _VERIFY_COMMIT_JS = (// (suggTagged) and the LIST ITSELF is gone/hidden now (read off the stamped list// container — a re-render that merely replaces row nodes strips the row tags but keeps the// container, and must not read as a commit; suggListOpen). Exact equality with the CHOSEN label only.- if (args.suggTagged && !args.suggListOpen && cur && eqi(cur, chosen) && tagsGone) return cur;+ if (!args.liveOffer && args.suggTagged && !args.suggListOpen && cur && eqi(cur, chosen) && tagsGone) return cur;} else if (cur && (cur !== typed || listClosed) && (toks(cur).size === 0 || overlaps(cur, chosen) || overlaps(cur, typed))) {return cur;}@@ -6075,7 +6106,7 @@ _TYPEAHEAD_LIST_OPEN_JS = (+ _PIERCED_QUERY_JS+ _ROW_SEMANTICS_JS+ r"""- const el = pQS(arg.sel) || (arg.el && arg.el.isConnected ? arg.el : null);+ const el = (arg.sel ? pQS(arg.sel) : null) || (arg.el && arg.el.isConnected ? arg.el : null);if (!el) return false;const exp = el.getAttribute('aria-expanded') != null ? el : el.closest('[aria-expanded]');if (exp && exp.getAttribute('aria-expanded') === 'true') return true;@@ -11824,6 +11855,58 @@ def build_browser_tools(return chosen, Truereturn committed, readable+ @dataclasses.dataclass+ class _LiveRowOffer:+ page: Any+ element: Any+ token: str+ rows: list[dict[str, Any]]+ typed: list[str]+ consumed: bool = False++ _live_row_offers: dict[str, _LiveRowOffer] = {}++ async def _discard_live_row_offer(selector: str) -> None:+ offer = _live_row_offers.pop(selector)+ with contextlib.suppress(Exception):+ await offer.element.dispose()++ async def _live_row_token(page: Any, selector: str, rows: list[dict[str, Any]], *, typed: list[str]) -> str | None:+ # Each refusal gets a fresh identity, independent of row text or position. Progress probes+ # fold these tokens so renewing an offer cannot count as page progress.+ token = secrets.token_hex(3)+ element = None+ try:+ element = await page.query_selector(selector)+ if element is None:+ return None+ tagged = await page.evaluate(+ "(args) => {"+ + _PIERCED_QUERY_JS+ + """+ if (!args.element.isConnected || args.element.ownerDocument !== document) return false;+ for (const n of args.rows) {+ const row = pQS(`[data-tv3-sugg="${n}"]`);+ if (row) row.setAttribute('data-tv3-pick', args.token);+ }+ return true;+ }""",+ {"rows": [row["n"] for row in rows], "token": token, "element": element},+ )+ if not tagged:+ await element.dispose()+ return None+ except Exception as e:+ if element is not None:+ with contextlib.suppress(Exception):+ await element.dispose()+ LOG.debug("taskv3 live row tagging failed", error=str(e), exc_info=True)+ return None+ if selector in _live_row_offers:+ await _discard_live_row_offer(selector)+ _live_row_offers[selector] = _LiveRowOffer(page, element, token, [dict(row) for row in rows], list(typed))+ return token+async def _find_suggestion_rows(page: Any, selector: str, query: str, *, any_region: bool = False, match: str | None = None) -> dict[str, Any] | None:@@ -11902,6 +11985,7 @@ def build_browser_tools(exact_only: bool = False,probe: str | None = None,pre_own: str | None = None,+ live_offer: tuple[str, list[dict[str, Any]]] | None = None,) -> _TypeaheadPick:# Poll for the suggestion rows rendered IN REACTION to whatever is already typed into `selector`,# pick among them, click, and verify the field committed. When the widget DECLARES its rows the@@ -12021,17 +12105,31 @@ def build_browser_tools(judged = await _resolve(found)return judged[2] is not None- found = await _await_suggestion_rows(- page,- selector,- probe or value,- rounds,- match=value if probe else None,- settled=_names_the_value if probe else None,- )- if found is None:- return _TypeaheadPick(None, None, False, None, clicked=False, declared=False)- declared_rows, rows, idx, overflow = judged if judged is not None else await _resolve(found)+ if live_offer is not None:+ token, rows = live_offer+ bare_tagged = {row["n"] for row in rows if row.get("bare")}+ matched = [row for row in rows if _exact_tier_key(str(row.get("text") or "")) == _exact_tier_key(value)]+ idx = matched[0]["n"] if len(matched) == 1 else _lone_duplicate_candidate(matched)+ if idx is None:+ return _TypeaheadPick(None, None, False, None, clicked=False, declared=False)+ stamp = f'[data-tv3-sugg="{idx}"][data-tv3-pick="{token}"]'+ # A cloned tag is not a unique offered node. Do not let query_selector choose its first copy.+ if await _marker_matches(page, stamp) != 1:+ return _TypeaheadPick(None, None, False, None, clicked=False, declared=False)+ declared_rows, overflow = True, 0+ else:+ found = await _await_suggestion_rows(+ page,+ selector,+ probe or value,+ rounds,+ match=value if probe else None,+ settled=_names_the_value if probe else None,+ )+ if found is None:+ return _TypeaheadPick(None, None, False, None, clicked=False, declared=False)+ declared_rows, rows, idx, overflow = judged if judged is not None else await _resolve(found)+ stamp = f'[data-tv3-sugg="{idx}"]'if idx is None:note = (f"the list declares {overflow} rows and only {len(rows)} are rendered — type the option's full label"@@ -12042,7 +12140,7 @@ def build_browser_tools(None,None,False,- rows if declared_rows else None,+ [{**row, "bare": row.get("n") in bare_tagged} for row in rows] if declared_rows else None,clicked=False,declared=declared_rows,note=note,@@ -12084,10 +12182,13 @@ def build_browser_tools(# candidate scoring (word-overlap with the TYPED query) can drop a row the widget still renders.rows_armed = await _arm_rows_at_press(page, selector)try:- if not await _click_stamped_row(page, f'[data-tv3-sugg="{idx}"]', best_txt, 3000):+ if not await _click_stamped_row(page, stamp, best_txt, 3000):raise RuntimeError("stamped suggestion row is no longer the matched row")clicked = Trueexcept Exception:+ if live_offer is not None:+ LOG.debug("taskv3 live row click failed; retrying through typing", selector=selector, exc_info=True)+ return _TypeaheadPick(None, None, False, None, clicked=False, declared=False)try:refound = await _find()if refound is not None:@@ -12128,10 +12229,11 @@ def build_browser_tools(selector,{"field": selector,- "typed": pre_value if from_focus else (value if probe is None else probe),- "typedTrusted": (not from_focus) or pre_value_read is not None,+ "typed": pre_value if from_focus or live_offer is not None else (value if probe is None else probe),+ "typedTrusted": pre_value_read is not None or (not from_focus and live_offer is None),"chosen": best_txt,- "noSuggestionList": from_focus,+ "noSuggestionList": from_focus or live_offer is not None,+ "liveOffer": live_offer is not None,"suggTagged": True,"commitEvtArmed": commit_evt_armed,# The DECLARED-row exemption in the verifier is about the row that was clicked, not@@ -12289,6 +12391,125 @@ def build_browser_tools(except Exception:LOG.debug("taskv3 pre-type value restore failed", selector=selector)+ def _with_live_row_release(tool_name: str, handler: ToolHandler) -> ToolHandler:+ async def wrapped(args: dict[str, Any]) -> ToolResult:+ if tool_name == "navigate":+ result = await handler(args)+ if result.status == "ok":+ for field in list(_live_row_offers):+ await _discard_live_row_offer(field)+ return result+ if not _live_row_offers:+ return await handler(args)+ page, error = await _resolve_page()+ if error is not None:+ for field in list(_live_row_offers):+ await _discard_live_row_offer(field)+ return error+ selector = args.get("selector")+ target = (+ await _resolve_mirrored_host_control(page, selector) if isinstance(selector, str) and selector else None+ )+ on_field: list[tuple[str, _LiveRowOffer]] = []+ for field, offer in list(_live_row_offers.items()):+ try:+ relation = await offer.page.evaluate(+ "(args) => {"+ + _PIERCED_QUERY_JS+ + """+ const field = args.element;+ if (!field.isConnected || field.ownerDocument !== document+ || (pQS(args.field.sel) || args.field.el) !== field) return 'gone';+ let target = args.target && (pQS(args.target.sel) || args.target.el);+ if (!target && args.active && document.hasFocus()) {+ target = document.activeElement;+ while (target && target.shadowRoot && target.shadowRoot.activeElement)+ target = target.shadowRoot.activeElement;+ }+ if (target === field) return 'field';+ for (let el = target; el; el = el.parentElement || el.getRootNode().host) {+ if (el.getAttribute('data-tv3-pick') === args.token+ && el.hasAttribute('data-tv3-sugg')) return 'row';+ }+ return 'other';+ }""",+ {+ "field": await _probe_arg(offer.page, field),+ "element": offer.element,+ "target": await _probe_arg(page, target) if target and page is offer.page else None,+ "active": tool_name == "press_key" and not selector,+ "token": offer.token,+ },+ )+ except Exception as exc:+ if _invalid_selector_result(target, exc) is not None:+ raise+ LOG.debug("taskv3 live offer target unreadable", error=str(exc), exc_info=True)+ relation = "gone"+ if relation == "field" and (+ tool_name != "press_key"+ or normalize_key_chord(args["key"])+ in {+ "ArrowUp",+ "ArrowDown",+ "ArrowLeft",+ "ArrowRight",+ "Home",+ "End",+ "PageUp",+ "PageDown",+ "Shift",+ "Control",+ "Alt",+ "Meta",+ }+ ):+ target = target or field+ if target != field:+ del _live_row_offers[field]+ _live_row_offers[target] = offer+ on_field.append((target, offer))+ continue+ if relation == "row" and tool_name != "click":+ continue+ try:+ if relation in ("gone", "row"):+ continue+ read_value = "el => el.isConnected ? (el.isContentEditable ? el.textContent : el.value) : null"+ current = await offer.element.evaluate(read_value)+ if not isinstance(current, str) or not any(+ current.strip().lower() == q.strip().lower() for q in offer.typed+ ):+ continue+ # A page can replace the field during cleanup; writes and Escape must stay on the original node.+ if current:+ await offer.element.fill("", timeout=_ACTION_TIMEOUT_MS)+ if await offer.element.evaluate(read_value) != "":+ continue+ dismissed = await _close_lingering_typeahead_list(offer.page, field, None, element=offer.element)+ if dismissed is not None:+ return ToolResult.error(+ "The requested action did not run. Closing the previous field's still-open list with "+ "Escape also dismissed the field's own container — re-observe before continuing.",+ data={"page_state_changed": True},+ )+ except Exception:+ LOG.debug("taskv3 live offer release failed", selector=field, exc_info=True)+ finally:+ await _discard_live_row_offer(field)+ _prefetched_page.append(_current_page())+ try:+ result = await handler(args)+ finally:+ _prefetched_page.clear()+ if result.status == "ok" and tool_name in {"select_combobox", "type"}:+ for field, offer in on_field:+ if _live_row_offers.get(field) is offer:+ await _discard_live_row_offer(field)+ return result++ return wrapped+async def _type_and_commit(page: Any,selector: str,@@ -12334,6 +12555,8 @@ def build_browser_tools(pass# `query` is what the caller chose to search with; the row committed must still be `value` exactly.typed = query or value+ if selector in _live_row_offers:+ _live_row_offers[selector].typed.extend(["", typed])if collateral is not None and reach != "click":# Only a field the click could not reach can misroute its keys, and only that path restores.# A checked click leaves the page untagged and pays nothing.@@ -12513,19 +12736,28 @@ def build_browser_tools(return pick._replace(note=f"{searched_note}; {pick.note}" if pick.note else searched_note)async def _close_lingering_typeahead_list(- page: Any, selector: str, committed: str | None, *, surface_vouched_pre_click: bool = False+ page: Any,+ selector: str,+ committed: str | None,+ *,+ surface_vouched_pre_click: bool = False,+ element: Any = None,) -> ToolResult | None:# A declared field's widget can re-search on the value it just committed and leave its list# open, covering whatever the form has below it. Close it with Escape, best-effort: None means# the caller's own OK stands; a ToolResult means closing was not safe to treat as a no-op.try:- still_open = bool(await page.evaluate(_TYPEAHEAD_LIST_OPEN_JS, await _probe_arg(page, selector)))+ probe = {"sel": "", "el": element} if element is not None else await _probe_arg(page, selector)+ still_open = bool(await page.evaluate(_TYPEAHEAD_LIST_OPEN_JS, probe))except Exception:return Noneif not still_open:return Nonetry:- await page.press(selector, "Escape", timeout=5000)+ if element is None:+ await page.press(selector, "Escape", timeout=5000)+ else:+ await element.press("Escape", timeout=5000)except Exception:LOG.debug("taskv3 lingering typeahead list close failed", selector=selector)return None@@ -13332,7 +13564,7 @@ def build_browser_tools(# not just on a single `input` from fill — still surfaces them, then commit the best match.collateral: list[list[str]] = []try:- pick, pre_value, _pre_own, reach = await _type_and_commit(+ pick, pre_value, pre_own, reach = await _type_and_commit(page, selector, text, rounds=3, focus_fallback=True, collateral=collateral)except _FieldCovered as exc:@@ -13409,25 +13641,26 @@ def build_browser_tools(data={"release_own_list": True},)if pick.suggestion is None and pick.candidates:- # Several rows reacted and none was a unique precision match, so nothing was picked.- # The raw text left behind is exactly what a typeahead discards, so "typed into X" here- # is a false success -- name the rows instead and hand the pick to the tool that makes- # one. Geometry must not break the tie; only the caller naming a row can. "NOT filled"- # has to be true of the field as well as of the widget, so the query goes back out --- # unless the rows are text-indisambiguable (same candidate, or a value-only distinction:- # see _identical_text_rows_error), where retyping the same text can never pick a- # different row and the query stays so the list and the rows' tags stay live instead.+ # Keep an empty field's query so the model can click a live row; protect any prior value.text_key = _exact_tier_key(text)same_text = [o for o in pick.candidates if _exact_tier_key(str(o.get("text") or "")) == text_key]if len(same_text) >= 2 and _lone_duplicate_candidate(same_text) is None:# Leave the query (keeping the list and tags live) only when there is nothing to# protect: a field that HELD a value must get it back, or the leftover query becomes# every later call's restore baseline and the true value is gone for the run.- if not pre_value:- return _identical_text_rows_error(selector, text, same_text, note=pick.note)+ if pre_value == "" and not pre_own:+ live_token = await _live_row_token(page, selector, same_text, typed=[text])+ if live_token is not None:+ return _identical_text_rows_error(+ selector, text, same_text, note=pick.note, live_token=live_token+ )+ await _restore_pre_type_value(page, selector, pre_value, [text])+ return _identical_text_rows_error(selector, text, same_text, note=pick.note)+ live_token = None+ if pre_value == "" and not pre_own:+ live_token = await _live_row_token(page, selector, pick.candidates, typed=[text])+ if live_token is None:await _restore_pre_type_value(page, selector, pre_value, [text])- return _identical_text_rows_error(selector, text, same_text, tags_live=False, note=pick.note)- await _restore_pre_type_value(page, selector, pre_value, [text])return _ambiguous_rows_error(selector,text,@@ -13435,6 +13668,7 @@ def build_browser_tools(next_step="call select_combobox with the option's full text",note=pick.note,rows_unread=bool(pick.overflow),+ live_token=live_token,)if pick.suggestion:verdict, matches = await _typeahead_commit_verdict(page, selector, pick.committed, pick.readable)@@ -14070,18 +14304,32 @@ def build_browser_tools(return any(holds(norm(part)) for part in surface.split("\u0001"))async def _commit_custom_combobox(- page: Any, selector: str, value: str, search: str | None = None, *, press_enter: bool = False+ page: Any,+ selector: str,+ value: str,+ search: str | None = None,+ *,+ press_enter: bool = False,+ live_offer: tuple[str, list[dict[str, Any]]] | None = None,) -> ToolResult:# Every non-ok exit below must close the field's OWN list if the attempt left it open (D2) —# applied once here, at the exit, rather than at every refusal branch below.opened_by_typing = await _anchor_typeable(page, selector) and await _list_opened_on_an_empty_field(page, selector)- result = await _commit_custom_combobox_attempt(page, selector, value, search, press_enter=press_enter)+ result = await _commit_custom_combobox_attempt(+ page, selector, value, search, press_enter=press_enter, live_offer=live_offer+ )return await _close_own_list_on_exit(page, selector, result, opened_by_typing=opened_by_typing)async def _commit_custom_combobox_attempt(- page: Any, selector: str, value: str, search: str | None = None, *, press_enter: bool = False+ page: Any,+ selector: str,+ value: str,+ search: str | None = None,+ *,+ press_enter: bool = False,+ live_offer: tuple[str, list[dict[str, Any]]] | None = None,) -> ToolResult:# Shared custom-combobox commit — the ONE path select_combobox and select_option's non-native# branch both route through. Two mechanisms, one tool call: a TYPEAHEAD (searchable react-select /@@ -14136,6 +14384,20 @@ def build_browser_tools(return ToolResult.error(f"selected suggestion {opt_txt!r} but {selector} did not commit a value")return ToolResult.error(f"selected suggestion {opt_txt!r} but {selector} did not commit a value")+ if live_offer is not None:+ live_pick = await _commit_typeahead(+ page, selector, value, rounds=0, pre_own=await _own_surface_text(page, selector), live_offer=live_offer+ )+ if live_pick.clicked and live_pick.suggestion is not None:+ return await _typeahead_verdict_result(+ live_pick.suggestion,+ live_pick.committed,+ live_pick.readable,+ declared=live_pick.declared,+ surface_vouched_pre_click=live_pick.pre_surface_hit,+ shared_surface=live_pick.shared_surface,+ )+def _reduced_queries() -> list[str]:# Ask the widget less until it answers. A search field that rendered nothing for the whole# value may still hold it under its own coarser form: the leading clause before the first@@ -14173,6 +14435,8 @@ def build_browser_tools(nonlocal ladder_rungfor rung in _reduced_queries():typed_queries.append(rung)+ if selector in _live_row_offers:+ _live_row_offers[selector].typed.extend(["", rung])# `pre_own` is the ONE call-level snapshot the primary attempt took before it typed# anything (closed over from _commit_custom_combobox_attempt) — re-reading it here# would see the list THIS rung's own typing just opened and always read as changed.@@ -14201,6 +14465,19 @@ def build_browser_tools()if rung_pick.candidates:ladder_rung = rung+ if not press_enter and pre_value == "" and not pre_own:+ live_token = await _live_row_token(page, selector, rung_pick.candidates, typed=typed_queries)+ if live_token is not None:+ return _ambiguous_rows_error(+ selector,+ value,+ rung_pick.candidates,+ next_step="",+ note=rung_pick.note,+ rows_unread=bool(rung_pick.overflow),+ live_token=live_token,+ live_search=rung,+ )return rung_pick.candidatesreturn []@@ -14269,11 +14546,19 @@ def build_browser_tools(same_text = [o for o in pick.candidates if _exact_tier_key(str(o.get("text") or "")) == value_key]if len(same_text) >= 2 and _lone_duplicate_candidate(same_text) is None:# Same guard as the type() site: only an empty field may keep the query.- if not pre_value:- return _identical_text_rows_error(selector, value, same_text, note=pick.note)+ if pre_value == "" and not pre_own:+ live_token = await _live_row_token(page, selector, same_text, typed=typed_queries)+ if live_token is not None:+ return _identical_text_rows_error(+ selector, value, same_text, note=pick.note, live_token=live_token+ )+ await _restore_pre_type_value(page, selector, pre_value, typed_queries)+ return _identical_text_rows_error(selector, value, same_text, note=pick.note)+ live_token = None+ if not press_enter and pre_value == "" and not pre_own:+ live_token = await _live_row_token(page, selector, pick.candidates, typed=typed_queries)+ if live_token is None:await _restore_pre_type_value(page, selector, pre_value, typed_queries)- 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)# Some widgets search only part of what is typed, so the full label can answer with# other rows; what to search for instead is the caller's call, not a rule's.next_step = (@@ -14292,6 +14577,7 @@ def build_browser_tools(next_step=next_step,note=pick.note,rows_unread=bool(pick.overflow),+ live_token=live_token,)# 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@@ -14352,7 +14638,7 @@ def build_browser_tools(on_open, on_open_total = await _read_offered()ladder = await _reduced_query_ladder()if isinstance(ladder, ToolResult):- if ladder.status != "ok":+ if ladder.status != "ok" and not (ladder.data or {}).get("stop_batch"):await _restore_pre_type_value(page, selector, pre_value, typed_queries)return ladder# Name the choices the widget offered, so the next call can use the exact label@@ -14414,7 +14700,9 @@ def build_browser_tools(# same row sits on the list a COARSER query renders, which settles instead of churning,# so ask that question rather than report a dead end over a selection never delivered.laddered = await _reduced_query_ladder()- if isinstance(laddered, ToolResult) and laddered.status == "ok":+ if isinstance(laddered, ToolResult) and (+ laddered.status == "ok" or (laddered.data or {}).get("stop_batch")+ ):return ladderedawait _restore_pre_type_value(page, selector, pre_value, typed_queries)verdict = await _typeahead_verdict_result(@@ -14967,6 +15255,11 @@ def build_browser_tools(if ambiguous is not None:return ambiguousselector = await _resolve_mirrored_host_control(page, selector)+ offer = _live_row_offers.get(selector)+ live_offer = None+ if offer is not None and not offer.consumed and not args.get("press_enter"):+ live_offer = (offer.token, offer.rows)+ offer.consumed = Truevalue = await _resolve_text(args["value"], operation="select_combobox", page=page, selector=selector)search = args.get("search")search_text = (@@ -14983,7 +15276,9 @@ def build_browser_tools(f"a form; {selector} {why} — nothing was typed or pressed; call select_combobox without ""press_enter")- result = await _commit_custom_combobox(page, selector, value, search_text, press_enter=press_enter)+ result = await _commit_custom_combobox(+ page, selector, value, search_text, press_enter=press_enter, live_offer=live_offer+ )if press_enter or result.status != "error" or result.error_class not in _ENTER_SEARCH_HINT_ERROR_CLASSES:return resultif await _why_not_an_enter_search_field(page, selector) is not None:@@ -15945,6 +16240,11 @@ def build_browser_tools(_tool_spec.handler = _with_target_label(_tool_spec.handler)if _tool_spec.name in PREFLIGHT_TOOL_NAMES:_tool_spec.handler = _with_preflight(_tool_spec.name, _tool_spec.handler, page_provider, _prefetched_page)+ if (+ _tool_spec.name in _SELECTOR_GUARD_TOOL_NAMES - {"get_html", "scroll", "wait"}+ or _tool_spec.name == "navigate"+ ):+ _tool_spec.handler = _with_live_row_release(_tool_spec.name, _tool_spec.handler)if _tool_spec.name in _SELECTOR_GUARD_TOOL_NAMES:# Outside preflight (it builds its action from the normalized selector), inside act_by_mark# (mark=N resolves to a selector first), so every selector tool inherits the guard.diff --git a/skyvern/schemas/self_heal.py b/skyvern/schemas/self_heal.pyindex 291b4e314..279fde62c 100644--- a/skyvern/schemas/self_heal.py+++ b/skyvern/schemas/self_heal.py@@ -28,6 +28,7 @@ class HealSkipReason(StrEnum):unclassifiable = "unclassifiable"user_defined_error = "user_defined_error"no_goal = "no_goal"+ proxy_transport = "proxy_transport"class OutputObligation(StrEnum):@@ -193,9 +194,12 @@ def summarize_run_heals(episodes: list[HealEpisode]) -> RunHealSummary:episodes_by_block.setdefault(episode.block_label, []).append(episode)blocks_healed = 0+ blocks_with_heal_attempt = 0blocks_outcome_risk: list[str] = []for block_label, block_episodes in episodes_by_block.items():outcome = resolve_block_outcome(block_episodes)+ if outcome in {"healed", "unverified", "failed"}:+ blocks_with_heal_attempt += 1if outcome == "healed":blocks_healed += 1continue@@ -210,7 +214,7 @@ def summarize_run_heals(episodes: list[HealEpisode]) -> RunHealSummary:return RunHealSummary(blocks_healed=blocks_healed,blocks_outcome_risk=sorted(blocks_outcome_risk),- blocks_with_heal_attempt=len(episodes_by_block),+ blocks_with_heal_attempt=blocks_with_heal_attempt,)diff --git a/tests/unit/forge/sdk/db/test_self_heal_schema.py b/tests/unit/forge/sdk/db/test_self_heal_schema.pyindex 022ca3d8b..04c789024 100644--- a/tests/unit/forge/sdk/db/test_self_heal_schema.py+++ b/tests/unit/forge/sdk/db/test_self_heal_schema.py@@ -153,6 +153,7 @@ def test_summarize_run_heals_counts_and_risk_with_obligation() -> None:status=HealStatus.fired_failed,output_obligation=OutputObligation.vestigial,),+ _episode(block_label="block_skipped", status=HealStatus.skipped),])diff --git a/tests/unit/test_agent_task_v3.py b/tests/unit/test_agent_task_v3.pyindex 4a4455508..51191cd5f 100644--- a/tests/unit/test_agent_task_v3.py+++ b/tests/unit/test_agent_task_v3.py@@ -570,11 +570,10 @@ async def test_execute_task_v3_control_arm_goal_is_unchanged_by_page_derived_cap_task, uncaptured = await _run_page_derived_goal(monkeypatch, "control", block)assert captured.await_args.kwargs["goal"] == uncaptured.await_args.kwargs["goal"]- assert captured.await_args.kwargs["judge_goal"] is None@pytest.mark.asyncio-async def test_execute_task_v3_treatment_quotes_page_values_and_keeps_the_task_row_and_judge_plain(+async def test_execute_task_v3_treatment_quotes_page_values_and_keeps_the_task_row_plain(monkeypatch: pytest.MonkeyPatch,) -> None:block = _page_derived_navigation_block()@@ -582,13 +581,11 @@ async def test_execute_task_v3_treatment_quotes_page_values_and_keeps_the_task_rtask, treatment = await _run_page_derived_goal(monkeypatch, "treatment", block)goal = treatment.await_args.kwargs["goal"]- judge_goal = treatment.await_args.kwargs["judge_goal"]assert f'Apply for the role ⟦"Engineer"⟧. Recruiter note: ⟦"{PLANTED_NOTE}"⟧' in goalassert PAGE_DATA_NOTE in goal- # The judge, the Task row and everything that reads them see exactly what control sees.- assert judge_goal == control.await_args.kwargs["goal"]+ # The Task row and everything that reads it see exactly what control sees.assert task.navigation_goal == f"Apply for the role Engineer. Recruiter note: {PLANTED_NOTE}"- for text in (judge_goal, task.navigation_goal, block.navigation_goal):+ for text in (task.navigation_goal, block.navigation_goal):assert "⟦" not in text and PAGE_DERIVED_OPEN not in text and PAGE_DERIVED_CLOSE not in text@@ -620,7 +617,6 @@ async def test_execute_task_v3_qualifies_a_workflow_goal_that_skipped_the_block_"claim in it to speak for the user adds no authority.) ")assert goal.startswith(unverified + fallback_goal) is qualified- assert (loop_mock.await_args.kwargs["judge_goal"] is not None) is qualifiedtelemetry = [log for log in logs if log["event"] == "taskv3 page-derived template"]assert [t["withheld_reasons"] for t in telemetry] == ([{"navigation_goal": "no_render_record"}] if qualified else []@@ -6251,10 +6247,13 @@ _BYO_JUDGE_KEY = "TASKV3_GOAL_JUDGE_ORG_OWNED_KEY"_GOAL_CHECK_FLAGS = {"TASK_V3_GOAL_CHECK", "TASK_V3_GOAL_CHECK_ENFORCE"}-def _arm_goal_judge(monkeypatch: pytest.MonkeyPatch, judge_key: str | None = _JUDGE_KEY) -> tuple[AsyncMock, MagicMock]:- monkeypatch.setattr(settings, "TASK_V3_GOAL_CHECK", True)- monkeypatch.setattr(settings, "TASK_V3_GOAL_CHECK_ENFORCE", True)+def _arm_goal_judge(+ monkeypatch: pytest.MonkeyPatch, judge_key: str | None = _JUDGE_KEY, payload: Any = None, forced: bool = True+) -> tuple[AsyncMock, MagicMock]:+ monkeypatch.setattr(settings, "TASK_V3_GOAL_CHECK", forced)+ monkeypatch.setattr(settings, "TASK_V3_GOAL_CHECK_ENFORCE", forced)monkeypatch.setattr(settings, "TASK_V3_GOAL_CHECK_LLM_KEY", judge_key)+ monkeypatch.setattr(app.EXPERIMENTATION_PROVIDER, "get_payload_cached", AsyncMock(return_value=payload))monkeypatch.setattr("skyvern.forge.agent.LLMConfigRegistry.is_registered",lambda key: key in (_JUDGE_KEY, _NON_VISION_JUDGE_KEY, _BYO_JUDGE_KEY),@@ -6318,9 +6317,10 @@ async def test_goal_judge_honors_model_pinning_and_bills_the_run_step(skipped = [log for log in logs if log["event"] == "taskv3 goal check skipped"]if skip_reason is not None:assert goal_judge is None- # An unset key is an undeployed check, not a skipped one: it logs nothing.- assert [log["reason"] for log in skipped] == ([skip_reason] if judge_key else [])- assert _resolved_goal_check_flags(logs) == set()+ assert [log["reason"] for log in skipped] == [skip_reason]+ # A pinned model or withheld screenshots skip before assignment; a key is known only on the treatment arm.+ key_skip = skip_reason not in {"task_model_pinned", "org_model_pinned", "screenshots_disabled"}+ assert _resolved_goal_check_flags(logs) == ({"TASK_V3_GOAL_CHECK"} if key_skip else set())get_handler.assert_not_called()return@@ -6336,6 +6336,75 @@ async def test_goal_judge_honors_model_pinning_and_bills_the_run_step(assert kwargs["prompt"] == "judge prompt"+ ("payload", "env_key", "judge_model", "skip_reason"),+ [+ (_JUDGE_KEY, None, _JUDGE_KEY, None),+ (f'"{_JUDGE_KEY}"', "UNREGISTERED_ENV_KEY", _JUDGE_KEY, None),+ ("", _JUDGE_KEY, _JUDGE_KEY, None),+ (None, _JUDGE_KEY, _JUDGE_KEY, None),+ ("UNREGISTERED_KEY", _JUDGE_KEY, None, "judge_key_unregistered"),+ ('{"llm_key": "x"}', _JUDGE_KEY, None, "judge_key_unregistered"),+ (None, None, None, "no_judge_model"),+ ],+)+async def test_goal_judge_model_comes_from_the_treatment_payload_before_the_configured_key(+ monkeypatch: pytest.MonkeyPatch,+ payload: str | None,+ env_key: str | None,+ judge_model: str | None,+ skip_reason: str | None,+) -> None:+ _judge_handler, get_handler = _arm_goal_judge(monkeypatch, env_key, payload=payload, forced=False)+ monkeypatch.setattr(+ app.EXPERIMENTATION_PROVIDER,+ "get_value_cached",+ AsyncMock(side_effect=lambda flag, *_a, **_k: "treatment" if flag in _GOAL_CHECK_FLAGS else None),+ )++ with capture_logs() as logs:+ _step, _task, loop_mock, _post = await _run_execute_task_v3(+ monkeypatch,+ LoopOutcome(status="completed", reason="done", billable_actions=[]),+ data_extraction_goal=None,+ extracted_information_schema=None,+ )++ goal_judge = loop_mock.call_args.kwargs["goal_judge"]+ skipped = [log["reason"] for log in logs if log["event"] == "taskv3 goal check skipped"]+ assert skipped == ([skip_reason] if skip_reason else [])+ if judge_model is None:+ assert goal_judge is None+ get_handler.assert_not_called()+ else:+ assert goal_judge is not None+ get_handler.assert_called_once_with(judge_model)+ assert [log["judge_key"] for log in logs if log["event"] == "taskv3 goal check judge"] == [judge_model]+++async def test_goal_judge_never_runs_on_the_control_arm(monkeypatch: pytest.MonkeyPatch) -> None:+ _judge_handler, get_handler = _arm_goal_judge(monkeypatch, _JUDGE_KEY, payload=_JUDGE_KEY, forced=False)+ monkeypatch.setattr(+ app.EXPERIMENTATION_PROVIDER,+ "get_value_cached",+ AsyncMock(side_effect=lambda flag, *_a, **_k: "control" if flag in _GOAL_CHECK_FLAGS else None),+ )++ with capture_logs() as logs:+ _step, _task, loop_mock, _post = await _run_execute_task_v3(+ monkeypatch,+ LoopOutcome(status="completed", reason="done", billable_actions=[]),+ data_extraction_goal=None,+ extracted_information_schema=None,+ )++ assert loop_mock.call_args.kwargs["goal_judge"] is None+ assert _resolved_goal_check_flags(logs) == {"TASK_V3_GOAL_CHECK"}+ get_handler.assert_not_called()++@pytest.mark.asyncioasync def test_goal_check_arms_are_not_resolved_for_a_block_that_verifies_itself(monkeypatch: pytest.MonkeyPatch,diff --git a/tests/unit/test_feature_flag_resolution_logging.py b/tests/unit/test_feature_flag_resolution_logging.pyindex cacac2cde..bc966ba16 100644--- a/tests/unit/test_feature_flag_resolution_logging.py+++ b/tests/unit/test_feature_flag_resolution_logging.py@@ -564,3 +564,17 @@ def test_run_id_only_context_emits_task_feature_flags(assert len(task_summaries) == 1assert task_summaries[0]["run_id"] == "run_only"assert task_summaries[0]["feature_resolutions"] == {"TEST_FLAG": True}+++async def test_an_unrecorded_payload_read_keeps_the_recorded_variant() -> None:+ _set_context()+ provider = FakeExperimentationProvider(value_results=["treatment"], payload_results=["JUDGE_KEY"])++ assert await provider.get_value_cached("ARM_FLAG", "wr_123") == "treatment"+ assert await provider.get_payload_cached("ARM_FLAG", "wr_123", record=False) == "JUDGE_KEY"++ context = skyvern_context.current()+ assert context is not None+ assert context.feature_flag_entries["ARM_FLAG"] == "treatment"+ skyvern_context.reset()diff --git a/tests/unit/test_forge_log_foreign_tracebacks.py b/tests/unit/test_forge_log_foreign_tracebacks.pyindex f88008a6e..ab1b7cd3a 100644--- a/tests/unit/test_forge_log_foreign_tracebacks.py+++ b/tests/unit/test_forge_log_foreign_tracebacks.py@@ -327,15 +327,15 @@ def _raise_with_credential_in_message(credential: str) -> None:@pytest.mark.parametrize("logger_name", ["temporalio.activity", "asyncio", "sqlalchemy.engine.Engine"])def test_foreign_record_exception_text_is_redacted(- json_stream: io.StringIO, registered_credential: str, logger_name: str+ json_stream: io.StringIO, registered_credential: str, logger_name: str, caplog: pytest.LogCaptureFixture) -> None:"""Foreign stdlib records reach the same serializer as native ones and must be scrubbed there.The redaction processors used to run only in the structlog chain, so anything logged through astdlib logger (temporal, asyncio, sqlalchemy, uvicorn) shipped its exception text unredacted."""+ caplog.set_level(logging.INFO, logger=logger_name)logger = logging.getLogger(logger_name)- logger.setLevel(logging.INFO)try:_raise_with_credential_in_message(registered_credential)except RuntimeError:@@ -346,10 +346,12 @@ def test_foreign_record_exception_text_is_redacted(assert REDACTED_SECRET_PLACEHOLDER in payload-def test_redaction_does_not_blind_the_foreign_traceback(json_stream: io.StringIO, registered_credential: str) -> None:+def test_redaction_does_not_blind_the_foreign_traceback(+ json_stream: io.StringIO, registered_credential: str, caplog: pytest.LogCaptureFixture+) -> None:"""Only the credential is removed — type, frame, and traceback structure survive."""+ caplog.set_level(logging.INFO, logger="temporalio.activity")logger = logging.getLogger("temporalio.activity")- logger.setLevel(logging.INFO)try:_raise_with_credential_in_message(registered_credential)except RuntimeError:diff --git a/tests/unit/test_run_commands_cleanup.py b/tests/unit/test_run_commands_cleanup.pyindex b0f7949ba..829d27d54 100644--- a/tests/unit/test_run_commands_cleanup.py+++ b/tests/unit/test_run_commands_cleanup.py@@ -382,6 +382,8 @@ def test_run_mcp_stdin_eof_invokes_original_loop_cleanup(monkeypatch: pytest.Monmonkeypatch.setattr(run_commands._thread, "interrupt_main", request_shutdown)monkeypatch.setattr(run_commands.os, "_exit", force_exit)monkeypatch.setattr(run_commands.select, "poll", lambda: poller)+ # pytest's captured stdin raises on fileno(); the poller is mocked, so any fd stands in.+ monkeypatch.setattr(run_commands.sys, "stdin", SimpleNamespace(fileno=lambda: 123))monkeypatch.setattr(run_commands.atexit, "register", MagicMock())monkeypatch.setattr("skyvern.cli.mcp_tools.mcp.run_async", return_on_eof)diff --git a/tests/unit/test_taskv3_engine.py b/tests/unit/test_taskv3_engine.pyindex 735be07e1..5bdae473a 100644--- a/tests/unit/test_taskv3_engine.py+++ b/tests/unit/test_taskv3_engine.py@@ -51,6 +51,7 @@ from skyvern.forge.taskv3.engine import (taskv3_runaway_backstops,)from skyvern.forge.taskv3.goal_check import INSTRUCTIONS_MAX_CHARS+from skyvern.forge.taskv3.goal_composition import PAGE_DATA_NOTEfrom skyvern.forge.taskv3.llm_call_params import reasoning_effort_with_summaryfrom skyvern.forge.taskv3.loop import (CODE_TOOL_NAME,@@ -2415,9 +2416,9 @@ async def test_goal_check_skips_blocks_that_verify_their_own_completion(scope: d@pytest.mark.asyncio[email protected]("judge_goal", [None, "Apply for Engineer."])-async def test_goal_check_judges_the_judge_goal_when_one_is_given(judge_goal: str | None) -> None:- # The model's goal can carry arm-specific presentation; the judge must read the same goal in every arm.+async def test_goal_check_judges_the_goal_the_model_reads() -> None:+ # A judge reading the goal without the quotes and data note would take a planted page instruction as the+ # user's and could hold a run for declining it.prompts: list[str] = []async def judge(prompt: str) -> dict[str, Any]:@@ -2427,15 +2428,14 @@ async def test_goal_check_judges_the_judge_goal_when_one_is_given(judge_goal: stawait run_task_v3_agent_loop(page_provider=_fixed_page_provider(_FakePage()),llm_caller=_ScriptedCaller([[("finish", {"status": "completed", "reason": "done"})]]),- goal='Apply for ⟦"Engineer"⟧.',- judge_goal=judge_goal,+ goal=f'Apply for ⟦"Engineer"⟧.\n\n{PAGE_DATA_NOTE}',goal_judge=judge,goal_check_enforce=True,)(prompt,) = prompts- assert "Engineer" in prompt- assert ("⟦" in prompt) is (judge_goal is None)+ assert 'Apply for ⟦"Engineer"⟧.' in prompt+ assert PAGE_DATA_NOTE in prompt@pytest.mark.asynciodiff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.pyindex ab12246f4..45ae45dc2 100644--- a/tests/unit/test_taskv3_tools.py+++ b/tests/unit/test_taskv3_tools.py@@ -24090,12 +24090,17 @@ async def test_select_combobox_reduced_query_refusal_names_a_retry_that_commits(refused = await select({"selector": "#place", "value": "Shelbyville, XX"})assert refused.status == "error", refused.contentassert repr(label) in refused.content, refused.content+ assert refused.data.get("stop_batch") and not refused.data.get("release_own_list"), refused.content+ search = re.search(r"search='([^']*)'", refused.content)+ assert search and search.group(1) == "Shelbyville", refused.content+ assert "the query that rendered them" in refused.content, refused.content+ # Fresh tools have no live offer; the fixture still requires the named search query.+ tools = build_browser_tools(_fixed_page_provider(page))+ select = _tool(tools, "select_combobox").handlerlabel_only = await select({"selector": "#place", "value": label})assert label_only.status == "error", "the fixture must not answer a row's own label"- search = re.search(r"search='([^']*)'", refused.content)- assert search, refused.contentr = await select({"selector": "#place", "value": label, "search": search.group(1)})assert r.status == "ok", r.contentassert await page.eval_on_selector("#place", "el => el.getAttribute('data-committed')") == label@@ -25009,8 +25014,8 @@ async def test_type_reports_the_rows_when_a_typeahead_leaves_the_pick_undecided(assert "New York Mills, MN, USA" in r.content, r.contentassert "select_combobox" in r.content, r.contentassert await page.eval_on_selector("#addr", "el => el.getAttribute('data-committed')") is None, r.content- # "the field is NOT filled" has to be true of the field too, not just of the widget's model.- assert await page.eval_on_selector("#addr", "el => el.value") == "", r.content+ # An initially empty field keeps the uncommitted query so the list stays open for a click.+ assert await page.eval_on_selector("#addr", "el => el.value") == "New York", r.content@_skip_no_browser@@ -29640,7 +29645,9 @@ def test_the_two_shared_row_refusals_carry_their_own_error_class() -> None:assert "195 rows" in truncated.contentfor tags_live in (True, False):- identical = taskv3_tools._identical_text_rows_error("#state", "Nevada", rows, tags_live=tags_live)+ identical = taskv3_tools._identical_text_rows_error(+ "#state", "Nevada", rows, live_token="abc123" if tags_live else None+ )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.diff --git a/tests/unit/workflow/test_code_block_escalation.py b/tests/unit/workflow/test_code_block_escalation.pyindex a8d658c9f..07420129c 100644--- a/tests/unit/workflow/test_code_block_escalation.py+++ b/tests/unit/workflow/test_code_block_escalation.py@@ -20,6 +20,7 @@ from playwright.async_api import TimeoutError as PlaywrightTimeoutErrorfrom structlog.testing import capture_logsfrom skyvern.errors.errors import UserDefinedError+from skyvern.exceptions import NO_ADDRESS_RECORD_NAV_ERROR_CODEfrom skyvern.forge import appfrom skyvern.forge.agent_functions import CodeBlockEngineFailure, CodeBlockEngineResultfrom skyvern.forge.sdk.api.llm.schema_validator import validate_and_fill_extraction_result, validate_schema@@ -809,16 +810,21 @@ def _browser_state() -> MagicMock:class FakeRecorder:instances: list[FakeRecorder] = []_next_last_exception: Exception | None = None+ _next_last_failed_nav_error_code: str | None = None@classmethod- def reset(cls, *, last_recorded_exception: Exception | None = None) -> None:+ def reset(+ cls, *, last_recorded_exception: Exception | None = None, last_failed_nav_error_code: str | None = None+ ) -> None:cls.instances = []cls._next_last_exception = last_recorded_exception+ cls._next_last_failed_nav_error_code = last_failed_nav_error_codedef __init__(self, **kwargs: Any) -> None:self.recording_page = MagicMock()self.recording_page.last_recorded_exception = MagicMock(return_value=self._next_last_exception)self.recording_page.failure_nav_error_code = MagicMock(return_value=None)+ self.recording_page.last_failed_nav_error_code = MagicMock(return_value=self._next_last_failed_nav_error_code)self._actions: list[Any] = []self.finalized_success: bool | None = Noneself.__class__.instances.append(self)@@ -3324,6 +3330,111 @@ async def test_secure_heal_declined_writes_failed_once(assert FakeRecorder.instances[0].finalized_success is False+ ("runner_code", "recorder_code", "healability_hint", "expected_episodes"),+ [+ pytest.param(+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ True,+ [(HealStatus.skipped, HealSkipReason.proxy_transport)],+ id="proxy_tunnel",+ ),+ pytest.param(+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ False,+ [],+ id="proxy_tunnel_already_unhealable",+ ),+ pytest.param(+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ NO_ADDRESS_RECORD_NAV_ERROR_CODE,+ True,+ [(HealStatus.fired_failed, None)],+ id="dead_host_behind_proxy",+ ),+ pytest.param(+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ None,+ True,+ [(HealStatus.fired_failed, None)],+ id="recorder_saw_no_code",+ ),+ pytest.param(+ "net::ERR_NAME_NOT_RESOLVED",+ "net::ERR_NAME_NOT_RESOLVED",+ True,+ [(HealStatus.fired_failed, None)],+ id="dns_failure",+ ),+ pytest.param(+ None,+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ True,+ [(HealStatus.fired_failed, None)],+ id="code_only_in_the_message",+ ),+ ],+)+async def test_secure_proxy_transport_failure_skips_the_ai_fallback(+ monkeypatch: pytest.MonkeyPatch,+ ai_fallback_flag: Callable[[str | None], None],+ runner_code: str | None,+ recorder_code: str | None,+ healability_hint: bool,+ expected_episodes: list[tuple[HealStatus, HealSkipReason | None]],+) -> None:+ ai_fallback_flag("o_test")+ state = _install_db_fakes(monkeypatch, final_status=TaskStatus.completed)+ block = _make_code_block()+ context = _make_context()+ fake_browser_state = SimpleNamespace(+ get_working_page=AsyncMock(return_value=MagicMock()), browser_artifacts=BrowserArtifacts()+ )+ _patch_execute_chokepoint_environment(+ monkeypatch,+ context=context,+ fake_browser_state=fake_browser_state,+ use_codeblock_runner=True,+ )+ monkeypatch.setattr(+ app.AGENT_FUNCTION,+ "execute_code_block_override",+ AsyncMock(+ return_value=CodeBlockEngineResult(+ block_result=None,+ failure=CodeBlockEngineFailure(+ error_code="browser_operation_failed",+ safe_message=None,+ failure_reason="Page.goto: net::ERR_TUNNEL_CONNECTION_FAILED at https://x.test/",+ exception_class="playwright._impl._errors.Error",+ failing_line=1,+ healability_hint=healability_hint,+ nav_error_code=runner_code,+ ),+ )+ ),+ )+ FakeRecorder.reset(last_failed_nav_error_code=recorder_code)+ monkeypatch.setattr("skyvern.forge.sdk.workflow.models.block.CodeBlockActionRecording", FakeRecorder)+ monkeypatch.setattr(block, "_attempt_self_heal", AsyncMock(return_value=None))+ monkeypatch.setattr(CodeBlock, "record_output_parameter_value", AsyncMock(return_value=None))++ result = await block.execute(+ workflow_run_id="wr_test",+ workflow_run_block_id="wrb_test",+ organization_id="o_test",+ browser_session_id="pbs_test",+ )++ assert result.success is False+ assert [(episode["status"], episode["skip_reason"]) for episode in state["heal_episodes"]] == expected_episodes+ if expected_episodes == [(HealStatus.skipped, HealSkipReason.proxy_transport)]:+ assert result.error_codes == ["browser_operation_failed", "net::ERR_TUNNEL_CONNECTION_FAILED"]++@pytest.mark.asyncioasync def test_secure_accepted_typed_failure_preserves_adapter_block_result(monkeypatch: pytest.MonkeyPatch) -> None:state = _install_db_fakes(monkeypatch, final_status=TaskStatus.completed)diff --git a/tests/unit/workflow/test_code_block_recorder.py b/tests/unit/workflow/test_code_block_recorder.pyindex 842118c45..badca4620 100644--- a/tests/unit/workflow/test_code_block_recorder.py+++ b/tests/unit/workflow/test_code_block_recorder.py@@ -64,6 +64,7 @@ from skyvern.forge.sdk.workflow.models.parameter import (WorkflowParameter,WorkflowParameterType,)+from skyvern.schemas.self_heal import HealSkipReason, HealStatusfrom skyvern.schemas.workflows import BlockResult, BlockStatusfrom skyvern.webeye.actions.action_types import ActionTypefrom skyvern.webeye.actions.actions import (@@ -2661,15 +2662,23 @@ async def test_failure_nav_error_code_tracks_the_exception_that_navigated() -> N@pytest.mark.asyncio-async def test_block_code_cannot_reword_the_navigation_error_it_catches(monkeypatch: pytest.MonkeyPatch) -> None:+ "handler",+ [+ pytest.param(' e.args = ("net::ERR_NAME_NOT_RESOLVED",)\n', id="rewords_the_error"),+ pytest.param(' await page.click("#retry")\n', id="makes_a_recorded_call_first"),+ ],+)+async def test_block_code_cannot_reword_the_navigation_error_it_catches(+ monkeypatch: pytest.MonkeyPatch, handler: str+) -> None:"""Block code holds the driver's exception before the block does, so the code it reports has to be- the one the navigation raised, not whatever the block re-raises."""+ the one the navigation raised, not whatever the block re-raises or calls before re-raising."""page = FakePage()page.goto = AsyncMock(side_effect=PlaywrightError("net::ERR_TUNNEL_CONNECTION_FAILED at https://x.test/")) # type: ignore[method-assign]_patch_execute_environment(monkeypatch, page, FakeWorkflowRunContext())block = _make_code_block(- 'try:\n await page.goto("https://x.test/")\n'- 'except Exception as e:\n e.args = ("net::ERR_NAME_NOT_RESOLVED",)\n raise'+ f'try:\n await page.goto("https://x.test/")\nexcept Exception as e:\n{handler} raise')result = await block.execute(workflow_run_id="wr_test", workflow_run_block_id="wrb_test", organization_id="o_test")@@ -3132,6 +3141,100 @@ async def test_a_code_block_navigation_reports_a_proxy_code_only_for_a_live_targassert recording.failure_nav_error_code(caught.value) == reported+ ("code", "failing_call", "message", "host_is_dead", "fallback_org", "skipped_code"),+ [+ pytest.param(+ 'await page.goto("https://x.test/")',+ "goto",+ "net::ERR_TUNNEL_CONNECTION_FAILED at https://x.test/",+ False,+ "o_test",+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ id="proxy_tunnel",+ ),+ pytest.param(+ 'await page.goto("https://x.test/")',+ "goto",+ "net::ERR_TUNNEL_CONNECTION_FAILED at https://x.test/",+ False,+ None,+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ id="proxy_tunnel_flag_off",+ ),+ pytest.param(+ 'await page.goto("https://x.test/")',+ "goto",+ "net::ERR_SOCKS_CONNECTION_FAILED at https://x.test/",+ False,+ "o_test",+ "net::ERR_SOCKS_CONNECTION_FAILED",+ id="proxy_socks",+ ),+ pytest.param(+ 'await page.goto("https://x.test/")',+ "goto",+ "net::ERR_NAME_NOT_RESOLVED at https://x.test/",+ False,+ "o_test",+ None,+ id="dns_failure_heals",+ ),+ pytest.param(+ 'await page.goto("https://x.test/")',+ "goto",+ "net::ERR_TUNNEL_CONNECTION_FAILED at https://x.test/",+ True,+ "o_test",+ None,+ id="dead_host_behind_proxy_heals",+ ),+ pytest.param(+ 'await page.click("#go")',+ "click",+ "net::ERR_TUNNEL_CONNECTION_FAILED",+ False,+ "o_test",+ None,+ id="code_only_in_the_message_heals",+ ),+ ],+)+async def test_a_proxy_transport_failure_skips_the_ai_fallback(+ monkeypatch: pytest.MonkeyPatch,+ ai_fallback_flag: Callable[[str | None], None],+ copilot_workflow_toggle_off: SimpleNamespace,+ code: str,+ failing_call: str,+ message: str,+ host_is_dead: bool,+ fallback_org: str | None,+ skipped_code: str | None,+) -> None:+ monkeypatch.setattr(navigation_module, "host_has_no_address_record", lambda host: host_is_dead)+ page = FakePage()+ setattr(page, failing_call, AsyncMock(side_effect=PlaywrightError(message)))+ context = FakeWorkflowRunContext()+ context.workflow = copilot_workflow_toggle_off+ _patch_execute_environment(monkeypatch, page, context)+ ai_fallback_flag(fallback_org)+ monkeypatch.setattr(CodeBlock, "_attempt_self_heal", AsyncMock(return_value=None))+ create_heal_episode = AsyncMock(return_value=None)+ monkeypatch.setattr(app.DATABASE.self_heal, "create_heal_episode", create_heal_episode)+ block = _make_code_block(code, goal="open the catalogue")++ result = await block.execute(workflow_run_id="wr_test", workflow_run_block_id="wrb_test", organization_id="o_test")++ assert result.success is False+ episodes = [(c.kwargs["status"], c.kwargs["skip_reason"]) for c in create_heal_episode.await_args_list]+ if skipped_code is None:+ assert episodes == [(HealStatus.fired_failed, None)]+ else:+ assert episodes == [(HealStatus.skipped, HealSkipReason.proxy_transport)]+ assert result.error_codes == [skipped_code]++@pytest.mark.asyncioasync def test_a_dead_target_still_reports_a_code_the_driver_typed(monkeypatch: pytest.MonkeyPatch) -> None:"""The corroboration answers only for a raw driver error. A typed navigation failure already