From d5fb57b4b9874ac5c00cfc595c37ece49bbb2fb4 Mon Sep 17 00:00:00 2001 From: Morgan Wowk Date: Wed, 4 Mar 2026 11:49:33 -0800 Subject: [PATCH] chore: Reduce RuntimeErrors for expected states with no container execution --- cloud_pipelines_backend/api_server_sql.py | 25 +++++++++++++------- cloud_pipelines_backend/backend_types_sql.py | 14 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/cloud_pipelines_backend/api_server_sql.py b/cloud_pipelines_backend/api_server_sql.py index 9341db4..025ed30 100644 --- a/cloud_pipelines_backend/api_server_sql.py +++ b/cloud_pipelines_backend/api_server_sql.py @@ -679,8 +679,14 @@ def get_container_execution_state( raise ItemNotFoundError(f"Execution with {id=} does not exist.") container_execution = execution.container_execution if not container_execution: - raise RuntimeError( - f"Execution with {id=} does not have container execution information." + status = execution.container_execution_status + if not status or status not in bts.CONTAINER_STATUSES_WITH_MISSING_EXECUTION_EXPECTED: + raise RuntimeError( + f"Execution with {id=} has status {status} " + f"but is missing its container execution record." + ) + raise errors.ItemNotFoundError( + f"Execution with {id=} has status {status.value} and does not have container execution information. This is expected for this status." ) return GetContainerExecutionStateResponse( status=container_execution.status, @@ -756,16 +762,19 @@ def get_container_execution_log( system_error_exception_full or orchestration_error_message ) if not container_execution: - if ( - execution.container_execution_status - == bts.ContainerExecutionStatus.SYSTEM_ERROR - ): + status = execution.container_execution_status + if not status or status not in bts.CONTAINER_STATUSES_WITH_MISSING_EXECUTION_EXPECTED: + raise RuntimeError( + f"Execution with {id=} has status {status} " + f"but is missing its container execution record." + ) + if status == bts.ContainerExecutionStatus.SYSTEM_ERROR: return GetContainerExecutionLogResponse( system_error_exception_full=system_error_exception_full, orchestration_error_message=orchestration_error_message, ) - raise RuntimeError( - f"Execution with {id=} does not have container execution information." + raise errors.ItemNotFoundError( + f"Execution with {id=} has status {status.value} and does not have a container execution log. This is expected for this status." ) log_text: str | None = None if container_execution.status in ( diff --git a/cloud_pipelines_backend/backend_types_sql.py b/cloud_pipelines_backend/backend_types_sql.py index 04a8bf5..92d8f05 100644 --- a/cloud_pipelines_backend/backend_types_sql.py +++ b/cloud_pipelines_backend/backend_types_sql.py @@ -42,6 +42,20 @@ class ContainerExecutionStatus(str, enum.Enum): ContainerExecutionStatus.SKIPPED, } +# Statuses where the ContainerExecution record may not exist yet (or ever). +# These represent expected states before the orchestrator creates and launches +# a container — e.g. waiting for inputs, sitting in queue, or terminated before +# launch (cancelled/skipped/system error before container creation). +CONTAINER_STATUSES_WITH_MISSING_EXECUTION_EXPECTED = { + ContainerExecutionStatus.INVALID, + ContainerExecutionStatus.UNINITIALIZED, + ContainerExecutionStatus.QUEUED, + ContainerExecutionStatus.WAITING_FOR_UPSTREAM, + ContainerExecutionStatus.SYSTEM_ERROR, + ContainerExecutionStatus.CANCELLED, + ContainerExecutionStatus.SKIPPED, +} + def generate_unique_id() -> str: """Generates a 10-byte (20 hex chars) unique ID.session.add