Skip to content

Automate browser based workflows with AI

SKY-10346: Render terminal anti-bot blockers (PR 12/12) (#6267)

Andrew Neilsonba00ef387d86
diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.py
index 24dbcde86..df6e78a04 100644
--- a/skyvern/forge/sdk/copilot/runtime.py
+++ b/skyvern/forge/sdk/copilot/runtime.py
@@ -149,6 +149,7 @@ class AgentContext:
last_failed_workflow_yaml: str | None = None
repeated_failure_streak_count: int = 0
repeated_failure_nudge_emitted_at_streak: int = 0
+ challenge_gated_proxy_retry_count: int = 0
last_test_non_retriable_nav_error: str | None = None
non_retriable_nav_error_last_emitted_signature: str | None = None
workflow_persisted: bool = False
@@ -176,7 +177,6 @@ class AgentContext:
post_run_page_observation_workflow_run_id: str | None = None
post_run_page_observation_after_failed_test: bool = False
post_run_current_page_inspection_workflow_run_id: str | None = None
- challenge_gated_proxy_retry_count: int = 0
# Set by tool gates / loop guards / tool-side error branches when a tool
# dispatch is blocked. The finalization shim in agent.py reads this at
diff --git a/skyvern/forge/sdk/copilot/tools.py b/skyvern/forge/sdk/copilot/tools.py
index 042ac2786..76728a7e1 100644
--- a/skyvern/forge/sdk/copilot/tools.py
+++ b/skyvern/forge/sdk/copilot/tools.py
@@ -800,6 +800,108 @@ def _post_budget_upstream_replay_signal(
)
+def _composition_control_label(control: dict[str, Any]) -> str:
+ parts: list[str] = []
+ for key in ("text", "name", "id", "selector"):
+ value = control.get(key)
+ if isinstance(value, str) and value.strip():
+ parts.append(value.strip())
+ unique = list(dict.fromkeys(parts))
+ return " / ".join(unique[:2])[:160] if unique else "submit/search control"
+
+
+def _disabled_submit_controls_from_evidence(evidence: dict[str, Any]) -> list[dict[str, Any]]:
+ controls: list[dict[str, Any]] = []
+ forms = evidence.get("forms")
+ if not isinstance(forms, list):
+ return controls
+ for form in forms:
+ if not isinstance(form, dict):
+ continue
+ for control in form.get("submit_controls") or []:
+ if isinstance(control, dict) and control.get("disabled") is True:
+ controls.append(control)
+ return controls[:5]
+
+
+def _post_run_terminal_challenge_reason(evidence: dict[str, Any]) -> str | None:
+ if evidence.get("observed_after_workflow_run") is not True:
+ return None
+
+ challenge_state = evidence.get("challenge_state")
+ if isinstance(challenge_state, dict):
+ gated_controls = [
+ control for control in challenge_state.get("gated_submit_controls") or [] if isinstance(control, dict)
+ ]
+ if challenge_state.get("gates_submit_controls") is True:
+ kind = str(challenge_state.get("kind") or "anti-bot challenge").replace("_", " ")
+ labels = ", ".join(_composition_control_label(control) for control in gated_controls[:3])
+ controls_text = f" ({labels})" if labels else ""
+ return f"{kind} is still gating disabled submit/search control(s){controls_text}"
+ if challenge_state.get("detected") is True and challenge_state.get("requires_human_verification") is True:
+ disabled_controls = _disabled_submit_controls_from_evidence(evidence)
+ if disabled_controls:
+ labels = ", ".join(_composition_control_label(control) for control in disabled_controls[:3])
+ return f"human-verification challenge remains while submit/search control(s) are disabled ({labels})"
+
+ indicators = evidence.get("anti_bot_indicators")
+ has_indicators = isinstance(indicators, list) and any(isinstance(item, str) and item.strip() for item in indicators)
+ if has_indicators:
+ disabled_controls = _disabled_submit_controls_from_evidence(evidence)
+ if disabled_controls:
+ labels = ", ".join(_composition_control_label(control) for control in disabled_controls[:3])
+ return f"anti-bot evidence remains while submit/search control(s) are disabled ({labels})"
+ return None
+
+
+def _post_budget_terminal_challenge_signal(
+ ctx: AgentContext, arguments: dict[str, Any] | None, tool_name: str
+) -> CopilotToolBlockerSignal | None:
+ evidence = getattr(ctx, "composition_page_evidence", None)
+ if not isinstance(evidence, dict):
+ return None
+
+ # A failed run with post-run page evidence can prove the same terminal
+ # challenge state even when the top-level failure category was not budget.
+ prior_budget_or_failed_run = (
+ getattr(ctx, "last_failure_category_top", None) == PER_TOOL_BUDGET_FAILURE_CATEGORY
+ or getattr(ctx, "last_test_ok", None) is False
+ or getattr(ctx, "post_run_page_observation_after_failed_test", False) is True
+ or bool(_per_tool_budget_problem_label_set(ctx))
+ )
+ if not prior_budget_or_failed_run:
+ return None
+
+ reason = _post_run_terminal_challenge_reason(evidence)
+ if not reason:
+ return None
+
+ requested_labels = _requested_block_label_set(arguments)
+ labels_text = f" Requested labels: {', '.join(sorted(requested_labels))}." if requested_labels else ""
+ agent_steering = (
+ "The prior block-running tool hit a failed/budgeted frontier, and bounded current-page inspection "
+ f"now shows: {reason}.{labels_text} Do NOT call "
+ f"{tool_name} again in this turn, do NOT try another proxy/location from this evidence state, and "
+ "do NOT claim registry results or no-results were verified. REPLY now with a blocker explanation "
+ "that names the observed challenge/disabled control and summarizes the tested workflow state."
+ )
+ user_facing = (
+ "The site's verification challenge is still blocking the submit/search control after live-page inspection, "
+ "so I stopped without claiming results."
+ )
+ return CopilotToolBlockerSignal(
+ blocker_kind="tool_error",
+ agent_steering_text=agent_steering,
+ user_facing_reason=user_facing,
+ recovery_hint="report_blocker_to_user",
+ cleared_by_tools=frozenset(),
+ preserves_workflow_draft=True,
+ renders_final_reply=True,
+ internal_reason_code="tool_error_post_budget_challenge_blocker",
+ blocked_tool=tool_name,
+ )
+
+
_RECONCILIATION_REQUIRES_INPUT_USER_FACING = (
"The previous run was canceled. Tell me whether to retry, keep the draft as-is, or adjust the workflow first."
)
@@ -1286,7 +1388,7 @@ def _challenge_gated_anti_bot_rerun_signal(
"Ask whether to try a materially different proxy/location, entrypoint, or alternate source."
)
user_facing = (
- "The site's verification challenge is still keeping the search control disabled, so I need to stop "
+ "The site's verification challenge is still keeping the submit/search control disabled, so I stopped "
"instead of retrying the same workflow path."
)
return CopilotToolBlockerSignal(
@@ -1296,7 +1398,7 @@ def _challenge_gated_anti_bot_rerun_signal(
recovery_hint="report_blocker_to_user",
cleared_by_tools=frozenset(),
preserves_workflow_draft=True,
- renders_final_reply=False,
+ renders_final_reply=True,
internal_reason_code="tool_error_challenge_gated_submit_disabled",
blocked_tool=tool_name,
)
@@ -1349,6 +1451,12 @@ def _tool_loop_error(ctx: AgentContext, tool_name: str, arguments: dict[str, Any
if inspection_signal is not None:
return _emit_tool_blocker_signal(ctx, inspection_signal)
+ # Terminal anti-bot evidence should produce the final user-facing reply
+ # before the generic budget rerun path can ask for another attempt.
+ post_budget_challenge_signal = _post_budget_terminal_challenge_signal(ctx, arguments, tool_name)
+ if post_budget_challenge_signal is not None:
+ return _emit_tool_blocker_signal(ctx, post_budget_challenge_signal)
+
budget_signal = _per_tool_budget_problem_rerun_signal(ctx, arguments, tool_name)
if budget_signal is not None:
return _emit_tool_blocker_signal(ctx, budget_signal)
@@ -1894,6 +2002,10 @@ async def _update_workflow(
if wait_block_error:
return {"ok": False, "error": wait_block_error}
+ challenge_http_error = _challenge_http_request_reject_message(ctx, workflow_yaml, ctx.workflow_yaml)
+ if challenge_http_error:
+ return {"ok": False, "error": challenge_http_error}
+
# Post-emission reject of copilot-v2 writes that introduce a banned
# block type. The schema pre_hook only fires when the LLM consults the
# schema; this safety net fires regardless of emission path. Label-based
@@ -4183,6 +4295,56 @@ def _detect_timing_only_challenge_wait_blocks(submitted_yaml: str | None) -> lis
return labels
+def _composition_evidence_has_challenge(ctx: AgentContext) -> bool:
+ evidence = getattr(ctx, "composition_page_evidence", None)
+ if not isinstance(evidence, dict):
+ return False
+ if evidence.get("anti_bot_indicators") or evidence.get("challenge_controls"):
+ return True
+ challenge_state = evidence.get("challenge_state")
+ return isinstance(challenge_state, dict) and challenge_state.get("detected") is True
+
+
+def _detect_new_http_request_blocks(submitted_yaml: str | None, prior_workflow_yaml: str | None) -> list[str]:
+ submitted_blocks = _parse_workflow_blocks(submitted_yaml)
+ if submitted_blocks is None:
+ return []
+ prior_blocks = _parse_workflow_blocks(prior_workflow_yaml)
+ prior_labels: set[str] = set()
+ for block in _iter_yaml_blocks(prior_blocks or []):
+ if str(block.get("block_type") or "").strip().lower() != "http_request":
+ continue
+ label = block.get("label")
+ if isinstance(label, str):
+ prior_labels.add(label)
+ labels: list[str] = []
+ for block in _iter_yaml_blocks(submitted_blocks):
+ if str(block.get("block_type") or "").strip().lower() != "http_request":
+ continue
+ label = block.get("label")
+ if isinstance(label, str) and label not in prior_labels:
+ labels.append(label)
+ return labels
+
+
+def _challenge_http_request_reject_message(
+ ctx: AgentContext, submitted_yaml: str | None, prior_workflow_yaml: str | None
+) -> str | None:
+ if not _composition_evidence_has_challenge(ctx):
+ return None
+ labels = _detect_new_http_request_blocks(submitted_yaml, prior_workflow_yaml)
+ if not labels:
+ return None
+ labels_text = ", ".join(sorted(set(labels)))
+ return (
+ "Workflow validation failed: raw http_request blocks are not allowed for a page with observed "
+ "anti-bot or human-verification challenge evidence. "
+ f"Offending labels: [{labels_text}]. "
+ "Use browser workflow blocks grounded in the observed page, include challenge handling only when visible, "
+ "or stop and report the observed challenge blocker if it cannot be completed."
+ )
+
+
def _timing_only_challenge_wait_reject_message(ctx: Any, submitted_yaml: str | None) -> str | None:
if not _has_confirmed_waf_or_site_block(ctx):
return None
@@ -5437,6 +5599,7 @@ _DISCOVERY_DOMAIN_WITH_PATH_RE = re.compile(
)
_DISCOVERY_BARE_WORD_RE = re.compile(r"^[a-z0-9-]{2,32}$", re.IGNORECASE)
_DISCOVERY_TOKEN_RE = re.compile(r"[a-z0-9]+", re.IGNORECASE)
+_DISCOVERY_CANDIDATE_EVIDENCE_STOPWORDS = frozenset({"a", "an", "and", "for", "in", "of", "on", "or", "the", "to"})
_DISCOVERY_LOGIN_TITLE_RE = re.compile(r"\b(sign\s*in|log\s*in|login)\b", re.IGNORECASE)
_DISCOVERY_PASSWORD_INPUT_RE = re.compile(
r"<input[^>]*type\s*=\s*[\"']password[\"']",
@@ -5496,6 +5659,14 @@ def _discovery_title_score(page_title: str, intent_tokens: set[str]) -> int:
return sum(1 for token in intent_tokens if token in lowered)
+def _discovery_candidate_evidence_tokens(intent_tokens: set[str]) -> set[str]:
+ return {
+ token
+ for token in intent_tokens
+ if len(token) > 2 and token.lower() not in _DISCOVERY_CANDIDATE_EVIDENCE_STOPWORDS
+ }
+
+
def _discovery_detect_login_wall(html: str, page_title: str) -> bool:
if _DISCOVERY_LOGIN_TITLE_RE.search(page_title or ""):
return True
@@ -6114,7 +6285,45 @@ async def _discovery_walk(
}
)
- if _discovery_detect_anti_bot(html, page_title):
+ title_score = _discovery_title_score(page_title, intent_tokens)
+
+ best_score = 0
+ best_href: str | None = None
+ best_anchor: dict[str, str] | None = None
+ for anchor in anchors:
+ score = _discovery_anchor_score(
+ anchor.get("text", ""),
+ anchor.get("title", ""),
+ anchor.get("href", ""),
+ intent_tokens,
+ )
+ if score > best_score:
+ resolved = _discovery_resolve_href(current_url, anchor.get("href", ""))
+ if resolved is None:
+ continue
+ best_score = score
+ best_href = resolved
+ best_anchor = anchor
+
+ evidence_tokens = _discovery_candidate_evidence_tokens(intent_tokens)
+ candidate_title_score = _discovery_title_score(page_title, evidence_tokens)
+ candidate_anchor_score = 0
+ for anchor in anchors:
+ candidate_anchor_score = max(
+ candidate_anchor_score,
+ _discovery_anchor_score(
+ anchor.get("text", ""),
+ anchor.get("title", ""),
+ anchor.get("href", ""),
+ evidence_tokens,
+ ),
+ )
+
+ anti_bot_detected = _discovery_detect_anti_bot(html, page_title)
+ anti_bot_has_no_candidate_evidence = (
+ not form_fields and candidate_title_score == 0 and candidate_anchor_score == 0
+ )
+ if anti_bot_detected and anti_bot_has_no_candidate_evidence:
origin_url = _discovery_origin_url(current_url)
if (
not retried_deep_link_from_origin
@@ -6142,26 +6351,6 @@ async def _discovery_walk(
failure_reason="login_wall",
)
- title_score = _discovery_title_score(page_title, intent_tokens)
-
- best_score = 0
- best_href: str | None = None
- best_anchor: dict[str, str] | None = None
- for anchor in anchors:
- score = _discovery_anchor_score(
- anchor.get("text", ""),
- anchor.get("title", ""),
- anchor.get("href", ""),
- intent_tokens,
- )
- if score > best_score:
- resolved = _discovery_resolve_href(current_url, anchor.get("href", ""))
- if resolved is None:
- continue
- best_score = score
- best_href = resolved
- best_anchor = anchor
-
if intent_tokens and title_score >= 2 and (form_fields or best_score <= title_score):
confidence = min(1.0, title_score / max(1, len(intent_tokens)))
return _discovery_build_result(
diff --git a/tests/unit/test_copilot_discovery.py b/tests/unit/test_copilot_discovery.py
index b2ab17636..543cefbc2 100644
--- a/tests/unit/test_copilot_discovery.py
+++ b/tests/unit/test_copilot_discovery.py
@@ -116,6 +116,50 @@ class _DeepLinkAntiBotRecoveryServer:
raise AssertionError(f"unexpected tool: {tool_name}")
+class _EmbeddedChallengeUsefulPageServer:
+ def __init__(self) -> None:
+ self.urls: list[str] = []
+
+ async def call_internal_tool(self, tool_name: str, arguments: dict[str, Any]) -> dict[str, Any]:
+ if tool_name == "skyvern_navigate":
+ self.urls.append(arguments["url"])
+ return {"ok": True, "data": {"url": arguments["url"]}}
+ if tool_name == "skyvern_get_html":
+ assert arguments == {"selector": "body"}
+ if self.urls[-1] == "https://certboard.test":
+ return {
+ "ok": True,
+ "data": {
+ "html": """
+ <html><head><title>Certification Board</title></head>
+ <body><a href="/registry/search">Find a Certificant</a></body></html>
+ """
+ },
+ }
+ return {
+ "ok": True,
+ "data": {
+ "html": """
+ <html>
+ <head>
+ <title>Certificant Registry</title>
+ <script src="https://challenges.example.test/turnstile/api.js"></script>
+ </head>
+ <body>
+ <form>
+ <label for="first-name">First Name</label>
+ <input id="first-name" name="first_name">
+ <label for="last-name">Last Name</label>
+ <input id="last-name" name="last_name">
+ </form>
+ </body>
+ </html>
+ """
+ },
+ }
+ raise AssertionError(f"unexpected tool: {tool_name}")
+
+
class _CurrentPageServer:
def __init__(self) -> None:
self.calls: list[str] = []
@@ -209,6 +253,25 @@ async def test_discovery_recovers_from_deep_link_anti_bot_by_clicking_from_origi
]
+async def test_discovery_keeps_candidate_when_challenge_markup_is_embedded_in_useful_page() -> None:
+ server = _EmbeddedChallengeUsefulPageServer()
+
+ result = await _discovery_walk(
+ _Ctx(server),
+ entry_url="https://certboard.test",
+ intent_hint="find certificant lookup page",
+ )
+
+ assert result["ok"] is True
+ assert result["data"]["candidate_url"] == "https://certboard.test/registry/search"
+ assert result["data"]["failure_reason"] is None
+ assert result["data"]["candidate_form_fields"] == [
+ {"label": "First Name", "name": "first_name", "type": "input", "value_hint": ""},
+ {"label": "Last Name", "name": "last_name", "type": "input", "value_hint": ""},
+ ]
+
+
@pytest.mark.asyncio
async def test_inspect_current_page_uses_existing_browser_page(monkeypatch: pytest.MonkeyPatch) -> None:
server = _CurrentPageServer()
diff --git a/tests/unit/test_copilot_per_tool_budget.py b/tests/unit/test_copilot_per_tool_budget.py
index 192ff93f5..a406b94ed 100644
--- a/tests/unit/test_copilot_per_tool_budget.py
+++ b/tests/unit/test_copilot_per_tool_budget.py
@@ -114,11 +114,11 @@ def test_record_per_tool_budget_with_current_url_requires_page_inspection() -> N
def test_record_preserves_pre_run_anti_bot_evidence_on_budget_trip() -> None:
ctx = _fresh_context()
ctx.composition_page_evidence = {
- "anti_bot_indicators": ["challenges.cloudflare.com", "cf-turnstile"],
- "challenge_controls": [{"selector": "#turnstile-widget"}],
+ "anti_bot_indicators": ["human-verification", "human-verification"],
+ "challenge_controls": [{"selector": "#human-verification-widget"}],
"challenge_state": {
"detected": True,
- "kind": "cloudflare_turnstile",
+ "kind": "human_verification",
"indicators": ["verify you are human"],
"gates_submit_controls": True,
"gated_submit_controls": [{"text": "Search", "disabled": True}],
@@ -129,7 +129,7 @@ def test_record_preserves_pre_run_anti_bot_evidence_on_budget_trip() -> None:
assert ctx.last_failure_category_top == PER_TOOL_BUDGET_FAILURE_CATEGORY
assert ctx.last_test_anti_bot is not None
- assert "cf-turnstile" in ctx.last_test_anti_bot
+ assert "human-verification" in ctx.last_test_anti_bot
assert "challenge-gated disabled submit/search control: Search" in ctx.last_test_anti_bot
@@ -138,8 +138,8 @@ def test_composition_anti_bot_reason_reads_typed_challenge_state_without_legacy_
ctx.composition_page_evidence = {
"challenge_state": {
"detected": True,
- "kind": "cloudflare_turnstile",
- "indicators": ["cf-turnstile-response"],
+ "kind": "human_verification",
+ "indicators": ["human-verification-response"],
"gates_submit_controls": True,
"gated_submit_controls": [{"text": "Search", "disabled": True}],
},
@@ -148,7 +148,7 @@ def test_composition_anti_bot_reason_reads_typed_challenge_state_without_legacy_
reason = _composition_anti_bot_reason(ctx)
assert reason is not None
- assert "cloudflare_turnstile" in reason
+ assert "human_verification" in reason
assert "challenge-gated disabled submit/search control: Search" in reason
@@ -275,7 +275,7 @@ def test_check_enforcement_emits_anti_bot_nudge_before_budget_when_challenge_obs
ctx.test_after_update_done = True
ctx.last_test_ok = False
ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
- ctx.last_test_anti_bot = "Observed anti-bot challenge evidence before the run: cf-turnstile"
+ ctx.last_test_anti_bot = "Observed anti-bot challenge evidence before the run: human-verification"
nudge = _check_enforcement(ctx)
@@ -289,8 +289,8 @@ def test_final_reply_after_post_run_observation_bypasses_stale_budget_and_anti_b
ctx.update_workflow_called = True
ctx.test_after_update_done = True
ctx.composition_page_evidence = {
- "anti_bot_indicators": ["cf-turnstile"],
- "challenge_controls": [{"selector": "#turnstile-widget"}],
+ "anti_bot_indicators": ["human-verification"],
+ "challenge_controls": [{"selector": "#human-verification-widget"}],
}
_record_run_blocks_result(ctx, _budget_trip_result("wr_budget"))
assert ctx.last_test_anti_bot is not None
@@ -298,8 +298,8 @@ def test_final_reply_after_post_run_observation_bypasses_stale_budget_and_anti_b
_record_composition_page_observation(
ctx,
source_tool="evaluate",
- url="https://certboard.example/registry/search?sendid=fixture",
- observed_data={"text": "Certification Number: CRED-000123"},
+ url="https://example.com/registry/search?sendid=494764",
+ observed_data={"text": "Credential Number: CRED-000123"},
)
assert _check_enforcement(ctx, _reply_result("Observed result: CRED-000123 expires 01/31/2030.")) is None
@@ -309,12 +309,12 @@ def test_progress_reply_after_post_run_observation_still_gets_anti_bot_nudge() -
ctx = _fresh_context()
ctx.update_workflow_called = True
ctx.test_after_update_done = True
- ctx.composition_page_evidence = {"anti_bot_indicators": ["cf-turnstile"]}
+ ctx.composition_page_evidence = {"anti_bot_indicators": ["human-verification"]}
_record_run_blocks_result(ctx, _budget_trip_result("wr_budget"))
_record_composition_page_observation(
ctx,
source_tool="evaluate",
- url="https://certboard.example/registry/search",
+ url="https://example.com/registry/search",
)
nudge = _check_enforcement(ctx, _reply_result("I will now proceed to inspect the result page."))
@@ -624,12 +624,12 @@ def test_tool_loop_error_allows_new_smaller_label_after_budget_problem() -> None
def test_tool_loop_error_blocks_challenge_gated_disabled_submit_rerun() -> None:
ctx = _fresh_context()
ctx.workflow_yaml = """
-title: Sample credential registry lookup
+title: Registry standard credential lookup
workflow_definition:
blocks:
- - label: open_find_certificant
+ - label: open_registry_search
block_type: goto_url
- url: https://certboard.example/registry/search
+ url: https://example.com/registry/search
"""
ctx.last_failed_workflow_yaml = ctx.workflow_yaml
ctx.last_test_anti_bot = (
@@ -641,7 +641,7 @@ workflow_definition:
ctx.composition_page_evidence = {
"challenge_state": {
"detected": True,
- "kind": "cloudflare_turnstile",
+ "kind": "human_verification",
"gates_submit_controls": True,
"gated_submit_controls": [{"text": "Search", "disabled": True}],
},
@@ -652,7 +652,7 @@ workflow_definition:
"update_and_run_blocks",
{
"workflow_yaml": ctx.workflow_yaml,
- "block_labels": ["fill_sample_person_credential_search"],
+ "block_labels": ["fill_sample_record_search"],
},
)
@@ -661,17 +661,18 @@ workflow_definition:
assert "disabled submit/search control" in msg
assert ctx.blocker_signal is not None
assert ctx.blocker_signal.internal_reason_code == "tool_error_challenge_gated_submit_disabled"
+ assert ctx.blocker_signal.renders_final_reply is True
def test_tool_loop_error_allows_challenge_gated_retry_with_changed_proxy_location() -> None:
ctx = _fresh_context()
ctx.last_failed_workflow_yaml = """
-title: Sample credential registry lookup
+title: Registry standard credential lookup
workflow_definition:
blocks:
- - label: open_find_certificant
+ - label: open_registry_search
block_type: goto_url
- url: https://certboard.example/registry/search
+ url: https://example.com/registry/search
"""
ctx.last_test_anti_bot = (
"Observed anti-bot challenge evidence before the run: challenge-gated disabled submit/search control: Search"
@@ -680,19 +681,19 @@ workflow_definition:
ctx.composition_page_evidence = {
"challenge_state": {
"detected": True,
- "kind": "cloudflare_turnstile",
+ "kind": "human_verification",
"gates_submit_controls": True,
"gated_submit_controls": [{"text": "Search", "disabled": True}],
},
}
changed_proxy_yaml = """
-title: Sample credential registry lookup
+title: Registry standard credential lookup
proxy_location: RESIDENTIAL
workflow_definition:
blocks:
- - label: open_find_certificant
+ - label: open_registry_search
block_type: goto_url
- url: https://certboard.example/registry/search
+ url: https://example.com/registry/search
"""
assert (
@@ -701,7 +702,7 @@ workflow_definition:
"update_and_run_blocks",
{
"workflow_yaml": changed_proxy_yaml,
- "block_labels": ["fill_sample_person_credential_search"],
+ "block_labels": ["fill_sample_record_search"],
},
)
is None
@@ -709,27 +710,99 @@ workflow_definition:
assert ctx.challenge_gated_proxy_retry_count == 1
+def test_tool_loop_error_blocks_post_budget_challenge_even_with_changed_proxy_location() -> None:
+ ctx = _fresh_context()
+ ctx.last_failure_category_top = PER_TOOL_BUDGET_FAILURE_CATEGORY
+ ctx.last_test_ok = False
+ ctx.per_tool_budget_problem_block_labels = ["submit_registry_search"]
+ ctx.last_failed_workflow_yaml = """
+title: Registry standard credential lookup
+workflow_definition:
+ blocks:
+ - label: open_registry_search
+ block_type: goto_url
+ url: https://example.com/registry/search
+ - label: submit_registry_search
+ block_type: navigation
+ goal: Submit the credential search
+"""
+ ctx.composition_page_evidence = {
+ "current_url": "https://example.com/registry/search",
+ "workflow_run_id": "wr_budget",
+ "observed_after_workflow_run": True,
+ "anti_bot_indicators": ["human-verification"],
+ "forms": [
+ {
+ "submit_controls": [
+ {
+ "text": "Search",
+ "selector": "#search",
+ "disabled": True,
+ }
+ ]
+ }
+ ],
+ "challenge_state": {
+ "detected": True,
+ "kind": "human_verification",
+ "requires_human_verification": True,
+ "gates_submit_controls": True,
+ "gated_submit_controls": [{"text": "Search", "disabled": True}],
+ },
+ }
+ changed_proxy_yaml = """
+title: Registry standard credential lookup
+proxy_location: US-CA
+workflow_definition:
+ blocks:
+ - label: open_registry_search
+ block_type: goto_url
+ url: https://example.com/registry/search
+ - label: submit_registry_search
+ block_type: navigation
+ goal: Submit the credential search
+"""
+
+ msg = _tool_loop_error(
+ ctx,
+ "update_and_run_blocks",
+ {
+ "workflow_yaml": changed_proxy_yaml,
+ "block_labels": ["open_registry_search", "submit_registry_search"],
+ },
+ )
+
+ assert msg is not None
+ assert "bounded current-page inspection" in msg
+ assert "disabled submit/search control" in msg
+ assert "another proxy" in msg
+ assert ctx.challenge_gated_proxy_retry_count == 0
+ assert ctx.blocker_signal is not None
+ assert ctx.blocker_signal.internal_reason_code == "tool_error_post_budget_challenge_blocker"
+ assert ctx.blocker_signal.renders_final_reply is True
+
+
def test_tool_loop_error_blocks_second_challenge_gated_proxy_retry() -> None:
ctx = _fresh_context()
ctx.challenge_gated_proxy_retry_count = 1
ctx.last_failed_workflow_yaml = """
-title: Sample credential registry lookup
+title: Registry standard credential lookup
workflow_definition:
blocks:
- - label: open_find_certificant
+ - label: open_registry_search
block_type: goto_url
- url: https://certboard.example/registry/search
+ url: https://example.com/registry/search
"""
ctx.last_test_anti_bot = "Extracted data reported anti-bot blocker: Verify you are human"
ctx.last_test_failure_reason = "Run completed, but extracted data reported a blocker: Verify you are human"
changed_proxy_yaml = """
-title: Sample credential registry lookup
+title: Registry standard credential lookup
proxy_location: US-NY
workflow_definition:
blocks:
- - label: open_find_certificant
+ - label: open_registry_search
block_type: goto_url
- url: https://certboard.example/registry/search
+ url: https://example.com/registry/search
"""
msg = _tool_loop_error(
@@ -737,7 +810,7 @@ workflow_definition:
"update_and_run_blocks",
{
"workflow_yaml": changed_proxy_yaml,
- "block_labels": ["search_sample_person_credential"],
+ "block_labels": ["search_sample_record"],
},
)
@@ -746,6 +819,7 @@ workflow_definition:
assert "blocker" in msg
assert ctx.blocker_signal is not None
assert ctx.blocker_signal.internal_reason_code == "tool_error_challenge_gated_submit_disabled"
+ assert ctx.blocker_signal.renders_final_reply is True
def test_terminal_anti_bot_blocker_requires_gated_submit_evidence_for_disabled_failure() -> None:
@@ -773,7 +847,7 @@ def test_record_run_blocks_treats_structured_anti_bot_blocker_as_failed_test() -
"overall_status": "completed",
"blocks": [
{
- "label": "extract_sample_person_credentials",
+ "label": "extract_sample_credentials",
"block_type": "EXTRACTION",
"status": "completed",
"extracted_data": {
diff --git a/tests/unit/test_copilot_probable_site_block.py b/tests/unit/test_copilot_probable_site_block.py
index 8fd05ceef..5ae497b00 100644
--- a/tests/unit/test_copilot_probable_site_block.py
+++ b/tests/unit/test_copilot_probable_site_block.py
@@ -19,6 +19,7 @@ from skyvern.forge.sdk.copilot.enforcement import (
_repeated_frontier_failure_nudge,
)
from skyvern.forge.sdk.copilot.tools import (
+ _challenge_http_request_reject_message,
_detect_probable_site_block_wall,
_detect_timing_only_challenge_wait_blocks,
_record_run_blocks_result,
@@ -421,3 +422,52 @@ def test_allows_conditional_challenge_action_after_block_evidence() -> None:
ctx.last_test_anti_bot = "challenge page detected"
assert _timing_only_challenge_wait_reject_message(ctx, _CONDITIONAL_ACTION_WORKFLOW) is None
+
+
+def test_rejects_new_http_request_after_observed_challenge_evidence() -> None:
+ existing_yaml = """
+workflow_definition:
+ blocks:
+ - label: open_lookup
+ block_type: goto_url
+ url: https://example.com/registry/search
+"""
+ submitted_yaml = """
+workflow_definition:
+ blocks:
+ - label: open_lookup
+ block_type: goto_url
+ url: https://example.com/registry/search
+ - label: submit_lookup
+ block_type: http_request
+ method: POST
+ url: https://example.com/registry/search?s=1
+"""
+ ctx = _fresh_context()
+ ctx.composition_page_evidence = {
+ "anti_bot_indicators": ["human-verification"],
+ "challenge_controls": [{"selector": "#human-verification"}],
+ }
+ ctx.workflow_yaml = existing_yaml
+
+ message = _challenge_http_request_reject_message(ctx, submitted_yaml, ctx.workflow_yaml)
+
+ assert message is not None
+ assert "submit_lookup" in message
+ assert "raw http_request blocks are not allowed" in message
+
+
+def test_allows_existing_http_request_when_challenge_evidence_is_added_later() -> None:
+ existing_yaml = """
+workflow_definition:
+ blocks:
+ - label: submit_lookup
+ block_type: http_request
+ method: POST
+ url: https://example.com/search
+"""
+ ctx = _fresh_context()
+ ctx.composition_page_evidence = {"anti_bot_indicators": ["human-verification"]}
+ ctx.workflow_yaml = existing_yaml
+
+ assert _challenge_http_request_reject_message(ctx, existing_yaml, ctx.workflow_yaml) is None