Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Task V3: say the page did not change in the repeated-action verdict only when its fingerprint never moved (SKY-17960) (#8864)
pedrohsdb94c7ee197fc5
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.pyindex 6dee9704d..2c21810ba 100644--- a/skyvern/forge/taskv3/loop.py+++ b/skyvern/forge/taskv3/loop.py@@ -2043,14 +2043,17 @@ def _verdict_target(return describe_target(tool, name, kind, secret_values)-def _action_loop_reason(target: str | None) -> str:+def _action_loop_reason(target: str | None, *, page_unchanged: bool) -> str:"""`target` is the control the run kept acting on, or None when the repeated call reported no name- (a failed call reports none) — then the verdict names no place rather than guessing one."""+ (a failed call reports none) — then the verdict names no place rather than guessing one.+ `page_unchanged` is True only when the streak's page fingerprint was sampled and never moved."""where = f" on {target}" if target else ""- return (- f"The run repeated the same action{where} and the page did not change in response, so the task "- "could not make progress — commonly the site rejecting the action and showing the same page again."- )+ if page_unchanged:+ return (+ f"The run repeated the same action{where} and the page did not change in response, so the task "+ "could not make progress — commonly the site rejecting the action and showing the same page again."+ )+ return f"The run repeated the same action{where} without making progress, so the task was stopped."def _budget_exhausted_reason(cap_trip: str) -> str:@@ -4973,7 +4976,10 @@ async def run_agent_tool_loop(label_secret_values,skyvern_ctx,)- st.outcome = _guard_verdict(ACTION_LOOP_GUARD, _action_loop_reason(named_target))+ page_unchanged = streak_fp is not None and batch_fp_before is not None and not streak_moved+ st.outcome = _guard_verdict(+ ACTION_LOOP_GUARD, _action_loop_reason(named_target, page_unchanged=page_unchanged)+ )_append_skipped_tool_results(st.messages, tool_calls[idx + 1 :], "action loop")breakif (diff --git a/tests/unit/test_taskv3_loop.py b/tests/unit/test_taskv3_loop.pyindex 025414efd..a48b214ce 100644--- a/tests/unit/test_taskv3_loop.py+++ b/tests/unit/test_taskv3_loop.py@@ -5241,6 +5241,36 @@ async def test_action_loop_terminates_with_bounded_verdict_on_resubmit_signatureassert caller.calls <= 15+ ("fingerprint_mode", "says_unchanged"),+ [("never_moves", True), ("moves", False), ("not_sampled", False)],+)+async def test_action_loop_verdict_says_the_page_did_not_change_only_when_its_fingerprint_never_moved(+ fingerprint_mode: str, says_unchanged: bool+) -> None:+ clicks: list[tuple[str, dict[str, Any]]] = []+ tools = [_billable_tool("click", clicks), _perception_tool("observe", _REJECTION_OBSERVE), make_finish_tool()]+ samples = {"n": 0}++ async def fingerprint() -> str:+ samples["n"] += 1+ return f"dom-{samples['n']}" if fingerprint_mode == "moves" else "rejected"++ outcome, _ = await _run(+ _resubmit_script(12),+ tools,+ max_turns=200,+ max_tool_calls=500,+ page_fingerprint=None if fingerprint_mode == "not_sampled" else fingerprint,+ )++ assert outcome.guard == ACTION_LOOP_GUARD+ assert outcome.reason.startswith("The run repeated the same action")+ assert ("did not change" in outcome.reason) is says_unchanged+ assert ("without making progress" in outcome.reason) is not says_unchanged++@pytest.mark.asyncioasync def test_action_loop_warns_once_naming_action_count_and_unchanged_state() -> None:# Compaction elides superseded observes, so the model cannot see its own repetition in the