Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-11121: collapse code-first copilot rung flags into the two master gates (#6669)
Andrew Neilsonbe16e5353113
diff --git a/skyvern/config.py b/skyvern/config.pyindex 2ab0aa9e5..eb1aec365 100644--- a/skyvern/config.py+++ b/skyvern/config.py@@ -162,16 +162,6 @@ class Settings(BaseSettings):# copilot stops re-running and escalates honestly. Set very high to disable the ceiling.COPILOT_REPAIR_CEILING_CONSECUTIVE_IDENTICAL: int = 3COPILOT_SCOUT_ACT_OBSERVE_TIMEOUT_SECONDS: float = 4.0- # On a repeat evaluate of an unchanged page with exactly one safe target, click it in-process- # instead of only advising. Off (default) leaves the advisory steer as the only response.- COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED: bool = False- # After a correct click reaches a same-host download affordance (or a browser download has- # already registered into a block output), attach a typed reached-download target and steer- # the agent to author one terminal download code block. Off (default) restores today's behavior.- COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED: bool = False- # On, a reached-download affordance compiles into the expect_download idiom in the code-block- # synthesizer; off (default) restores today's bare-click synthesis. Per-rung gate.- COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED: bool = False# Staged rollout for treating omitted runtime workflow proxy values as direct/no-proxy.# Off preserves the historical implicit residential default for anti-bot-sensitive traffic.RUNTIME_PROXY_DEFAULT_NONE_ENABLED: bool = False@@ -183,12 +173,6 @@ class Settings(BaseSettings):# Experimental Workflow Copilot v2 branch mode.# Off = standard block authoring. On = prefer code blocks for browser work.WORKFLOW_COPILOT_CODE_BLOCK_MODE: bool = False- # Default-off companion to code-block mode. When enabled, Copilot can impose- # strict scout-trajectory synthesis at the persist seam for the narrow PR-1 envelope.- WORKFLOW_COPILOT_CODE_BLOCK_IMPOSE_SYNTHESIS: bool = False- # Flag-gate for the optional LLM pass that rewrites code-block step descriptions.- # Off (default) = deterministic templated descriptions; On = LLM rewrites descriptions only.- WORKFLOW_COPILOT_CODE_BLOCK_STEP_DESCRIPTIONS_LLM: bool = False# Any copilot test-run whose leading block replays a login fill on a scout-authenticated# workflow runs in a fresh browser session, so that fill is not replayed into the scout's# already-authenticated session (the first run and every login-replaying repair re-run alike).diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.pyindex d87d010a9..ce1a1b029 100644--- a/skyvern/forge/agent_functions.py+++ b/skyvern/forge/agent_functions.py@@ -1197,7 +1197,7 @@ class AgentFunction:resolved = settings.WORKFLOW_COPILOT_CODE_BLOCK_MODE if code_block_mode is None else code_block_modereturn CopilotConfig(block_authoring_policy=block_authoring_policy_from_code_only_mode(resolved),- impose_synthesized_code_block=settings.WORKFLOW_COPILOT_CODE_BLOCK_IMPOSE_SYNTHESIS,+ impose_synthesized_code_block=True,)async def get_copilot_config_for_request(diff --git a/skyvern/forge/prompts/skyvern/workflow-copilot-code-block-steps.j2 b/skyvern/forge/prompts/skyvern/workflow-copilot-code-block-steps.j2deleted file mode 100644index 9555b11e5..000000000--- a/skyvern/forge/prompts/skyvern/workflow-copilot-code-block-steps.j2+++ /dev/null@@ -1,21 +0,0 @@-You are labeling a Playwright/SkyvernPage code block for a non-technical reader.--You are given the block's goal and an ordered list of detected actions. Each action already has a-fixed `action_type` and the code line(s) it covers. Rewrite ONLY the `description` of each action into-a short, plain-language sentence (max ~8 words, imperative, no code, no selectors-as-jargon). Do not-change `action_type`, `line_start`, or `line_end`, and do not add or remove actions.--Goal: {{ goal }}--Code:-```python-{{ code }}-```--Actions (JSON):-```json-{{ actions_json }}-```--Return ONLY a JSON array of objects with keys `line_start` and `description`, one per input action,-in the same order. Example: [{"line_start": 2, "description": "Open the homepage"}]diff --git a/skyvern/forge/sdk/copilot/code_block_steps.py b/skyvern/forge/sdk/copilot/code_block_steps.pyindex ad9bf08b6..1123a26fb 100644--- a/skyvern/forge/sdk/copilot/code_block_steps.py+++ b/skyvern/forge/sdk/copilot/code_block_steps.py@@ -1,8 +1,6 @@from __future__ import annotationsimport ast-import asyncio-import jsonimport refrom dataclasses import dataclassfrom typing import Any, Iterator@@ -10,9 +8,6 @@ from typing import Any, Iteratorimport structlogimport yaml-from skyvern.config import settings-from skyvern.forge.prompts import prompt_engine-LOG = structlog.get_logger()# Playwright/SkyvernPage method name -> step action_type (values are ActionType members;@@ -181,77 +176,11 @@ def _iter_code_block_dicts(node: Any) -> Iterator[dict[str, Any]]:yield from _iter_code_block_dicts(item)-_STEP_DESC_PROMPT = "workflow-copilot-code-block-steps"-_STEP_DESC_TIMEOUT_SECONDS = 20---async def refine_step_descriptions(- code: str,- goal: str | None,- steps: list[dict[str, Any]],- handler: Any | None,-) -> list[dict[str, Any]]:- """Rewrite only the `description` of each step via an LLM; return steps unchanged on any failure."""- if not steps or handler is None:- return steps- actions_json = json.dumps([{"line_start": s["line_start"], "action_type": s["action_type"]} for s in steps])- try:- prompt = prompt_engine.load_prompt(- template=_STEP_DESC_PROMPT,- goal=(goal or "").strip(),- code=code,- actions_json=actions_json,- )- raw = await asyncio.wait_for(- handler(prompt=prompt, prompt_name=_STEP_DESC_PROMPT),- timeout=_STEP_DESC_TIMEOUT_SECONDS,- )- except Exception as exc:- LOG.info("code-block step description pass failed; keeping templated descriptions", error=str(exc))- return steps-- overrides = _parse_description_overrides(raw)- if not overrides:- return steps- return [{**s, "description": overrides.get(s["line_start"], s["description"])} for s in steps]---def _parse_description_overrides(raw: Any) -> dict[int, str]:- """Parse the LLM response into {line_start: description}; tolerant of dict/str/list shapes."""- payload = raw- if isinstance(raw, dict):- payload = raw.get("content") or raw.get("response") or raw- if isinstance(payload, str):- try:- payload = json.loads(payload)- except json.JSONDecodeError:- return {}- if not isinstance(payload, list):- return {}- result: dict[int, str] = {}- for item in payload:- if not isinstance(item, dict):- continue- raw_line = item.get("line_start")- # LLMs occasionally stringify the integer; accept "2" as 2 but reject bools/non-numerics.- if isinstance(raw_line, bool) or not isinstance(raw_line, (int, str)):- continue- try:- line_start = int(raw_line)- except (TypeError, ValueError):- continue- description = str(item.get("description") or "").strip()- if description:- result[line_start] = description- return result--def derive_code_block_steps_in_yaml(workflow_yaml: str) -> str:"""Return workflow_yaml with each code block's `steps` filled from its `code` when absent.- Deterministic, sync, and refinement-safe: a block that already carries steps- (e.g. an LLM description pass) is left untouched, so this can run on the shared- YAML->Workflow seam without clobbering richer steps produced upstream."""+ Deterministic and sync: a block that already carries steps is left untouched, so this+ can run on the shared YAML->Workflow seam without clobbering steps produced upstream."""try:data = yaml.safe_load(workflow_yaml)except yaml.YAMLError:@@ -322,7 +251,7 @@ def fill_code_block_prompts_in_yaml(return yaml.safe_dump(data, sort_keys=False)-async def apply_derived_code_block_steps(workflow_yaml: str, handler: Any | None = None) -> str:+async def apply_derived_code_block_steps(workflow_yaml: str) -> str:"""Return workflow_yaml with each code block's `steps` recomputed from its `code`."""try:data = yaml.safe_load(workflow_yaml)@@ -331,13 +260,9 @@ async def apply_derived_code_block_steps(workflow_yaml: str, handler: Any | Noneif not isinstance(data, (dict, list)):return workflow_yaml- use_llm = settings.WORKFLOW_COPILOT_CODE_BLOCK_STEP_DESCRIPTIONS_LLM and handler is not Nonechanged = Falsefor block in _iter_code_block_dicts(data):- steps = derive_code_block_steps(block["code"], block.get("prompt"))- if use_llm:- steps = await refine_step_descriptions(block["code"], block.get("prompt"), steps, handler)- block["steps"] = steps+ block["steps"] = derive_code_block_steps(block["code"], block.get("prompt"))changed = Trueif not changed:diff --git a/skyvern/forge/sdk/copilot/code_block_synthesis.py b/skyvern/forge/sdk/copilot/code_block_synthesis.pyindex cdedafb73..ebcec8e35 100644--- a/skyvern/forge/sdk/copilot/code_block_synthesis.py+++ b/skyvern/forge/sdk/copilot/code_block_synthesis.py@@ -16,7 +16,6 @@ from dataclasses import dataclass, fieldfrom typing import Anyfrom urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit-from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.composition_evidence import SCOUT_INTERACTION_EVIDENCE_TOOLfrom skyvern.forge.sdk.copilot.reached_download_target import ReachedDownloadTargetfrom skyvern.utils.strings import escape_code_fences@@ -503,8 +502,7 @@ def synthesize_code_block(credential_param_keys: dict[str, str] = {}used_download_vars: set[str] = set()compile_download_target = (- settings.COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED- and reached_download_target is not None+ reached_download_target is not Noneand not reached_download_target.already_registeredand bool(reached_download_target.selector))diff --git a/skyvern/forge/sdk/copilot/tools/guardrails.py b/skyvern/forge/sdk/copilot/tools/guardrails.pyindex 4d0613efa..1a65b0f30 100644--- a/skyvern/forge/sdk/copilot/tools/guardrails.py+++ b/skyvern/forge/sdk/copilot/tools/guardrails.py@@ -6,7 +6,6 @@ from typing import Anyimport structlogfrom agents import ToolGuardrailFunctionOutput, ToolInputGuardrail, ToolInputGuardrailData-from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.blocker_signal import CopilotToolBlockerSignal, RecoveryHintfrom skyvern.forge.sdk.copilot.build_phase import _phase_blocker_signalfrom skyvern.forge.sdk.copilot.composition_evidence import (@@ -184,10 +183,6 @@ def _download_scout_required_error(copilot_ctx: Any, workflow_yaml: str | None)synthesizer can compile the terminal download step. Active in code-only browser mode."""if _copilot_block_authoring_policy(copilot_ctx) != BlockAuthoringPolicy.CODE_ONLY_BROWSER:return None- if not settings.COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED:- # The gate is cleared by the reached-download scout interaction, which is only registered- # when author-steer is on; enforcing it without that flag deadlocks until the retry cap.- return Noneif copilot_ctx is None or workflow_yaml is None:return Nonedownload_labels = _download_intent_block_labels(workflow_yaml)diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.pyindex d55a55a83..9a4d27f3f 100644--- a/skyvern/forge/sdk/copilot/tools/run_execution.py+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py@@ -30,6 +30,7 @@ from skyvern.forge.sdk.copilot.code_block_synthesis import (from skyvern.forge.sdk.copilot.completion_verification import (CompletionVerificationResult,)+from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicyfrom skyvern.forge.sdk.copilot.context import CopilotContextfrom skyvern.forge.sdk.copilot.diagnosis_repair_contract import (DiagnosisRepairContract,@@ -95,6 +96,7 @@ from ._shared import (_valid_runtime_anchor_url,_workflow_verification_evidence,)+from .banned_blocks import _copilot_block_authoring_policyfrom .blockers import (_active_block_run_budget_seconds,_active_run_terminal_evidence_detected,@@ -1256,11 +1258,16 @@ async def _run_blocks_and_collect_debug("page_title": page_title,"action_trace_summary": action_trace_summary,}- if SettingsManager.get_settings().COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED:- reached_download = _derive_reached_download_from_block_outputs(block_outputs_by_label)- if reached_download is not None:- result_data["reached_download_target"] = reached_download.to_dict()- result_data["reached_download_guidance"] = _reached_download_guidance_for(reached_download)+ # Code-first only: the guidance steers toward an expect_download code block (ADR 0010), which+ # standard-mode v2 does not author.+ reached_download = (+ _derive_reached_download_from_block_outputs(block_outputs_by_label)+ if _copilot_block_authoring_policy(ctx) == BlockAuthoringPolicy.CODE_ONLY_BROWSER+ else None+ )+ if reached_download is not None:+ result_data["reached_download_target"] = reached_download.to_dict()+ result_data["reached_download_guidance"] = _reached_download_guidance_for(reached_download)if runtime_frontier_anchor_url is not None:result_data["runtime_frontier_anchor_url"] = runtime_frontier_anchor_urlif runtime_frontier_starter_url_seeded:diff --git a/skyvern/forge/sdk/copilot/tools/scouting.py b/skyvern/forge/sdk/copilot/tools/scouting.pyindex 433e2425b..23b8bba09 100644--- a/skyvern/forge/sdk/copilot/tools/scouting.py+++ b/skyvern/forge/sdk/copilot/tools/scouting.py@@ -775,11 +775,8 @@ async def _maybe_steer_evaluate_to_action(if signature != ctx.last_auto_acted_signature and ctx.last_auto_acted_signature is not None:ctx.last_auto_acted_signature = Nonetargets = _actionable_targets_for_result(identities)- if (- settings.COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED- and is_repeat- and ctx.last_auto_acted_signature != signature- ):+ # Generic evaluate-loop breaker: intentionally fires for all v2 policies, not only code-first.+ if is_repeat and ctx.last_auto_acted_signature != signature:candidate = _auto_act_candidate(parsed)if candidate is not None:ctx.last_auto_acted_signature = signature@@ -842,11 +839,13 @@ async def _maybe_attach_reached_download_target() -> None:"""Attach a typed reached-download target + guidance when the page exposes exactly one same-hostdownload affordance, matched on the captured selector (never URL — a download does not change the SPA URL)."""- if not settings.COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED:- returndata = result.get("data")if not isinstance(data, dict):return+ # Code-first only: the guidance steers toward an expect_download code block (ADR 0010), which+ # standard-mode v2 does not author.+ if _copilot_block_authoring_policy(ctx) != BlockAuthoringPolicy.CODE_ONLY_BROWSER:+ returntry:parsed = (await _scout_act_observe_page_evidence(ctx, url=url)@@ -860,7 +859,7 @@ async def _maybe_attach_reached_download_target(returndata["reached_download_target"] = target.to_dict()data["reached_download_guidance"] = _reached_download_guidance_for(target)- if settings.COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED and not target.already_registered:+ if not target.already_registered:# The pure synthesizer compiles the terminal expect_download step from this typed object.ctx.reached_download_target = targetif ctx.synthesized_block_offered and not ctx.update_workflow_called:@@ -868,10 +867,7 @@ async def _maybe_attach_reached_download_target(# non-download idiom. Reopen the latch once so the post-turn fallback re-fires carrying it.ctx.synthesized_block_offered = FalseLOG.info("copilot_synthesized_block_offer_latch_reset_for_download", url=url)- if (- _copilot_block_authoring_policy(ctx) == BlockAuthoringPolicy.CODE_ONLY_BROWSER- and not target.already_registered- ):+ if not target.already_registered:_register_reached_download_scout_interaction(ctx, target, url=url)LOG.info("copilot_reached_download_target_steer",diff --git a/skyvern/forge/sdk/copilot/tools/workflow_update.py b/skyvern/forge/sdk/copilot/tools/workflow_update.pyindex a7c69d9ca..ebed9ed00 100644--- a/skyvern/forge/sdk/copilot/tools/workflow_update.py+++ b/skyvern/forge/sdk/copilot/tools/workflow_update.py@@ -12,7 +12,6 @@ import structlogimport yamlfrom pydantic import AliasChoices, BaseModel, Field, ValidationError-from skyvern.config import settingsfrom skyvern.forge import appfrom skyvern.forge.sdk.copilot.attribution import resolve_copilot_created_by_stampfrom skyvern.forge.sdk.copilot.blocker_signal import clear_terminal_evidence_on_workflow_edit@@ -36,7 +35,6 @@ from skyvern.forge.sdk.copilot.enforcement import (_completion_contract_unknown_due_to_policy_fallback,_goal_likely_needs_more_blocks,)-from skyvern.forge.sdk.copilot.llm_config import resolve_main_copilot_handlerfrom skyvern.forge.sdk.copilot.loop_detection import clear_failed_step_tracker_for_tools_in_ctxfrom skyvern.forge.sdk.copilot.outcome_verification_trace import record_code_artifact_violationsfrom skyvern.forge.sdk.copilot.output_policy import (@@ -2108,10 +2106,7 @@ async def _update_workflow()# Derive plain-language steps from each code block's code so the editor timeline# mirrors the actual code (deterministic action_type + line ranges).- steps_handler = None- if settings.WORKFLOW_COPILOT_CODE_BLOCK_STEP_DESCRIPTIONS_LLM:- steps_handler = await resolve_main_copilot_handler(ctx.workflow_permanent_id, ctx.organization_id)- workflow_yaml_with_steps = await apply_derived_code_block_steps(workflow_yaml, handler=steps_handler)+ workflow_yaml_with_steps = await apply_derived_code_block_steps(workflow_yaml)workflow = _process_workflow_yaml(workflow_id=ctx.workflow_id,workflow_permanent_id=ctx.workflow_permanent_id,diff --git a/tests/unit/test_code_block_steps.py b/tests/unit/test_code_block_steps.pyindex d7bbc688b..30c925710 100644--- a/tests/unit/test_code_block_steps.py+++ b/tests/unit/test_code_block_steps.py@@ -7,7 +7,6 @@ from skyvern.forge.sdk.copilot.code_block_steps import (derive_code_block_steps,derive_code_block_steps_in_yaml,fill_code_block_prompts_in_yaml,- refine_step_descriptions,)from skyvern.webeye.actions.action_types import ActionType@@ -278,21 +277,6 @@ async def test_apply_derived_steps_on_copilot_yaml_shape():assert steps[1]["action_type"] == "input_text"-async def test_refine_overrides_descriptions_by_line_start():- steps = [- {"description": "Open https://x.com/", "action_type": "goto_url", "line_start": 2, "line_end": 2},- {"description": 'Click "Go"', "action_type": "click", "line_start": 3, "line_end": 3},- ]-- async def handler(prompt: str, prompt_name: str):- return '[{"line_start": 2, "description": "Open the homepage"}, {"line_start": 3, "description": "Start the search"}]'-- out = await refine_step_descriptions("code", None, steps, handler=handler)- assert [s["description"] for s in out] == ["Open the homepage", "Start the search"]- assert [s["action_type"] for s in out] == ["goto_url", "click"] # labels & lines unchanged--def test_multiline_call_span_covers_all_lines():code = "async def run(page):\n await page.get_by_label('Email').fill(\n str(email)\n )\n"spans = analyze_code_actions(code)@@ -304,16 +288,3 @@ def test_get_by_role_without_name_falls_back_to_the_element():code = "async def run(page):\n await page.get_by_role('button').click()\n"steps = derive_code_block_steps(code)assert steps[0]["description"] == "Click the element"---async def test_refine_falls_back_to_input_on_handler_failure():- steps = [{"description": "Open https://x.com/", "action_type": "goto_url", "line_start": 2, "line_end": 2}]-- async def handler(prompt: str, prompt_name: str):- raise RuntimeError("llm down")-- out = await refine_step_descriptions("code", None, steps, handler=handler)- assert out == steps # unchanged on failure-- assert await refine_step_descriptions("code", None, steps, handler=None) == steps # no handler -> unchangeddiff --git a/tests/unit/test_copilot_code_block_persist_seam.py b/tests/unit/test_copilot_code_block_persist_seam.pyindex cf309a942..d2dd6a430 100644--- a/tests/unit/test_copilot_code_block_persist_seam.py+++ b/tests/unit/test_copilot_code_block_persist_seam.py@@ -12,7 +12,6 @@ from types import SimpleNamespaceimport pytestimport yaml-from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.blocker_signal import assert_clean_user_facing_textfrom skyvern.forge.sdk.copilot.config import BlockAuthoringPolicyfrom skyvern.forge.sdk.copilot.context import CopilotContext@@ -618,10 +617,7 @@ class TestCompiledAuthoringImposition:async def test_imposition_forwards_reached_target_and_emits_download_terminal(self, monkeypatch: pytest.MonkeyPatch) -> None:- from skyvern.config import settings-_stub_successful_update(monkeypatch)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = self._download_ctx()submitted = _yaml("""@@ -648,10 +644,7 @@ class TestCompiledAuthoringImposition:@pytest.mark.asyncioasync def test_imposed_download_terminal_clears_binding_gate(self, monkeypatch: pytest.MonkeyPatch) -> None:- from skyvern.config import settings-_stub_successful_update(monkeypatch)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = self._download_ctx()ctx.flow_evidence = [{@@ -681,7 +674,6 @@ class TestCompiledAuthoringImposition:async def test_imposition_carries_reached_download_target_to_synthesized_code(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = _code_only_ctx()_enable_imposition(ctx)ctx.scout_trajectory = [diff --git a/tests/unit/test_copilot_code_block_synthesis.py b/tests/unit/test_copilot_code_block_synthesis.pyindex 2537ae4e6..cbbd95107 100644--- a/tests/unit/test_copilot_code_block_synthesis.py+++ b/tests/unit/test_copilot_code_block_synthesis.py@@ -13,7 +13,6 @@ from typing import Anyimport pytest-from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.code_block_preflight import preflight_code_blockfrom skyvern.forge.sdk.copilot.code_block_synthesis import (_DOWNLOAD_VAR_BASE,@@ -1312,7 +1311,6 @@ class TestDownloadRungSynthesis:ast.parse("async def _block(page):\n" + result.code)def test_appended_terminal_step_compiled_from_typed_target(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_nav_click()], reached_download_target=_download_target())assert result is not Noneassert "_scout_entry_reused_current_page = False" in result.code@@ -1331,32 +1329,21 @@ class TestDownloadRungSynthesis:assert 'wait_for_load_state("load")' not in download_stepdef test_already_registered_emits_no_download_step(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_nav_click()], reached_download_target=_download_target(already_registered=True, selector=""))assert result is not Noneassert "expect_download" not in result.code- def test_flag_off_with_target_byte_identical_to_base(self, monkeypatch: pytest.MonkeyPatch) -> None:- trajectory = [_nav_click()]- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", False)- base = synthesize_code_block(trajectory)- with_target = synthesize_code_block(trajectory, reached_download_target=_download_target())- assert base is not None and with_target is not None- assert base.code == with_target.code- assert "expect_download" not in with_target.code-def test_target_none_byte_identical_to_base(self, monkeypatch: pytest.MonkeyPatch) -> None:trajectory = [_nav_click()]- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)base = synthesize_code_block(trajectory)none_target = synthesize_code_block(trajectory, reached_download_target=None)assert base is not None and none_target is not Noneassert base.code == none_target.codeassert "expect_download" not in none_target.code- def test_non_download_trajectories_byte_identical_across_flag_states(self, monkeypatch: pytest.MonkeyPatch) -> None:+ def test_non_download_trajectory_emits_no_download_terminal(self) -> None:trajectory = [_interaction("type_text", selector="#user", source_url="https://example.com/", typed_value="abc"),_interaction("select_option", selector="#state", value="CA"),@@ -1370,16 +1357,11 @@ class TestDownloadRungSynthesis:_interaction("press_key", selector="#user", key="Enter"),_interaction("click", selector="#submit", source_url="https://example.com/"),]- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", False)- off = synthesize_code_block(trajectory)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)- on = synthesize_code_block(trajectory)- assert off is not None and on is not None- assert off.code == on.code- assert "expect_download" not in on.code+ result = synthesize_code_block(trajectory)+ assert result is not None+ assert "expect_download" not in result.codedef test_user_param_named_dl_info_is_renamed_via_reserved_path(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_interaction(@@ -1400,7 +1382,6 @@ class TestDownloadRungSynthesis:assert f"async with page.expect_download() as {_DOWNLOAD_VAR_BASE}:" in result.codedef test_emitted_download_snippet_is_safe_and_parses(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_nav_click()], reached_download_target=_download_target())assert result is not Nonewrapped = "async def _block(page):\n" + result.code@@ -1409,7 +1390,6 @@ class TestDownloadRungSynthesis:ast.parse(wrapped)def test_download_snippet_awaits_completion_without_save_as(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_nav_click()], reached_download_target=_download_target())assert result is not Nonedownload_obj = f"{_DOWNLOAD_VAR_BASE}_file"@@ -1421,7 +1401,6 @@ class TestDownloadRungSynthesis:CodeBlock.is_safe_code("async def _block(page):\n" + result.code)def test_download_offer_text_only_present_for_download_snippet(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)download = synthesize_code_block([_nav_click()], reached_download_target=_download_target())plain = synthesize_code_block([_interaction("click", selector="#go", source_url="https://example.com/")])assert download is not None and plain is not None@@ -1429,7 +1408,6 @@ class TestDownloadRungSynthesis:assert "expect_download" not in render_synthesized_offer_text(plain)def test_non_live_call_sites_compile_without_kwarg(self, monkeypatch: pytest.MonkeyPatch) -> None:- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)result = synthesize_code_block([_nav_click()])assert result is not Noneassert "expect_download" not in result.codediff --git a/tests/unit/test_copilot_hooks.py b/tests/unit/test_copilot_hooks.pyindex 26e1f5228..4675ce706 100644--- a/tests/unit/test_copilot_hooks.py+++ b/tests/unit/test_copilot_hooks.py@@ -1550,12 +1550,9 @@ class TestClickPostHookReachedDownloadTarget:async def test_click_on_download_affordance_populates_reached_download_target(self, monkeypatch: pytest.MonkeyPatch) -> None:- from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.tools.mcp_hooks import _click_post_hookself._patch_scouting(monkeypatch, page_evidence=self._SINGLE_DOWNLOAD_EVIDENCE)- monkeypatch.setattr(settings, "COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED", True)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = self._ctx()result = {"ok": True, "data": {"selector": 'a[href="/x/statement.pdf"]'}}@@ -1566,12 +1563,9 @@ class TestClickPostHookReachedDownloadTarget:@pytest.mark.asyncioasync def test_click_post_hook_is_noop_in_standard_mode(self, monkeypatch: pytest.MonkeyPatch) -> None:- from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.tools.mcp_hooks import _click_post_hookself._patch_scouting(monkeypatch, page_evidence=self._SINGLE_DOWNLOAD_EVIDENCE)- monkeypatch.setattr(settings, "COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED", True)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = self._ctx(BlockAuthoringPolicy.STANDARD)result = {"ok": True, "data": {"selector": 'a[href="/x/statement.pdf"]'}}@@ -1581,7 +1575,6 @@ class TestClickPostHookReachedDownloadTarget:@pytest.mark.asyncioasync def test_click_on_two_affordances_leaves_target_unset(self, monkeypatch: pytest.MonkeyPatch) -> None:- from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.tools.mcp_hooks import _click_post_hooktwo = {@@ -1591,8 +1584,6 @@ class TestClickPostHookReachedDownloadTarget:]}self._patch_scouting(monkeypatch, page_evidence=two)- monkeypatch.setattr(settings, "COPILOT_REACHED_DOWNLOAD_TARGET_AUTHOR_STEER_ENABLED", True)- monkeypatch.setattr(settings, "COPILOT_DOWNLOAD_RUNG_SYNTHESIS_ENABLED", True)ctx = self._ctx()result = {"ok": True, "data": {"selector": 'a[href="/x/a.pdf"]'}}diff --git a/tests/unit/test_evaluate_actionable_target.py b/tests/unit/test_evaluate_actionable_target.pyindex 51439c82f..447ea47d3 100644--- a/tests/unit/test_evaluate_actionable_target.py+++ b/tests/unit/test_evaluate_actionable_target.py@@ -4,7 +4,6 @@ import jsonimport pytest-from skyvern.config import settingsfrom skyvern.forge.sdk.copilot.runtime import AgentContextfrom skyvern.forge.sdk.copilot.tools import scouting@@ -441,7 +440,6 @@ def test_auto_act_candidate_rejects_javascript_href() -> None:@pytest.mark.asyncioasync def test_multiple_candidates_no_auto_act(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -461,7 +459,6 @@ async def test_multiple_candidates_no_auto_act(monkeypatch) -> None:@pytest.mark.asyncioasync def test_high_tier_no_auto_act(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -481,7 +478,6 @@ async def test_high_tier_no_auto_act(monkeypatch) -> None:@pytest.mark.asyncioasync def test_bare_button_submit_no_auto_act(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/checkout"@@ -501,7 +497,6 @@ async def test_bare_button_submit_no_auto_act(monkeypatch) -> None:@pytest.mark.asyncioasync def test_empty_text_link_no_auto_act(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -521,7 +516,6 @@ async def test_empty_text_link_no_auto_act(monkeypatch) -> None:@pytest.mark.asyncioasync def test_single_low_tier_link_auto_acts(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -549,7 +543,6 @@ async def test_single_low_tier_link_auto_acts(monkeypatch) -> None:@pytest.mark.asyncioasync def test_auto_act_post_evidence_none_sheds_bulky_result_under_cap(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -578,7 +571,6 @@ async def test_auto_act_post_evidence_none_sheds_bulky_result_under_cap(monkeypa@pytest.mark.asyncioasync def test_auto_act_success_branch_sheds_oversized_page_under_cap(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -625,7 +617,6 @@ async def test_auto_act_success_branch_sheds_oversized_page_under_cap(monkeypatc@pytest.mark.asyncioasync def test_auto_act_re_arms_on_changed_signature(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -666,7 +657,6 @@ async def test_auto_act_re_arms_on_changed_signature(monkeypatch) -> None:@pytest.mark.asyncioasync def test_auto_act_idempotent_on_unchanged_signature(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -681,29 +671,8 @@ async def test_auto_act_idempotent_on_unchanged_signature(monkeypatch) -> None:assert [call[0] for call in server.calls] == ["skyvern_click"]-async def test_auto_act_flag_off_pure_advisory(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", False)- server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})- ctx = _auto_act_ctx(server)- url = "https://apexbiz.example.com/bill"-- async def fake(c, *, url):- return _single_link_packet()-- monkeypatch.setattr(scouting, "_scout_act_observe_page_evidence", fake)- first = {"ok": True, "data": {"url": url}}- await scouting._maybe_steer_evaluate_to_action(ctx, first, url=url)- second = {"ok": True, "data": {"url": url}}- await scouting._maybe_steer_evaluate_to_action(ctx, second, url=url)- assert server.calls == []- assert "auto_acted" not in second["data"]- assert second["data"].get("next_action") == "click"--@pytest.mark.asyncioasync def test_auto_act_click_failure_degrades_to_advisory(monkeypatch) -> None:- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": False, "error": "element not found"})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"@@ -726,7 +695,6 @@ async def test_auto_act_click_failure_degrades_to_advisory(monkeypatch) -> None:async def test_auto_act_front_runs_the_third_evaluate(monkeypatch) -> None:from skyvern.forge.sdk.copilot.loop_detection import detect_tool_loop- monkeypatch.setattr(settings, "COPILOT_EVALUATE_AUTO_ACT_ON_REPEAT_ENABLED", True)server = _FakeDiscoveryServer({"ok": True, "data": {"selector": "#stmt"}})ctx = _auto_act_ctx(server)url = "https://apexbiz.example.com/bill"