Skip to content

Automate browser based workflows with AI

Admit verification-URL blocks into the workflow-block engine A/B (SKY-14816) (#8536)

pedrohsdb412c833249b1
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py
index 0014090f3..238c48548 100644
--- a/skyvern/forge/sdk/workflow/models/block.py
+++ b/skyvern/forge/sdk/workflow/models/block.py
@@ -17085,7 +17085,6 @@ class V3AbIneligibleReason(StrEnum):
script_run = "script_run"
pinned_engine = "pinned_engine"
unsupported_block = "unsupported_block"
- block_totp_verification_url = "block_totp_verification_url"
no_reroutable_blocks = "no_reroutable_blocks"
@@ -17118,7 +17117,7 @@ def v3_ab_ineligibility_reason(blocks: list[BlockTypeVar], *, is_script_run: boo
# A prompt-criteria branch evaluates through a synthetic extraction block that follows
# the run's arm, so it is a rerouted surface this predicate must count; jinja-only
# conditionals are pure control flow and stay invisible to the A/B. Both this type and
- # the while-loop below skip the pinned-engine/totp checks: neither exposes those fields.
+ # the while-loop below skip the pinned-engine check: neither exposes that field.
if any(isinstance(branch.criteria, PromptBranchCriteria) for branch in block.branch_conditions):
reroutable_blocks += 1
continue
@@ -17136,11 +17135,6 @@ def v3_ab_ineligibility_reason(blocks: list[BlockTypeVar], *, is_script_run: boo
return V3AbIneligibleReason.pinned_engine
if not _task_block_supports_v3(block):
return V3AbIneligibleReason.unsupported_block
- # A/B rerouting never admits a run with a verification-URL block (a block explicitly pinned to
- # v3 is honored as requested); bare tasks with a verification URL are rerouted. Block-run
- # code/budget dynamics are unmeasured (SKY-14816).
- if block.totp_verification_url:
- return V3AbIneligibleReason.block_totp_verification_url
reroutable_blocks += 1
# A run with nothing to reroute would be bucketed and recorded as an exposure while both arms
# execute identically, diluting the experiment.
diff --git a/skyvern/forge/taskv3/auth_tools.py b/skyvern/forge/taskv3/auth_tools.py
index 28ff89dce..79c62e8d8 100644
--- a/skyvern/forge/taskv3/auth_tools.py
+++ b/skyvern/forge/taskv3/auth_tools.py
@@ -485,6 +485,9 @@ def build_auth_tools(
# lives on `state` so the finish gate can see what is left of it. Re-derived here rather than
# taken from the state's default because a caller may have built the state before the setting was
# read, and the budget must be the one in force where it is actually drawn down.
+ # Scope is this task, so each block of a workflow run draws its own budget. Deliberate, not
+ # emergent: v1's poll sites start a fresh full window on every invocation (`poll_otp_value`
+ # callers pass no `max_wait_seconds`), so a per-run cap here would be stricter than v1.
state.budget_seconds = settings.VERIFICATION_CODE_POLLING_TIMEOUT_MINS * 60.0
# A value one tool resolved that the other tool owns (the webhook source does not filter by type).
cached_otp_value: OTPValue | None = None
diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.py
index 871026ee0..dd7161800 100644
--- a/skyvern/forge/taskv3/engine.py
+++ b/skyvern/forge/taskv3/engine.py
@@ -367,6 +367,7 @@ async def run_task_v3_agent_loop(
activity=activity,
submit_watch=None if page_free else submit_watch,
completion_probe=completion_probe,
+ verification_blocker=verification_blocker,
staged_downloads=staged_downloads,
initial_navigation_status=initial_navigation_status,
page_probe=None if page_free else page_probe,
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.py
index 50d323c37..010c4ba98 100644
--- a/skyvern/forge/taskv3/loop.py
+++ b/skyvern/forge/taskv3/loop.py
@@ -1942,6 +1942,11 @@ class LoopState:
page_state_ever_judged: bool = False
page_state_nudge_delivered: bool = False
page_state_nudge_due: bool = False
+ # The download-completion probe refused by the verification gate. The model was told the run
+ # auto-completes on download, so a silent refusal leaves it acting blindly until a stall guard
+ # terminates it; this hands it the reason once so it can finish failed instead.
+ verification_refusal_nudge: str | None = None
+ verification_refusal_nudged: bool = False
# The last fingerprint sample from the PREVIOUS batch: a delayed render can land between one
# batch's after-sample and the next batch's before-sample, so movement is checked across
# batches, not only within them.
@@ -2039,6 +2044,7 @@ async def run_agent_tool_loop(
submit_watch: SubmitWatch | None = None,
telemetry_salt: str | None = None,
completion_probe: CompletionProbe | None = None,
+ verification_blocker: VerificationBlocker | None = None,
staged_downloads: set[str] | None = None,
initial_navigation_status: int | None = None,
page_probe: Callable[[], Awaitable[str | None]] | None = None,
@@ -2247,6 +2253,26 @@ async def run_agent_tool_loop(
return None
if not completion_reason:
return None
+ # The probe is the second path to a completed outcome, and it never reaches the finish tool.
+ # Without this the verification gate would hold only one of the two, so a run whose code
+ # never arrived could still end `completed` on a file that happened to land.
+ if verification_blocker is not None:
+ try:
+ verification_message = await verification_blocker("completed")
+ except Exception:
+ # Fail closed, as the finish tool's completed side does: a broken gate must not let
+ # a blank verification step read as done.
+ LOG.warning("taskv3 completion probe verification gate failed; failing closed", exc_info=True)
+ return None
+ if verification_message:
+ LOG.info(
+ "taskv3 loop completion probe refused by the verification gate",
+ tool=tool_name,
+ turn=st.turns,
+ )
+ if not st.verification_refusal_nudged:
+ st.verification_refusal_nudge = verification_message
+ return None
LOG.info("taskv3 loop completion probe fired", tool=tool_name, turn=st.turns)
# No tracker-wide clear here: the probe firing is download progress for the COMPLETING
# touch only, and its call site drops that one target's pending rungs — a whole-generation
@@ -3411,6 +3437,10 @@ async def run_agent_tool_loop(
st.page_state_nudge_delivered = True
LOG.info("taskv3 loop page state stall nudged", rounds=st.trailing_page_state_stall_rounds, turn=st.turns)
nudge_parts.append(_page_state_nudge_text(st.trailing_page_state_stall_rounds))
+ if st.outcome is None and st.verification_refusal_nudge is not None:
+ nudge_parts.append(st.verification_refusal_nudge)
+ st.verification_refusal_nudge = None
+ st.verification_refusal_nudged = True
if st.outcome is None and action_nudges_due:
# Deliver only warnings whose streak survived the batch AND spans turns: a later call in
# the same batch (an observe showing the page changed, a download) may have cleared it,
diff --git a/tests/unit/test_taskv3_loop.py b/tests/unit/test_taskv3_loop.py
index d596391ef..9c1530b74 100644
--- a/tests/unit/test_taskv3_loop.py
+++ b/tests/unit/test_taskv3_loop.py
@@ -16,6 +16,7 @@ import random
import subprocess
import sys
import time
+from datetime import UTC, datetime
from types import SimpleNamespace
from typing import Any
@@ -27,6 +28,7 @@ from skyvern.forge.sdk.api.llm.exceptions import LLMProviderErrorRetryableTask
from skyvern.forge.sdk.core import skyvern_context
from skyvern.forge.sdk.core.skyvern_context import SkyvernContext
from skyvern.forge.taskv3 import loop as loop_module
+from skyvern.forge.taskv3.auth_tools import _COMPLETION_BLOCKED, VerificationFailure, VerificationState
from skyvern.forge.taskv3.engine import MAX_TOKENS_CEILING, MAX_TOKENS_PER_ACTION_STEP, taskv3_runaway_backstops
from skyvern.forge.taskv3.loop import (
ACTION_BUDGET_EXTENDED_EVENT,
@@ -80,6 +82,7 @@ from skyvern.forge.taskv3.loop import (
run_agent_tool_loop,
)
from skyvern.forge.taskv3.opaque_refs import mask_opaque_urls
+from tests.unit.helpers import make_organization, make_task
class _ScriptedCaller:
@@ -6324,6 +6327,46 @@ async def test_completion_probe_ends_loop_mid_batch_without_finish() -> None:
assert recorded_rounds == [[RoundAction("click", {"selector": "#a"}, True, billable=True)]]
+async def test_completion_probe_is_refused_while_verification_never_delivered() -> None:
+ # The probe is a second path to `completed` that never reaches the finish tool, so it needs the
+ # same verification gate: a file landing after the code source gave up must not read as success.
+ now = datetime.now(UTC)
+ task = make_task(now, make_organization(now), totp_verification_url="https://example.com/otp")
+
+ async def probe(_staged: frozenset[str]) -> str | None:
+ return "a file finished downloading"
+
+ gave_up = VerificationState(task=task)
+ gave_up.arm(VerificationFailure.BUDGET_EXHAUSTED, "get_verification_code")
+ outcome, caller = await _run(
+ [
+ [("click", {"selector": "#a"})],
+ [("finish", {"status": "failed", "reason": "the verification step never completed"})],
+ ],
+ [_billable_tool("click", []), make_finish_tool()],
+ completion_probe=probe,
+ verification_blocker=gave_up.block_finish,
+ )
+ assert outcome.status == "failed", outcome.reason
+ # The refusal has to REACH the model. DOWNLOAD_COMPLETION_GUIDANCE tells it the run ends on its
+ # own and not to call finish(completed), so a silent refusal would leave it acting until a stall
+ # guard terminated the run instead of finishing failed with the verification reason.
+ assert _COMPLETION_BLOCKED in json.dumps(caller.message_history, default=str)
+
+ # Control: the identical landed download still completes when the source never failed, so the
+ # refusal above is the gate firing and not the probe being disabled.
+ healthy = VerificationState(task=task)
+ ok_outcome, _ = await _run(
+ [[("click", {"selector": "#a"})]],
+ [_billable_tool("click", []), make_finish_tool()],
+ completion_probe=probe,
+ verification_blocker=healthy.block_finish,
+ )
+ assert ok_outcome.status == "completed"
+ assert ok_outcome.reason == "a file finished downloading"
+
+
@pytest.mark.asyncio
async def test_completion_probe_ignores_staged_download_unless_download_notice_too() -> None:
# file_upload stages an http(s) source file into the same downloads dir and marks it via
diff --git a/tests/unit/test_workflow_block_engine.py b/tests/unit/test_workflow_block_engine.py
index fcc4e5275..d1df6a4aa 100644
--- a/tests/unit/test_workflow_block_engine.py
+++ b/tests/unit/test_workflow_block_engine.py
@@ -152,8 +152,9 @@ def test_mixed_eligibility_run_download_gated_validation_block_is_not_eligible(
async def test_mixed_eligibility_run_pins_whole_run_to_control(scoped_context: SkyvernContext) -> None:
eligible_1 = _make_block(TaskBlock, label="t1")
eligible_2 = _make_block(NavigationBlock, label="t2", navigation_goal="Apply to the job")
- totp_block = _make_block(TaskBlock, label="totp", totp_verification_url="https://example.com/otp")
- blocks: list[BaseTaskBlock] = [eligible_1, eligible_2, totp_block]
+ ineligible_block = _make_block(TaskBlock, label="unsupported")
+ ineligible_block.block_type = BlockType.WAIT
+ blocks: list[BaseTaskBlock] = [eligible_1, eligible_2, ineligible_block]
assert run_is_eligible_for_v3_ab(blocks, is_script_run=False) is False
@@ -162,7 +163,7 @@ async def test_mixed_eligibility_run_pins_whole_run_to_control(scoped_context: S
scoped_context,
provider,
workflow_run_id="wr_mixed",
- ineligibility_reason=V3AbIneligibleReason.block_totp_verification_url,
+ ineligibility_reason=V3AbIneligibleReason.unsupported_block,
)
for block in blocks:
@@ -558,7 +559,12 @@ def _download_gated_validation_blocks() -> list[BaseTaskBlock]:
def _totp_blocks() -> list[BaseTaskBlock]:
- return [_make_block(TaskBlock, label="totp", totp_verification_url="https://example.com/otp")]
+ # The multi-block shape the removed gate excluded: a verification-URL block alongside an ordinary
+ # one. v3 carries the verification source per block, so neither block disqualifies the run.
+ return [
+ _make_block(TaskBlock, label="signin", totp_verification_url="https://example.com/otp"),
+ _make_block(NavigationBlock, label="after_signin", navigation_goal="Apply to the job"),
+ ]
def _no_reroutable_blocks() -> list[BaseTaskBlock]:
@@ -614,7 +620,7 @@ def _jinja_condition_while_loop_blocks() -> list[Block]:
(_pinned_engine_blocks, False, V3AbIneligibleReason.pinned_engine),
(_unsupported_block_type_blocks, False, V3AbIneligibleReason.unsupported_block),
(_download_gated_validation_blocks, False, V3AbIneligibleReason.unsupported_block),
- (_totp_blocks, False, V3AbIneligibleReason.block_totp_verification_url),
+ (_totp_blocks, False, None),
(_no_reroutable_blocks, False, V3AbIneligibleReason.no_reroutable_blocks),
(_eligible_mix_blocks, False, None),
(_prompt_branch_conditional_only_blocks, False, None),
@@ -627,7 +633,7 @@ def _jinja_condition_while_loop_blocks() -> list[Block]:
"pinned_engine",
"unsupported_block_type",
"unsupported_block_validation_download",
- "block_totp_verification_url",
+ "totp_verification_url_is_admitted",
"no_reroutable_blocks",
"eligible",
"prompt_branch_conditional_is_a_reroutable_surface",