Skip to content

Automate browser based workflows with AI

Commit a single filtered AngularJS ui-select match during text input (#8425)

LawyZheng36f58c78f4a2
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index b47098f30..c482f1520 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -1850,16 +1850,17 @@ def _make_agent_result(
unresolved_failure = None
detector_disposition = "not_evaluated"
if ctx is not None and note_eligible:
- # Only the workflow the user can actually run clears a failure. A staged proposal may be
- # shown, tested, or auto-applied later, but this terminal is assembled before the route
- # commits it, so at claim time it is not yet what anyone would run. `workflow_was_persisted`
- # records a mid-turn canonical write that can still be rolled back, so it proves nothing here.
+ # Only the workflow the user can actually run clears a failure, and while one is saved a
+ # staged proposal is not it: this terminal is assembled before the route commits the proposal,
+ # and `workflow_was_persisted` records a mid-turn write that can still be rolled back. With
+ # nothing saved there is no such workflow, so a run's own receipts stand in -- hence the
+ # persisted flag below, which says that is what an absent report means here.
# Deliberately a different question from the tested pill above, which judges the proposal:
# both can hold at once, and a turn that repairs a block it authored this turn will say the
# draft tested clean while its saved workflow still carries the failure.
reported_workflow_yaml = ctx.persisted_workflow_yaml
unresolved_failure, detector_disposition = unresolved_runtime_block_failure_with_disposition(
- ctx, reported_workflow_yaml=reported_workflow_yaml
+ ctx, reported_workflow_yaml=reported_workflow_yaml, reported_workflow_is_persisted=True
)
if ctx is not None and history_has_runtime_block_failure(ctx):
# A turn that sets a runtime failure aside otherwise leaves no record of having done so, which
diff --git a/skyvern/forge/sdk/copilot/build_test_outcome.py b/skyvern/forge/sdk/copilot/build_test_outcome.py
index d12e81728..d6f6c6a1f 100644
--- a/skyvern/forge/sdk/copilot/build_test_outcome.py
+++ b/skyvern/forge/sdk/copilot/build_test_outcome.py
@@ -11,7 +11,7 @@ from urllib.parse import urlsplit
import structlog
import yaml
-from pydantic import BaseModel, ConfigDict, Field, JsonValue, field_validator, model_validator
+from pydantic import BaseModel, ConfigDict, Field, JsonValue, ValidationError, field_validator, model_validator
from skyvern.forge.sdk.copilot.build_test_connect_failure import (
BuildTestConnectFailure,
@@ -28,7 +28,11 @@ from skyvern.forge.sdk.copilot.completion_verification import (
)
from skyvern.forge.sdk.copilot.composition_evidence import page_evidence_source_matches_run, workflow_target_url
from skyvern.forge.sdk.copilot.context import CodeAuthoringRepairContext, PageObstruction
-from skyvern.forge.sdk.copilot.failure_tracking import selector_identities_in_text, selector_identity_from_failure
+from skyvern.forge.sdk.copilot.failure_tracking import (
+ selector_identities_in_text,
+ selector_identity_from_failure,
+ selector_identity_from_literal,
+)
from skyvern.forge.sdk.copilot.request_policy import redact_raw_secrets_for_prompt
from skyvern.forge.sdk.copilot.run_outcome import RecordedRunOutcome
from skyvern.forge.sdk.copilot.secret_scrub import scrub_all_registered_from_text
@@ -97,6 +101,7 @@ _INSPECT_PAGE_SOURCE_TOOL = "inspect_page_for_composition"
_UNRECOVERABLE_TOOL_ERROR_CATEGORY = "UNRECOVERABLE_TOOL_ERROR"
_BROWSER_OPERATION_FAILED: BuildTestFailedOperationKind = "browser_operation_failed"
_EXECUTED_BLOCK_STATUSES = frozenset(status.value for status in BlockStatus if status != BlockStatus.skipped)
+_FAILED_BLOCK_STATUSES = frozenset({"failed", "terminated", "canceled", "timed_out"})
# Sandbox-process faults, not authored-code faults. ``timeout`` and ``user_code_error`` stay
# out: both are repairable despite also carrying ``runner_internal_error``. ``busy`` is in —
# a saturated runner gate says nothing about the code, so rewriting it cannot help.
@@ -386,6 +391,9 @@ class RecordedBuildTestOutcome(BaseModel):
block_labels: list[str] = Field(default_factory=list)
requested_block_labels: list[str] = Field(default_factory=list)
executed_block_labels: list[str] = Field(default_factory=list)
+ # ``failed_operation`` is only populated for browser-operation failures, so it cannot stand in
+ # for "this run had no failed block": a plain Python exception leaves it None.
+ failed_block_labels: list[str] = Field(default_factory=list)
block_shape_hashes: dict[str, str] = Field(default_factory=dict)
structural_failure_identity: str = ""
verified_progress_marker: str = ""
@@ -488,6 +496,7 @@ def _history_entry(ctx: _RecordedBuildTestOutcomeContext, outcome: RecordedBuild
outcome.connect_failure.model_dump(mode="json") if outcome.connect_failure is not None else None
),
"failed_operation_call_signature": outcome.failed_operation_call_signature,
+ "executed_block_evidence": _executed_block_evidence(ctx, outcome),
}
@@ -573,6 +582,77 @@ def _executed_workflow_yaml(ctx: _RecordedBuildTestOutcomeContext) -> str:
return ctx.staged_workflow_yaml or ctx.workflow_yaml
+_EXECUTED_CALL_REF_LIMIT = 64
+
+
+class ExecutedBlockEvidence(BaseModel):
+ """Source binding for a block a run actually executed, captured when that run was recorded."""
+
+ model_config = ConfigDict(extra="ignore")
+
+ signature: str = ""
+ call_refs: list[str] = Field(default_factory=list)
+ call_refs_truncated: bool = False
+ removal_provable: bool = False
+ yaml_digest: str = "absent"
+
+
+def _failed_block_labels(blocks: Sequence[Mapping[str, object]]) -> list[str]:
+ """Every failed block, not just the first: the block being judged may be a later one."""
+ return [
+ label
+ for block in blocks
+ if _safe_str(block.get("status")).lower() in _FAILED_BLOCK_STATUSES and (label := _safe_str(block.get("label")))
+ ]
+
+
+def _executed_block_evidence(
+ ctx: _RecordedBuildTestOutcomeContext, outcome: RecordedBuildTestOutcome
+) -> dict[str, dict[str, object]]:
+ """Bind the executed snapshot at record time; re-deriving it later would read a draft the run
+ never ran. Digests and labels only -- ``_HISTORY_LIMIT`` bounds entry count, not entry size."""
+ if not outcome.executed_block_labels:
+ return {}
+ executed_yaml = _executed_workflow_yaml(ctx)
+ if not executed_yaml:
+ return {}
+ yaml_digest = _yaml_digest(executed_yaml)
+ signatures = authored_block_signatures_from_workflow(executed_yaml)
+ code_by_label = _code_blocks_by_label(executed_yaml)
+ failed = set(outcome.failed_block_labels)
+ evidence: dict[str, dict[str, object]] = {}
+ for label in outcome.executed_block_labels:
+ # A block that failed in this run proves nothing about its own repair.
+ if label in failed:
+ continue
+ code = code_by_label.get(label)
+ call_refs = sorted(selector_identities_in_text(code)) if code else []
+ truncated = len(call_refs) > _EXECUTED_CALL_REF_LIMIT
+ evidence[label] = ExecutedBlockEvidence(
+ signature=signatures.get(label, ""),
+ # Stored whole rather than shortened: absence is what clears a failure, and a shortened
+ # ref would read as absent while the call it names is still there.
+ call_refs=call_refs[:_EXECUTED_CALL_REF_LIMIT],
+ call_refs_truncated=truncated,
+ removal_provable=(not truncated and _selector_removal_is_provable(code)) if code else False,
+ yaml_digest=yaml_digest,
+ ).model_dump(mode="json")
+ return evidence
+
+
+def _executed_block_evidence_for_label(entry: Mapping[str, object], label: str) -> ExecutedBlockEvidence | None:
+ raw = entry.get("executed_block_evidence")
+ if not isinstance(raw, Mapping):
+ return None
+ value = raw.get(label)
+ if not isinstance(value, Mapping):
+ return None
+ try:
+ return ExecutedBlockEvidence.model_validate(dict(value))
+ except ValidationError:
+ return None
+
+
def _code_for_runner_association(
ctx: _RecordedBuildTestOutcomeContext,
workflow_yaml: str | None,
@@ -688,13 +768,25 @@ def _selector_removal_is_provable(code: str) -> bool:
wrapper = _parse_block_code(code)
if wrapper is None:
return False
+ scanned = selector_identities_in_text(code)
for node in ast.walk(wrapper):
if not (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)):
continue
if node.func.attr not in _SELECTOR_CALL_ATTRS:
continue
selector_args = [*node.args, *(kw.value for kw in node.keywords if kw.arg == "name")]
- if any(not isinstance(arg, ast.Constant) or not isinstance(arg.value, str) for arg in selector_args):
+ literals = [arg.value for arg in selector_args if isinstance(arg, ast.Constant) and isinstance(arg.value, str)]
+ if len(literals) != len(selector_args):
+ return False
+ # The scan and this proof must read the same selector. Adjacent literals ("#a" "#b") and
+ # triple quotes parse to one constant the text scan spells differently, so a selector the
+ # scan never recorded would read as one the edit removed.
+ identity = selector_identity_from_literal(
+ node.func.attr,
+ literals[0] if literals else "",
+ literals[1] if len(literals) > 1 else "",
+ )
+ if identity and identity not in scanned:
return False
return True
@@ -704,6 +796,44 @@ def _yaml_digest(text: str | None) -> str:
return hashlib.sha256((text or "").encode()).hexdigest()[:16] if text else "absent"
+def _executed_snapshot_clearance(
+ later_runs: Sequence[object],
+ *,
+ label: str,
+ signature: str,
+ call_ref: str,
+ source_digest: str,
+) -> str | None:
+ """Clearance from a run's own receipts: the run executed this block, and the snapshot it ran
+ carries the same proof of change the delivered workflow would have to carry."""
+ for entry_after in later_runs:
+ if not isinstance(entry_after, Mapping):
+ continue
+ # A run that completed without evaluating its outputs still carries a failed_operation when one
+ # of its blocks re-failed; admitting that would clear the failure and record no new one.
+ completed_unevaluated = (
+ entry_after.get("verdict") == "not_authoritative"
+ and entry_after.get("reason_code") == "run_completed_unevaluated"
+ and entry_after.get("failed_operation") is None
+ )
+ if not (entry_after.get("verdict") == "progress_observed" or completed_unevaluated):
+ continue
+ evidence = _executed_block_evidence_for_label(entry_after, label)
+ if evidence is None:
+ continue
+ # The snapshot that ran has to still be the source being judged. Any edit after that run --
+ # a revert to the code that failed included -- leaves the run proving nothing about it.
+ if evidence.yaml_digest != source_digest:
+ continue
+ run_id = _safe_str(entry_after.get("workflow_run_id"))
+ if call_ref:
+ if call_ref not in evidence.call_refs and evidence.removal_provable:
+ return f"executed_snapshot_call_removed:{run_id}:{label}"
+ elif signature and evidence.signature and evidence.signature != signature:
+ return f"executed_snapshot_signature_changed:{run_id}:{label}"
+ return None
+
+
def unresolved_runtime_block_failure(
ctx: _RecordedBuildTestOutcomeContext,
*,
@@ -720,6 +850,7 @@ def unresolved_runtime_block_failure_with_disposition(
*,
reported_workflow_yaml: str | None = None,
pending_later_run_id: str | None = None,
+ reported_workflow_is_persisted: bool = False,
) -> tuple[UnresolvedRuntimeFailure | None, str]:
"""The newest runtime block failure the retained evidence does not show was resolved.
@@ -727,6 +858,10 @@ def unresolved_runtime_block_failure_with_disposition(
the condition that failed: a login step can fail against an already-authenticated page and pass
against a signed-out one, same lines, opposite precondition. Only evidence that the code itself
changed -- the failing call removed, or the block's signature changed -- clears the failure.
+
+ ``reported_workflow_is_persisted`` says what an absent ``reported_workflow_yaml`` means. Callers
+ reading persistence pass it, so absence means nothing is saved and the run's own receipts may
+ stand in; a caller judging a proposal leaves it false, where absence only means it has none.
"""
raw_history = getattr(ctx, "recorded_build_test_outcome_history", None)
history: list[dict[str, object]] = raw_history if isinstance(raw_history, list) else []
@@ -752,8 +887,18 @@ def unresolved_runtime_block_failure_with_disposition(
# failure and decline.
if pending_later_run_id and pending_later_run_id != run_id:
later_runs.append({"workflow_run_id": pending_later_run_id})
- # Clearance reads only the workflow the user can actually run. A draft that drops the failing
- # call would clear a failure the delivered workflow still carries.
+ if label and run_id and later_runs and (reported_workflow_yaml or reported_workflow_is_persisted):
+ executed_snapshot_disposition = _executed_snapshot_clearance(
+ later_runs,
+ label=label,
+ signature=signature,
+ call_ref=call_ref,
+ source_digest=_yaml_digest(reported_workflow_yaml or _executed_workflow_yaml(ctx)),
+ )
+ if executed_snapshot_disposition is not None:
+ return None, executed_snapshot_disposition
+ # Clearance reads the workflow the user can actually run, or -- when nothing is saved yet --
+ # the snapshot a run proved above. A draft neither of those covers clears nothing.
delivered_yaml = reported_workflow_yaml
code = _code_blocks_by_label(delivered_yaml).get(label) if delivered_yaml else None
if not (label and run_id and later_runs and code):
@@ -1292,6 +1437,7 @@ def recorded_outcome_from_run_blocks_result(
block_labels=block_labels,
requested_block_labels=requested_block_labels,
executed_block_labels=executed_block_labels,
+ failed_block_labels=_failed_block_labels(blocks),
block_shape_hashes=block_shape_hashes,
executed_block_associations=executed_block_associations,
page_capture=page_capture,
@@ -1750,7 +1896,7 @@ def _block_dicts(value: object) -> list[Mapping[str, object]]:
def _first_failed_block(blocks: Sequence[Mapping[str, object]]) -> Mapping[str, object] | None:
for block in blocks:
- if _safe_str(block.get("status")).lower() in {"failed", "terminated", "canceled", "timed_out"}:
+ if _safe_str(block.get("status")).lower() in _FAILED_BLOCK_STATUSES:
return block
return None
diff --git a/skyvern/forge/sdk/copilot/failure_tracking.py b/skyvern/forge/sdk/copilot/failure_tracking.py
index f8b867299..f14b54f26 100644
--- a/skyvern/forge/sdk/copilot/failure_tracking.py
+++ b/skyvern/forge/sdk/copilot/failure_tracking.py
@@ -154,6 +154,17 @@ def selector_identity_from_failure(text: str) -> str:
return f"{_CSS_SELECTOR_KIND if kind == 'selector' else kind}:{value}" if kind else ""
+def selector_identity_from_literal(attr: str, selector: str, name: str = "") -> str:
+ """Identity for a selector read from source as a literal, spelled as ``selector_identities_in_text`` would."""
+ if attr == "get_by_role":
+ role = _normalize_signature_text(selector)
+ role_name = _normalize_signature_text(name)
+ return f"role:{role}:{role_name}" if role_name else f"role:{role}"
+ if attr == "locator":
+ return f"{_CSS_SELECTOR_KIND}:{_normalize_signature_text(selector)}"
+ return ""
+
+
def selector_identities_in_text(text: str) -> set[str]:
"""Every locator identity in ``text``, normalized to match ``selector_identity_from_failure``."""
identities: set[str] = set()
diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.py
index 762dccb1c..82f3331b3 100644
--- a/skyvern/forge/sdk/copilot/tools/run_execution.py
+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py
@@ -4580,6 +4580,7 @@ def _carry_unresolved_failure_into_result(copilot_ctx: Any, result: dict[str, An
copilot_ctx,
reported_workflow_yaml=copilot_ctx.persisted_workflow_yaml,
pending_later_run_id=this_run_id if isinstance(this_run_id, str) else None,
+ reported_workflow_is_persisted=True,
)
# This seam is load-bearing for repair: a failure it fails to carry is one the model decides
# without. One bounded event per successful hand-back, so a miss is attributable rather than
diff --git a/skyvern/forge/sdk/experimentation/workflow_block_engine.py b/skyvern/forge/sdk/experimentation/workflow_block_engine.py
index 0a6c3541a..7cf276d04 100644
--- a/skyvern/forge/sdk/experimentation/workflow_block_engine.py
+++ b/skyvern/forge/sdk/experimentation/workflow_block_engine.py
@@ -107,3 +107,26 @@ def workflow_block_engine_override(workflow_run_id: str | None) -> RunEngine | N
if context is None or context.workflow_block_engine_resolved_run_id != workflow_run_id:
return None
return context.workflow_block_engine_override
+
+
+def resolved_workflow_block_engine_arm_label(workflow_run_id: str | None) -> str | None:
+ """Three-way arm label for finalize-time telemetry: "treatment"/"control" when this run's
+ own context resolved an arm, None when this run's own context is current but never
+ resolved one, "unknown" when a different (or no) context is current.
+
+ The third case is the shape every out-of-band finalizer has -- API cancel, the stuck-run
+ sweep, copilot cooperative cancel -- which runs in a different task/process than the one
+ that resolved the arm, so its own context (if any) is either absent or belongs to whatever
+ request triggered it, not to this workflow run. Collapsing that into None would read as
+ "never entered the A/B", silently biasing per-arm duration reads against exactly the
+ canceled/timed-out population; "unknown" keeps that attribution-lost mass a visible facet
+ instead (SKY-15561).
+ """
+ if not workflow_run_id:
+ return "unknown"
+ context = skyvern_context.current()
+ if context is None or context.workflow_run_id != workflow_run_id:
+ return "unknown"
+ if context.workflow_block_engine_resolved_run_id != workflow_run_id:
+ return None
+ return "treatment" if context.workflow_block_engine_override == RunEngine.skyvern_v3 else "control"
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index 8d86a64ac..6656917c6 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -90,7 +90,10 @@ from skyvern.forge.sdk.db.id import generate_output_parameter_id, generate_workf
from skyvern.forge.sdk.enterprise_features import collect_enterprise_gated_run_features
from skyvern.forge.sdk.experimentation.enrich_tree import resolve_enrich_tree_for_context
from skyvern.forge.sdk.experimentation.transient_ui_capture import resolve_transient_ui_capture_arm
-from skyvern.forge.sdk.experimentation.workflow_block_engine import resolve_workflow_block_engine_arm
+from skyvern.forge.sdk.experimentation.workflow_block_engine import (
+ resolve_workflow_block_engine_arm,
+ resolved_workflow_block_engine_arm_label,
+)
from skyvern.forge.sdk.forge_log import exception_log_fields
from skyvern.forge.sdk.models import Step, StepStatus
from skyvern.forge.sdk.schemas.browser_profiles import BrowserProfile
@@ -956,6 +959,28 @@ def _as_utc(dt: datetime) -> datetime:
return dt.replace(tzinfo=UTC) if dt.tzinfo is None else dt.astimezone(UTC)
+def _task_v3_ab_arm_for_duration_log(workflow_run_id: str) -> str | None:
+ """Best-effort read of the workflow-block engine A/B arm pinned on this run's context.
+
+ Three-way: "treatment"/"control" when this run's own context resolved an arm in-band,
+ None when this run's own context never resolved one, "unknown" when finalization runs
+ out-of-band (API cancel, the stuck-run sweep, copilot cooperative cancel) so no context
+ for this run is current -- attribution is lost, not "never entered the A/B".
+
+ Telemetry only: a lookup failure must never break run finalization, so any exception is
+ swallowed and logged as a warning rather than propagated (SKY-15561, mirrors SKY-15499).
+ """
+ try:
+ return resolved_workflow_block_engine_arm_label(workflow_run_id)
+ except Exception:
+ LOG.warning(
+ "task_v3_ab_arm resolution for duration metrics failed",
+ workflow_run_id=workflow_run_id,
+ exc_info=True,
+ )
+ return None
+
+
def _get_workflow_run_max_elapsed_timeout_seconds(workflow_run: WorkflowRun) -> float:
effective_minutes = get_effective_workflow_run_max_elapsed_time_minutes(workflow_run.max_elapsed_time_minutes)
started_at = _as_utc(workflow_run.started_at or workflow_run.created_at)
@@ -9554,6 +9579,7 @@ class WorkflowService:
ai_fallback=workflow_run.ai_fallback,
trigger_type=workflow_run.trigger_type,
workflow_schedule_id=workflow_run.workflow_schedule_id,
+ task_v3_ab_arm=_task_v3_ab_arm_for_duration_log(workflow_run_id),
)
# Run minutes measure compute. A run finalized without ever reaching
# `running` held no pod, and the created_at fallback above would bill its
@@ -10065,6 +10091,7 @@ class WorkflowService:
ai_fallback=updated.ai_fallback,
trigger_type=updated.trigger_type,
workflow_schedule_id=updated.workflow_schedule_id,
+ task_v3_ab_arm=_task_v3_ab_arm_for_duration_log(workflow_run_id),
)
# Same compute gate as ``_after_workflow_run_status_write``: cancelling a run
# that never started bills queue age, not compute, so it records as a tagged
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py
index 0ef5817b8..d6af09174 100644
--- a/skyvern/webeye/actions/handler.py
+++ b/skyvern/webeye/actions/handler.py
@@ -6823,6 +6823,61 @@ def _attr_indicates_aria_invalid(raw: object) -> bool:
return str(raw).strip().casefold() not in ("", "false")
+def _has_exact_class_token(class_attr: str | None, token: str) -> bool:
+ return class_attr is not None and token in str(class_attr).split()
+
+
+# Owner-scoped ui-select state read before and after Enter (`owned` reachable for a ui-select nested in another's
+# dropdown). Disabled = stock 0.19.8 forms only: `disabled` attr/class, `select2-disabled`, non-"false" `aria-disabled`.
+_UI_SELECT_STATE_JS = """
+(el) => {
+ const container = el.closest('.ui-select-container');
+ if (container === null) { return null; }
+ const owned = (n) => n.closest('.ui-select-container') === container;
+ const rows = [...container.querySelectorAll('.ui-select-choices-row')].filter((r) => owned(r) && r.getClientRects().length > 0);
+ const isDisabled = (r) => r.hasAttribute('disabled') || r.classList.contains('disabled') || r.classList.contains('select2-disabled') || (r.hasAttribute('aria-disabled') && (r.getAttribute('aria-disabled') || '').trim().toLowerCase() !== 'false');
+ const matches = [...container.querySelectorAll('.ui-select-match-text, .select2-chosen, .ui-select-match-item, .ui-select-match')].filter((m) => owned(m) && m.getClientRects().length > 0).slice(0, 20).map((m) => (m.textContent || '').trim());
+ return { enabledRowCount: rows.filter((r) => !isDisabled(r)).length, firstVisibleEnabled: rows.length > 0 && !isDisabled(rows[0]), firstVisibleLabel: rows.length > 0 ? (rows[0].textContent || '').trim() : '', choicesOpen: rows.length > 0 || [...container.querySelectorAll('.ui-select-choices')].some((c) => owned(c) && c.getClientRects().length > 0), matchTexts: matches, searchValue: typeof el.value === 'string' ? el.value : '' };
+}
+"""
+
+
+def _ui_select_commit_result(
+ action: InputTextAction,
+ pre: dict,
+ post: Any,
+ candidate: str,
+ text: str,
+) -> ActionResult | None:
+ """Adjudicate a ui-select Enter from the same-owner post-settle state: ``ActionSuccess`` (with evidence) only
+ on a proven commit (choices closed + search emptied + a match display for the candidate); ``None`` on a proven
+ clean no-op (byte-identical to pre-Enter) → fall through; else ``NoAvailableOptionFoundForCustomSelection``."""
+ if isinstance(post, dict) and not post.get("choicesOpen") and post.get("searchValue") == "":
+ normalized_candidate = _normalize_select_shadow_text(candidate)
+ for observed in post.get("matchTexts") or []:
+ if normalized_candidate and _normalize_select_shadow_text(observed) == normalized_candidate:
+ result = ActionSuccess(
+ committed_option=_truncate_select_shadow_field(candidate),
+ committed_value=_truncate_select_shadow_field(str(observed)),
+ )
+ action.set_has_mini_agent()
+ if action.stop_batch_after_dropdown_select:
+ result.skip_remaining_actions = True
+ return result
+ if (
+ isinstance(post, dict)
+ and post.get("choicesOpen")
+ and post.get("searchValue") == text
+ and post.get("matchTexts") == pre.get("matchTexts")
+ ):
+ return None
+ return ActionFailure(
+ NoAvailableOptionFoundForCustomSelection(
+ reason="ui-select Enter commit could not be verified", target_value=candidate
+ )
+ )
+
+
async def _is_combobox_or_typeahead(skyvern_element: SkyvernElement) -> bool:
# role=combobox or aria-autocomplete list/both/inline marks a control whose options surface only as characters
# are entered. This structural identity -- not the post-input aria-invalid state -- decides whether the
@@ -7163,6 +7218,61 @@ async def _handle_input_text_action(
)
]
+ # ui-select (AngularJS) resets activeIndex to the first visible row per keystroke, so Enter commits rows[0].
+ # Press it only when that first visible row is the unique enabled one, then prove the commit landed before
+ # recording it (see _ui_select_commit_result). Run before the generic probe.
+ if (
+ text
+ and tag_name == InteractiveElement.INPUT
+ and not is_secret_value
+ and not is_totp_value
+ and (input_or_select_context is None or input_or_select_context.is_date_related is not True)
+ and _has_exact_class_token(await skyvern_element.get_attr("class"), "ui-select-search")
+ ):
+ await incremental_scraped.start_listen_dom_increment(await skyvern_element.get_element_handler())
+ try:
+ try:
+ await skyvern_element.input_clear()
+ except Exception:
+ LOG.info(
+ "Failed to clear ui-select search before filtering; failing closed",
+ element_id=skyvern_element.get_id(),
+ )
+ return [ActionFailure(FailedToClearInputField(element_id=action.element_id, tag_name=tag_name))]
+ pre: Any = None
+ try:
+ await skyvern_element.input_sequentially(text=text)
+ await skyvern_frame.safe_wait_for_animation_end(caller="input_text.ui_select")
+ if await get_input_value(tag_name, skyvern_element.get_locator()) == text:
+ pre = await _evaluate_element_scoped(skyvern_element, _UI_SELECT_STATE_JS)
+ except Exception:
+ LOG.info("Failed to filter/probe ui-select rows, falling back", element_id=skyvern_element.get_id())
+ if (
+ isinstance(pre, dict)
+ and pre.get("enabledRowCount") == 1
+ and pre.get("firstVisibleEnabled")
+ and pre.get("firstVisibleLabel")
+ ):
+ candidate = str(pre["firstVisibleLabel"])
+ await skyvern_element.press_key("Enter")
+ post: Any = None
+ try:
+ await _wait_custom_select_render_settle(skyvern_element)
+ post = await _evaluate_element_scoped(skyvern_element, _UI_SELECT_STATE_JS)
+ except Exception:
+ LOG.info("Failed to read ui-select state after Enter", element_id=skyvern_element.get_id())
+ commit_result = _ui_select_commit_result(action, pre, post, candidate, text)
+ if commit_result is not None:
+ return [commit_result] # None → proven clean no-op: fall through to the generic path
+ finally:
+ await incremental_scraped.stop_listen_dom_increment()
+ # Not commit-ready or a proven no-op: clear the probe so the ordinary path does not double the typed value.
+ try:
+ await skyvern_element.input_clear()
+ except Exception:
+ LOG.warning("Failed to clear ui-select probe before fallthrough", element_id=skyvern_element.get_id())
+ return [ActionFailure(FailedToClearInputField(element_id=action.element_id, tag_name=tag_name))]
+
# check if it's selectable
if (
input_or_select_context is not None
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/captured_repair_then_completed_run.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/captured_repair_then_completed_run.json
new file mode 100644
index 000000000..bc42b51a1
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/captured_repair_then_completed_run.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "extracted_from_captured_run",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "Verbatim from the capture: two runtime block failures on one code block, then a run that completed and registered its output over changed code. The two failure signatures replay byte-equal to the ones the backend logged, which is what binds these YAMLs to that session."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "not_authoritative",
+ "reason_code": "run_completed_unevaluated",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "executed_snapshot_signature_changed:wr_569288397328868066:calculate_and_extract_quote_total",
+ "attached": false,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/completed_run_whose_block_re_failed.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/completed_run_whose_block_re_failed.json
new file mode 100644
index 000000000..7a7408d1d
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/completed_run_whose_block_re_failed.json
@@ -0,0 +1,82 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "captured_repair_then_completed_run.json with the final run's own block re-failed",
+ "notes": "Same captured YAMLs and run ids; the completed run carries a failed_operation for the same block, the shape a run that completes without evaluating its outputs takes when one of its blocks re-failed."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "not_authoritative",
+ "reason_code": "run_completed_unevaluated",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ],
+ "failed_operation": {
+ "kind": "browser_operation_failed",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_label": "calculate_and_extract_quote_total"
+ }
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/partial_run_failed_label_uncovered.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/partial_run_failed_label_uncovered.json
new file mode 100644
index 000000000..550cdb723
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/partial_run_failed_label_uncovered.json
@@ -0,0 +1,75 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "The later run succeeded over changed source but recorded no executed block at all."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/persisted_source_with_staged_repair.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/persisted_source_with_staged_repair.json
new file mode 100644
index 000000000..af9b31416
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/persisted_source_with_staged_repair.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "derived from captured_repair_then_completed_run.json",
+ "notes": "branch_local_witness derived from the captured run in captured_repair_then_completed_run.json: the same recorded failure and success bodies, re-scripted to the situation named below. Not an independently captured run. Here the repair is staged rather than saved, so the runnable workflow is unchanged."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "not_authoritative",
+ "reason_code": "run_completed_unevaluated",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "expect": {
+ "baseline_disposition": "unresolved",
+ "baseline_attached": true,
+ "disposition": "unresolved",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_call_removed.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_call_removed.json
new file mode 100644
index 000000000..dd5df5d83
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_call_removed.json
@@ -0,0 +1,57 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "Captured first failure, which named a locator, followed by a verified success over a snapshot that no longer contains it."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"#totals-panel\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "executed_snapshot_call_removed:wr_569288397328868066:calculate_and_extract_quote_total",
+ "attached": false,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_signature_changed.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_signature_changed.json
new file mode 100644
index 000000000..d81302719
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/progress_observed_signature_changed.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "Captured trio with the final run recorded as a verified success; only its verdict differs from the capture."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "executed_snapshot_signature_changed:wr_569288397328868066:calculate_and_extract_quote_total",
+ "attached": false,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/repair_then_reverted_source.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/repair_then_reverted_source.json
new file mode 100644
index 000000000..c895ef048
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/repair_then_reverted_source.json
@@ -0,0 +1,78 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "derived from captured_repair_then_completed_run.json",
+ "notes": "branch_local_witness derived from the captured run in captured_repair_then_completed_run.json: the same recorded failure and success bodies, re-scripted to the situation named below. Not an independently captured run. Here the user reverts the draft to the failing body after the clean run."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "not_authoritative",
+ "reason_code": "run_completed_unevaluated",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "final_workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/sibling_only_coverage.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/sibling_only_coverage.json
new file mode 100644
index 000000000..d916f7084
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/sibling_only_coverage.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "The later run succeeded over changed source but executed a sibling block, not the one that failed."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = \"\"\n for _ in range(20):\n total_text = (await page_total.inner_text()).strip()\n if total_text.startswith(\"$\"):\n break\n await page.wait_for_timeout(500)\n if not total_text.startswith(\"$\"):\n raise ValueError(\"The calculated page total did not become available\")\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n - block_type: code\n label: notify_owner\n prompt: Post the total to the internal notifier.\n code: |\n await page.goto(\"http://localhost:8900/notifier/\")\n return {\"posted\": True}\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "notify_owner"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/truncated_call_refs.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/truncated_call_refs.json
new file mode 100644
index 000000000..c6c2a4b89
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/truncated_call_refs.json
@@ -0,0 +1,57 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "derived from captured_repair_then_completed_run.json",
+ "notes": "branch_local_witness derived from the captured run in captured_repair_then_completed_run.json: the same recorded failure and success bodies, re-scripted to the situation named below. Not an independently captured run. The failing block is widened past the stored call-ref cap so the ref list is incomplete."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n code: |\n await page.locator(\"#field-0\").click()\n await page.locator(\"#field-1\").click()\n await page.locator(\"#field-2\").click()\n await page.locator(\"#field-3\").click()\n await page.locator(\"#field-4\").click()\n await page.locator(\"#field-5\").click()\n await page.locator(\"#field-6\").click()\n await page.locator(\"#field-7\").click()\n await page.locator(\"#field-8\").click()\n await page.locator(\"#field-9\").click()\n await page.locator(\"#field-10\").click()\n await page.locator(\"#field-11\").click()\n await page.locator(\"#field-12\").click()\n await page.locator(\"#field-13\").click()\n await page.locator(\"#field-14\").click()\n await page.locator(\"#field-15\").click()\n await page.locator(\"#field-16\").click()\n await page.locator(\"#field-17\").click()\n await page.locator(\"#field-18\").click()\n await page.locator(\"#field-19\").click()\n await page.locator(\"#field-20\").click()\n await page.locator(\"#field-21\").click()\n await page.locator(\"#field-22\").click()\n await page.locator(\"#field-23\").click()\n await page.locator(\"#field-24\").click()\n await page.locator(\"#field-25\").click()\n await page.locator(\"#field-26\").click()\n await page.locator(\"#field-27\").click()\n await page.locator(\"#field-28\").click()\n await page.locator(\"#field-29\").click()\n await page.locator(\"#field-30\").click()\n await page.locator(\"#field-31\").click()\n await page.locator(\"#field-32\").click()\n await page.locator(\"#field-33\").click()\n await page.locator(\"#field-34\").click()\n await page.locator(\"#field-35\").click()\n await page.locator(\"#field-36\").click()\n await page.locator(\"#field-37\").click()\n await page.locator(\"#field-38\").click()\n await page.locator(\"#field-39\").click()\n await page.locator(\"#field-40\").click()\n await page.locator(\"#field-41\").click()\n await page.locator(\"#field-42\").click()\n await page.locator(\"#field-43\").click()\n await page.locator(\"#field-44\").click()\n await page.locator(\"#field-45\").click()\n await page.locator(\"#field-46\").click()\n await page.locator(\"#field-47\").click()\n await page.locator(\"#field-48\").click()\n await page.locator(\"#field-49\").click()\n await page.locator(\"#field-50\").click()\n await page.locator(\"#field-51\").click()\n await page.locator(\"#field-52\").click()\n await page.locator(\"#field-53\").click()\n await page.locator(\"#field-54\").click()\n await page.locator(\"#field-55\").click()\n await page.locator(\"#field-56\").click()\n await page.locator(\"#field-57\").click()\n await page.locator(\"#field-58\").click()\n await page.locator(\"#field-59\").click()\n await page.locator(\"#field-60\").click()\n await page.locator(\"#field-61\").click()\n await page.locator(\"#field-62\").click()\n await page.locator(\"#field-63\").click()\n await page.locator(\"#field-64\").click()\n await page.locator(\"#field-65\").click()\n await page.locator(\"#field-66\").click()\n await page.locator(\"#field-67\").click()\n await page.locator(\"#field-68\").click()\n await page.locator(\"#field-69\").click()\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "not_authoritative",
+ "reason_code": "run_completed_unevaluated",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/unbindable_executed_snapshot.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/unbindable_executed_snapshot.json
new file mode 100644
index 000000000..ebb40082a
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/unbindable_executed_snapshot.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "The later run covered the failed label but its executed snapshot carries no such block, so nothing binds."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks: []\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/fixtures/copilot/unresolved_failure_clearance/unchanged_source.json b/tests/unit/fixtures/copilot/unresolved_failure_clearance/unchanged_source.json
new file mode 100644
index 000000000..325eb01c3
--- /dev/null
+++ b/tests/unit/fixtures/copilot/unresolved_failure_clearance/unchanged_source.json
@@ -0,0 +1,77 @@
+{
+ "provenance": {
+ "kind": "branch_local_witness",
+ "source": "sky-15308-base-20260831-194437/run2-repeat-failure-then-clean/call-0026.json + backend.log.capture-slice",
+ "notes": "The later run executed the failed block to success over the very snapshot that failed."
+ },
+ "steps": [
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n await total_panel.locator(\"strong\").wait_for(state=\"visible\", timeout=10000)\n total_text = (await total_panel.locator(\"strong\").inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "locator:div.totals",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288173990568574",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288173990568574"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "attempted_block_label": "calculate_and_extract_quote_total",
+ "attempted_call_ref": "",
+ "verdict": "repairable_failure",
+ "reason_code": "runtime_block_failure",
+ "workflow_run_id": "wr_569288324314423984",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "structural_failure_identity": "code-block-exception:wr_569288324314423984"
+ }
+ },
+ {
+ "workflow_yaml": "title: Retrieve deferred freight quote total\nworkflow_definition:\n parameters: []\n blocks:\n - block_type: code\n label: calculate_and_extract_quote_total\n prompt: Open quote QF-4821, calculate its shipping-inclusive order total, and return the page-displayed total as a number.\n code: |\n await page.goto(\"http://localhost:8900/deferred_total_quote/\")\n quote_heading = page.get_by_text(\"Quote QF-4821\", exact=True)\n await quote_heading.wait_for(state=\"visible\", timeout=10000)\n total_panel = page.locator(\"div.totals\")\n await total_panel.wait_for(state=\"visible\", timeout=10000)\n await page.locator(\"#calculate-total\").click()\n page_total = page.locator(\"#order-total\")\n await page_total.wait_for(state=\"visible\", timeout=10000)\n total_text = (await page_total.inner_text()).strip()\n normalized_total = total_text.replace(\"$\", \"\").replace(\",\", \"\").strip()\n order_total = float(normalized_total)\n return {\n \"quote_id\": \"QF-4821\",\n \"order_total\": order_total,\n \"displayed_total\": total_text,\n \"evidence_text\": (await total_panel.inner_text()).strip()\n }\n",
+ "staged_workflow_yaml": null,
+ "outcome": {
+ "phase": "persisted_block_run",
+ "attempted_tool": "update_and_run_blocks",
+ "verdict": "progress_observed",
+ "reason_code": "verified_success",
+ "workflow_run_id": "wr_569288397328868066",
+ "block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "executed_block_labels": [
+ "calculate_and_extract_quote_total"
+ ],
+ "evidence_refs": [
+ "calculate_and_extract_quote_total_output"
+ ]
+ }
+ }
+ ],
+ "reported_workflow_yaml": null,
+ "expect": {
+ "baseline_disposition": "no_reported_candidate",
+ "baseline_attached": true,
+ "disposition": "no_reported_candidate",
+ "attached": true,
+ "history_retains_failure": true
+ }
+}
diff --git a/tests/unit/test_copilot_build_test_outcome.py b/tests/unit/test_copilot_build_test_outcome.py
index a106dfaed..a2a035046 100644
--- a/tests/unit/test_copilot_build_test_outcome.py
+++ b/tests/unit/test_copilot_build_test_outcome.py
@@ -15,11 +15,13 @@ from skyvern.forge.sdk.copilot import tools as tools_module
from skyvern.forge.sdk.copilot.agent import (
_build_dynamic_system_prompt,
_build_user_context,
+ _make_agent_result,
_prior_run_debug_text,
_recorded_build_test_outcome_prompt,
)
from skyvern.forge.sdk.copilot.build_test_connect_failure import build_test_connect_failure_sentence
from skyvern.forge.sdk.copilot.build_test_outcome import (
+ _EXECUTED_CALL_REF_LIMIT,
BuildTestConnectFailure,
BuildTestEvidencePacket,
BuildTestFailedOperation,
@@ -39,6 +41,7 @@ from skyvern.forge.sdk.copilot.build_test_outcome import (
recorded_outcome_from_run_blocks_result,
recorded_outcome_from_scout_act_observe_hollow,
unresolved_runtime_block_failure,
+ unresolved_runtime_block_failure_with_disposition,
)
from skyvern.forge.sdk.copilot.completion_verification import CompletionVerificationResult, CriterionVerdict
from skyvern.forge.sdk.copilot.config import BlockAuthoringPolicy, CopilotConfig
@@ -65,7 +68,7 @@ from skyvern.forge.sdk.copilot.tools.run_execution import (
build_test_evidence_packet,
)
from skyvern.forge.sdk.copilot.workflow_yaml import runner_code_block_associations
-from skyvern.forge.sdk.schemas.copilot_turn_outcome import UnresolvedRuntimeFailure
+from skyvern.forge.sdk.schemas.copilot_turn_outcome import ResponseKind, TurnOutcome, UnresolvedRuntimeFailure
from skyvern.forge.sdk.workflow.models.block import CodeBlock
from skyvern.forge.sdk.workflow.models.parameter import OutputParameter, ParameterType
from skyvern.webeye.browser_artifacts import BrowserArtifacts
@@ -5030,3 +5033,498 @@ async def test_watchdog_paused_result_is_recorded_before_the_captcha_probe(
"wr_prior_failure",
"wr_paused",
]
+
+
+def _signature_only_failure(run_id: str) -> RecordedBuildTestOutcome:
+ return RecordedBuildTestOutcome(
+ phase="persisted_block_run",
+ attempted_tool="update_and_run_blocks",
+ attempted_block_label="sign_in_and_read",
+ verdict="repairable_failure",
+ reason_code="runtime_block_failure",
+ workflow_run_id=run_id,
+ block_labels=["sign_in_and_read"],
+ structural_failure_identity="value-error-identity",
+ )
+
+
+def _executing_run(
+ run_id: str,
+ executed_block_labels: list[str],
+ *,
+ verdict: str = "progress_observed",
+ reason_code: str = "",
+ failed_operation: BuildTestFailedOperation | None = None,
+ failed_block_labels: list[str] | None = None,
+) -> RecordedBuildTestOutcome:
+ default_reason_code = "verified_success" if verdict == "progress_observed" else "run_completed_unevaluated"
+ return RecordedBuildTestOutcome(
+ phase="persisted_block_run",
+ attempted_tool="update_and_run_blocks",
+ verdict=verdict, # type: ignore[arg-type]
+ reason_code=reason_code or default_reason_code, # type: ignore[arg-type]
+ workflow_run_id=run_id,
+ block_labels=["sign_in_and_read"],
+ executed_block_labels=executed_block_labels,
+ failed_block_labels=failed_block_labels or [],
+ evidence_refs=["rows:1"],
+ failed_operation=failed_operation,
+ )
+
+
+def _executed_snapshot_history(
+ failure: RecordedBuildTestOutcome,
+ later_run: RecordedBuildTestOutcome,
+ *,
+ executed_yaml: str,
+ failing_yaml: str = "",
+) -> SimpleNamespace:
+ ctx = _run_history_ctx(failing_yaml or two_page_login_yaml())
+ ctx.persisted_workflow_yaml = None
+ record_build_test_outcome(ctx, failure)
+ ctx.workflow_yaml = executed_yaml
+ record_build_test_outcome(ctx, later_run)
+ return ctx
+
+
+def test_a_run_over_a_changed_snapshot_that_drops_the_failing_call_clears_the_failure() -> None:
+ """The snapshot a run executed is evidence the delivered workflow cannot supply when nothing is
+ persisted yet, and it is bound when that run is recorded rather than read back off the draft."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved is None
+ assert disposition == "executed_snapshot_call_removed:wr_2:sign_in_and_read"
+ assert [entry["workflow_run_id"] for entry in ctx.recorded_build_test_outcome_history] == ["wr_1", "wr_2"]
+ assert ctx.recorded_build_test_outcome_history[0]["reason_code"] == "runtime_block_failure"
+
+
+def test_a_run_over_a_changed_snapshot_clears_a_failure_that_named_no_call() -> None:
+ ctx = _executed_snapshot_history(
+ _signature_only_failure("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=straight_line_login_yaml(),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved is None
+ assert disposition == "executed_snapshot_signature_changed:wr_2:sign_in_and_read"
+
+
+def test_a_later_run_that_executed_no_block_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", []),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_run_covering_only_a_sibling_block_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["read_metric"]),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_run_over_the_same_source_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=two_page_login_yaml(),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_run_over_a_snapshot_of_runtime_built_selectors_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1").model_copy(update={"attempted_call_ref": "locator:#submit-btn"}),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=_templated_selector_yaml(),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_run_over_the_same_source_still_carries_a_failure_that_named_no_call() -> None:
+ ctx = _executed_snapshot_history(
+ _signature_only_failure("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=two_page_login_yaml(),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_run_whose_snapshot_carries_no_such_block_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ _signature_only_failure("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml="title: Sign in and read the metric\nworkflow_definition:\n blocks: []\n",
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+ "reason_code",
+ [
+ "unrecoverable_tool_error",
+ "terminal_challenge_blocker",
+ "no_meaningful_output",
+ "fallback_floor_turn_unsatisfiable",
+ ],
+)
+def test_a_later_run_that_reached_no_evaluated_completion_still_carries_the_failure(reason_code: str) -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"], verdict="not_authoritative", reason_code=reason_code),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_later_completed_run_whose_own_block_failed_still_carries_the_failure() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run(
+ "wr_2",
+ ["sign_in_and_read"],
+ verdict="not_authoritative",
+ failed_operation=BuildTestFailedOperation(
+ kind="browser_operation_failed",
+ workflow_run_id="wr_2",
+ block_label="sign_in_and_read",
+ ),
+ ),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_completed_run_that_evaluated_no_output_clears_over_a_changed_snapshot() -> None:
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"], verdict="not_authoritative"),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved is None
+ assert disposition == "executed_snapshot_call_removed:wr_2:sign_in_and_read"
+
+
+def test_the_tool_result_and_the_terminal_agree_once_the_executed_snapshot_cleared_the_failure() -> None:
+ ctx = make_copilot_ctx(workflow_yaml=two_page_login_yaml())
+ ctx.persisted_workflow_yaml = None
+ record_build_test_outcome(ctx, failed_second_factor_run("wr_1"))
+ ctx.workflow_yaml = two_page_login_yaml(submit_selector="Continue")
+ record_build_test_outcome(ctx, _executing_run("wr_2", ["sign_in_and_read"]))
+ ctx.last_run_blocks_workflow_run_id = "wr_2"
+ result = _run_result_ok()
+
+ run_execution_module._carry_unresolved_failure_into_result(ctx, result, "update_and_run_blocks")
+ terminal = _make_agent_result(
+ ctx,
+ user_response="Built it and tested it.",
+ updated_workflow=object(),
+ global_llm_context=None,
+ turn_outcome=TurnOutcome(response_kind=ResponseKind.BUILD),
+ narrative_payload={"terminalMessage": "Built it and tested it.", "narrativeSummary": "Built it and tested it."},
+ )
+
+ assert "unresolved_earlier_failure" not in result["data"]
+ assert terminal.turn_outcome is not None
+ assert terminal.turn_outcome.unresolved_runtime_failure is None
+ assert terminal.narrative_payload is not None
+ assert terminal.narrative_payload["terminalMessage"] == "Built it and tested it."
+
+
+def _many_literal_selectors_yaml(selector_count: int) -> str:
+ calls = "".join(f' await page.locator("#field-{index}").click()\n' for index in range(selector_count))
+ return (
+ "title: Sign in and read the metric\n"
+ "workflow_definition:\n"
+ " blocks:\n"
+ " - block_type: code\n"
+ " label: sign_in_and_read\n"
+ " code: |\n" + calls
+ )
+
+
+def test_reverting_the_draft_to_the_code_that_failed_carries_the_failure_again() -> None:
+ """A clean run proves nothing about source it no longer describes, so a revert re-carries."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+ ctx.workflow_yaml = two_page_login_yaml()
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_signature_change_on_a_snapshot_the_draft_no_longer_holds_carries_the_failure() -> None:
+ """The signature arm is bound to the source being judged the same way the call arm is."""
+ ctx = _executed_snapshot_history(
+ _signature_only_failure("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=straight_line_login_yaml(),
+ )
+ ctx.workflow_yaml = two_page_login_yaml()
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_snapshot_with_more_calls_than_the_evidence_holds_cannot_prove_removal() -> None:
+ """Past the cap the ref list is incomplete, and an incomplete list cannot show a call is gone."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=_many_literal_selectors_yaml(_EXECUTED_CALL_REF_LIMIT + 6),
+ )
+ evidence = ctx.recorded_build_test_outcome_history[-1]["executed_block_evidence"]["sign_in_and_read"]
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert len(evidence["call_refs"]) == _EXECUTED_CALL_REF_LIMIT
+ assert evidence["call_refs_truncated"] is True
+ assert evidence["removal_provable"] is False
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_staged_repair_does_not_clear_a_failure_the_saved_workflow_still_carries() -> None:
+ """A repair the user has not saved leaves the workflow they can run carrying the failure."""
+ saved = two_page_login_yaml()
+ ctx = _run_history_ctx(saved)
+ record_build_test_outcome(ctx, failed_second_factor_run("wr_1"))
+ ctx.staged_workflow_yaml = two_page_login_yaml(submit_selector="Continue")
+ record_build_test_outcome(ctx, _executing_run("wr_2", ["sign_in_and_read"]))
+ ctx.staged_workflow_yaml = None
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(ctx, reported_workflow_yaml=saved)
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "unresolved"
+
+
+def test_a_run_over_a_changed_staged_proposal_clears_when_nothing_is_persisted() -> None:
+ """The ticket's shape: the proposal that ran was never saved, so only its own receipts prove the repair."""
+ ctx = _run_history_ctx(two_page_login_yaml())
+ ctx.persisted_workflow_yaml = None
+ record_build_test_outcome(ctx, failed_second_factor_run("wr_1"))
+ # Stays staged: the terminal is assembled before the route commits the proposal.
+ ctx.staged_workflow_yaml = two_page_login_yaml(submit_selector="Continue")
+ record_build_test_outcome(ctx, _executing_run("wr_2", ["sign_in_and_read"]))
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved is None
+ assert disposition == "executed_snapshot_call_removed:wr_2:sign_in_and_read"
+
+
+def test_a_caller_judging_a_proposal_does_not_read_the_draft_when_it_has_none() -> None:
+ """An absent proposal means the caller has nothing to show, not that nothing is saved."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(ctx, reported_workflow_yaml=None)
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def test_a_completed_run_whose_block_failed_without_a_browser_error_still_carries_the_failure() -> None:
+ """``failed_operation`` is only set for browser failures, so it cannot mean no block failed."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run(
+ "wr_2",
+ ["sign_in_and_read"],
+ verdict="not_authoritative",
+ failed_block_labels=["sign_in_and_read"],
+ ),
+ executed_yaml=two_page_login_yaml(submit_selector="Continue"),
+ )
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def _adjacent_literal_selector_yaml() -> str:
+ """Adjacent string literals parse to one constant, which the text scan reads as a shorter selector."""
+ return """
+ title: Sign in and read the metric
+ workflow_definition:
+ blocks:
+ - block_type: code
+ label: sign_in_and_read
+ code: |
+ await page.locator("#sub" "mit").click()
+ return {"visitors": "9.42K"}
+ """
+
+
+def test_a_selector_the_text_scan_cannot_read_whole_cannot_prove_removal() -> None:
+ """The scan records ``#sub`` while the call runs ``#submit``; absence from the scan is not removal."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=_adjacent_literal_selector_yaml(),
+ )
+
+ evidence = ctx.recorded_build_test_outcome_history[-1]["executed_block_evidence"]["sign_in_and_read"]
+
+ assert evidence["call_refs"] == ["locator:#sub"]
+ assert evidence["removal_provable"] is False
+
+
+def test_a_later_failed_block_is_captured_so_it_cannot_witness_its_own_repair() -> None:
+ """Capturing only the first failed block let a second one mint evidence and clear its own failure."""
+ outcome = recorded_outcome_from_run_blocks_result(
+ {
+ "ok": True,
+ "data": {
+ "workflow_run_id": "wr_2",
+ "blocks": [
+ {"label": "open_page", "status": "failed", "failure_type": "runtime_error"},
+ {"label": "sign_in_and_read", "status": "failed", "failure_type": "runtime_error"},
+ ],
+ },
+ },
+ recorded_run_outcome=RecordedRunOutcome(verdict="not_evaluated", workflow_run_id="wr_2"),
+ )
+
+ assert outcome is not None
+ assert outcome.failed_block_labels == ["open_page", "sign_in_and_read"]
+
+ ctx = _run_history_ctx(two_page_login_yaml())
+ ctx.persisted_workflow_yaml = None
+ record_build_test_outcome(ctx, failed_second_factor_run("wr_1"))
+ ctx.workflow_yaml = two_page_login_yaml(submit_selector="Continue")
+ record_build_test_outcome(ctx, outcome)
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
+
+
+def _runtime_built_role_name_yaml() -> str:
+ """A per-account accessible name built at runtime, which the literal scan cannot see."""
+ return """
+ title: Sign in and read the metric
+ workflow_definition:
+ blocks:
+ - block_type: code
+ label: sign_in_and_read
+ code: |
+ account = "acct-42"
+ await page.get_by_role("button", name=account).click()
+ return {"visitors": "9.42K"}
+ """
+
+
+def test_a_selector_argument_built_at_runtime_cannot_prove_removal() -> None:
+ """The role alone resolves to an identity the scan did record, so only the literal count is left
+ to separate a dynamic argument from a call the scan read whole."""
+ ctx = _executed_snapshot_history(
+ failed_second_factor_run("wr_1"),
+ _executing_run("wr_2", ["sign_in_and_read"]),
+ executed_yaml=_runtime_built_role_name_yaml(),
+ )
+
+ evidence = ctx.recorded_build_test_outcome_history[-1]["executed_block_evidence"]["sign_in_and_read"]
+
+ assert evidence["removal_provable"] is False
+
+ unresolved, disposition = unresolved_runtime_block_failure_with_disposition(
+ ctx, reported_workflow_yaml=None, reported_workflow_is_persisted=True
+ )
+
+ assert unresolved == UnresolvedRuntimeFailure(workflow_run_id="wr_1", block_label="sign_in_and_read")
+ assert disposition == "no_reported_candidate"
diff --git a/tests/unit/test_copilot_enforcement_pruning.py b/tests/unit/test_copilot_enforcement_pruning.py
index e59083929..59a8c0528 100644
--- a/tests/unit/test_copilot_enforcement_pruning.py
+++ b/tests/unit/test_copilot_enforcement_pruning.py
@@ -388,6 +388,7 @@ def _fresh_ctx_for_record() -> SimpleNamespace:
last_good_workflow_yaml=None,
non_retriable_nav_error_last_emitted_signature=None,
workflow_yaml=None,
+ staged_workflow_yaml=None,
executed_block_labels=set(),
executed_block_fingerprints={},
last_workflow=None,
diff --git a/tests/unit/test_workflow_run_minutes_gate.py b/tests/unit/test_workflow_run_minutes_gate.py
index 95a4859c8..ce1cf6547 100644
--- a/tests/unit/test_workflow_run_minutes_gate.py
+++ b/tests/unit/test_workflow_run_minutes_gate.py
@@ -17,6 +17,7 @@ only the post-claim row can say whether the task started.
from __future__ import annotations
import copy
+from collections.abc import Iterator
from datetime import UTC, datetime, timedelta, tzinfo
from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock
@@ -26,11 +27,14 @@ import pytest
from skyvern.forge import agent as agent_module
from skyvern.forge import app
from skyvern.forge.agent import ForgeAgent
+from skyvern.forge.sdk.core import skyvern_context
+from skyvern.forge.sdk.core.skyvern_context import SkyvernContext
from skyvern.forge.sdk.schemas.tasks import Task, TaskStatus
from skyvern.forge.sdk.workflow import service as service_module
from skyvern.forge.sdk.workflow.models.block import BlockType
from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus
from skyvern.forge.sdk.workflow.service import WorkflowService
+from skyvern.schemas.run_enums import RunEngine
def _make_row(*, started: bool) -> MagicMock:
@@ -438,3 +442,163 @@ def test_run_type_by_engine_mapping_is_exhaustive() -> None:
assert set(_RUN_TYPE_BY_ENGINE) == set(RunEngine)
assert set(_RUN_TYPE_BY_ENGINE.values()) <= {t.value for t in RunType}
+
+
+def scoped_context() -> Iterator[SkyvernContext]:
+ context = SkyvernContext()
+ skyvern_context.set(context)
+ try:
+ yield context
+ finally:
+ skyvern_context.reset()
+
+
+def _pin_workflow_block_engine_arm(context: SkyvernContext, *, workflow_run_id: str, engine: RunEngine | None) -> None:
+ # workflow_run_id itself is what marks the context as belonging to THIS run -- an
+ # out-of-band finalizer's context (if any) belongs to whatever request triggered it, not
+ # to this run, so it never has this set.
+ context.workflow_run_id = workflow_run_id
+ context.workflow_block_engine_resolved_run_id = workflow_run_id
+ context.workflow_block_engine_override = engine
+
+
+ "engine,expected_arm",
+ [
+ (RunEngine.skyvern_v3, "treatment"),
+ (None, "control"),
+ # Finding 2: only an explicit v3 override reads as treatment -- a future non-v3
+ # override on this field must not silently pass a truthiness check.
+ (RunEngine.openai_cua, "control"),
+ ],
+)
+async def test_after_status_write_duration_log_carries_the_pinned_arm(
+ scoped_context: SkyvernContext,
+ record_run_duration: AsyncMock,
+ engine: RunEngine | None,
+ expected_arm: str,
+) -> None:
+ # SKY-15561: the arm resolved once at execution start (resolve_workflow_block_engine_arm)
+ # is pinned on the run's own context, so the terminal writer reads it back from there --
+ # no new DB lookup needed at finalize time.
+ from structlog.testing import capture_logs
+
+ _pin_workflow_block_engine_arm(scoped_context, workflow_run_id="wr_gate", engine=engine)
+
+ with capture_logs() as logs:
+ await WorkflowService()._after_workflow_run_status_write(_make_row(started=True), WorkflowRunStatus.canceled)
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] == expected_arm
+
+
[email protected]("engine,expected_arm", [(RunEngine.skyvern_v3, "treatment"), (None, "control")])
+async def test_conditional_cancel_duration_log_carries_the_pinned_arm(
+ monkeypatch: pytest.MonkeyPatch,
+ scoped_context: SkyvernContext,
+ record_run_duration: AsyncMock,
+ engine: RunEngine | None,
+ expected_arm: str,
+) -> None:
+ # Same field, the other emission site (SKY-15561).
+ from structlog.testing import capture_logs
+
+ row = _make_row(started=True)
+ monkeypatch.setattr(
+ app.DATABASE.workflow_runs,
+ "update_workflow_run_if_not_final",
+ AsyncMock(return_value=row),
+ )
+ _pin_workflow_block_engine_arm(scoped_context, workflow_run_id="wr_gate", engine=engine)
+
+ with capture_logs() as logs:
+ await WorkflowService().mark_workflow_run_as_canceled_if_not_final(workflow_run_id="wr_gate")
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] == expected_arm
+
+
+async def test_duration_log_reads_unknown_when_no_context_is_current(
+ record_run_duration: AsyncMock,
+) -> None:
+ # No context at all is current (e.g. a worker process finalizing with nothing bound):
+ # attribution is lost, not "confirmed control" -- the field must read "unknown".
+ from structlog.testing import capture_logs
+
+ with capture_logs() as logs:
+ await WorkflowService()._after_workflow_run_status_write(_make_row(started=True), WorkflowRunStatus.canceled)
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] == "unknown"
+
+
+async def test_duration_log_reads_none_when_this_runs_own_context_never_resolved_an_arm(
+ scoped_context: SkyvernContext,
+ record_run_duration: AsyncMock,
+) -> None:
+ # This run's own context is current (e.g. task_v2 / cached-script helper paths, which never
+ # call resolve_workflow_block_engine_arm) but never resolved an arm: genuinely never
+ # entered the A/B, distinct from the out-of-band "unknown" case below.
+ from structlog.testing import capture_logs
+
+ scoped_context.workflow_run_id = "wr_gate"
+
+ with capture_logs() as logs:
+ await WorkflowService()._after_workflow_run_status_write(_make_row(started=True), WorkflowRunStatus.canceled)
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] is None
+
+
+async def test_duration_log_reads_unknown_for_a_different_runs_context(
+ scoped_context: SkyvernContext,
+ record_run_duration: AsyncMock,
+) -> None:
+ # The exact API-cancel/stuck-run-sweep shape (SKY-15561 finding 1): the finalizer for
+ # wr_gate runs in a request/task whose current context belongs to a different run
+ # (wr_other) entirely. Reading that as "control" would silently bias per-arm duration
+ # reads against exactly the canceled/timed-out population; it must read "unknown".
+ from structlog.testing import capture_logs
+
+ _pin_workflow_block_engine_arm(scoped_context, workflow_run_id="wr_other", engine=RunEngine.skyvern_v3)
+
+ with capture_logs() as logs:
+ await WorkflowService()._after_workflow_run_status_write(_make_row(started=True), WorkflowRunStatus.canceled)
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] == "unknown"
+
+
+async def test_duration_log_survives_a_failed_arm_lookup(
+ monkeypatch: pytest.MonkeyPatch,
+ record_run_duration: AsyncMock,
+) -> None:
+ # The arm read is best-effort telemetry: a lookup failure must neither drop the log nor
+ # break run finalization (SKY-15561, mirrors SKY-15499's task_run_type discipline).
+ from structlog.testing import capture_logs
+
+ monkeypatch.setattr(
+ service_module,
+ "resolved_workflow_block_engine_arm_label",
+ MagicMock(side_effect=RuntimeError("context lookup blew up")),
+ )
+
+ with capture_logs() as logs:
+ await WorkflowService()._after_workflow_run_status_write(_make_row(started=True), WorkflowRunStatus.canceled)
+
+ duration_logs = [e for e in logs if e.get("event") == "Workflow run duration metrics"]
+ assert len(duration_logs) == 1
+ assert duration_logs[0]["task_v3_ab_arm"] is None
+ assert record_run_duration.await_count == 1