Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-12916 Let Copilot safely continue through login and verification pages (#7699)
Andrew Neilsonf1d2ec8fe923
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.pyindex 2efb3f536..6ac1a09d0 100644--- a/skyvern/forge/sdk/copilot/agent.py+++ b/skyvern/forge/sdk/copilot/agent.py@@ -968,6 +968,38 @@ def _recorded_build_test_outcome_prompt(ctx: CopilotContext | None) -> str:lines.append(f"- {'; '.join(fields)}")if outcome.workflow_run_id:lines.append(f"workflow_run_id: {_clean_authoring_repair_prompt_atom(outcome.workflow_run_id)}")+ page_path_failure = outcome.page_path_failure+ if page_path_failure is not None and page_path_failure.is_page_path:+ lines.extend(+ [+ "POST-RUN PAGE-PATH CONTINUATION:",+ f"kind: {_clean_authoring_repair_prompt_atom(page_path_failure.kind)}",+ ]+ )+ for target in page_path_failure.continuation_targets:+ selector = _clean_authoring_repair_prompt_atom(target.selector)+ lines.append(f"- allowed click: selector={selector}")+ if page_path_failure.enter_allowed and target.kind in {"form_submit", "challenge"}:+ lines.append(f"- allowed Enter: selector={selector}")+ lines.append(+ "Continue from the current page with one exact listed click or Enter action. "+ "Do not navigate away or re-author the workflow before attempting that bounded continuation."+ )+ elif (+ page_path_failure is None+ and outcome.phase == "persisted_block_run"+ and outcome.reason_code == "outcome_not_demonstrated"+ and outcome.workflow_run_id+ ):+ lines.extend(+ [+ "POST-RUN PAGE-PATH CONTRACT UNBOUND:",+ 'Before any click or key press, call inspect_page_for_composition with target_url="current_page". '+ "Do not use evaluate as a substitute. If the fresh same-run observation is page-path-shaped, it "+ "will emit the exact allowed click or Enter selector; use only that selector without navigating or "+ "re-authoring first. Otherwise the existing blocker remains in force.",+ ]+ )if outcome.observed_evidence_summary:lines.append(f"observed_evidence: {_clean_authoring_repair_prompt_atom(outcome.observed_evidence_summary)}")if outcome.observed_page_value_excerpt:diff --git a/skyvern/forge/sdk/copilot/build_test_outcome.py b/skyvern/forge/sdk/copilot/build_test_outcome.pyindex bf53c19f5..19299d4dc 100644--- a/skyvern/forge/sdk/copilot/build_test_outcome.py+++ b/skyvern/forge/sdk/copilot/build_test_outcome.py@@ -12,14 +12,17 @@ import structlogimport yamlfrom pydantic import BaseModel, ConfigDict, Field-from skyvern.forge.sdk.copilot.challenge_evidence import carrier_backed_anti_bot_categories+from skyvern.forge.sdk.copilot.challenge_evidence import (+ carrier_backed_anti_bot_categories,+ interactive_challenge_controls,+)from skyvern.forge.sdk.copilot.code_block_preflight import SANDBOX_UNRESOLVED_NAME_REASON_CODEfrom skyvern.forge.sdk.copilot.completion_verification import (CompletionVerificationResult,CriterionVerdict,only_degraded_blocking,)-from skyvern.forge.sdk.copilot.composition_evidence import has_bounded_page_schema+from skyvern.forge.sdk.copilot.composition_evidence import has_bounded_page_schema, workflow_target_urlfrom skyvern.forge.sdk.copilot.context import CodeAuthoringRepairContextfrom skyvern.forge.sdk.copilot.request_policy import redact_raw_secrets_for_promptfrom skyvern.forge.sdk.copilot.result_evidence import (@@ -74,6 +77,8 @@ MetadataRejectFamily = Literal["recorded_outcome_output_coverage",]MetadataRejectLadderAction = Literal["rung_1", "rung_2", "terminal"]+PostRunPagePathKind = Literal["login", "challenge", "incomplete_navigation", "non_page_outcome"]+PostRunPagePathTargetKind = Literal["form_submit", "navigation", "clickable", "challenge"]_STRUCTURAL_KEY_VERSION = "recorded_build_test_outcome:v1"_AUTHORED_STRUCTURE_VERSION = "recorded_build_test_outcome_authored_structure:v1"@@ -90,6 +95,27 @@ _PLAYWRIGHT_LOCATOR_WAIT_RE = re.compile(_PLAYWRIGHT_HIDDEN_TAG_RE = re.compile(r"locator resolved to hidden <(?P<tag>[a-z0-9:-]+)", re.IGNORECASE)+class PostRunPagePathTarget(BaseModel):+ model_config = ConfigDict(extra="forbid", frozen=True)++ kind: PostRunPagePathTargetKind+ selector: str = Field(min_length=1)+++class PostRunPagePathFailure(BaseModel):+ model_config = ConfigDict(extra="forbid", frozen=True)++ kind: PostRunPagePathKind+ workflow_run_id: str = Field(min_length=1)+ current_url: str = Field(min_length=1)+ continuation_targets: tuple[PostRunPagePathTarget, ...]+ enter_allowed: bool = False++ @property+ def is_page_path(self) -> bool:+ return self.kind != "non_page_outcome" and bool(self.continuation_targets)++class RecordedBuildTestOutcome(BaseModel):model_config = ConfigDict(extra="forbid")@@ -110,6 +136,7 @@ class RecordedBuildTestOutcome(BaseModel):evidence_refs: list[str] = Field(default_factory=list)missing_requested_output_facts: list[dict[str, object]] = Field(default_factory=list)runtime_output_repair_facts: list[dict[str, object]] = Field(default_factory=list)+ page_path_failure: PostRunPagePathFailure | None = Noneauthored_structure_signature: str | None = Nonedisplay_text: str = ""observed_page_value_excerpt: str = ""@@ -311,6 +338,7 @@ class RecordedOutcomeBindingConstraint(BaseModel):class _RecordedBuildTestOutcomeContext(Protocol):+ workflow_yaml: strlatest_recorded_build_test_outcome: RecordedBuildTestOutcome | Nonerecorded_build_test_outcome_history: list[dict[str, object]]recorded_persisted_block_run_workflow_run_id: str | None@@ -353,6 +381,32 @@ def record_build_test_outcome(ctx: _RecordedBuildTestOutcomeContext, outcome: Re)+def bind_post_run_page_path_failure(+ ctx: _RecordedBuildTestOutcomeContext,+ page_evidence: Mapping[str, object],+) -> bool:+ """Bind a fresh same-run page-path condition without changing the outcome's structural identity."""+ latest = ctx.latest_recorded_build_test_outcome+ if (+ not isinstance(latest, RecordedBuildTestOutcome)+ or not latest.is_authoritative+ or latest.phase != "persisted_block_run"+ or latest.reason_code != "outcome_not_demonstrated"+ or latest.verdict != "repairable_failure"+ or not latest.workflow_run_id+ ):+ return False+ condition = _post_run_page_path_failure(+ page_evidence,+ latest.workflow_run_id,+ required_target_url=workflow_target_url(ctx.workflow_yaml),+ )+ if condition is None:+ return False+ ctx.latest_recorded_build_test_outcome = latest.model_copy(update={"page_path_failure": condition})+ return True++def authored_structure_signature_from_workflow(workflow_yaml: str | None,code_artifact_metadata: object = None,@@ -1062,6 +1116,7 @@ def recorded_outcome_from_run_blocks_result(authoritative_workflow_run_id = (recorded_run_outcome.workflow_run_id if recorded_run_outcome is not None else None) or workflow_run_id+ page_path_failure = _post_run_page_path_failure(page_evidence, authoritative_workflow_run_id or None)runtime_output_facts = _runtime_output_repair_facts(completion_verification,blocks,@@ -1175,6 +1230,7 @@ def recorded_outcome_from_run_blocks_result(evidence_refs=evidence_refs,missing_requested_output_facts=missing_output_facts,runtime_output_repair_facts=runtime_output_facts,+ page_path_failure=page_path_failure,authored_structure_signature=authored_structure_signature,observed_evidence_summary=recorded_run_outcome.display_reason or "",key_provenance={@@ -1183,6 +1239,7 @@ def recorded_outcome_from_run_blocks_result("evidence_refs": "run output structure","missing_requested_output_facts": "CompletionVerificationResult unsatisfied output paths and run output shape","runtime_output_repair_facts": "same-run registered output parameters and completion verdicts",+ "page_path_failure": "same-run bounded post-run page structure and executable continuations",},)run_status = _safe_str(data.get("overall_status"))@@ -1582,6 +1639,159 @@ def _page_evidence_refs(page_evidence: Mapping[str, object] | None) -> list[str]return refs[:12]+def _post_run_page_path_failure(+ page_evidence: Mapping[str, object] | None,+ workflow_run_id: str | None,+ *,+ required_target_url: str | None = None,+) -> PostRunPagePathFailure | None:+ if (+ page_evidence is None+ or not workflow_run_id+ or page_evidence.get("observed_after_workflow_run") is not True+ or page_evidence.get("workflow_run_id") != workflow_run_id+ ):+ return None+ current_url = _safe_str(page_evidence.get("current_url")) or _safe_str(page_evidence.get("inspected_url"))+ if not current_url:+ return None++ def collect_targets(kind: PostRunPagePathTargetKind, controls: object) -> list[PostRunPagePathTarget]:+ return [+ PostRunPagePathTarget(kind=kind, selector=selector)+ for control in _mapping_list(controls)+ if control.get("disabled") is not True and (selector := _safe_str(control.get("selector")).strip())+ ]++ def structural_submit_controls(+ controls: Sequence[Mapping[str, object]],+ ) -> list[Mapping[str, object]]:+ return [+ control+ for control in controls+ if control.get("disabled") is not True and _safe_str(control.get("type")).strip().casefold() == "submit"+ ]++ def structural_challenge_controls(+ controls: Sequence[Mapping[str, object]],+ ) -> list[Mapping[str, object]]:+ # Admission must never key on page text: labels are untrusted, page-controlled+ # input. Only carrier membership plus typed control structure may mint a target.+ enabled = [control for control in controls if control.get("disabled") is not True]+ toggles = [+ control+ for control in enabled+ if _safe_str(control.get("tag")).strip().casefold() == "input"+ and _safe_str(control.get("type")).strip().casefold() in {"checkbox", "radio"}+ and control.get("checked") is not True+ ]+ non_toggle_controls = [+ control+ for control in enabled+ if (+ _safe_str(control.get("tag")).strip().casefold() == "button"+ or (+ _safe_str(control.get("tag")).strip().casefold() == "input"+ and _safe_str(control.get("type")).strip().casefold() in {"button", "submit"}+ )+ )+ ]+ submit_controls = structural_submit_controls(non_toggle_controls)+ return [*toggles, *submit_controls]++ forms = _mapping_list(page_evidence.get("forms"))+ login_targets: list[PostRunPagePathTarget] = []+ for form in forms:+ fields = _mapping_list(form.get("fields"))+ has_password_field = any(_safe_str(field.get("type")).strip().casefold() == "password" for field in fields)+ if not has_password_field:+ continue+ login_targets.extend(+ collect_targets(+ "form_submit",+ structural_submit_controls(_mapping_list(form.get("submit_controls"))),+ )+ )++ challenge_state = page_evidence.get("challenge_state")+ challenge_targets: list[PostRunPagePathTarget] = []+ if isinstance(challenge_state, Mapping):+ gated_submit_controls = _mapping_list(challenge_state.get("gated_submit_controls"))+ challenge_targets.extend(collect_targets("challenge", gated_submit_controls))+ challenge_targets.extend(+ collect_targets(+ "challenge",+ structural_challenge_controls(+ interactive_challenge_controls(_mapping_list(page_evidence.get("challenge_controls")))+ ),+ )+ )++ navigation_targets: list[PostRunPagePathTarget] = []+ if required_target_url:+ for control in _mapping_list(page_evidence.get("navigation_targets")):+ if not _same_navigation_target_url(_safe_str(control.get("href")), required_target_url):+ continue+ navigation_targets.extend(collect_targets("navigation", [control]))++ challenge_associated = isinstance(challenge_state, Mapping) and (+ challenge_state.get("gates_submit_controls") is True or bool(challenge_targets)+ )+ if challenge_associated and challenge_targets:+ kind: PostRunPagePathKind = "challenge"+ targets = _dedupe_page_path_targets(challenge_targets)+ elif login_targets:+ kind = "login"+ targets = _dedupe_page_path_targets(login_targets)+ elif navigation_targets:+ kind = "incomplete_navigation"+ targets = _dedupe_page_path_targets(navigation_targets)+ else:+ kind = "non_page_outcome"+ targets = []+ return PostRunPagePathFailure(+ kind=kind,+ workflow_run_id=workflow_run_id,+ current_url=current_url,+ continuation_targets=targets,+ enter_allowed=kind in {"login", "challenge"}+ and any(target.kind in {"form_submit", "challenge"} for target in targets),+ )+++def _dedupe_page_path_targets(+ targets: Sequence[PostRunPagePathTarget],+) -> list[PostRunPagePathTarget]:+ deduped: list[PostRunPagePathTarget] = []+ seen: set[str] = set()+ for target in targets:+ if target.selector in seen:+ continue+ seen.add(target.selector)+ deduped.append(target)+ return deduped+++def _same_navigation_target_url(left: str, right: str) -> bool:+ if not left or not right:+ return False+ left_parts = urlsplit(left)+ right_parts = urlsplit(right)+ return (+ left_parts.scheme.casefold(),+ left_parts.netloc.casefold(),+ left_parts.path.rstrip("/") or "/",+ left_parts.query,+ left_parts.fragment,+ ) == (+ right_parts.scheme.casefold(),+ right_parts.netloc.casefold(),+ right_parts.path.rstrip("/") or "/",+ right_parts.query,+ right_parts.fragment,+ )++def _form_refs(value: object) -> list[str]:if not isinstance(value, list):return []diff --git a/skyvern/forge/sdk/copilot/challenge_evidence.py b/skyvern/forge/sdk/copilot/challenge_evidence.pyindex 7222bf3fc..a52f6c065 100644--- a/skyvern/forge/sdk/copilot/challenge_evidence.py+++ b/skyvern/forge/sdk/copilot/challenge_evidence.py@@ -4,7 +4,7 @@ values are not carriers, and a category without one is untrusted."""from __future__ import annotations-from collections.abc import Mapping+from collections.abc import Mapping, Sequencefrom enum import StrEnumfrom typing import Any@@ -103,11 +103,13 @@ ANTI_BOT_ARTIFACT_MARKER_VALUES: frozenset[str] = frozenset(_MAX_ARTIFACT_FLAG_DEPTH = 5-def interactive_challenge_controls(challenge_controls: list[dict[str, Any]] | None) -> list[dict[str, Any]]:+def interactive_challenge_controls(+ challenge_controls: Sequence[object] | None,+) -> list[Mapping[str, Any]]:return [controlfor control in challenge_controls or []- if isinstance(control, dict) and str(control.get("tag") or "").lower() not in _PASSIVE_CHALLENGE_TAGS+ if isinstance(control, Mapping) and str(control.get("tag") or "").lower() not in _PASSIVE_CHALLENGE_TAGS]diff --git a/skyvern/forge/sdk/copilot/composition_browser_expressions.py b/skyvern/forge/sdk/copilot/composition_browser_expressions.pyindex 0487b90b3..b743bce16 100644--- a/skyvern/forge/sdk/copilot/composition_browser_expressions.py+++ b/skyvern/forge/sdk/copilot/composition_browser_expressions.py@@ -486,7 +486,10 @@ for (const form of document.querySelectorAll('form')) {const submitControls = [];for (const node of form.querySelectorAll('input,select,textarea,button')) {const tag = (node.tagName || '').toLowerCase();- const fieldType = lower(attr(node, 'type') || tag || 'text');+ const declaredType = lower(attr(node, 'type'));+ const fieldType = tag === 'button'+ ? (['button', 'reset', 'submit'].includes(declaredType) ? declaredType : 'submit')+ : (declaredType || tag || 'text');if (tag === 'input' && (fieldType === 'hidden' || fieldType === 'reset')) continue;if (tag === 'button' || fieldType === 'submit' || fieldType === 'button') {submitControls.push({ text: nodeText(node) || attr(node, 'value'), name: attr(node, 'name'), id: attr(node, 'id'), value: attr(node, 'value'), class: classesFor(node), type: fieldType, disabled: controlDisabled(node), selector: selectorFor(node) });@@ -524,6 +527,12 @@ const clickableSelector = (el) => {return '';};const clickableText = (el) => nodeText(el) || attr(el, 'aria-label') || attr(el, 'value') || attr(el, 'title');+const elementVisible = (node) => {+ if (!node || !node.getBoundingClientRect) return false;+ let style; try { style = window.getComputedStyle(node); } catch (e) { return false; }+ const rect = node.getBoundingClientRect();+ return style.display !== 'none' && style.visibility !== 'hidden' && Number.parseFloat(style.opacity || '1') > 0.05 && rect.width > 0 && rect.height > 0;+};const usedClickableSelectors = new Set();for (const f of forms) for (const sc of (f.submit_controls || [])) if (sc.selector) usedClickableSelectors.add(sc.selector);for (const n of navTargets) if (n.selector) usedClickableSelectors.add(n.selector);@@ -533,6 +542,7 @@ for (const el of document.querySelectorAll('button,[role="button"],[data-action]if (clickableControls.length >= MAX_CLICKABLE_CONTROLS) break;const tag = (el.tagName || '').toLowerCase();if (SKIP_TAGS.has(tag)) continue;+ if (!elementVisible(el)) continue;if (el.closest && el.closest('form')) continue;const text = clickableText(el);const selector = clickableSelector(el);@@ -552,12 +562,6 @@ for (const el of document.querySelectorAll('button,[role="button"],[data-action]const resultContainers = [];let resultContainersTruncated = false;const selectorMatchCount = (selector) => { if (!selector) return 0; try { return document.querySelectorAll(selector).length; } catch (e) { return 0; } };-const elementVisible = (node) => {- if (!node || !node.getBoundingClientRect) return false;- let style; try { style = window.getComputedStyle(node); } catch (e) { return false; }- const rect = node.getBoundingClientRect();- return style.display !== 'none' && style.visibility !== 'hidden' && Number.parseFloat(style.opacity || '1') > 0.05 && rect.width > 0 && rect.height > 0;-};const resultRowTextIsContent = (s) => {const text = lower(String(s || '').replace(/\s+/g, ' ').trim());return !!text && !['0 results', 'no matching records', 'no records found', 'no results', 'no results found', 'nothing found'].some((p) => text.includes(p));@@ -669,15 +673,28 @@ for (const node of all) {const challengeControls = [];const seenChallenge = new Set();+const challengeIdentity = (node) => {+ const tag = (node.tagName || '').toLowerCase();+ return [tag, attr(node, 'id'), attr(node, 'name'), classesFor(node).join(' '), attr(node, 'src'), attr(node, 'type'), attr(node, 'data-sitekey'), attr(node, 'data-callback'), attr(node, 'data-expired-callback'), attr(node, 'data-error-callback'), attr(node, 'aria-label'), attr(node, 'title')].join(' ').toLowerCase();+};+const insideChallengeCarrier = (node) => {+ for (let ancestor = node.parentElement; ancestor; ancestor = ancestor.parentElement) {+ const identity = challengeIdentity(ancestor);+ if (ANTI_BOT_PATTERNS.some((p) => identity.includes(p))) return true;+ }+ return false;+};for (const node of all) {if (challengeControls.length >= MAX_CHALLENGE_CONTROLS) break;+ if (!elementVisible(node)) continue;const tag = (node.tagName || '').toLowerCase();- const identity = [tag, attr(node, 'id'), attr(node, 'name'), '', attr(node, 'src'), attr(node, 'type'), attr(node, 'data-sitekey'), attr(node, 'data-callback'), attr(node, 'data-expired-callback'), attr(node, 'data-error-callback'), attr(node, 'aria-label'), attr(node, 'title')].join(' ').toLowerCase();- if (!ANTI_BOT_PATTERNS.some((p) => identity.includes(p))) continue;+ const identity = challengeIdentity(node);+ const interactiveDescendant = ['a', 'button', 'input', 'select', 'textarea'].includes(tag) && insideChallengeCarrier(node);+ if (!ANTI_BOT_PATTERNS.some((p) => identity.includes(p)) && !interactiveDescendant) continue;const selector = selectorFor(node);if (seenChallenge.has(selector)) continue;seenChallenge.add(selector);- const entry = { tag: tag, id: attr(node, 'id'), name: attr(node, 'name'), class: classesFor(node), type: attr(node, 'type'), selector: selector, text: nodeText(node) || attr(node, 'aria-label') };+ const entry = { tag: tag, id: attr(node, 'id'), name: attr(node, 'name'), class: classesFor(node), type: attr(node, 'type'), selector: selector, text: nodeText(node) || attr(node, 'value') || attr(node, 'aria-label'), checked: !!node.checked, disabled: controlDisabled(node) };for (const k of ['src', 'title', 'data-sitekey', 'data-callback', 'data-expired-callback', 'data-error-callback']) {const v = attr(node, k);if (v) entry[k.split('-').join('_')] = v;diff --git a/skyvern/forge/sdk/copilot/composition_evidence.py b/skyvern/forge/sdk/copilot/composition_evidence.pyindex c0f8bc177..d2e97c644 100644--- a/skyvern/forge/sdk/copilot/composition_evidence.py+++ b/skyvern/forge/sdk/copilot/composition_evidence.py@@ -1694,15 +1694,23 @@ def _result_container_entry(node: Any, *, soup: Any) -> dict[str, Any]:def _challenge_control_entry(node: Any) -> dict[str, Any]:tag_name = str(getattr(node, "name", "") or "").lower()+ control_type = _attr_value(node, "type")[:40]entry: dict[str, Any] = {"tag": tag_name,"id": _attr_value(node, "id")[:120],"name": _attr_value(node, "name")[:120],"class": " ".join(_classes_for(node)[:5])[:160],- "type": _attr_value(node, "type")[:40],+ "type": control_type,"selector": _selector_for(node)[:160],- "text": _schema_text(_node_text(node) or _attr_value(node, "aria-label"), 200),+ "text": _schema_text(+ _node_text(node) or _attr_value(node, "value") or _attr_value(node, "aria-label"),+ 200,+ ),}+ if tag_name == "input" and control_type.casefold() in {"checkbox", "radio"}:+ entry["checked"] = node.has_attr("checked")+ if _control_disabled(node):+ entry["disabled"] = Truefor key in ("src", "title", "data-sitekey", "data-callback", "data-expired-callback", "data-error-callback"):value = _attr_value(node, key)if value:@@ -1710,30 +1718,44 @@ def _challenge_control_entry(node: Any) -> dict[str, Any]:return {key: value for key, value in entry.items() if value}+def _challenge_identity(node: Any) -> str:+ return " ".join(+ str(value or "")+ for value in (+ getattr(node, "name", ""),+ _attr_value(node, "id"),+ _attr_value(node, "name"),+ " ".join(_classes_for(node)),+ _attr_value(node, "src"),+ _attr_value(node, "type"),+ _attr_value(node, "data-sitekey"),+ _attr_value(node, "data-callback"),+ _attr_value(node, "data-expired-callback"),+ _attr_value(node, "data-error-callback"),+ _attr_value(node, "aria-label"),+ _attr_value(node, "title"),+ )+ ).lower()+++def _is_interactive_challenge_descendant(node: Any) -> bool:+ if str(getattr(node, "name", "") or "").lower() not in {"a", "button", "input", "select", "textarea"}:+ return False+ return any(+ any(pattern in _challenge_identity(ancestor) for pattern in _ANTI_BOT_PATTERNS)+ for ancestor in getattr(node, "parents", [])+ )++def _challenge_controls(soup: Any) -> list[dict[str, Any]]:controls: list[dict[str, Any]] = []seen_selectors: set[str] = set()for node in soup.find_all(True):if len(controls) >= _MAX_CHALLENGE_CONTROLS:break- identity = " ".join(- str(value or "")- for value in (- getattr(node, "name", ""),- _attr_value(node, "id"),- _attr_value(node, "name"),- _attr_value(node, "class"),- _attr_value(node, "src"),- _attr_value(node, "type"),- _attr_value(node, "data-sitekey"),- _attr_value(node, "data-callback"),- _attr_value(node, "data-expired-callback"),- _attr_value(node, "data-error-callback"),- _attr_value(node, "aria-label"),- _attr_value(node, "title"),- )- ).lower()- if not any(pattern in identity for pattern in _ANTI_BOT_PATTERNS):+ if not any(pattern in _challenge_identity(node) for pattern in _ANTI_BOT_PATTERNS) and not (+ _is_interactive_challenge_descendant(node)+ ):continue# A widget inside a hidden ancestor (solved/stale challenge markup) may# trigger the visual fallback but must not read as a rendered control.@@ -1933,7 +1955,12 @@ def parse_composition_html(html: str, *, inspected_url: str, current_url: str) -submit_controls: list[dict[str, Any]] = []for node in form.find_all(["input", "select", "textarea", "button"]):tag_name = str(getattr(node, "name", "") or "").lower()- field_type = str(node.get("type") or tag_name or "text").lower()+ declared_type = str(node.get("type") or "").strip().lower()+ field_type = (+ (declared_type if declared_type in {"button", "reset", "submit"} else "submit")+ if tag_name == "button"+ else (declared_type or tag_name or "text")+ )if tag_name == "input" and field_type in {"hidden", "reset"}:continueif tag_name == "button" or field_type in {"submit", "button"}:@@ -2377,6 +2404,10 @@ def _structured_challenge_controls(value: Any) -> list[dict[str, Any]]:"selector": _structured_str(node.get("selector"))[:160],"text": _schema_text(_structured_str(node.get("text")), 200),}+ if node.get("checked") is True:+ entry["checked"] = True+ if node.get("disabled") is True:+ entry["disabled"] = Truefor key in ("src", "title", "data_sitekey", "data_callback", "data_expired_callback", "data_error_callback"):field_value = _structured_str(node.get(key)).strip()if field_value:diff --git a/skyvern/forge/sdk/copilot/enforcement.py b/skyvern/forge/sdk/copilot/enforcement.pyindex 8c1a5e1f7..3e940c088 100644--- a/skyvern/forge/sdk/copilot/enforcement.py+++ b/skyvern/forge/sdk/copilot/enforcement.py@@ -30,6 +30,7 @@ from skyvern.forge.sdk.copilot.blocker_signal import ()from skyvern.forge.sdk.copilot.build_phase import DISCOVERY_PERMITTED_PHASESfrom skyvern.forge.sdk.copilot.build_test_outcome import (+ PostRunPagePathFailure,RecordedBuildTestOutcome,author_time_reject_missing_output_paths,latest_recorded_build_test_outcome_repeated,@@ -141,6 +142,7 @@ from skyvern.forge.sdk.copilot.run_outcome import (from skyvern.forge.sdk.copilot.runtime import (AgentContext,AuthorTimeGateAblationPayload,+ PostRunPagePathInteractionWindow,record_author_time_gate_ablation_event,)from skyvern.forge.sdk.copilot.screenshot_utils import ScreenshotEntry@@ -162,6 +164,8 @@ from skyvern.forge.sdk.copilot.turn_ownership import (TurnClaimant,claim_and_stash_blocker_signal,claim_turn,+ claimant_outranks,+ current_turn_owner,emit_blocker_signal_payload,)from skyvern.forge.sdk.copilot.unrecoverable_tool_error import (@@ -252,6 +256,7 @@ _SYNTHESIZED_BLOCK_PERSISTENCE_MUTATING_TOOLS = frozenset(# for either or an update_workflow re-author silently spends the one-shot rescout._SYNTHESIZED_BLOCK_REAUTHORING_TOOLS = frozenset({SYNTHESIZED_BLOCK_PERSISTENCE_TOOL, "update_workflow"})_SYNTHESIZED_BLOCK_COMMIT_TOOLS = frozenset({"click", "press_key"})+_POST_RUN_PAGE_PATH_INTERACTION_BUDGET = 4_LOGIN_SUBMIT_NAME_PATTERN = re.compile(r"^(?:log in|login|sign in|authenticate)(?: now| securely| to continue)?$",re.I,@@ -3297,11 +3302,142 @@ def _should_block_tool_after_unresolved_recorded_outcome(ctx: Any, tool_name: streturn _completion_verification_unsatisfied(ctx)+def _post_run_page_path_tool_allowed(+ condition: PostRunPagePathFailure,+ tool_name: str,+ arguments: Mapping[str, Any] | None,+) -> bool:+ if not condition.is_page_path or not isinstance(arguments, Mapping):+ return False+ selectors = {target.selector for target in condition.continuation_targets}+ if tool_name == "click":+ selector = arguments.get("selector")+ return isinstance(selector, str) and selector in selectors+ if tool_name != "press_key" or arguments.get("key") != "Enter" or not condition.enter_allowed:+ return False+ selector = arguments.get("selector")+ enter_selectors = {+ target.selector for target in condition.continuation_targets if target.kind in {"form_submit", "challenge"}+ }+ return isinstance(selector, str) and selector in enter_selectors+++def _latest_scout_trajectory_index(ctx: CopilotContext) -> int:+ return max(+ (+ trajectory_index+ for interaction in ctx.scout_trajectory+ if isinstance((trajectory_index := interaction.get("trajectory_index")), int)+ ),+ default=-1,+ )+++def _post_run_page_path_successful_interactions(+ ctx: CopilotContext,+ window: PostRunPagePathInteractionWindow,+) -> int:+ return sum(+ 1+ for interaction in ctx.scout_trajectory+ if isinstance((trajectory_index := interaction.get("trajectory_index")), int)+ and trajectory_index > window.trajectory_anchor+ and str(interaction.get("tool_name") or "") in _SYNTHESIZED_BLOCK_COMMIT_TOOLS+ )+++def _post_run_page_path_admission_state(+ ctx: CopilotContext,+ tool_name: str,+ arguments: Mapping[str, Any] | None,+) -> tuple[PostRunPagePathInteractionWindow, str, str, int, int] | None:+ if not _should_block_tool_after_unresolved_recorded_outcome(ctx, tool_name):+ return None+ latest = ctx.latest_recorded_build_test_outcome+ if latest is None:+ return None+ condition = latest.page_path_failure+ if condition is None or not _post_run_page_path_tool_allowed(condition, tool_name, arguments):+ return None+ structural_key = latest.structural_key+ workflow_run_id = latest.workflow_run_id+ if not structural_key or not workflow_run_id:+ return None+ if (+ ctx.post_run_page_observation_after_failed_test is not True+ or ctx.post_run_page_observation_tool not in _POST_RUN_PAGE_OBSERVATION_TOOLS+ or ctx.post_run_page_observation_workflow_run_id != workflow_run_id+ or ctx.post_run_page_observation_url != condition.current_url+ or condition.workflow_run_id != workflow_run_id+ or ctx.last_run_blocks_workflow_run_id != workflow_run_id+ ):+ return None+ window = ctx.post_run_page_path_interaction_window+ if window is None or (window.structural_key, window.workflow_run_id) != (structural_key, workflow_run_id):+ window = PostRunPagePathInteractionWindow(+ structural_key=structural_key,+ workflow_run_id=workflow_run_id,+ trajectory_anchor=_latest_scout_trajectory_index(ctx),+ )+ successful_interactions = _post_run_page_path_successful_interactions(ctx, window)+ observation_generation = ctx.post_run_page_observation_generation+ if window.admitted_attempts >= _POST_RUN_PAGE_PATH_INTERACTION_BUDGET or (+ successful_interactions > window.observed_successful_interactions+ and observation_generation <= window.observation_generation+ ):+ return None+ owner = current_turn_owner(ctx)+ if (+ owner is not None+ and owner.claimant is not TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION+ and not claimant_outranks(TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION, owner.claimant)+ ):+ return None+ return window, structural_key, workflow_run_id, successful_interactions, observation_generation+++def post_run_page_path_interaction_allowed(+ ctx: CopilotContext,+ tool_name: str,+ arguments: Mapping[str, Any] | None,+) -> bool:+ return _post_run_page_path_admission_state(ctx, tool_name, arguments) is not None+++def try_admit_post_run_page_path_interaction(+ ctx: CopilotContext,+ tool_name: str,+ arguments: Mapping[str, Any] | None,+) -> bool:+ state = _post_run_page_path_admission_state(ctx, tool_name, arguments)+ if state is None:+ return False+ window, structural_key, workflow_run_id, successful_interactions, observation_generation = state+ if claim_turn(ctx, TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION) is ClaimOutcome.YIELDED:+ return False+ ctx.post_run_page_path_interaction_window = replace(+ window,+ admitted_attempts=window.admitted_attempts + 1,+ observation_generation=observation_generation,+ observed_successful_interactions=successful_interactions,+ )+ LOG.info(+ "copilot post-run page-path interaction admitted",+ tool_name=tool_name,+ selector=arguments.get("selector") if isinstance(arguments, Mapping) else None,+ structural_key=structural_key,+ workflow_run_id=workflow_run_id,+ admitted_attempts=window.admitted_attempts + 1,+ observation_generation=observation_generation,+ )+ return True++def synthesized_block_persistence_signal(ctx: Any, tool_name: str, arguments: Mapping[str, Any] | None = None) -> CopilotToolBlockerSignal | None:if _should_block_tool_after_unresolved_recorded_outcome(ctx, tool_name):- return CopilotToolBlockerSignal(+ signal = CopilotToolBlockerSignal(blocker_kind="tool_error",agent_steering_text=("The last recorded test outcome is authoritative and still has unsatisfied completion criteria. "@@ -3317,6 +3453,9 @@ def synthesized_block_persistence_signal(blocked_tool=tool_name,extra={"recorded_outcome_reason_code": "outcome_not_demonstrated"},)+ if try_admit_post_run_page_path_interaction(ctx, tool_name, arguments):+ return None+ return signalif tool_name in _SYNTHESIZED_BLOCK_PERSISTENCE_ALLOWED_TOOLS:return Noneambiguous_selector_rescout_state = _ambiguous_bare_selector_rescout_signal_state(ctx, tool_name)diff --git a/skyvern/forge/sdk/copilot/mcp_adapter.py b/skyvern/forge/sdk/copilot/mcp_adapter.pyindex 9178ef175..2388e2d15 100644--- a/skyvern/forge/sdk/copilot/mcp_adapter.py+++ b/skyvern/forge/sdk/copilot/mcp_adapter.py@@ -35,9 +35,11 @@ from skyvern.forge.sdk.copilot.blocker_signal import ()from skyvern.forge.sdk.copilot.build_phase import _phase_blocker_signalfrom skyvern.forge.sdk.copilot.enforcement import (+ post_run_page_path_interaction_allowed,register_no_progress_interaction_click,synthesized_block_persistence_signal,terminal_challenge_blocker_signal_from_current_page_evidence,+ try_admit_post_run_page_path_interaction,)from skyvern.forge.sdk.copilot.loop_detection import (detect_failed_tool_step_loop_for_ctx,@@ -81,6 +83,9 @@ _POST_HOOK_CONTEXT_ROLLBACK_FIELDS = ("post_run_page_observation_tool","post_run_page_observation_url","post_run_page_observation_workflow_run_id",+ "post_run_page_observation_after_failed_test",+ "post_run_page_observation_generation",+ "latest_recorded_build_test_outcome","code_only_target_page_evidence_seen","last_evaluate_actionable_signature","last_evaluate_actionable_url",@@ -456,7 +461,12 @@ class SkyvernOverlayMCPServer(MCPServer):return _copilot_to_call_tool_result({"ok": False, "error": payload})refresh_held_loop_blocker_evidence(copilot_ctx)- if tool_name in _CURRENT_PAGE_TERMINAL_CHALLENGE_MCP_TOOLS:+ post_run_page_path_allowed = post_run_page_path_interaction_allowed(+ copilot_ctx,+ tool_name,+ arguments,+ )+ if not post_run_page_path_allowed and tool_name in _CURRENT_PAGE_TERMINAL_CHALLENGE_MCP_TOOLS:terminal_challenge_payload = _stash_and_emit_current_page_terminal_challenge_blocker(copilot_ctx,tool_name,@@ -468,7 +478,11 @@ class SkyvernOverlayMCPServer(MCPServer):)return _copilot_to_call_tool_result({"ok": False, "error": terminal_challenge_payload})- persistence_signal = synthesized_block_persistence_signal(copilot_ctx, tool_name, arguments)+ persistence_signal = (+ None+ if post_run_page_path_allowed+ else synthesized_block_persistence_signal(copilot_ctx, tool_name, arguments)+ )if persistence_signal is not None:LOG.warning("Synthesized block persistence required before MCP tool",@@ -509,6 +523,18 @@ class SkyvernOverlayMCPServer(MCPServer):record_tool_step_result_for_ctx(copilot_ctx, tool_name, arguments, hook_result)return _copilot_to_call_tool_result(hook_result)+ if post_run_page_path_allowed and not try_admit_post_run_page_path_interaction(+ copilot_ctx,+ tool_name,+ arguments,+ ):+ persistence_signal = synthesized_block_persistence_signal(copilot_ctx, tool_name, arguments)+ if persistence_signal is not None:+ payload = emit_blocker_signal_payload(copilot_ctx, persistence_signal)+ result = {"ok": False, "error": payload}+ record_tool_step_result_for_ctx(copilot_ctx, tool_name, arguments, result)+ return _copilot_to_call_tool_result(result)+mcp_name = self._alias_map.get(tool_name, tool_name)mcp_args = _transform_args(arguments, overlay)diff --git a/skyvern/forge/sdk/copilot/runtime.py b/skyvern/forge/sdk/copilot/runtime.pyindex b1c1cb020..74d4ce8c9 100644--- a/skyvern/forge/sdk/copilot/runtime.py+++ b/skyvern/forge/sdk/copilot/runtime.py@@ -307,6 +307,16 @@ class NeverCapturedObligation:replay_payload: NeverCapturedReplayPayload | None = None+@dataclass(frozen=True)+class PostRunPagePathInteractionWindow:+ structural_key: str+ workflow_run_id: str+ trajectory_anchor: int+ admitted_attempts: int = 0+ observation_generation: int = 0+ observed_successful_interactions: int = 0++@dataclassclass AgentContext:organization_id: str@@ -470,6 +480,8 @@ class AgentContext:post_run_page_observation_url: str | None = Nonepost_run_page_observation_workflow_run_id: str | None = Nonepost_run_page_observation_after_failed_test: bool = False+ post_run_page_observation_generation: int = 0+ post_run_page_path_interaction_window: PostRunPagePathInteractionWindow | None = Nonepost_run_current_page_inspection_workflow_run_id: str | None = Nonelast_evaluate_actionable_signature: str | None = Nonelast_evaluate_actionable_url: str | None = Nonediff --git a/skyvern/forge/sdk/copilot/tools/completion.py b/skyvern/forge/sdk/copilot/tools/completion.pyindex c50d89c45..30f56e78e 100644--- a/skyvern/forge/sdk/copilot/tools/completion.py+++ b/skyvern/forge/sdk/copilot/tools/completion.py@@ -591,7 +591,7 @@ async def _maybe_run_completion_verification_from_page_observation(title: str = "",observed_data: object | None = None,) -> CompletionVerificationResult | None:- """Verify completion only for post-run page observations after failed tests."""+ """Verify completion only after failed or authoritative-unsatisfied runs."""existing = getattr(copilot_ctx, "completion_verification_result", None)if isinstance(existing, CompletionVerificationResult) and existing.is_fully_satisfied():diff --git a/skyvern/forge/sdk/copilot/tools/composition_capture.py b/skyvern/forge/sdk/copilot/tools/composition_capture.pyindex 21b7d0c41..6bb2ca997 100644--- a/skyvern/forge/sdk/copilot/tools/composition_capture.py+++ b/skyvern/forge/sdk/copilot/tools/composition_capture.py@@ -855,7 +855,12 @@ async def _inspect_page_for_composition_impl(run_id = getattr(copilot_ctx, "last_run_blocks_workflow_run_id", None)if isinstance(run_id, str) and run_id:evidence = store_post_run_page_evidence(copilot_ctx, evidence, run_id=run_id, current_url=current_url)- _mark_post_run_page_observed(copilot_ctx, source_tool="inspect_page_for_composition", url=current_url)+ _mark_post_run_page_observed(+ copilot_ctx,+ source_tool="inspect_page_for_composition",+ url=current_url,+ page_evidence=evidence,+ )else:copilot_ctx.composition_page_evidence = evidencediff --git a/skyvern/forge/sdk/copilot/tools/page_observation.py b/skyvern/forge/sdk/copilot/tools/page_observation.pyindex 69eaaab94..e59ffa6ba 100644--- a/skyvern/forge/sdk/copilot/tools/page_observation.py+++ b/skyvern/forge/sdk/copilot/tools/page_observation.py@@ -348,7 +348,6 @@ def _record_composition_page_observation() -> int | None:if not url:return None- _mark_post_run_page_observed(ctx, source_tool=source_tool, url=url)if title:_workflow_verification_evidence(ctx).page_title = title[:160]existing = ctx.composition_page_evidence@@ -382,6 +381,12 @@ def _record_composition_page_observation(if isinstance(run_id, str) and run_id:evidence["workflow_run_id"] = run_idevidence["observed_after_workflow_run"] = True+ _mark_post_run_page_observed(+ ctx,+ source_tool=source_tool,+ url=url,+ page_evidence=evidence if has_bounded_page_schema(evidence) else None,+ )observation_step: int | None = Noneif append_to_flow and has_bounded_page_schema(evidence):diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.pyindex 8be3dbaa3..7ae32ccd7 100644--- a/skyvern/forge/sdk/copilot/tools/run_execution.py+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py@@ -3386,7 +3386,12 @@ def _mark_stored_post_run_failure_page(copilot_ctx: Any) -> None:if not post_run_inspection_cleanly_matches(evidence, run_id):returnurl = evidence.get("current_url") or evidence.get("inspected_url") or ""- _mark_post_run_page_observed(copilot_ctx, source_tool="inspect_page_for_composition", url=url)+ _mark_post_run_page_observed(+ copilot_ctx,+ source_tool="inspect_page_for_composition",+ url=url,+ page_evidence=evidence,+ )page_title = evidence.get("page_title")if isinstance(page_title, str) and page_title:_workflow_verification_evidence(copilot_ctx).page_title = page_title[:160]diff --git a/skyvern/forge/sdk/copilot/tools/scouting.py b/skyvern/forge/sdk/copilot/tools/scouting.pyindex 181898e04..4a7918fa6 100644--- a/skyvern/forge/sdk/copilot/tools/scouting.py+++ b/skyvern/forge/sdk/copilot/tools/scouting.py@@ -13,6 +13,8 @@ import structlogfrom skyvern.config import settingsfrom skyvern.forge.sdk.copilot.build_test_outcome import (+ RecordedBuildTestOutcome,+ bind_post_run_page_path_failure,record_build_test_outcome,recorded_outcome_from_loaded_result_evidence,recorded_outcome_from_scout_act_observe_hollow,@@ -1019,6 +1021,7 @@ async def _register_scout_interaction_observation(record_scouted_output_coverage(ctx, parsed, contract=contract, include_lexical=has_actionable_steer_content(parsed))+ _mark_post_run_page_observed(ctx, source_tool="evaluate", url=url, page_evidence=parsed)# The schema is already attached; leaving the marker set would let a# later evaluate/inspect mint a second interaction credit for one click._clear_pending_browser_interaction_observation(ctx)@@ -1747,14 +1750,41 @@ async def _steer_evaluate_result(ctx: AgentContext, result: dict[str, Any], *, u)-def _mark_post_run_page_observed(ctx: AgentContext, *, source_tool: str, url: str) -> None:+def _mark_post_run_page_observed(+ ctx: AgentContext,+ *,+ source_tool: str,+ url: str,+ page_evidence: dict[str, Any] | None = None,+) -> None:run_id = getattr(ctx, "last_run_blocks_workflow_run_id", None)if not isinstance(run_id, str) or not run_id:returnctx.post_run_page_observation_tool = source_toolctx.post_run_page_observation_url = urlctx.post_run_page_observation_workflow_run_id = run_id- ctx.post_run_page_observation_after_failed_test = getattr(ctx, "last_test_ok", None) is False+ latest_outcome = getattr(ctx, "latest_recorded_build_test_outcome", None)+ authoritative_unsatisfied = (+ isinstance(latest_outcome, RecordedBuildTestOutcome)+ and latest_outcome.is_authoritative+ and latest_outcome.phase == "persisted_block_run"+ and latest_outcome.reason_code == "outcome_not_demonstrated"+ and latest_outcome.workflow_run_id == run_id+ )+ ctx.post_run_page_observation_after_failed_test = (+ getattr(ctx, "last_test_ok", None) is False or authoritative_unsatisfied+ )+ if page_evidence is not None and ctx.post_run_page_observation_after_failed_test:+ bound_evidence = {+ **page_evidence,+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": url,+ }+ if bind_post_run_page_path_failure(ctx, bound_evidence):+ ctx.post_run_page_observation_generation = (+ getattr(ctx, "post_run_page_observation_generation", 0) or 0+ ) + 1evidence = _workflow_verification_evidence(ctx)evidence.live_page_state_verified = Trueevidence.verified_from_current_browser_state = Truediff --git a/skyvern/forge/sdk/copilot/turn_ownership.py b/skyvern/forge/sdk/copilot/turn_ownership.pyindex e15ef8d2d..1caa1eebd 100644--- a/skyvern/forge/sdk/copilot/turn_ownership.py+++ b/skyvern/forge/sdk/copilot/turn_ownership.py@@ -41,6 +41,7 @@ class TurnClaimant(StrEnum):METADATA_RUN_PREFLIGHT_REJECT = "metadata_run_preflight_reject"ACTUATION_OBLIGATION_FILL = "actuation_obligation_fill"ACTUATION_OBLIGATION_LOGIN_COMPLETION = "actuation_obligation_login_completion"+ POST_RUN_PAGE_PATH_INTERACTION = "post_run_page_path_interaction"CAPTURE_OBLIGATION_REOPEN = "capture_obligation_reopen"CREDENTIAL_SCOUT_REOPEN = "credential_scout_reopen"UNCOVERED_OUTPUT_RESCOUT_STEER = "uncovered_output_rescout_steer"@@ -75,6 +76,8 @@ _PRECEDENCE_ORDER: tuple[TurnClaimant, ...] = (# Login-completion carve-out admits the submit and 2FA-confirm interactions the admitted fills# began; predicate-gated at its call site and bounded by the post-credential commit.TurnClaimant.ACTUATION_OBLIGATION_LOGIN_COMPLETION,+ # Post-run page-path repair admits only its outcome-bound click/Enter window.+ TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION,# A never-captured obligation admits only the exact canonical interaction that can satisfy it.TurnClaimant.CAPTURE_OBLIGATION_REOPEN,# One-shot credential-scout reopen admits evaluate through the persistence gate;@@ -106,6 +109,7 @@ CLAIMANT_REASON_CODE_FAMILIES: dict[TurnClaimant, frozenset[str]] = {TurnClaimant.METADATA_RUN_PREFLIGHT_REJECT: frozenset(),TurnClaimant.ACTUATION_OBLIGATION_FILL: frozenset(),TurnClaimant.ACTUATION_OBLIGATION_LOGIN_COMPLETION: frozenset(),+ TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION: frozenset(),TurnClaimant.CAPTURE_OBLIGATION_REOPEN: frozenset(),TurnClaimant.CREDENTIAL_SCOUT_REOPEN: frozenset(),TurnClaimant.UNCOVERED_OUTPUT_RESCOUT_STEER: frozenset({UNCOVERED_OUTPUT_RESCOUT_STEER_REASON_CODE}),@@ -136,6 +140,7 @@ _TRANSIENT_CLAIMANTS = frozenset(TurnClaimant.METADATA_RUN_PREFLIGHT_REJECT,TurnClaimant.ACTUATION_OBLIGATION_FILL,TurnClaimant.ACTUATION_OBLIGATION_LOGIN_COMPLETION,+ TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION,TurnClaimant.CAPTURE_OBLIGATION_REOPEN,TurnClaimant.CREDENTIAL_SCOUT_REOPEN,}diff --git a/tests/unit/test_copilot_agent_helpers.py b/tests/unit/test_copilot_agent_helpers.pyindex fd06f54c8..c17940316 100644--- a/tests/unit/test_copilot_agent_helpers.py+++ b/tests/unit/test_copilot_agent_helpers.py@@ -33,7 +33,11 @@ from skyvern.forge.sdk.copilot.authoring_parameter_binding import ()from skyvern.forge.sdk.copilot.blocker_signal import CopilotToolBlockerSignalfrom skyvern.forge.sdk.copilot.build_phase import BuildPhase-from skyvern.forge.sdk.copilot.build_test_outcome import RecordedBuildTestOutcome+from skyvern.forge.sdk.copilot.build_test_outcome import (+ PostRunPagePathFailure,+ PostRunPagePathTarget,+ RecordedBuildTestOutcome,+)from skyvern.forge.sdk.copilot.code_block_preflight import SANDBOX_UNRESOLVED_NAME_REASON_CODEfrom skyvern.forge.sdk.copilot.completion_criteria_store import (StoredCriteriaSet,@@ -1042,6 +1046,80 @@ workflow_definition:assert "page_evidence_refs: form:Search #search, result:#results rows=unknown" in promptassert "change the next authored step, selector, extraction, or binding based on" in prompt+ def test_recorded_build_test_outcome_prompt_renders_exact_post_run_page_path_actions(self) -> None:+ ctx = _ctx(+ block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,+ latest_recorded_build_test_outcome=RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id="wr_failed",+ structural_failure_identity="completion:page-path",+ page_path_failure=PostRunPagePathFailure(+ kind="challenge",+ workflow_run_id="wr_failed",+ current_url="https://example.test/challenge",+ continuation_targets=(+ PostRunPagePathTarget(kind="challenge", selector="#notRobot"),+ PostRunPagePathTarget(kind="challenge", selector="#continue"),+ ),+ enter_allowed=True,+ ),+ ),+ )++ prompt = agent_module._recorded_build_test_outcome_prompt(ctx)++ assert "POST-RUN PAGE-PATH CONTINUATION:" in prompt+ assert "kind: challenge" in prompt+ assert "- allowed click: selector=#notRobot" in prompt+ assert "- allowed Enter: selector=#continue" in prompt+ assert "Do not navigate away or re-author the workflow" in prompt++ def test_recorded_build_test_outcome_prompt_requires_fresh_inspection_when_page_path_is_unbound(self) -> None:+ ctx = _ctx(+ block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,+ latest_recorded_build_test_outcome=RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id="wr_failed",+ structural_failure_identity="completion:page-path",+ ),+ )++ prompt = agent_module._recorded_build_test_outcome_prompt(ctx)++ assert "POST-RUN PAGE-PATH CONTRACT UNBOUND:" in prompt+ assert 'inspect_page_for_composition with target_url="current_page"' in prompt+ assert "Do not use evaluate as a substitute" in prompt++ def test_recorded_build_test_outcome_prompt_does_not_offer_page_actions_for_non_page_outcome(self) -> None:+ ctx = _ctx(+ block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,+ latest_recorded_build_test_outcome=RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id="wr_failed",+ structural_failure_identity="completion:non-page",+ page_path_failure=PostRunPagePathFailure(+ kind="non_page_outcome",+ workflow_run_id="wr_failed",+ current_url="https://example.test/results",+ continuation_targets=(),+ ),+ ),+ )++ prompt = agent_module._recorded_build_test_outcome_prompt(ctx)++ assert "POST-RUN PAGE-PATH CONTINUATION:" not in prompt+ assert "POST-RUN PAGE-PATH CONTRACT UNBOUND:" not in prompt+def test_recorded_build_test_outcome_prompt_renders_exact_missing_output_paths(self) -> None:ctx = _ctx(block_authoring_policy=BlockAuthoringPolicy.CODE_ONLY_BROWSER,diff --git a/tests/unit/test_copilot_composition_evidence.py b/tests/unit/test_copilot_composition_evidence.pyindex 861e91e54..2b1135dff 100644--- a/tests/unit/test_copilot_composition_evidence.py+++ b/tests/unit/test_copilot_composition_evidence.py@@ -170,6 +170,28 @@ def test_composition_parse_html_extracts_labeled_fields_and_submit_controls() ->assert parsed["source_tool"] == "inspect_page_for_composition"+def test_composition_parse_html_records_effective_button_submit_types() -> None:+ parsed = parse_composition_html(+ """+ <html><body>+ <form>+ <input type="password" id="password" />+ <button id="sign-in">Sign in</button>+ <button id="delete-account" type="button">Delete account</button>+ <button id="reset" type="reset">Reset</button>+ </form>+ </body></html>+ """,+ inspected_url="https://example.com/login",+ current_url="https://example.com/login",+ )++ controls_by_id = {control["id"]: control for control in parsed["forms"][0]["submit_controls"]}+ assert controls_by_id["sign-in"]["type"] == "submit"+ assert controls_by_id["delete-account"]["type"] == "button"+ assert controls_by_id["reset"]["type"] == "reset"++def test_composition_parse_html_excludes_css_hidden_text_from_visible_excerpt() -> None:parsed = parse_composition_html("""@@ -658,6 +680,37 @@ def test_composition_parse_html_excludes_challenge_controls_inside_hidden_ancestassert composition_challenge_carrier(parsed) == ChallengeEvidenceSource.CHALLENGE_STATE+def test_composition_parse_html_surfaces_interactive_descendants_of_challenge_carrier() -> None:+ parsed = parse_composition_html(+ """+ <html><head><title>Login Confirmation</title></head><body>+ <div data-challenge-state="captcha_pending" data-captcha-widget="login-confirmation"+ aria-label="Login confirmation challenge">+ <h1>Login Confirmation</h1>+ <div class="challenge">+ <input type="checkbox" id="notRobot" />+ <label for="notRobot">I'm not a robot</label>+ </div>+ <button class="btn-primary">Continue</button>+ <button class="goback">Go back to login</button>+ <button id="disabled" disabled>Verify</button>+ <span style="display: none"><button id="hidden">Continue</button></span>+ </div>+ </body></html>+ """,+ inspected_url="https://example.com/challenge",+ current_url="https://example.com/challenge",+ )++ selectors = {control["selector"] for control in parsed["challenge_controls"]}+ assert {"#notRobot", "button.btn-primary", "button.goback"}.issubset(selectors)+ assert "#hidden" not in selectors+ assert (+ next(control for control in parsed["challenge_controls"] if control["selector"] == "#disabled")["disabled"]+ is True+ )++def test_composition_parse_html_passed_challenge_markup_escalates_without_assertion() -> None:parsed = parse_composition_html("""@@ -2970,6 +3023,70 @@ async def test_structured_extractor_matches_html_parser_on_live_dom() -> None:assert any(overlay["selector"] == "#signup" for overlay in structured["modal_overlays"])+@_skip_no_browser+async def test_structured_extractor_records_effective_button_submit_types() -> None:+ url = "https://test.example.com/login"+ html = """+ <html><body>+ <form>+ <input type="password" id="password" />+ <button id="sign-in">Sign in</button>+ <button id="delete-account" type="button">Delete account</button>+ <button id="reset" type="reset">Reset</button>+ </form>+ </body></html>+ """+ raw, content = await _capture_live_dom(url, html, "#sign-in")++ structured = parse_composition_structured(json.loads(raw), inspected_url=url, current_url=url)+ html_parsed = parse_composition_html(content, inspected_url=url, current_url=url)++ assert structured is not None+ structured_types = {control["id"]: control["type"] for control in structured["forms"][0]["submit_controls"]}+ html_types = {control["id"]: control["type"] for control in html_parsed["forms"][0]["submit_controls"]}+ assert (+ structured_types+ == html_types+ == {+ "sign-in": "submit",+ "delete-account": "button",+ "reset": "reset",+ }+ )+++@_skip_no_browser+async def test_structured_extractor_matches_class_only_challenge_carrier_controls() -> None:+ url = "https://test.example.com/challenge"+ html = """+ <html><head><title>Verify</title></head><body>+ <div class="captcha-container">+ <input id="human" type="checkbox" />+ <button id="continue">Continue</button>+ <input id="verify" type="submit" value="Verify" />+ <button id="disabled" disabled>Verify</button>+ <span style="display: none"><button id="hidden">Continue</button></span>+ </div>+ </body></html>+ """+ raw, content = await _capture_live_dom(url, html, "#continue")++ structured = parse_composition_structured(json.loads(raw), inspected_url=url, current_url=url)+ html_parsed = parse_composition_html(content, inspected_url=url, current_url=url)++ assert structured is not None+ assert _ac_projection(structured) == _ac_projection(html_parsed)+ selectors = {control["selector"] for control in structured["challenge_controls"]}+ assert {"#human", "#continue", "#verify", "#disabled"}.issubset(selectors)+ assert "#hidden" not in selectors+ assert (+ next(control for control in structured["challenge_controls"] if control["selector"] == "#disabled")["disabled"]+ is True+ )++_HEAVY_URL = "https://test.example.com/cart"diff --git a/tests/unit/test_copilot_enforcement_pruning.py b/tests/unit/test_copilot_enforcement_pruning.pyindex 626660bb1..f79f3cdd2 100644--- a/tests/unit/test_copilot_enforcement_pruning.py+++ b/tests/unit/test_copilot_enforcement_pruning.py@@ -24,8 +24,12 @@ from skyvern.forge.sdk.copilot.blocker_signal import (stash_blocker_signal,)from skyvern.forge.sdk.copilot.build_test_outcome import (+ PostRunPagePathFailure,+ PostRunPagePathTarget,RecordedBuildTestOutcome,+ _post_run_page_path_failure,author_time_reject_missing_output_paths,+ bind_post_run_page_path_failure,recorded_outcome_from_author_time_reject,)from skyvern.forge.sdk.copilot.code_block_synthesis import SynthesizedCodeBlock@@ -70,6 +74,8 @@ from skyvern.forge.sdk.copilot.enforcement import ()from skyvern.forge.sdk.copilot.mcp_adapter import (_POST_HOOK_CONTEXT_ROLLBACK_FIELDS,+ SchemaOverlay,+ SkyvernOverlayMCPServer,_restore_post_hook_context,_snapshot_post_hook_context,)@@ -85,13 +91,18 @@ from skyvern.forge.sdk.copilot.streaming_adapter import _update_enforcement_fromfrom skyvern.forge.sdk.copilot.tools import (_INTERNAL_RUN_CANCELLED_BY_WATCHDOG_KEY,_analyze_run_blocks,+ _click_post_hook,_is_meaningful_extracted_data,+ _press_key_post_hook,_record_run_blocks_result,_record_workflow_update_result,+ mcp_hooks,)+from skyvern.forge.sdk.copilot.tools.page_observation import _record_composition_page_observationfrom skyvern.forge.sdk.copilot.tools.scouting import (_MAX_SCOUTED_INTERACTIONS,_capped_with_eviction_accounting,+ _mark_post_run_page_observed,_record_scout_page_observation,)from skyvern.forge.sdk.copilot.turn_halt import stash_turn_halt_from_blocker_signal@@ -153,11 +164,20 @@ class _Ctx:self.scout_observed_terminal_criterion_ids: set[str] = set()self.scout_observation_contract: object | None = Noneself.flow_evidence: list[dict[str, object]] = []+ self.composition_page_evidence = Noneself.copilot_config: CopilotConfig | None = Noneself.uncovered_output_rescout_context_key = Noneself.uncovered_output_rescout_steer_key = Noneself.latest_recorded_build_test_outcome = Noneself.last_run_blocks_workflow_run_id = None+ self.post_run_page_observation_tool = None+ self.post_run_page_observation_url = None+ self.post_run_page_observation_workflow_run_id = None+ self.post_run_page_observation_after_failed_test = False+ self.post_run_page_observation_generation = 0+ self.post_run_page_path_interaction_window = None+ self.workflow_yaml = ""+ self.workflow_verification_evidence = WorkflowVerificationEvidence()self.completion_criteria_turn_state = Noneself.reached_download_target: ReachedDownloadTarget | None = Noneself.author_time_gate_log_only_ids: frozenset[str] = frozenset()@@ -769,6 +789,939 @@ class TestSynthesizedOfferPersistenceGate:assert synthesized_block_persistence_signal(ctx, "update_and_run_blocks") is Noneassert synthesized_block_persistence_signal(ctx, "evaluate") is None+ def _post_run_page_path_ctx(+ self,+ *,+ workflow_run_id: str = "wr_129160000000000001",+ structural_failure_identity: str = "completion:page-path",+ trajectory: list[dict[str, object]] | None = None,+ page_path_failure: PostRunPagePathFailure | None = None,+ ) -> _Ctx:+ ctx = _Ctx()+ ctx.turn_intent = TurnIntent(+ mode=TurnIntentMode.BUILD,+ authority=TurnIntentAuthority(may_update_workflow=True, may_run_blocks=True),+ )+ ctx.block_authoring_policy = BlockAuthoringPolicy.CODE_ONLY_BROWSER+ ctx.completion_verification_result = self._unsatisfied_verification()+ ctx.latest_recorded_build_test_outcome = RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id=workflow_run_id,+ structural_failure_identity=structural_failure_identity,+ page_path_failure=page_path_failure+ or PostRunPagePathFailure(+ kind="challenge",+ workflow_run_id=workflow_run_id,+ current_url="https://example.test/challenge",+ continuation_targets=[+ PostRunPagePathTarget(kind="challenge", selector="#continue"),+ PostRunPagePathTarget(kind="challenge", selector="#token"),+ PostRunPagePathTarget(kind="challenge", selector="#missing"),+ ],+ enter_allowed=True,+ ),+ )+ ctx.last_run_blocks_workflow_run_id = workflow_run_id+ ctx.post_run_page_observation_tool = "evaluate"+ ctx.post_run_page_observation_url = "https://example.test/challenge"+ ctx.post_run_page_observation_workflow_run_id = workflow_run_id+ ctx.post_run_page_observation_after_failed_test = True+ ctx.post_run_page_observation_generation = 1+ ctx.scout_trajectory = trajectory or []+ return ctx++ @pytest.mark.asyncio+ async def test_post_run_page_path_admission_uses_existing_hooks_to_record_click_and_enter(+ self,+ monkeypatch: pytest.MonkeyPatch,+ ) -> None:+ async def no_role_name(*_args: object, **_kwargs: object) -> tuple[str, str]:+ return "", ""++ async def no_observation(*_args: object, **_kwargs: object) -> tuple[None, None]:+ return None, None++ monkeypatch.setattr(mcp_hooks, "_resolve_scout_role_name", no_role_name)+ monkeypatch.setattr(mcp_hooks, "_register_scout_interaction_observation", no_observation)+ ctx = make_copilot_context()+ qualified = self._post_run_page_path_ctx()+ for field in (+ "turn_intent",+ "block_authoring_policy",+ "completion_verification_result",+ "latest_recorded_build_test_outcome",+ "last_run_blocks_workflow_run_id",+ "post_run_page_observation_tool",+ "post_run_page_observation_url",+ "post_run_page_observation_workflow_run_id",+ "post_run_page_observation_after_failed_test",+ ):+ setattr(ctx, field, getattr(qualified, field))++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ ctx.pending_scout_source_url = "https://example.test/challenge"+ await _click_post_hook(+ {"ok": True, "data": {"selector": "#continue"}},+ {"browser_context": {"url": "https://example.test/mfa", "title": "MFA"}},+ ctx,+ )+ assert [(item["tool_name"], item["trajectory_index"]) for item in ctx.scout_trajectory] == [("click", 0)]++ enter_ctx = make_copilot_context()+ qualified = self._post_run_page_path_ctx()+ for field in (+ "turn_intent",+ "block_authoring_policy",+ "completion_verification_result",+ "latest_recorded_build_test_outcome",+ "last_run_blocks_workflow_run_id",+ "post_run_page_observation_tool",+ "post_run_page_observation_url",+ "post_run_page_observation_workflow_run_id",+ "post_run_page_observation_after_failed_test",+ "post_run_page_observation_generation",+ ):+ setattr(enter_ctx, field, getattr(qualified, field))+ assert (+ synthesized_block_persistence_signal(+ enter_ctx,+ "press_key",+ {"key": "Enter", "selector": "#token"},+ )+ is None+ )+ enter_ctx.pending_scout_source_url = "https://example.test/challenge"+ await _press_key_post_hook(+ {"ok": True, "data": {"selector": "#token", "key": "Enter"}},+ {"browser_context": {"url": "https://example.test/dashboard", "title": "Dashboard"}},+ enter_ctx,+ )+ assert [(item["tool_name"], item["trajectory_index"]) for item in enter_ctx.scout_trajectory] == [+ ("press_key", 0)+ ]+ assert ctx.turn_ownership is not None+ assert TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION in ctx.turn_ownership.claims+ assert enter_ctx.turn_ownership is not None+ assert TurnClaimant.POST_RUN_PAGE_PATH_INTERACTION in enter_ctx.turn_ownership.claims+ assert isinstance(+ synthesized_block_persistence_signal(ctx, "click", {"selector": "#unrelated"}),+ CopilotToolBlockerSignal,+ )++ @pytest.mark.asyncio+ async def test_post_run_page_path_admission_precedes_only_matching_current_page_challenge_action(+ self,+ ) -> None:+ class RawResult:+ structured_content = {"ok": True, "data": {"selector": "#continue"}}+ is_error = False+ content: list[object] = []++ class RecordingClient:+ def __init__(self) -> None:+ self.calls: list[tuple[str, dict[str, object]]] = []++ async def call_tool(+ self,+ name: str,+ arguments: dict[str, object],+ raise_on_error: bool = False,+ ) -> RawResult:+ self.calls.append((name, arguments))+ return RawResult()++ def challenge_ctx() -> Any:+ ctx = make_copilot_context()+ qualified = self._post_run_page_path_ctx()+ for field in (+ "turn_intent",+ "block_authoring_policy",+ "completion_verification_result",+ "latest_recorded_build_test_outcome",+ "last_run_blocks_workflow_run_id",+ "post_run_page_observation_tool",+ "post_run_page_observation_url",+ "post_run_page_observation_workflow_run_id",+ "post_run_page_observation_after_failed_test",+ "post_run_page_observation_generation",+ ):+ setattr(ctx, field, getattr(qualified, field))+ ctx.composition_page_evidence = {+ "observed_after_workflow_run": True,+ "workflow_run_id": "wr_129160000000000001",+ "challenge_state": {+ "detected": True,+ "kind": "verification",+ "requires_human_verification": True,+ "gates_submit_controls": True,+ },+ "challenge_controls": [{"selector": "#continue", "interactive": True}],+ }+ return ctx++ admitted_ctx = challenge_ctx()+ admitted_client = RecordingClient()+ admitted_server = SkyvernOverlayMCPServer(+ transport=MagicMock(),+ overlays={"click": SchemaOverlay()},+ alias_map={},+ allowlist=frozenset(),+ context_provider=lambda: admitted_ctx,+ )+ admitted_server._client = admitted_client++ admitted = await admitted_server.call_tool("click", {"selector": "#continue"})++ assert admitted.isError is False+ assert admitted_client.calls == [("click", {"selector": "#continue"})]+ assert admitted_ctx.turn_halt is None++ blocked_ctx = challenge_ctx()+ blocked_client = RecordingClient()+ blocked_server = SkyvernOverlayMCPServer(+ transport=MagicMock(),+ overlays={"click": SchemaOverlay()},+ alias_map={},+ allowlist=frozenset(),+ context_provider=lambda: blocked_ctx,+ )+ blocked_server._client = blocked_client++ blocked = await blocked_server.call_tool("click", {"selector": "#unrelated"})++ assert blocked.isError is True+ assert blocked_client.calls == []+ assert blocked_ctx.turn_halt is not None++ terminal_ctx = challenge_ctx()+ terminal_signal = CopilotToolBlockerSignal(+ blocker_kind="tool_error",+ agent_steering_text="The current page is a terminal challenge.",+ user_facing_reason="I could not continue past the site challenge.",+ recovery_hint="report_blocker_to_user",+ cleared_by_tools=frozenset(),+ preserves_workflow_draft=True,+ renders_final_reply=True,+ internal_reason_code="probable_site_block_stop",+ blocked_tool="click",+ )+ assert stash_turn_halt_from_blocker_signal(terminal_ctx, terminal_signal, source="test") is not None+ terminal_client = RecordingClient()+ terminal_server = SkyvernOverlayMCPServer(+ transport=MagicMock(),+ overlays={"click": SchemaOverlay()},+ alias_map={},+ allowlist=frozenset(),+ context_provider=lambda: terminal_ctx,+ )+ terminal_server._client = terminal_client++ terminal = await terminal_server.call_tool("click", {"selector": "#continue"})++ assert terminal.isError is True+ assert terminal_client.calls == []+ assert terminal_ctx.turn_halt.blocker_signal == terminal_signal+ assert terminal_ctx.post_run_page_path_interaction_window is None++ @pytest.mark.asyncio+ async def test_post_run_page_path_pre_hook_rejection_does_not_spend_admission_budget(self) -> None:+ class RecordingClient:+ calls: list[tuple[str, dict[str, object]]] = []++ async def call_tool(+ self,+ name: str,+ arguments: dict[str, object],+ raise_on_error: bool = False,+ ) -> None:+ self.calls.append((name, arguments))++ async def reject_before_dispatch(+ _arguments: dict[str, Any],+ _ctx: Any,+ ) -> dict[str, object]:+ return {"ok": False, "error": "pre-dispatch rejection"}++ ctx = make_copilot_context()+ qualified = self._post_run_page_path_ctx()+ for field in (+ "turn_intent",+ "block_authoring_policy",+ "completion_verification_result",+ "latest_recorded_build_test_outcome",+ "last_run_blocks_workflow_run_id",+ "post_run_page_observation_tool",+ "post_run_page_observation_url",+ "post_run_page_observation_workflow_run_id",+ "post_run_page_observation_after_failed_test",+ "post_run_page_observation_generation",+ ):+ setattr(ctx, field, getattr(qualified, field))+ client = RecordingClient()+ server = SkyvernOverlayMCPServer(+ transport=MagicMock(),+ overlays={"click": SchemaOverlay(pre_hook=reject_before_dispatch)},+ alias_map={},+ allowlist=frozenset(),+ context_provider=lambda: ctx,+ )+ server._client = client++ result = await server.call_tool("click", {"selector": "#continue"})++ assert result.isError is True+ assert client.calls == []+ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_admission_requires_typed_page_path_failure_contract(self) -> None:+ ctx = self._post_run_page_path_ctx(+ page_path_failure=PostRunPagePathFailure(+ kind="non_page_outcome",+ workflow_run_id="wr_129160000000000001",+ current_url="https://example.test/challenge",+ continuation_targets=[],+ enter_allowed=False,+ )+ )+ expected_ctx = self._post_run_page_path_ctx()+ expected_ctx.post_run_page_observation_after_failed_test = False+ expected = synthesized_block_persistence_signal(expected_ctx, "click", {"selector": "#continue"})++ blocked = synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"})++ assert isinstance(expected, CopilotToolBlockerSignal)+ assert isinstance(blocked, CopilotToolBlockerSignal)+ assert blocked.model_dump() == expected.model_dump()+ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_contract_mints_only_structured_current_page_continuations(self) -> None:+ run_id = "wr_129160000000000001"+ base_evidence = {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/login",+ "forms": [+ {+ "fields": [{"type": "password", "selector": "#password"}],+ "submit_controls": [{"type": "submit", "selector": "#continue"}],+ }+ ],+ }++ page_path = _post_run_page_path_failure(base_evidence, run_id)+ non_page = _post_run_page_path_failure(+ {+ **base_evidence,+ "forms": [],+ "navigation_targets": [{"selector": "#settings"}],+ "result_containers": [{"selector": "#results"}],+ },+ run_id,+ )++ assert page_path is not None+ assert page_path.kind == "login"+ assert page_path.continuation_targets == (PostRunPagePathTarget(kind="form_submit", selector="#continue"),)+ assert page_path.enter_allowed is True+ assert non_page is not None+ assert non_page.kind == "non_page_outcome"+ assert non_page.continuation_targets == ()++ def test_post_run_page_path_contract_mints_only_structural_password_form_submits(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/login",+ "forms": [+ {+ "fields": [{"type": "password", "selector": "#password"}],+ "submit_controls": [+ {"type": "submit", "text": "Sign in", "selector": "#sign-in"},+ {"type": "button", "text": "Delete account", "selector": "#delete-account"},+ {"type": "button", "text": "Cancel", "selector": "#cancel"},+ ],+ }+ ],+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "login"+ assert condition.continuation_targets == (PostRunPagePathTarget(kind="form_submit", selector="#sign-in"),)+ assert condition.enter_allowed is True++ def test_post_run_page_path_contract_requires_explicit_navigation_and_challenge_association(self) -> None:+ run_id = "wr_129160000000000001"+ base_evidence = {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/interstitial",+ "forms": [+ {+ "fields": [{"type": "search", "selector": "#query"}],+ "submit_controls": [{"selector": "#delete"}],+ }+ ],+ "clickable_controls": [{"selector": "#delete"}],+ "navigation_targets": [+ {"selector": "#settings", "href": "https://example.test/settings"},+ {"selector": "#continue", "href": "https://example.test/report"},+ ],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": False,+ "gated_submit_controls": [],+ },+ }++ unrelated = _post_run_page_path_failure(base_evidence, run_id)+ navigation = _post_run_page_path_failure(+ base_evidence,+ run_id,+ required_target_url="https://example.test/report",+ )++ assert unrelated is not None+ assert unrelated.kind == "non_page_outcome"+ assert unrelated.continuation_targets == ()+ assert navigation is not None+ assert navigation.kind == "incomplete_navigation"+ assert navigation.continuation_targets == (PostRunPagePathTarget(kind="navigation", selector="#continue"),)++ def test_post_run_page_path_contract_distinguishes_hash_route_navigation_targets(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/app#/login",+ "navigation_targets": [+ {"selector": "#settings", "href": "https://example.test/app#/settings"},+ {"selector": "#delete", "href": "https://example.test/app#/delete"},+ ],+ },+ run_id,+ required_target_url="https://example.test/app#/settings",+ )++ assert condition is not None+ assert condition.kind == "incomplete_navigation"+ assert condition.continuation_targets == (PostRunPagePathTarget(kind="navigation", selector="#settings"),)++ def test_post_run_page_path_contract_excludes_unrelated_form_submit_from_challenge(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "forms": [{"submit_controls": [{"selector": "#newsletter"}]}],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": True,+ "gated_submit_controls": [{"selector": "#continue"}],+ },+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "challenge"+ assert condition.continuation_targets == (PostRunPagePathTarget(kind="challenge", selector="#continue"),)++ def test_post_run_page_path_contract_does_not_bind_selectorless_label_to_form_control(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "forms": [+ {+ "submit_controls": [+ {"text": "Delete account", "selector": "#delete-account"},+ {"text": "Subscribe", "selector": "#newsletter"},+ ]+ }+ ],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": True,+ "gated_submit_controls": [{"text": "Delete account", "disabled": True}],+ },+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "non_page_outcome"+ assert condition.continuation_targets == ()++ def test_post_run_page_path_contract_keeps_structurally_proven_challenge_descendants_only(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "challenge_controls": [+ {"tag": "div", "selector": "div", "text": "Login confirmation challenge"},+ {"tag": "input", "type": "checkbox", "selector": "#notRobot", "checked": False},+ {"tag": "input", "type": "checkbox", "selector": "#alreadyChecked", "checked": True},+ {"tag": "button", "type": "submit", "selector": "button.btn-primary", "text": "Continue"},+ {"tag": "button", "selector": "button.goback", "text": "Go back to login"},+ {"tag": "button", "selector": "#delete", "text": "Delete account"},+ {"tag": "button", "selector": "#disabled", "text": "Verify", "disabled": True},+ {"tag": "a", "selector": "#privacy", "text": "Privacy policy"},+ {"tag": "textarea", "selector": "#notes", "text": "Notes"},+ ],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": False,+ "gated_submit_controls": [],+ },+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "challenge"+ assert condition.continuation_targets == (+ PostRunPagePathTarget(kind="challenge", selector="#notRobot"),+ PostRunPagePathTarget(kind="challenge", selector="button.btn-primary"),+ )++ def test_post_run_page_path_contract_does_not_admit_lone_destructive_challenge_control(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "challenge_controls": [+ {"tag": "div", "selector": "#challenge-carrier"},+ {"tag": "button", "selector": "#zurueck", "text": "Zurück zur Anmeldung"},+ ],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": False,+ "gated_submit_controls": [],+ },+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "non_page_outcome"+ assert condition.continuation_targets == ()++ def test_post_run_page_path_contract_rejects_ambiguous_loose_challenge_buttons(self) -> None:+ run_id = "wr_129160000000000001"+ condition = _post_run_page_path_failure(+ {+ "workflow_run_id": run_id,+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "challenge_controls": [+ {"tag": "div", "selector": "#challenge-carrier"},+ {"tag": "button", "selector": "#weiter", "text": "Weiter"},+ {"tag": "button", "selector": "#bestaetigen", "text": "Bestätigen"},+ ],+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": False,+ "gated_submit_controls": [],+ },+ },+ run_id,+ )++ assert condition is not None+ assert condition.kind == "non_page_outcome"+ assert condition.continuation_targets == ()++ def test_post_run_page_path_contract_does_not_change_structural_identity_across_runs(self) -> None:+ def outcome(run_id: str) -> RecordedBuildTestOutcome:+ return RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id=run_id,+ structural_failure_identity="completion:page-path",+ page_path_failure=PostRunPagePathFailure(+ kind="challenge",+ workflow_run_id=run_id,+ current_url=f"https://example.test/challenge?run={run_id}",+ continuation_targets=[PostRunPagePathTarget(kind="challenge", selector="#continue")],+ ),+ )++ assert outcome("wr_129160000000000001").structural_key == outcome("wr_129160000000000002").structural_key++ def test_post_run_observation_binds_typed_failure_to_existing_authoritative_outcome(self) -> None:+ ctx = self._post_run_page_path_ctx()+ ctx.latest_recorded_build_test_outcome = ctx.latest_recorded_build_test_outcome.model_copy(+ update={"page_path_failure": None}+ )+ ctx.last_test_ok = True+ ctx.post_run_page_observation_generation = 0+ page_evidence = {+ "workflow_run_id": "wr_129160000000000001",+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/challenge",+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": True,+ "gated_submit_controls": [{"selector": "#continue"}],+ },+ }++ _mark_post_run_page_observed(+ ctx,+ source_tool="inspect_page_for_composition",+ url="https://example.test/challenge",+ page_evidence=page_evidence,+ )++ assert ctx.post_run_page_observation_generation == 1+ assert ctx.latest_recorded_build_test_outcome.page_path_failure == PostRunPagePathFailure(+ kind="challenge",+ workflow_run_id="wr_129160000000000001",+ current_url="https://example.test/challenge",+ continuation_targets=[PostRunPagePathTarget(kind="challenge", selector="#continue")],+ enter_allowed=True,+ )+ assert ctx.post_run_page_observation_after_failed_test is True++ def test_post_run_page_path_binding_replaces_stale_target_with_fresh_page_contract(self) -> None:+ ctx = self._post_run_page_path_ctx()++ bind_post_run_page_path_failure(+ ctx,+ {+ "workflow_run_id": "wr_129160000000000001",+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/mfa",+ "forms": [+ {+ "fields": [{"type": "password", "selector": "#token"}],+ "submit_controls": [{"type": "submit", "selector": "#verify"}],+ }+ ],+ },+ )++ condition = ctx.latest_recorded_build_test_outcome.page_path_failure+ assert condition is not None+ assert condition.current_url == "https://example.test/mfa"+ assert condition.continuation_targets == (PostRunPagePathTarget(kind="form_submit", selector="#verify"),)++ def test_schema_empty_screenshot_does_not_replace_post_run_page_path_contract(self) -> None:+ ctx = self._post_run_page_path_ctx()+ original = ctx.latest_recorded_build_test_outcome.page_path_failure++ _record_composition_page_observation(+ ctx,+ source_tool="get_browser_screenshot",+ url="https://example.test/challenge",+ title="Challenge",+ )++ assert ctx.latest_recorded_build_test_outcome.page_path_failure == original+ assert ctx.post_run_page_observation_generation == 1++ def test_post_run_page_path_admission_rejects_non_page_verification_failure(self) -> None:+ ctx = self._post_run_page_path_ctx(page_path_failure=None)+ ctx.latest_recorded_build_test_outcome = ctx.latest_recorded_build_test_outcome.model_copy(+ update={"page_path_failure": None}+ )++ blocked = synthesized_block_persistence_signal(ctx, "press_key", {"key": "Enter", "selector": "#continue"})++ assert isinstance(blocked, CopilotToolBlockerSignal)+ assert blocked.internal_reason_code == SYNTHESIZED_BLOCK_PERSISTENCE_REASON_CODE+ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_admission_requires_current_page_contract_url(self) -> None:+ ctx = self._post_run_page_path_ctx()+ ctx.post_run_page_observation_url = "https://example.test/other"++ blocked = synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"})++ assert isinstance(blocked, CopilotToolBlockerSignal)+ assert blocked.internal_reason_code == SYNTHESIZED_BLOCK_PERSISTENCE_REASON_CODE+ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_admission_rejects_click_outside_recorded_continuation(self) -> None:+ ctx = self._post_run_page_path_ctx()++ for arguments in (+ None,+ {},+ {"selector": ""},+ {"selector": "#unrelated"},+ {"selector": "button:contains('Continue')"},+ ):+ blocked = synthesized_block_persistence_signal(ctx, "click", arguments)+ assert isinstance(blocked, CopilotToolBlockerSignal)++ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_admission_rejects_blast_radius_sibling_without_contract(self) -> None:+ ctx = self._post_run_page_path_ctx()+ ctx.latest_recorded_build_test_outcome = ctx.latest_recorded_build_test_outcome.model_copy(+ update={"page_path_failure": None}+ )++ for tool_name, arguments in (("click", {"selector": "#continue"}), ("press_key", {"key": "Enter"})):+ blocked = synthesized_block_persistence_signal(ctx, tool_name, arguments)+ assert isinstance(blocked, CopilotToolBlockerSignal)+ assert blocked.internal_reason_code == SYNTHESIZED_BLOCK_PERSISTENCE_REASON_CODE++ def test_post_run_page_path_invalid_click_does_not_spend_admission_budget(self) -> None:+ ctx = self._post_run_page_path_ctx()++ blocked = synthesized_block_persistence_signal(ctx, "click", {"selector": "#not-recorded"})++ assert isinstance(blocked, CopilotToolBlockerSignal)+ assert ctx.post_run_page_path_interaction_window is None+ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ assert ctx.post_run_page_path_interaction_window.admitted_attempts == 1++ def test_post_run_page_path_admission_is_same_run_and_argument_exact(self) -> None:+ ctx = self._post_run_page_path_ctx()++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ assert (+ synthesized_block_persistence_signal(+ ctx,+ "press_key",+ {"key": "Enter", "selector": "#token"},+ )+ is None+ )+ assert ctx.post_run_page_path_interaction_window.admitted_attempts == 2+ for malformed in (+ None,+ {},+ {"key": "Enter"},+ {"key": "enter", "selector": "#token"},+ {"key": " Enter ", "selector": "#token"},+ {"key": 1, "selector": "#token"},+ {"key": "Enter", "selector": "#unrelated"},+ ):+ assert isinstance(+ synthesized_block_persistence_signal(ctx, "press_key", malformed),+ CopilotToolBlockerSignal,+ )+ assert isinstance(+ synthesized_block_persistence_signal(ctx, "type_text", {"selector": "#token", "text": "123456"}),+ CopilotToolBlockerSignal,+ )++ ctx.post_run_page_observation_workflow_run_id = "wr_129160000000000099"+ assert isinstance(+ synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}),+ CopilotToolBlockerSignal,+ )++ ctx = self._post_run_page_path_ctx()+ ctx.latest_recorded_build_test_outcome = ctx.latest_recorded_build_test_outcome.model_copy(+ update={"workflow_run_id": None}+ )+ assert isinstance(+ synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}),+ CopilotToolBlockerSignal,+ )+ assert ctx.post_run_page_path_interaction_window is None++ def test_post_run_page_path_window_anchors_after_stale_trajectory(self) -> None:+ stale_reached_trajectory = [+ {"tool_name": "click", "selector": "#open", "trajectory_index": 3},+ {"tool_name": "click", "selector": "#submit", "trajectory_index": 4},+ ]+ ctx = self._post_run_page_path_ctx(trajectory=stale_reached_trajectory)++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ assert ctx.post_run_page_path_interaction_window.trajectory_anchor == 4+ assert ctx.post_run_page_path_interaction_window.admitted_attempts == 1++ def test_post_run_page_path_success_requires_fresh_observation_and_closes_on_completed_page(self) -> None:+ ctx = self._post_run_page_path_ctx()++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ ctx.scout_trajectory.append(+ {+ "tool_name": "click",+ "selector": "#continue",+ "source_url": "https://example.test/challenge",+ "trajectory_index": 0,+ }+ )+ expected_ctx = self._post_run_page_path_ctx()+ expected_ctx.post_run_page_observation_after_failed_test = False+ expected = synthesized_block_persistence_signal(expected_ctx, "click", {"selector": "#continue"})++ stale = synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"})++ assert isinstance(expected, CopilotToolBlockerSignal)+ assert isinstance(stale, CopilotToolBlockerSignal)+ assert stale.model_dump() == expected.model_dump()++ ctx.last_test_ok = False+ _mark_post_run_page_observed(+ ctx,+ source_tool="evaluate",+ url="https://example.test/dashboard",+ page_evidence={+ "workflow_run_id": "wr_129160000000000001",+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/dashboard",+ "result_containers": [{"selector": "#results"}],+ },+ )++ completed = synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"})+ assert isinstance(completed, CopilotToolBlockerSignal)+ assert completed.model_dump() == expected.model_dump()++ def test_post_run_page_path_fresh_observation_supports_three_steps_without_resetting_budget(self) -> None:+ ctx = self._post_run_page_path_ctx()++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}) is None+ ctx.scout_trajectory.append(+ {+ "tool_name": "click",+ "selector": "#continue",+ "source_url": "https://example.test/challenge",+ "trajectory_index": 0,+ }+ )+ ctx.last_test_ok = False+ _mark_post_run_page_observed(+ ctx,+ source_tool="evaluate",+ url="https://example.test/mfa",+ page_evidence={+ "workflow_run_id": "wr_129160000000000001",+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/mfa",+ "forms": [+ {+ "fields": [{"type": "password", "selector": "#token"}],+ "submit_controls": [{"type": "submit", "selector": "#verify"}],+ }+ ],+ },+ )++ assert isinstance(+ synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"}),+ CopilotToolBlockerSignal,+ )+ assert (+ synthesized_block_persistence_signal(+ ctx,+ "press_key",+ {"key": "Enter", "selector": "#verify"},+ )+ is None+ )+ assert ctx.post_run_page_path_interaction_window.admitted_attempts == 2+ ctx.scout_trajectory.append(+ {+ "tool_name": "press_key",+ "selector": "#verify",+ "key": "Enter",+ "source_url": "https://example.test/mfa",+ "trajectory_index": 1,+ }+ )+ _mark_post_run_page_observed(+ ctx,+ source_tool="inspect_page_for_composition",+ url="https://example.test/confirmation",+ page_evidence={+ "workflow_run_id": "wr_129160000000000001",+ "observed_after_workflow_run": True,+ "current_url": "https://example.test/confirmation",+ "challenge_state": {+ "detected": True,+ "gates_submit_controls": True,+ "gated_submit_controls": [{"selector": "#confirm"}],+ },+ },+ )++ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#confirm"}) is None+ assert ctx.post_run_page_path_interaction_window.admitted_attempts == 3++ def test_post_run_page_path_window_charges_failed_attempts_and_resets_for_new_identity(self) -> None:+ ctx = self._post_run_page_path_ctx()++ for _ in range(4):+ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#missing"}) is None+ expected_blocker_ctx = self._post_run_page_path_ctx()+ expected_blocker_ctx.post_run_page_observation_after_failed_test = False+ expected = synthesized_block_persistence_signal(expected_blocker_ctx, "click", {"selector": "#missing"})+ exhausted = synthesized_block_persistence_signal(ctx, "click", {"selector": "#missing"})+ assert isinstance(expected, CopilotToolBlockerSignal)+ assert isinstance(exhausted, CopilotToolBlockerSignal)+ assert exhausted.model_dump() == expected.model_dump()++ ctx.latest_recorded_build_test_outcome = RecordedBuildTestOutcome(+ phase="persisted_block_run",+ attempted_tool="update_and_run_blocks",+ verdict="repairable_failure",+ reason_code="outcome_not_demonstrated",+ workflow_run_id="wr_129160000000000002",+ structural_failure_identity="completion:new-page-path",+ page_path_failure=PostRunPagePathFailure(+ kind="incomplete_navigation",+ workflow_run_id="wr_129160000000000002",+ current_url="https://example.test/challenge",+ continuation_targets=[+ PostRunPagePathTarget(kind="navigation", selector="#missing"),+ ],+ ),+ )+ ctx.last_run_blocks_workflow_run_id = "wr_129160000000000002"+ ctx.post_run_page_observation_workflow_run_id = "wr_129160000000000002"+ ctx.scout_trajectory = [+ {"tool_name": "click", "selector": f"#evicted-{index}", "trajectory_index": index}+ for index in range(80, 100)+ ]+ for _ in range(4):+ assert synthesized_block_persistence_signal(ctx, "click", {"selector": "#missing"}) is None+ assert ctx.post_run_page_path_interaction_window.trajectory_anchor == 99++ def test_post_run_page_path_admission_yields_to_terminal_owner_without_spending_budget(self) -> None:+ ctx = self._post_run_page_path_ctx()+ terminal_signal = CopilotToolBlockerSignal(+ blocker_kind="tool_error",+ agent_steering_text="The current page is a terminal challenge.",+ user_facing_reason="I could not continue past the site challenge.",+ recovery_hint="report_blocker_to_user",+ cleared_by_tools=frozenset(),+ preserves_workflow_draft=True,+ renders_final_reply=True,+ internal_reason_code="probable_site_block_stop",+ blocked_tool="click",+ )+ assert stash_turn_halt_from_blocker_signal(ctx, terminal_signal, source="test") is not None++ signal = synthesized_block_persistence_signal(ctx, "click", {"selector": "#continue"})++ assert isinstance(signal, CopilotToolBlockerSignal)+ assert ctx.post_run_page_path_interaction_window is None+@pytest.mark.parametrize("ctx_attrs",[