From 5bfa0b0961aaa28b0a3e7b1d279d7612be7711c3 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Thu, 15 Jan 2026 11:43:02 -0800 Subject: [PATCH] bug fix - task v2 keeps going back to the original url (#4462) --- skyvern/services/task_v2_service.py | 61 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/skyvern/services/task_v2_service.py b/skyvern/services/task_v2_service.py index 53fa44d9..043f7649 100644 --- a/skyvern/services/task_v2_service.py +++ b/skyvern/services/task_v2_service.py @@ -621,49 +621,46 @@ async def run_task_v2_helper( browser_session_id=browser_session_id, browser_profile_id=workflow_run.browser_profile_id, ) - - fallback_occurred = False - if url != current_url: - if page is None: - page = await browser_state.get_or_create_page( - url=url, - proxy_location=workflow_run.proxy_location, - task_id=task_v2.task_id, - workflow_run_id=workflow_run_id, - script_id=task_v2.script_id, - organization_id=organization_id, - extra_http_headers=task_v2.extra_http_headers, - browser_profile_id=workflow_run.browser_profile_id, - ) - else: - await browser_state.navigate_to_url(page, url) - + page = await browser_state.get_working_page() + should_fallback = False + # if page is None: + # page = await browser_state.get_or_create_page( + # url=url, + # proxy_location=workflow_run.proxy_location, + # task_id=task_v2.task_id, + # workflow_run_id=workflow_run_id, + # script_id=task_v2.script_id, + # organization_id=organization_id, + # extra_http_headers=task_v2.extra_http_headers, + # browser_profile_id=workflow_run.browser_profile_id, + # ) + if page: + current_url = await SkyvernFrame.get_url(page) page_loaded = False - if page: - try: - # Check if the page has a body element to verify it loaded - # page will always be None if browser state failed to load - page_loaded = await browser_state.validate_browser_context(page) - except Exception: - page_loaded = False - LOG.warning( - "Page failed to load properly, fallback to Google", - exc_info=True, - url=url, - current_url=current_url, - ) + try: + # Check if the page has a body element to verify it loaded + # page will always be None if browser state failed to load + page_loaded = await browser_state.validate_browser_context(page) + except Exception: + page_loaded = False + LOG.warning( + "Page failed to load properly, fallback to Google", + exc_info=True, + url=url, + current_url=current_url, + ) if not page_loaded: # Page failed to load properly, fallback to Google if page: try: await page.goto(fallback_url, timeout=settings.BROWSER_LOADING_TIMEOUT_MS) - fallback_occurred = True + should_fallback = True except Exception: LOG.exception("Failed to load Google fallback", exc_info=True, url=url, current_url=current_url) if i == 0 and current_url != url: - if fallback_occurred: + if should_fallback: plan = f"Go to Google because the intended website ({url}) failed to load properly." task_type = "goto_url" task_history_record = {"type": task_type, "task": plan}