Skip to content

Automate browser based workflows with AI

fix(SKY-11851): treat missing S3 object as terminal not-found on download (#7350)

Aaron Perez3ab8761881ea
diff --git a/skyvern/forge/sdk/api/aws.py b/skyvern/forge/sdk/api/aws.py
index 92d6417dc..3d982f318 100644
--- a/skyvern/forge/sdk/api/aws.py
+++ b/skyvern/forge/sdk/api/aws.py
@@ -27,6 +27,8 @@ add_type("text/plain", ".log")
add_type("application/zstd", ".zst")
_S3_OPERATION_RETRIES = 2
+# get_object on a missing key raises NoSuchKey; head-style paths use 404/NotFound.
+_S3_NOT_FOUND_ERROR_CODES = frozenset({"NoSuchKey", "NotFound", "404"})
LOG = structlog.get_logger()
@@ -108,6 +110,12 @@ class AsyncAWSClient:
"""Check if an exception is an AWS ExpiredTokenException."""
return isinstance(error, ClientError) and error.response.get("Error", {}).get("Code") == "ExpiredTokenException"
+ def _is_not_found_error(self, error: Exception) -> bool:
+ """Check if an exception is a missing-object (terminal not-found) error."""
+ return (
+ isinstance(error, ClientError) and error.response.get("Error", {}).get("Code") in _S3_NOT_FOUND_ERROR_CODES
+ )
+
def _error_code(self, error: Exception) -> str:
if isinstance(error, ClientError):
return error.response.get("Error", {}).get("Code", error.__class__.__name__)
@@ -331,7 +339,14 @@ class AsyncAWSClient:
try:
return await self._s3_with_retry("download", _op, uri=uri)
- except Exception:
+ except Exception as e:
+ # A missing object is terminal not-found, not a transient failure (e.g. first-run
+ # profile restore before any archive exists). Log once without a traceback so callers
+ # fall back immediately instead of surfacing repeated ERROR tracebacks.
+ if self._is_not_found_error(e):
+ if log_exception:
+ LOG.info("S3 object not found", uri=uri)
+ return None
if log_exception:
LOG.exception("S3 download failed", uri=uri)
return None
diff --git a/tests/unit/test_aws_client_ttl.py b/tests/unit/test_aws_client_ttl.py
index 80e8bede6..646603f70 100644
--- a/tests/unit/test_aws_client_ttl.py
+++ b/tests/unit/test_aws_client_ttl.py
@@ -12,6 +12,46 @@ _EXPIRED_TOKEN_ERROR = ClientError(
)
+def _client_error(code: str) -> ClientError:
+ return ClientError({"Error": {"Code": code, "Message": code}}, "GetObject")
+
+
[email protected]("code", ["NoSuchKey", "NotFound", "404"])
+def test_is_not_found_error_true_for_missing_object_codes(code: str) -> None:
+ client = aws.AsyncAWSClient()
+ assert client._is_not_found_error(_client_error(code)) is True
+
+
[email protected]("error", [_client_error("AccessDenied"), Exception("boom")])
+def test_is_not_found_error_false_for_other_errors(error: Exception) -> None:
+ client = aws.AsyncAWSClient()
+ assert client._is_not_found_error(error) is False
+
+
+async def test_download_file_missing_key_returns_none_without_traceback() -> None:
+ client = aws.AsyncAWSClient()
+ with (
+ patch.object(client, "_s3_with_retry", AsyncMock(side_effect=_client_error("NoSuchKey"))),
+ patch.object(aws, "LOG") as mock_log,
+ ):
+ result = await client.download_file("s3://bucket/missing.zip")
+ assert result is None
+ mock_log.exception.assert_not_called()
+
+
+async def test_download_file_real_error_still_logs_exception() -> None:
+ client = aws.AsyncAWSClient()
+ with (
+ patch.object(client, "_s3_with_retry", AsyncMock(side_effect=_client_error("AccessDenied"))),
+ patch.object(aws, "LOG") as mock_log,
+ ):
+ result = await client.download_file("s3://bucket/denied.zip")
+ assert result is None
+ mock_log.exception.assert_called_once()
+
+
@pytest.fixture(autouse=True)
def reset_aws_client():
"""Reset the global singleton before each test."""