Skip to content

Automate browser based workflows with AI

Handle interrupted native downloads in Task V3 (SKY-18624) (#9009)

LawyZheng218cb0c23ffc
diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py
index 6de7213fc..01cbde791 100644
--- a/skyvern/forge/agent.py
+++ b/skyvern/forge/agent.py
@@ -338,6 +338,7 @@ from skyvern.webeye.actions.parse_actions import (
parse_ui_tars_actions,
)
from skyvern.webeye.actions.responses import STALE_TARGET_TOOL_RESULT, ActionFailure, ActionResult, ActionSuccess
+from skyvern.webeye.browser_artifacts import DownloadBinding
from skyvern.webeye.browser_driver_errors import is_driver_error
from skyvern.webeye.browser_engine import BrowserEngineSelection, is_any_engine_error
from skyvern.webeye.browser_errors import (
@@ -355,6 +356,7 @@ from skyvern.webeye.cdp_download_interceptor import (
settle_browser_downloads_for_context,
)
from skyvern.webeye.dom_inspection import read_current_url
+from skyvern.webeye.native_downloads import NativeDownloadAttempt, NativeDownloads
from skyvern.webeye.scraper.scraped_page import ElementTreeFormat, ScrapedPage
from skyvern.webeye.scraper.scraper import page_is_dead_blank, page_is_http_survivor
from skyvern.webeye.utils.document import get_main_document_loader_id
@@ -2036,6 +2038,7 @@ class ForgeAgent:
attempt_started_at: datetime | None = None,
exhausted: set[str] | None = None,
should_cancel: Callable[[], Awaitable[bool]] | None = None,
+ native_failure_quiescent: Callable[[], Awaitable[bool]] | None = None,
) -> bool:
"""Block until any download the task already kicked off settles (or times out).
@@ -2077,7 +2080,7 @@ class ForgeAgent:
if timeout_cap is not None:
timeout = min(timeout, timeout_cap)
try:
- if should_cancel is None:
+ if should_cancel is None and native_failure_quiescent is None:
await wait_for_download_finished(
downloading_files=downloading_files,
timeout=timeout,
@@ -2087,6 +2090,7 @@ class ForgeAgent:
downloading_files=downloading_files,
timeout=timeout,
should_cancel=should_cancel,
+ native_failure_quiescent=native_failure_quiescent,
)
except DownloadFileMaxWaitingTime as e:
LOG.warning(
@@ -2103,19 +2107,34 @@ class ForgeAgent:
*,
downloading_files: list[str],
timeout: float,
- should_cancel: Callable[[], Awaitable[bool]],
+ should_cancel: Callable[[], Awaitable[bool]] | None,
+ native_failure_quiescent: Callable[[], Awaitable[bool]] | None = None,
) -> bool:
"""Returns True when should_cancel fired and the wait was cut short; False on normal completion."""
wait_task = asyncio.ensure_future(
wait_for_download_finished(downloading_files=downloading_files, timeout=timeout)
)
+ native_check: asyncio.Task[bool] | None = None
+
+ async def check_native() -> bool:
+ if native_failure_quiescent is not None and await native_failure_quiescent():
+ # Stop at the observation, before another poll could reuse a stale quiescent result.
+ wait_task.cancel()
+ return True
+ return False
+
try:
+ # Probe at once: a retained partial from an already-failed download would otherwise cost a poll per call.
+ if native_failure_quiescent is not None:
+ native_check = asyncio.ensure_future(check_native())
while True:
done, _pending = await asyncio.wait({wait_task}, timeout=1.0)
if wait_task in done:
+ if wait_task.cancelled() and native_check is not None and await native_check:
+ return False
await wait_task
return False
- if await should_cancel():
+ if should_cancel is not None and await should_cancel():
LOG.info(
"Cancelling in-flight download wait: run was canceled",
downloading_files=downloading_files,
@@ -2124,11 +2143,19 @@ class ForgeAgent:
with contextlib.suppress(asyncio.CancelledError):
await wait_task
return True
+ if native_check is not None and native_check.done():
+ # A True probe already cancelled wait_task; re-probing could re-raise that cancellation.
+ if await native_check:
+ return False
+ native_check = None
+ if native_failure_quiescent is not None and native_check is None:
+ native_check = asyncio.ensure_future(check_native())
finally:
- if not wait_task.done():
- wait_task.cancel()
- with contextlib.suppress(asyncio.CancelledError):
- await wait_task
+ pending: list[asyncio.Future[Any]] = [wait_task] if native_check is None else [wait_task, native_check]
+ for pending_task in pending:
+ if not pending_task.done():
+ pending_task.cancel()
+ await asyncio.gather(*pending, return_exceptions=True)
async def create_task_and_step_from_block(
self,
@@ -2688,6 +2715,35 @@ class ForgeAgent:
def _provider_wait_seconds(block: BaseTaskBlock) -> float:
return min(block.download_timeout or PROVIDER_DOWNLOAD_WAIT_SECONDS, loop_deadline_at - time.monotonic())
+ native_download_attempt: NativeDownloadAttempt | None = None
+
+ def _native_attempt_eligible() -> bool:
+ artifacts = browser_state.browser_artifacts
+ observer = artifacts.native_downloads
+ if (
+ native_download_attempt is None
+ or observer is None
+ or observer.attempt is not native_download_attempt
+ or native_download_attempt.task_id != task.task_id
+ or browser_state.browser_context is not observer.context
+ or workflow_download_directory is None
+ or observer.download_dir != workflow_download_directory.resolve()
+ or task.browser_session_id
+ or browser_session_id
+ or artifacts.download_binding != DownloadBinding.RUN_DIR
+ or artifacts.get_action_download_source() is not None
+ or getattr(observer.context, "_skyvern_cdp_download_interceptor", None) is not None
+ or getattr(observer.context, "_skyvern_external_browser", False) is True
+ ):
+ return False
+ return True
+
+ async def _native_failure_quiescent() -> bool:
+ if not _native_attempt_eligible() or native_download_attempt is None:
+ return False
+ quiet = await native_download_attempt.failed_and_quiescent()
+ return quiet and _native_attempt_eligible()
+
download_wait: DownloadWait | None = None
download_settle: DownloadSettle | None = None
if task_block is not None and task_block.complete_on_download and task.workflow_run_id:
@@ -2707,6 +2763,7 @@ class ForgeAgent:
exhausted=download_wait_exhausted,
should_cancel=_should_cancel,
attempt_started_at=attempt_started_at,
+ native_failure_quiescent=_native_failure_quiescent,
)
if cancelled:
# The run is being canceled; even if a file landed while we waited, don't
@@ -2763,6 +2820,10 @@ class ForgeAgent:
exhausted=download_wait_exhausted,
should_cancel=_should_cancel,
attempt_started_at=attempt_started_at,
+ # Only a complete_on_download block has the failure watch that tells the model why it ended early.
+ native_failure_quiescent=_native_failure_quiescent
+ if wait_only_block.complete_on_download
+ else None,
):
return
# A vendor session can keep a file its replay could not fetch; reading it back into the run dir is
@@ -3172,6 +3233,15 @@ class ForgeAgent:
prev_active_credential_parameter_key = context.active_credential_parameter_key if context else None
if context and credential_parameter_key is not None:
context.active_credential_parameter_key = credential_parameter_key
+ observer = browser_state.browser_artifacts.native_downloads
+ if (
+ isinstance(observer, NativeDownloads)
+ and observer.context is browser_state.browser_context
+ and task_block is not None
+ and not task.browser_session_id
+ and not browser_session_id
+ ):
+ native_download_attempt = observer.begin_attempt(task.task_id)
try:
# Built AFTER the credential pin: the code-source check (has_credential_totp_candidate)
# must see the pinned key, or a multi-credential context reads as having no code source.
@@ -3332,6 +3402,7 @@ class ForgeAgent:
),
download_wait=download_wait,
download_settle=download_settle,
+ native_download_attempt=native_download_attempt,
completion_gate=_completion_gate,
staged_downloads=staged_downloads,
deadline_seconds=loop_deadline_seconds,
@@ -3356,6 +3427,8 @@ class ForgeAgent:
anthropic_cache_markers=uses_only_anthropic_models(llm_caller.llm_config),
)
finally:
+ if native_download_attempt is not None:
+ native_download_attempt.end()
input_dispatch.end_login_pace()
if context and credential_parameter_key is not None:
context.active_credential_parameter_key = prev_active_credential_parameter_key
diff --git a/skyvern/forge/sdk/artifact/storage/azure.py b/skyvern/forge/sdk/artifact/storage/azure.py
index 7ff8c276d..80aebcab0 100644
--- a/skyvern/forge/sdk/artifact/storage/azure.py
+++ b/skyvern/forge/sdk/artifact/storage/azure.py
@@ -585,6 +585,8 @@ class AzureStorage(BaseStorage):
skipped_files: list[str] = []
unchanged_file_count = 0
for file in files:
+ if file.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
fpath = os.path.join(download_dir, file)
if not os.path.isfile(fpath):
continue
@@ -721,6 +723,8 @@ class AzureStorage(BaseStorage):
file_infos: list[FileInfo] = []
for key in object_keys:
+ if key.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
object_uri = f"azure://{settings.AZURE_STORAGE_CONTAINER_UPLOADS}/{key}"
metadata = {}
diff --git a/skyvern/forge/sdk/artifact/storage/base.py b/skyvern/forge/sdk/artifact/storage/base.py
index 22da8bd0a..31e1e3595 100644
--- a/skyvern/forge/sdk/artifact/storage/base.py
+++ b/skyvern/forge/sdk/artifact/storage/base.py
@@ -9,6 +9,7 @@ from urllib.parse import unquote
import structlog
+from skyvern.constants import BROWSER_DOWNLOADING_SUFFIX
from skyvern.forge import app
from skyvern.forge.sdk.artifact.models import Artifact, ArtifactType, LogEntityType
from skyvern.forge.sdk.artifact.signing import SENSITIVE_ARTIFACT_TYPES, SENSITIVE_ARTIFACT_URL_EXPIRY_SECONDS
@@ -304,7 +305,10 @@ async def _file_infos_from_download_artifacts(artifacts: list[Artifact]) -> list
pre-existing import sites keep working without each having to thread the
artifact_type through.
"""
- return await _file_infos_from_artifacts(artifacts, artifact_type=ArtifactType.DOWNLOAD)
+ return await _file_infos_from_artifacts(
+ [a for a in artifacts if not artifact_filename_from_uri(a.uri).endswith(BROWSER_DOWNLOADING_SUFFIX)],
+ artifact_type=ArtifactType.DOWNLOAD,
+ )
# TODO: This should be a part of the ArtifactType model
diff --git a/skyvern/forge/sdk/artifact/storage/gcs.py b/skyvern/forge/sdk/artifact/storage/gcs.py
index e97aa3175..403942dbd 100644
--- a/skyvern/forge/sdk/artifact/storage/gcs.py
+++ b/skyvern/forge/sdk/artifact/storage/gcs.py
@@ -600,6 +600,8 @@ class GcsStorage(BaseStorage):
skipped_files: list[str] = []
unchanged_file_count = 0
for file in files:
+ if file.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
fpath = os.path.join(download_dir, file)
if not os.path.isfile(fpath):
continue
@@ -735,6 +737,8 @@ class GcsStorage(BaseStorage):
file_infos: list[FileInfo] = []
for key in object_keys:
+ if key.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
object_uri = f"gs://{settings.GCS_BUCKET_UPLOADS}/{key}"
metadata = {}
diff --git a/skyvern/forge/sdk/artifact/storage/local.py b/skyvern/forge/sdk/artifact/storage/local.py
index 602912830..7e00c1740 100644
--- a/skyvern/forge/sdk/artifact/storage/local.py
+++ b/skyvern/forge/sdk/artifact/storage/local.py
@@ -9,7 +9,7 @@ import aiofiles
import structlog
from skyvern.config import settings
-from skyvern.constants import DOWNLOAD_FILE_PREFIX
+from skyvern.constants import BROWSER_DOWNLOADING_SUFFIX, DOWNLOAD_FILE_PREFIX
from skyvern.exceptions import DownloadSaveIncompleteError
from skyvern.forge import app
from skyvern.forge.sdk.api.files import (
@@ -441,6 +441,8 @@ class LocalStorage(BaseStorage):
saved = download_checksums_by_uri(artifacts)
skipped: list[str] = []
for filename in files:
+ if filename.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
source = Path(download_dir) / filename
if not source.is_file():
continue
@@ -605,6 +607,7 @@ class LocalStorage(BaseStorage):
if uri.startswith("file://")
and (snapshot_path := Path(parse_uri_to_path(uri))).is_relative_to(snapshot_root)
and snapshot_path.is_file()
+ and not snapshot_path.name.endswith(BROWSER_DOWNLOADING_SUFFIX)
}
snapshot_contents = {
(Path(parse_uri_to_path(artifact.uri)).name, artifact.checksum) for artifact in snapshots.values()
@@ -622,6 +625,8 @@ class LocalStorage(BaseStorage):
]
files_and_folders = os.listdir(download_dir)
for file_or_folder in files_and_folders:
+ if file_or_folder.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
path = os.path.join(download_dir, file_or_folder)
if os.path.isfile(path):
checksum = calculate_sha256_for_file(path)
diff --git a/skyvern/forge/sdk/artifact/storage/s3.py b/skyvern/forge/sdk/artifact/storage/s3.py
index 6e7d3a8d6..cb3481e1a 100644
--- a/skyvern/forge/sdk/artifact/storage/s3.py
+++ b/skyvern/forge/sdk/artifact/storage/s3.py
@@ -866,6 +866,8 @@ class S3Storage(BaseStorage, StreamingArtifactStorage):
skipped_files: list[str] = []
unchanged_file_count = 0
for file in files:
+ if file.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
fpath = os.path.join(download_dir, file)
if not os.path.isfile(fpath):
continue
@@ -1067,6 +1069,8 @@ class S3Storage(BaseStorage, StreamingArtifactStorage):
file_infos: list[FileInfo] = []
for key in object_keys:
+ if key.endswith(BROWSER_DOWNLOADING_SUFFIX):
+ continue
object_uri = f"s3://{bucket}/{key}"
metadata = {}
diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.py
index bf90d3519..681ae8798 100644
--- a/skyvern/forge/taskv3/engine.py
+++ b/skyvern/forge/taskv3/engine.py
@@ -93,6 +93,7 @@ from skyvern.schemas.workflows import BlockType
from skyvern.services.otp_service import iter_totp_from_navigation_inputs
from skyvern.utils.prompt_engine import PROMPT_HARD_CEILING_TOKENS
from skyvern.utils.token_counter import approx_count_tokens, count_tokens
+from skyvern.webeye.native_downloads import NativeDownloadAttempt
LOG = structlog.get_logger()
@@ -284,6 +285,7 @@ async def run_task_v3_agent_loop(
pending_marker: Callable[[str], Awaitable[str | None]] | None = None,
download_wait: DownloadWait | None = None,
download_settle: DownloadSettle | None = None,
+ native_download_attempt: NativeDownloadAttempt | None = None,
completion_gate: CompletionGate | None = None,
staged_downloads: set[str] | None = None,
verification_blocker: VerificationBlocker | None = None,
@@ -421,7 +423,11 @@ async def run_task_v3_agent_loop(
)
)
unseen_text = None if page_free else UnseenPageText()
- failure_watch = None if page_free or download_settle is None else DownloadFailureWatch(page_provider, refs)
+ failure_watch = (
+ None
+ if page_free or download_settle is None
+ else DownloadFailureWatch(page_provider, refs, native_download_attempt=native_download_attempt)
+ )
browser_tools = (
[]
if page_free
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.py
index fd68fd095..a36f253c9 100644
--- a/skyvern/forge/taskv3/tools.py
+++ b/skyvern/forge/taskv3/tools.py
@@ -129,6 +129,7 @@ from skyvern.webeye.actions.key_names import normalize_key_chord
from skyvern.webeye.browser_driver_errors import is_driver_error, is_driver_timeout_error
from skyvern.webeye.browser_state import BLANK_PAGE_URLS, is_selectable_page_url
from skyvern.webeye.cdp_download_interceptor import download_tally_for_context
+from skyvern.webeye.native_downloads import NativeDownloadAttempt
from skyvern.webeye.navigation import driver_nav_error_code, record_task_nav_error_code, redact_url_secrets
from skyvern.webeye.utils.challenge_signature import CHALLENGE_VENDOR_FRAME_URL, CHALLENGE_VENDOR_SIGNATURE
from skyvern.webeye.utils.flutter_semantics import (
@@ -23486,8 +23487,16 @@ class DownloadFailureWatch:
"""Records, on a download block, xhr/fetch requests and documents a call started that came back 4xx/5xx or failed,
and browser downloads the interceptor could not save, into `facts` for the next tool result to report."""
- def __init__(self, page_provider: PageProvider, opaque_refs: OpaqueUrlRefs | None = None) -> None:
+ def __init__(
+ self,
+ page_provider: PageProvider,
+ opaque_refs: OpaqueUrlRefs | None = None,
+ *,
+ native_download_attempt: NativeDownloadAttempt | None = None,
+ ) -> None:
self.facts = DownloadFailureFacts(refresh=self._read_tally)
+ self._native_download_attempt = native_download_attempt
+ self._native_failures_seen = (0, 0)
self._page_provider = page_provider
self._opaque_refs = opaque_refs
self._context: BrowserContext | None = None
@@ -23592,6 +23601,13 @@ class DownloadFailureWatch:
self.facts.add(f"Request failed: {self._describe(request)} {what}", repeat=self._live[request] is not None)
def _read_tally(self) -> None:
+ attempt = self._native_download_attempt
+ if attempt is not None and not attempt.closed and attempt.observer.context is self._context:
+ if attempt.interrupted > self._native_failures_seen[0]:
+ self.facts.add("Browser download interrupted before completion.", repeat=True)
+ if attempt.cancelled_by_skyvern > self._native_failures_seen[1]:
+ self.facts.add("Browser download cancelled at the configured download timeout.", repeat=True)
+ self._native_failures_seen = (attempt.interrupted, attempt.cancelled_by_skyvern)
tally = download_tally_for_context(self._context)
if tally is None:
return
@@ -23640,7 +23656,7 @@ class DownloadFailureWatch:
request for request, started in self._live.items() if started == call and request not in self._responded
]
- async def settle(self, call: int, *, wait: bool) -> list[str]:
+ async def settle(self, call: int, *, wait: bool, deliver: bool = True) -> list[str]:
"""Waits, boundedly and only when `wait`, for the requests call `call` started, then hands out the
undelivered facts and the requests still unanswered."""
deadline = time.monotonic() + _DOWNLOAD_FAILURE_SETTLE_SECONDS
@@ -23665,7 +23681,7 @@ class DownloadFailureWatch:
await asyncio.wait_for(self._changed.wait(), remaining)
finally:
self.end()
- return self.facts.deliver() + pending
+ return (self.facts.deliver() if deliver else []) + pending
def close(self) -> None:
for working_page in list(self._named_pages):
@@ -23853,7 +23869,7 @@ def _apply_download_signal(
failures: list[str] = []
page_names: Mapping[str, str] = {}
if failure_watch is not None:
- failures = await failure_watch.settle(call, wait=_may_submit(_tool_name, args))
+ failures = await failure_watch.settle(call, wait=_may_submit(_tool_name, args), deliver=False)
# A file a tool staged itself (file_upload) is not a download to wait for.
staged = bool((result.data or {}).get("staged_download"))
if download_wait is not None and ((_billable and not staged) or _list_split()[1]):
@@ -23862,6 +23878,7 @@ def _apply_download_signal(
except Exception:
LOG.warning("taskv3 download wait failed", tool=_tool_name, exc_info=True)
if failure_watch is not None:
+ failures = failure_watch.facts.deliver() + failures
landed = [name for name in _list_split()[0] if name not in seen_completed]
if landed:
page_names = await failure_watch.page_names(landed)
diff --git a/skyvern/webeye/browser_artifacts.py b/skyvern/webeye/browser_artifacts.py
index 64041aa26..95daaf9c8 100644
--- a/skyvern/webeye/browser_artifacts.py
+++ b/skyvern/webeye/browser_artifacts.py
@@ -11,6 +11,8 @@ import structlog
from playwright.async_api import Page
from pydantic import BaseModel, PrivateAttr
+from skyvern.webeye.native_downloads import NativeDownloads
+
LOG = structlog.get_logger()
@@ -124,6 +126,14 @@ class BrowserArtifacts(BaseModel):
_requested_graphics_flags: tuple[str, ...] | None = PrivateAttr(default=None)
# Whether the creator started this browser's process on this host itself, rather than dialing one.
_spawned_local_browser: bool = PrivateAttr(default=False)
+ _native_downloads: NativeDownloads | None = PrivateAttr(default=None)
+
+ @property
+ def native_downloads(self) -> NativeDownloads | None:
+ return self._native_downloads
+
+ def attach_native_downloads(self, observer: NativeDownloads | None) -> None:
+ self._native_downloads = observer
def local_paths(self) -> list[str]:
"""Files and folders on this host that the browser writes to: recordings, HAR, traces, profile, console log."""
diff --git a/skyvern/webeye/browser_factory.py b/skyvern/webeye/browser_factory.py
index e13bc4e1a..ba5b17bff 100644
--- a/skyvern/webeye/browser_factory.py
+++ b/skyvern/webeye/browser_factory.py
@@ -17,7 +17,7 @@ from contextlib import suppress
from dataclasses import dataclass
from datetime import UTC, datetime
from pathlib import Path
-from typing import Any, Awaitable, Callable, Coroutine, Literal, Protocol, cast
+from typing import Any, Awaitable, Callable, Literal, Protocol, cast
from urllib.parse import parse_qsl, urlparse
import psutil
@@ -41,6 +41,7 @@ from playwright.async_api import (
from skyvern.config import settings
from skyvern.constants import (
BROWSER_DOWNLOAD_TIMEOUT,
+ BROWSER_DOWNLOADING_SUFFIX,
SAVE_DOWNLOADED_FILES_TIMEOUT,
SKYVERN_DIR,
)
@@ -94,6 +95,11 @@ from skyvern.webeye.display_recorder import (
release_display_recorder,
release_started_display_recording,
)
+from skyvern.webeye.native_downloads import (
+ DOWNLOAD_FAILURE_READ_TIMEOUT_SECONDS,
+ NativeDownloadAttempt,
+ NativeDownloads,
+)
from skyvern.webeye.playwright_input import register_playwright_input_context
from skyvern.webeye.profile_download_state import strip_download_history_state
from skyvern.webeye.session_cookies import (
@@ -360,7 +366,6 @@ def _consume_abandoned_task_result(task: asyncio.Task) -> None:
task.exception()
-DOWNLOAD_FAILURE_READ_TIMEOUT_SECONDS = 5.0
_DOWNLOADS_CANCELLED_BY_SKYVERN: weakref.WeakSet[Download] = weakref.WeakSet()
@@ -428,6 +433,12 @@ def set_popup_video_listener(browser_context: BrowserContext, browser_artifacts:
asyncio.ensure_future(_on_page(page))
+def _completed_file_suffix(name: str) -> str:
+ # Storage treats the in-progress suffix as a partial, so a finished file named "x.crdownload" must not take it.
+ suffix = Path(name).suffix
+ return "" if suffix == BROWSER_DOWNLOADING_SUFFIX else suffix
+
+
def _redact_url_query(url: str) -> str:
# Download URLs are often S3 presigned, carrying an X-Amz signature in the query — drop it before logging.
try:
@@ -437,12 +448,25 @@ def _redact_url_query(url: str) -> str:
def set_download_file_listener(
- browser_context: BrowserContext, download_timeout: float | None = None, **kwargs: Any
+ browser_context: BrowserContext,
+ download_timeout: float | None = None,
+ browser_artifacts: BrowserArtifacts | None = None,
+ **kwargs: Any,
) -> None:
async def save_download(
- download: Download, context: SkyvernContext | None, owner_task_id: str | None, residential_egress: bool
+ download: Download,
+ context: SkyvernContext | None,
+ owner_task_id: str | None,
+ residential_egress: bool,
+ observer: NativeDownloads | None,
+ attempt: NativeDownloadAttempt | None,
) -> None:
download_started_at = time.monotonic()
+ failed = False
+ self_cancelled = False
+ # An unreadable terminal state stays pending: only a known outcome may release the wait.
+ settled = True
+ resolved = False
workflow_run_id = (context.workflow_run_id if context else None) or kwargs.get("workflow_run_id")
task_id = owner_task_id or (context.task_id if context else None) or kwargs.get("task_id")
# Read when the download starts, not when the context is built: one browser serves many tasks.
@@ -463,7 +487,10 @@ def set_download_file_listener(
)
mark_download_cancelled_by_skyvern(download)
await download.cancel()
+ self_cancelled = await read_download_failure(download) is not None
+ settled = self_cancelled
return
+ resolved = True
if context and owner_task_id:
context.download_completed_task_ids.add(owner_task_id)
file_path = Path(resolved_path)
@@ -487,7 +514,7 @@ def set_download_file_listener(
suggested_filename_fp=diagnostic_fingerprint(download.suggested_filename),
url=_redact_url_query(download.url),
)
- suffix = Path(download.suggested_filename).suffix
+ suffix = _completed_file_suffix(download.suggested_filename)
if suffix:
LOG.info(
"Add extension according to suggested filename",
@@ -502,7 +529,7 @@ def set_download_file_listener(
parsed_qs = parse_qsl(parsed_url.query)
for key, value in parsed_qs:
if key.lower() == "filename":
- suffix = Path(value).suffix
+ suffix = _completed_file_suffix(value)
if suffix:
LOG.info(
"Add extension according to the parsed query params of download url",
@@ -513,7 +540,7 @@ def set_download_file_listener(
file_path.rename(str(file_path) + suffix)
return
- suffix = Path(parsed_url.path).suffix
+ suffix = _completed_file_suffix(parsed_url.path)
if suffix:
LOG.info(
"Add extension according to download url path",
@@ -525,10 +552,17 @@ def set_download_file_listener(
return
# TODO: maybe should try to parse it from URL response
+ except asyncio.CancelledError:
+ settled = False
+ raise
except Exception:
# An aborted transfer surfaces here as a path() error; reporting it as a rename failure
# sends triage to the wrong subsystem and hides that no file was ever saved.
- failure = await read_download_failure(download)
+ try:
+ failure = await read_download_failure(download)
+ except asyncio.CancelledError:
+ settled = False
+ raise
if (
failure == "canceled"
and not was_download_cancelled_by_skyvern(download)
@@ -539,6 +573,8 @@ def set_download_file_listener(
):
context.residential_download_interrupted_task_ids.add(owner_task_id)
if failure is not None:
+ failed = True
+ self_cancelled = was_download_cancelled_by_skyvern(download)
LOG.warning(
"Browser aborted the download before any file was saved",
workflow_run_id=workflow_run_id,
@@ -550,13 +586,18 @@ def set_download_file_listener(
signed_url_ttl_remaining_s=signed_url_ttl_remaining_seconds(download.url, datetime.now(UTC)),
)
return
+ settled = resolved
LOG.exception(
"Failed to add file extension name to downloaded file",
workflow_run_id=workflow_run_id,
task_id=task_id,
)
- def listen_to_download(download: Download) -> Coroutine[Any, Any, None]:
+ finally:
+ if observer is not None and settled:
+ observer.finished(download, attempt, failed=failed, self_cancelled=self_cancelled)
+
+ def on_download(download: Download) -> asyncio.Task[None]:
# Snapshot the task synchronously at event delivery; the context can change before the coroutine runs.
# Callback kwargs can belong to an older task or run and cannot establish ownership.
context = current()
@@ -573,12 +614,23 @@ def set_download_file_listener(
residential_egress = app.AGENT_FUNCTION.is_residential_browser_egress(browser_context)
except Exception:
owner_task_id = None
- return save_download(download, context, owner_task_id, residential_egress)
+ observer = browser_artifacts.native_downloads if browser_artifacts is not None else None
+ if observer is not None and observer.context is not browser_context:
+ observer = None
+ attempt = observer.started(download) if observer is not None else None
+ return asyncio.create_task(
+ save_download(download, context, owner_task_id, residential_egress, observer, attempt)
+ )
def listen_to_new_page(page: Page) -> None:
- page.on("download", listen_to_download)
+ page.on("download", on_download)
browser_context.on("page", listen_to_new_page)
+ for page in browser_context.pages:
+ listen_to_new_page(page)
+ observer = browser_artifacts.native_downloads if browser_artifacts is not None else None
+ if observer is not None and observer.context is browser_context:
+ observer.listeners_registered()
async def start_unreported_download_renamer(cdp_port: int, download_dir: str) -> asyncio.Task[None] | None:
@@ -633,7 +685,7 @@ def _add_suggested_extension(event: dict[str, Any], suggested_filenames: dict[st
suggested_filenames[params["guid"]] = params["suggestedFilename"]
if event.get("method") != "Browser.downloadProgress" or params["state"] == "inProgress":
return
- suffix = Path(suggested_filenames.pop(params["guid"], "")).suffix
+ suffix = _completed_file_suffix(suggested_filenames.pop(params["guid"], ""))
file_path = download_dir / params["guid"]
# set_download_file_listener also checks and renames without awaiting in between, so on one event loop whichever
# runs second finds the file already renamed and skips it.
@@ -949,7 +1001,7 @@ class BrowserContextFactory:
# created regardless of who launched the browser).
if not attach_only_enforcing() and browser_artifacts._display_recorder is None:
set_popup_video_listener(browser_context=browser_context, browser_artifacts=browser_artifacts)
- set_download_file_listener(browser_context=browser_context, **kwargs)
+ set_download_file_listener(browser_context=browser_context, browser_artifacts=browser_artifacts, **kwargs)
set_dialog_handler(browser_context=browser_context)
route_handlers_allowed = None
if scoped_headers or route_policy_url is not None:
@@ -1247,6 +1299,18 @@ async def _create_headless_chromium(
discard_temp_working_dir(read_only_copy)
raise
browser_artifacts.note_requested_launch_args(browser_args.get("args"))
+ browser_artifacts.attach_native_downloads(
+ NativeDownloads.attach(
+ browser_context,
+ download_dir=download_dir,
+ before_activity=(
+ not loaded_from_saved_profile
+ and not settings.EXTENSIONS
+ and not settings.BROWSER_ADDITIONAL_ARGS
+ and not cdp_port
+ ),
+ )
+ )
return browser_context, browser_artifacts, _read_only_copy_cleanup(read_only_copy)
@@ -1381,6 +1445,18 @@ async def _create_headful_chromium(
await release_started_display_recording(browser_artifacts)
raise
browser_artifacts.note_requested_launch_args(browser_args.get("args"))
+ browser_artifacts.attach_native_downloads(
+ NativeDownloads.attach(
+ browser_context,
+ download_dir=download_dir,
+ before_activity=(
+ not loaded_from_saved_profile
+ and not settings.EXTENSIONS
+ and not settings.BROWSER_ADDITIONAL_ARGS
+ and not cdp_port
+ ),
+ )
+ )
return browser_context, browser_artifacts, _read_only_copy_cleanup(read_only_copy)
diff --git a/skyvern/webeye/native_downloads.py b/skyvern/webeye/native_downloads.py
new file mode 100644
index 000000000..992b7a74d
--- /dev/null
+++ b/skyvern/webeye/native_downloads.py
@@ -0,0 +1,100 @@
+from __future__ import annotations
+
+from pathlib import Path
+
+from playwright.async_api import BrowserContext, Download
+
+DOWNLOAD_FAILURE_READ_TIMEOUT_SECONDS = 5.0
+
+
+class NativeDownloadAttempt:
+ def __init__(self, observer: NativeDownloads, task_id: str) -> None:
+ self.observer = observer
+ self.task_id = task_id
+ self.pending: set[Download] = set()
+ self.interrupted = 0
+ self.cancelled_by_skyvern = 0
+ self.closed = False
+
+ def started(self, download: Download) -> None:
+ if not self.closed:
+ self.pending.add(download)
+
+ def finished(self, download: Download, *, failed: bool = False, self_cancelled: bool = False) -> None:
+ if self.closed or download not in self.pending:
+ return
+ self.pending.remove(download)
+ if self_cancelled:
+ self.cancelled_by_skyvern += 1
+ elif failed:
+ self.interrupted += 1
+
+ def end(self) -> None:
+ self.closed = True
+ self.pending.clear()
+
+ async def failed_and_quiescent(self) -> bool:
+ if self.closed or self.pending or not (self.interrupted or self.cancelled_by_skyvern):
+ return False
+ return (
+ await self.observer.quiescent() and not self.closed and not self.pending and self.observer.attempt is self
+ )
+
+
+class NativeDownloads:
+ """Context-wide native download liveness from the Playwright Download handles the page listeners receive.
+
+ Playwright reports downloads from no-opener tabs on the opener page, so these handles cover the context only when
+ the listeners were registered before any page activity; otherwise the context stays uncovered.
+ """
+
+ def __init__(self, context: BrowserContext, download_dir: str | None, *, covered: bool) -> None:
+ self.context = context
+ self.download_dir = Path(download_dir).resolve() if download_dir is not None else None
+ self._covered = covered
+ self._pending: set[Download] = set()
+ self.attempt: NativeDownloadAttempt | None = None
+ context.on("close", self.invalidate)
+
+ @classmethod
+ def attach(
+ cls, context: BrowserContext, *, before_activity: bool, download_dir: str | None = None
+ ) -> NativeDownloads:
+ return cls(context, download_dir, covered=before_activity)
+
+ def invalidate(self, *_: object) -> None:
+ self._covered = False
+ if self.attempt is not None:
+ self.attempt.end()
+
+ def listeners_registered(self) -> None:
+ if any(page.url != "about:blank" for page in self.context.pages):
+ self.invalidate()
+
+ def started(self, download: Download) -> NativeDownloadAttempt | None:
+ self._pending.add(download)
+ attempt = self.attempt
+ if attempt is not None:
+ attempt.started(download)
+ return attempt
+
+ def finished(
+ self,
+ download: Download,
+ attempt: NativeDownloadAttempt | None,
+ *,
+ failed: bool = False,
+ self_cancelled: bool = False,
+ ) -> None:
+ self._pending.discard(download)
+ if attempt is not None:
+ attempt.finished(download, failed=failed, self_cancelled=self_cancelled)
+
+ def begin_attempt(self, task_id: str) -> NativeDownloadAttempt:
+ if self.attempt is not None:
+ self.attempt.end()
+ self.attempt = NativeDownloadAttempt(self, task_id)
+ return self.attempt
+
+ async def quiescent(self) -> bool:
+ return self._covered and not self._pending
diff --git a/tests/unit/test_agent_cleanup_download_suffix.py b/tests/unit/test_agent_cleanup_download_suffix.py
index 33cb8bba6..c8b91e23f 100644
--- a/tests/unit/test_agent_cleanup_download_suffix.py
+++ b/tests/unit/test_agent_cleanup_download_suffix.py
@@ -1038,6 +1038,98 @@ async def test_wait_for_in_flight_downloads_completes_normally_when_should_cance
assert cancelled is False
+async def test_native_probe_does_not_delay_user_cancellation_or_outlive_wait(tmp_path) -> None:
+ residual = tmp_path / "unfinished.crdownload"
+ residual.write_bytes(b"partial")
+ probe_started = asyncio.Event()
+ probe_reaped = asyncio.Event()
+
+ async def stalled_probe() -> bool:
+ probe_started.set()
+ try:
+ await asyncio.Event().wait()
+ finally:
+ probe_reaped.set()
+ return False
+
+ async def should_cancel() -> bool:
+ return probe_started.is_set()
+
+ async with asyncio.timeout(4):
+ cancelled = await ForgeAgent()._wait_for_download_finished_cancellable(
+ downloading_files=[str(residual)],
+ timeout=30,
+ should_cancel=should_cancel,
+ native_failure_quiescent=stalled_probe,
+ )
+ assert cancelled and probe_reaped.is_set()
+ assert residual.read_bytes() == b"partial"
+
+
+async def test_an_already_quiescent_native_failure_does_not_wait_a_poll(tmp_path) -> None:
+ residual = tmp_path / "unfinished.crdownload"
+ residual.write_bytes(b"partial")
+ async with asyncio.timeout(0.5):
+ cancelled = await ForgeAgent()._wait_for_download_finished_cancellable(
+ downloading_files=[str(residual)],
+ timeout=30,
+ should_cancel=None,
+ native_failure_quiescent=AsyncMock(return_value=True),
+ )
+ assert cancelled is False
+ assert residual.read_bytes() == b"partial"
+
+
+async def test_unknown_native_liveness_preserves_timeout_cap_and_exhausted(tmp_path) -> None:
+ residual = tmp_path / "unfinished.crdownload"
+ residual.write_bytes(b"partial")
+ task = _make_task()
+ exhausted: set[str] = set()
+ with (
+ patch("skyvern.forge.agent.get_path_for_workflow_download_directory", return_value=tmp_path),
+ patch("skyvern.forge.agent.skyvern_context.current", return_value=None),
+ ):
+ async with asyncio.timeout(3):
+ result = await ForgeAgent()._wait_for_in_flight_downloads(
+ task,
+ SimpleNamespace(download_timeout=30),
+ task.organization_id,
+ timeout_cap=1.2,
+ exhausted=exhausted,
+ native_failure_quiescent=AsyncMock(return_value=False),
+ )
+ assert result is False and exhausted == {str(residual)}
+ assert residual.read_bytes() == b"partial"
+
+
+async def test_native_probe_error_still_reaps_the_file_wait(tmp_path) -> None:
+ residual = tmp_path / "unfinished.crdownload"
+ residual.write_bytes(b"partial")
+ reaped = asyncio.Event()
+
+ async def file_wait(**kwargs):
+ try:
+ await asyncio.Event().wait()
+ finally:
+ reaped.set()
+
+ with patch("skyvern.forge.agent.wait_for_download_finished", file_wait):
+ async with asyncio.timeout(4):
+ with pytest.raises(RuntimeError, match="probe unavailable"):
+ await ForgeAgent()._wait_for_download_finished_cancellable(
+ downloading_files=[str(residual)],
+ timeout=30,
+ should_cancel=None,
+ native_failure_quiescent=AsyncMock(side_effect=RuntimeError("probe unavailable")),
+ )
+ assert reaped.is_set()
+ assert residual.exists()
+
+
@pytest.mark.asyncio
async def test_finalize_skips_session_copy_whose_bytes_already_in_run_dir(tmp_path) -> None:
# A persistent-session blob: download lands in BOTH the session downloads dir and the run dir
diff --git a/tests/unit/test_agent_task_v3.py b/tests/unit/test_agent_task_v3.py
index 13a94637c..fb6d4de68 100644
--- a/tests/unit/test_agent_task_v3.py
+++ b/tests/unit/test_agent_task_v3.py
@@ -111,6 +111,8 @@ from skyvern.webeye.actions.actions import (
SolveCaptchaAction,
UploadFileAction,
)
+from skyvern.webeye.browser_artifacts import DownloadBinding
+from skyvern.webeye.native_downloads import NativeDownloads
from tests.unit._download_provider_fakes import (
_ActionDownloadSource,
_FakeActionDownloadObservation,
@@ -7062,6 +7064,63 @@ def _record_provider_sleeps(monkeypatch: pytest.MonkeyPatch) -> list[float]:
return sleeps
+ "guard", ["provider", "session_directory", "external", "replaced_context", "unknown_directory"]
+)
+async def test_native_quiescence_never_overrides_an_unknown_download_owner(monkeypatch, tmp_path, guard):
+ original_state = make_browser_state
+ observers = []
+ waits = []
+ real_wait = ForgeAgent._wait_for_in_flight_downloads
+
+ def owned_state():
+ state, browser, page = original_state()
+ observer = NativeDownloads(
+ state.browser_context, str(tmp_path) if guard != "unknown_directory" else None, covered=True
+ )
+ observer.quiescent = AsyncMock(return_value=True)
+ state.browser_artifacts.native_downloads = observer
+ state.browser_artifacts.download_binding = DownloadBinding.RUN_DIR
+ state.browser_context._skyvern_external_browser = guard == "external"
+ if guard == "session_directory":
+ state.browser_artifacts.download_binding = DownloadBinding.SESSION_DIR
+ observers.append(observer)
+ return state, browser, page
+
+ async def observed_wait(self, *args, **kwargs):
+ result = await real_wait(self, *args, **kwargs)
+ waits.append((result, set(kwargs["exhausted"])))
+ return result
+
+ async def run_loop(kwargs, captured):
+ observer = observers[0]
+ assert observer.attempt is kwargs["native_download_attempt"]
+ observer.attempt.interrupted = 1
+ if guard == "replaced_context":
+ observer.context = MagicMock()
+ residual = tmp_path / "retained.crdownload"
+ residual.write_bytes(b"partial")
+ await kwargs["download_wait"]()
+ assert residual.exists()
+ return LoopOutcome(status="terminated", reason="Observed transfer outcome.", billable_actions=[])
+
+ monkeypatch.setattr(__name__ + ".make_browser_state", owned_state)
+ monkeypatch.setattr(ForgeAgent, "_wait_for_in_flight_downloads", observed_wait)
+ source = _ActionDownloadSource(_FakeActionDownloadObservation([])) if guard == "provider" else None
+ await _run_execute_task_v3_download(
+ monkeypatch,
+ tmp_path,
+ drop_file=False,
+ provider_source=source,
+ download_timeout=1.2,
+ loop_fn=run_loop,
+ )
+ assert waits == [(False, {str(tmp_path / "retained.crdownload")})]
+ assert observers[0].attempt.closed
+ observers[0].quiescent.assert_not_awaited()
+
+
@pytest.mark.asyncio
async def test_v3_download_reads_a_provider_owned_file_back_when_the_replay_saves_nothing(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
diff --git a/tests/unit/test_download_dir_rebind.py b/tests/unit/test_download_dir_rebind.py
index 3d1147dca..1d144d48a 100644
--- a/tests/unit/test_download_dir_rebind.py
+++ b/tests/unit/test_download_dir_rebind.py
@@ -29,6 +29,7 @@ from skyvern.webeye.browser_factory import (
set_download_file_listener,
was_download_cancelled_by_skyvern,
)
+from skyvern.webeye.native_downloads import NativeDownloads
from skyvern.webeye.real_browser_manager import RealBrowserManager
@@ -482,6 +483,43 @@ async def test_listener_logs_run_identity_from_context(tmp_path: Path) -> None:
assert captured.get("task_id") == "task_real"
+async def test_listener_cancelled_while_reading_a_failure_keeps_the_download_pending() -> None:
+ browser_context = MagicMock()
+ browser_context.pages = []
+ page_listener: dict[str, object] = {}
+ browser_context.on = lambda event, handler: page_listener.setdefault(event, handler)
+ observer = NativeDownloads(browser_context, None, covered=True)
+ attempt = observer.begin_attempt("task_real")
+ set_download_file_listener(browser_context, browser_artifacts=SimpleNamespace(native_downloads=observer))
+ page = MagicMock()
+ page_handlers: dict[str, object] = {}
+ page.on = lambda _event, handler: page_handlers.setdefault("download", handler)
+ page_listener["page"](page)
+
+ reading = asyncio.Event()
+
+ async def stalled_failure_read(_download: object) -> str | None:
+ reading.set()
+ await asyncio.Event().wait()
+ return None
+
+ download = MagicMock()
+ download.path = AsyncMock(side_effect=RuntimeError("download aborted"))
+ with (
+ patch("skyvern.webeye.browser_factory.current", return_value=None),
+ patch("skyvern.webeye.browser_factory.read_download_failure", stalled_failure_read),
+ ):
+ task = page_handlers["download"](download)
+ await asyncio.wait_for(reading.wait(), timeout=2)
+ task.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await task
+
+ assert download in attempt.pending
+ assert not await observer.quiescent()
+
+
@pytest.mark.asyncio
async def test_listener_falls_back_to_kwargs_without_context(tmp_path: Path) -> None:
captured: dict[str, object] = {}
diff --git a/tests/unit/test_downloaded_files_artifact_urls.py b/tests/unit/test_downloaded_files_artifact_urls.py
index 4d91dc60f..8bf1c9bce 100644
--- a/tests/unit/test_downloaded_files_artifact_urls.py
+++ b/tests/unit/test_downloaded_files_artifact_urls.py
@@ -1265,3 +1265,104 @@ def test_local_snapshot_aliases_consume_primary_before_live_baseline_and_preserv
{DOWNLOADED_FILE_SIGS_KEY: [to_downloaded_file_signature(live)]},
aliases=storage.get_downloaded_file_signature_aliases,
) == [retry]
+
+
[email protected]("backend", ["local", "s3", "azure", "gcs"])
[email protected]("signed", [False, True])
[email protected]("run_id", ["wr_1", "tsk_1"])
+async def test_partial_bytes_are_neither_published_nor_returned(tmp_path, monkeypatch, backend, signed, run_id):
+ monkeypatch.setattr(settings, "ARTIFACT_CONTENT_HMAC_KEYRING", _DUMMY_KEYRING_JSON if signed else None)
+ storage = {
+ "local": lambda: LocalStorage(str(tmp_path / "artifacts")),
+ "s3": S3Storage,
+ "azure": lambda: AzureStorageForTests("uploads"),
+ "gcs": lambda: GcsStorageForTests("uploads"),
+ }[backend]()
+ storage.async_client = MagicMock()
+ if backend in ("s3", "gcs"):
+ monkeypatch.setattr(storage, "_get_storage_class_for_org", AsyncMock(return_value="STANDARD"))
+ if backend == "gcs":
+ monkeypatch.setattr(storage, "_get_tags_for_org", AsyncMock(return_value=None))
+ directory = tmp_path / "downloads"
+ directory.mkdir()
+ (directory / "extensionless").write_bytes(b"complete")
+ (directory / "unconfirmed.crdownload").write_bytes(b"partial")
+ rows = []
+ objects = {}
+ metadata = {}
+ now = datetime.now(UTC)
+
+ async def create(**kwargs):
+ row = Artifact(**kwargs, created_at=now, modified_at=now)
+ rows.append(row)
+ return row
+
+ async def upload(*, uri, file_path, **kwargs):
+ objects[uri] = Path(file_path).read_bytes()
+ metadata[uri] = {
+ "Metadata": kwargs.get("metadata", {}),
+ "ContentLength": len(objects[uri]),
+ "LastModified": now,
+ }
+
+ manager = ArtifactManager()
+ fake_app = SimpleNamespace(
+ ARTIFACT_MANAGER=manager,
+ WORKFLOW_CONTEXT_MANAGER=WorkflowContextManager(),
+ DATABASE=SimpleNamespace(
+ workflow_run_attempts=SimpleNamespace(get_attempts=AsyncMock(return_value=[])),
+ workflow_runs=SimpleNamespace(get_workflow_run=AsyncMock(return_value=None)),
+ artifacts=SimpleNamespace(
+ find_download_artifact=AsyncMock(return_value=None),
+ create_artifact=create,
+ list_artifacts_for_run_by_type=AsyncMock(side_effect=lambda **_: list(rows)),
+ ),
+ ),
+ )
+ module = {"local": local_module, "s3": s3_module, "azure": azure_module, "gcs": gcs_module}[backend]
+ for item in (module, base_module, manager_module):
+ monkeypatch.setattr(item, "app", fake_app)
+ monkeypatch.setattr(module, "get_download_dir", lambda **_: str(directory))
+ monkeypatch.setattr(
+ manager_module.skyvern_context,
+ "current",
+ lambda: SkyvernContext(workflow_run_id=run_id if run_id.startswith("wr_") else None),
+ )
+ storage.async_client.upload_file_from_path = upload
+ storage.async_client.list_files = AsyncMock(
+ side_effect=lambda **_: [urlparse(uri).path.lstrip("/") for uri in objects]
+ )
+ storage.async_client.get_object_info = AsyncMock(side_effect=lambda uri: metadata[uri])
+ signing = {
+ "s3": "create_presigned_urls",
+ "azure": "create_sas_urls",
+ "gcs": "create_signed_urls",
+ "local": "unused",
+ }[backend]
+ setattr(
+ storage.async_client,
+ signing,
+ AsyncMock(side_effect=lambda uris: ["https://storage.example/file" for _ in uris]),
+ )
+ monkeypatch.setattr(
+ manager,
+ "resolve_share_url",
+ AsyncMock(side_effect=lambda artifact, **_: f"https://api.example/{artifact.artifact_id}"),
+ )
+ monkeypatch.setattr(manager, "resolve_artifact_url_expiry_seconds", AsyncMock(return_value=3600))
+ await storage.save_downloaded_files(organization_id="o_1", run_id=run_id)
+ assert len(rows) == 1 and rows[0].uri.endswith("/extensionless")
+ assert all(not uri.endswith(".crdownload") for uri in objects)
+ legacy = rows[0].model_copy(
+ update={"artifact_id": "a_legacy_partial", "uri": rows[0].uri.rsplit("/", 1)[0] + "/legacy.crdownload"}
+ )
+ rows.append(legacy)
+ if backend == "local":
+ Path(parse_uri_to_path(legacy.uri)).write_bytes(b"legacy partial")
+ else:
+ objects[legacy.uri] = b"legacy partial"
+ metadata[legacy.uri] = {"Metadata": {}, "ContentLength": 14, "LastModified": now}
+ infos = await storage.get_downloaded_files(organization_id="o_1", run_id=run_id)
+ assert [info.filename for info in infos] == ["extensionless"]
+ assert (directory / "unconfirmed.crdownload").read_bytes() == b"partial"
diff --git a/uv.lock b/uv.lock
index 991148cdf..6b2e4afba 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1275,11 +1275,11 @@ wheels = [
[[package]]
name = "distlib"
-version = "0.4.0"
+version = "0.4.4"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/96/8e/709914eb2b5749865801041647dc7f4e6d00b549cfe88b65ca192995f07c/distlib-0.4.0.tar.gz", hash = "sha256:feec40075be03a04501a973d81f633735b4b69f98b05450592310c0f401a4e0d", size = 614605, upload-time = "2025-07-17T16:52:00.465Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/68/bc/d36966de7304047a1001a7559fbf266c464bb5d8cc85464536ef8c9bcc32/distlib-0.4.4.tar.gz", hash = "sha256:ca4175b4ac7f71223cc30ed7248c45d2b38c2439d8ee6e498ab67ed63cf3508d", size = 621304, upload-time = "2026-10-16T13:56:34.203Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/33/6b/e0547afaf41bf2c42e52430072fa5658766e3d65bd4b03a563d1b6336f57/distlib-0.4.0-py2.py3-none-any.whl", hash = "sha256:9659f7d87e46584a30b5780e43ac7a2143098441670ff0a49d5f9034c54a6c16", size = 469047, upload-time = "2025-07-17T16:51:58.613Z" },
+ { url = "https://files.pythonhosted.org/packages/c1/2b/238f02a4927fa2e27aa995371d240a468b52e42eae44a678434aff736b38/distlib-0.4.4-py2.py3-none-any.whl", hash = "sha256:cf09d55b1e85a89576b036aeb71550bfd68320f3f21761ca329eadadad918638", size = 472099, upload-time = "2026-10-16T13:56:32.053Z" },
]
[[package]]
@@ -4839,11 +4839,11 @@ wheels = [
[[package]]
name = "packaging"
-version = "26.1"
+version = "26.3"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/df/de/0d2b39fb4af88a0258f3bac87dfcbb48e73fbdea4a2ed0e2213f9a4c2f9a/packaging-26.1.tar.gz", hash = "sha256:f042152b681c4bfac5cae2742a55e103d27ab2ec0f3d88037136b6bfe7c9c5de", size = 215519, upload-time = "2026-04-14T21:12:49.362Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/7a/c2/920ef838e2f0028c8262f16101ec09ebd5969864e5a64c4c05fad0617c56/packaging-26.1-py3-none-any.whl", hash = "sha256:5d9c0669c6285e491e0ced2eee587eaf67b670d94a19e94e3984a481aba6802f", size = 95831, upload-time = "2026-04-14T21:12:47.56Z" },
+ { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" },
]
[[package]]
@@ -8030,7 +8030,7 @@ wheels = [
[[package]]
name = "virtualenv"
-version = "21.14.2"
+version = "21.14.12"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "distlib" },
@@ -8039,9 +8039,9 @@ dependencies = [
{ name = "platformdirs" },
{ name = "python-discovery" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/67/57/630a01cf5ab58f33b9c7dc8a7f13464cb5740b5227f8a08cab9d798bd532/virtualenv-21.14.2.tar.gz", hash = "sha256:571930928b11e43db690073ad8228162eca8a3f8fd3a87acdeae07df7dd57068", size = 5463798, upload-time = "2026-10-01T06:22:46.965Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/c9/2c/1a69b3346931e9a7db9cc00cc0fa847c843a85fa7cf52a598f57261c68df/virtualenv-21.14.12.tar.gz", hash = "sha256:bbcfb78e36c22ad70c6917c4aecb5e63477d3c138e9f88c946f320e31859c76a", size = 5562800, upload-time = "2026-10-21T01:58:51.724Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/1c/e0/10bb71ddf2946ccbe4ae06fca4e951212531e148daa3f45fa6b907bcafcf/virtualenv-21.14.2-py3-none-any.whl", hash = "sha256:6a8b7fd4e4ee00ebcdc1c5ee8cffd035d1fe130e354e8c9a44f510aac8affdc1", size = 5487107, upload-time = "2026-10-01T06:22:44.56Z" },
+ { url = "https://files.pythonhosted.org/packages/a0/92/f3b8af2d36ddec4dc61dc25655dc010e419ff456cb4ca0e720c8112f1047/virtualenv-21.14.12-py3-none-any.whl", hash = "sha256:7820aeaef23f1f59a96458edfc7f9d3deac937155718de15f1c9a64471e15551", size = 5556824, upload-time = "2026-10-21T01:58:48.505Z" },
]
[[package]]