This is an automated email from the ASF dual-hosted git repository.

amoghrajesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 0354004df00 Add durable execution to SnowparkContainerJobOperator 
(#76106)
0354004df00 is described below

commit 0354004df00854402e75301d75fba0bcb1f25907
Author: Justin Pakzad <[email protected]>
AuthorDate: Wed Nov 25 22:26:25 2026 -0500

    Add durable execution to SnowparkContainerJobOperator (#76106)
---
 providers/snowflake/docs/changelog.rst             |   6 +
 .../docs/operators/snowpark_containers.rst         |  38 ++
 .../snowflake/operators/snowpark_containers.py     | 142 +++++--
 .../snowflake/triggers/snowpark_containers.py      |   7 +
 .../snowflake/utils/snowpark_containers.py         |   3 +
 .../operators/test_snowpark_containers.py          | 411 ++++++++++++++++++---
 .../snowflake/triggers/test_snowpark_containers.py |   8 +
 7 files changed, 545 insertions(+), 70 deletions(-)

diff --git a/providers/snowflake/docs/changelog.rst 
b/providers/snowflake/docs/changelog.rst
index 9c37b31b9bf..79f68b7d048 100644
--- a/providers/snowflake/docs/changelog.rst
+++ b/providers/snowflake/docs/changelog.rst
@@ -27,6 +27,12 @@
 Changelog
 ---------
 
+.. note::
+
+    The private ``SnowparkContainerJobOperator`` methods ``_submit_job`` and 
``_poll_for_status``
+    are replaced by ``submit_job`` and ``poll_until_complete``. Subclasses 
overriding them must
+    move to the new methods.
+
 6.21.0
 ......
 
diff --git a/providers/snowflake/docs/operators/snowpark_containers.rst 
b/providers/snowflake/docs/operators/snowpark_containers.rst
index 3d475350db1..bbb5a00fc19 100644
--- a/providers/snowflake/docs/operators/snowpark_containers.rst
+++ b/providers/snowflake/docs/operators/snowpark_containers.rst
@@ -75,3 +75,41 @@ An example usage of the SnowparkContainerJobOperator is as 
follows:
 
   Parameters that can be passed onto the operator will be given priority over 
the parameters already given
   in the Airflow connection metadata (such as ``schema``, ``role``, 
``database`` and so forth).
+
+Durable execution
+^^^^^^^^^^^^^^^^^
+
+By default the operator runs in a *durable* mode that makes the synchronous 
poll crash-safe.
+Before polling begins the job name is persisted to :doc:`task state store
+<apache-airflow:core-concepts/task-state-store>`, so if the worker crashes and 
the task is
+retried, the operator reconnects to the job already running in Snowflake 
instead of submitting
+a duplicate. If the task is killed, including by a graceful worker shutdown or 
pod eviction,
+``on_kill`` drops the job service and the retry submits a fresh job. Set 
``cancel_on_kill=False``
+to keep the job running so the retry reconnects to it.
+
+On retry the operator checks the prior job's status:
+
+* pending or running: reconnect and continue polling
+* already succeeded: finalize the job (logs and cleanup) without resubmitting
+* any other status, or the service no longer exists without having succeeded: 
submit a fresh job
+
+``timeout`` applies per try, so a retry that reconnects to a running job gets 
a full ``timeout`` again.
+
+Unlike a retry, clearing the task instance from the UI or the REST API 
discards the stored job name by
+default, so the next try submits a fresh job. To have it handled like a retry 
instead, tick
+**Keep task state and resume** in the Clear dialog or pass 
``keep_task_state=true`` to the clear
+endpoint. A job that already succeeded is then not run again, unless 
``[state_store] clear_on_success``
+is on.
+Clearing a running task drops its service through ``on_kill``. With 
``cancel_on_kill=False`` the job
+keeps running, so keep the task state to reconnect to it rather than starting 
a second job.
+
+Before Airflow 3.5, clearing the whole Dag run, marking a task as success or 
failed, and
+``airflow tasks clear`` / ``airflow dags clear`` keep the stored job name, so 
clear the task instance
+itself to start fresh. From Airflow 3.5, every way of clearing discards it by 
default. See
+:ref:`apache-airflow:concepts-resumable-tasks` for details.
+
+Durable execution requires Airflow 3.3 or newer, since it relies on the task 
state store. On
+earlier versions the flag is a no-op (setting it only emits a warning) and the 
operator always
+submits a fresh job on retry. Durable execution only applies to the 
synchronous polling path. It has no effect when
+``wait_for_completion=False`` or ``deferrable=True``. Set ``durable=False`` to 
opt out and always
+submit a fresh job on retry.
diff --git 
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
 
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
index d5c0d640f80..3ff704ae9e7 100644
--- 
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
+++ 
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
@@ -21,24 +21,30 @@ import time
 from collections.abc import Sequence
 from datetime import timedelta
 from functools import cached_property
-from typing import TYPE_CHECKING, Any
+from typing import TYPE_CHECKING, Any, cast
 
-from airflow.providers.common.compat.sdk import conf
+from snowflake.connector.errors import ProgrammingError
+
+from airflow.providers.common.compat.sdk import ResumableJobMixin, conf
 from airflow.providers.common.compat.standard.operators import BaseOperator
 from airflow.providers.common.sql.hooks.handlers import fetch_one_handler
 from airflow.providers.snowflake.hooks.snowflake import SnowflakeHook
 from airflow.providers.snowflake.triggers.snowpark_containers import 
SnowparkContainerJobTrigger
 from airflow.providers.snowflake.utils.snowpark_containers import (
     NON_TERMINAL_STATUSES,
+    NOT_FOUND_STATUS,
+    OBJECT_NOT_EXIST_ERROR_CODE,
     TERMINAL_STATUSES,
     SnowparkContainerJobStatus,
 )
 
 if TYPE_CHECKING:
+    from pydantic import JsonValue
+
     from airflow.providers.common.compat.sdk import Context
 
 
-class SnowparkContainerJobOperator(BaseOperator):
+class SnowparkContainerJobOperator(ResumableJobMixin, BaseOperator):
     """
     Execute a job on Snowpark Container Services.
 
@@ -81,6 +87,15 @@ class SnowparkContainerJobOperator(BaseOperator):
         ``wait_for_completion`` is True. With ``wait_for_completion=False`` the
         operator submits the job and returns immediately without deferring.
         (default value: False)
+    :param durable: When ``True``, the submitted job name is persisted to
+        task state before polling begins. A worker crash on retry reconnects 
to the existing
+        job instead of resubmitting the SQL. Set to ``False`` to always submit 
fresh on
+        retry. Requires Airflow 3.3+; ignored on earlier versions.
+        With ``wait_for_completion=False`` or ``deferrable=True`` durable has 
no effect. (default value: True)
+    :param cancel_on_kill: If True, drop the job service when the task is 
killed. This applies
+        both while the operator is running and, for a deferred task, while it 
waits in the
+        triggerer. With ``durable``, set this to False so the job survives a 
graceful worker
+        shutdown or pod eviction. (default value: True)
     :param timeout: Maximum seconds to wait for the job to reach a terminal
         state. When it elapses the task fails. (default value: 86400)
     :param database: name of database (will overwrite database defined
@@ -94,6 +109,8 @@ class SnowparkContainerJobOperator(BaseOperator):
         own SQL commands, not for the container's queries
     """
 
+    external_id_key = "snowpark_container_job_name"
+    _job_done_marker_key = "snowpark_container_job_done_marker"
     template_fields: Sequence[str] = (
         "compute_pool",
         "spec",
@@ -123,6 +140,8 @@ class SnowparkContainerJobOperator(BaseOperator):
         poll_interval: int = 10,
         snowflake_conn_id: str = "snowflake_default",
         deferrable: bool = conf.getboolean("operators", "default_deferrable", 
fallback=False),
+        durable: bool | None = None,
+        cancel_on_kill: bool = True,
         timeout: int = 24 * 60 * 60,
         database: str | None = None,
         schema: str | None = None,
@@ -130,9 +149,13 @@ class SnowparkContainerJobOperator(BaseOperator):
         warehouse: str | None = None,
         **kwargs: Any,
     ) -> None:
-        super().__init__(**kwargs)
         if spec_text is not None and (spec is not None or spec_stage is not 
None):
             raise ValueError("Cannot specify both 'spec_text' and 
'spec'/'spec_stage'")
+        # durable is a named parameter here (not left to **kwargs) so 
default_args={"durable": ...}
+        # reaches it on every supported Airflow version.
+        if durable is not None:
+            kwargs["durable"] = durable
+        super().__init__(**kwargs)
         self.compute_pool = compute_pool
         self.container_name = container_name
         self.spec = spec
@@ -147,6 +170,7 @@ class SnowparkContainerJobOperator(BaseOperator):
         self.poll_interval = poll_interval
         self.snowflake_conn_id = snowflake_conn_id
         self.deferrable = deferrable
+        self.cancel_on_kill = cancel_on_kill
         self.timeout = timeout
         self.database = database
         self.schema = schema
@@ -154,6 +178,9 @@ class SnowparkContainerJobOperator(BaseOperator):
         self.warehouse = warehouse
         # Set after the job is submitted, parsed from the job submission 
response.
         self.job_name: str | None = None
+        # On a fresh submit the mixin runs both poll_until_complete and 
get_job_result.
+        # poll_until_complete sets this so get_job_result does not finalize a 
second time.
+        self._poll_until_complete_ran = False
 
         if self.deferrable and not self.wait_for_completion:
             self.log.warning("deferrable has no effect when 
wait_for_completion is False.")
@@ -187,11 +214,24 @@ class SnowparkContainerJobOperator(BaseOperator):
             sql += f" FROM {self.spec_stage} SPEC = '{self.spec}'"
         return sql
 
-    def _run_one(self, sql: str, return_dictionaries: bool = False) -> Any:
+    def _run_one(
+        self, sql: str, return_dictionaries: bool = False, parameters: 
dict[str, Any] | None = None
+    ) -> Any:
         """Run a single statement that returns one row via 
fetch_one_handler."""
-        return self._hook.run(sql, handler=fetch_one_handler, 
return_dictionaries=return_dictionaries)
+        return self._hook.run(
+            sql, parameters=parameters, handler=fetch_one_handler, 
return_dictionaries=return_dictionaries
+        )
 
-    def _submit_job(self) -> str:
+    def _describe_status(self, external_id: JsonValue) -> str:
+        """Describe the job's current status."""
+        response = self._run_one(
+            "DESCRIBE SERVICE IDENTIFIER(%(job_name)s)",
+            return_dictionaries=True,
+            parameters={"job_name": external_id},
+        )
+        return response.get("status")
+
+    def submit_job(self, context: Context) -> str:
         """Submit the job and return the name."""
         response = self._run_one(self._build_sql())
 
@@ -202,12 +242,38 @@ class SnowparkContainerJobOperator(BaseOperator):
         if len(parts) < 3 or not parts[1]:
             raise RuntimeError(f"Unexpected job submission response: 
{response!r}")
 
-        job_name = parts[1]
+        self.job_name = parts[1]
 
-        return job_name
+        return self.job_name
+
+    def get_job_status(self, external_id: JsonValue, context: Context) -> str:
+        """Return DONE if a prior try stored it, NOT_FOUND if the service is 
gone, else the current status."""
+        if not isinstance(external_id, str):
+            raise TypeError(f"Stored job name {external_id!r} is not a string")
+        if (task_state_store := context.get("task_state_store")) is not None:
+            marker = task_state_store.get(self._job_done_marker_key)
+            if isinstance(marker, dict) and marker.get(external_id) == 
SnowparkContainerJobStatus.DONE:
+                return SnowparkContainerJobStatus.DONE
+        try:
+            return self._describe_status(external_id)
+        except ProgrammingError as e:
+            if e.errno == OBJECT_NOT_EXIST_ERROR_CODE:
+                return NOT_FOUND_STATUS
+            raise
+
+    def is_job_active(self, status: str) -> bool:
+        """Return True while the job is still running."""
+        return status in (SnowparkContainerJobStatus.PENDING, 
SnowparkContainerJobStatus.RUNNING)
+
+    def is_job_succeeded(self, status: str) -> bool:
+        """Return True when the job has completed successfully."""
+        return status == SnowparkContainerJobStatus.DONE
+
+    def poll_until_complete(self, external_id: JsonValue, context: Context) -> 
None:
+        """Poll the job until it reaches a terminal state and handle the final 
status."""
+        # On reconnect the mixin skips submit_job, so set the job name from 
the external id here.
+        self.job_name = cast("str", external_id)
 
-    def _poll_for_status(self) -> str:
-        """Poll until the job reaches a terminal state."""
         status = None
         end_time = time.monotonic() + self.timeout
         while True:
@@ -216,20 +282,44 @@ class SnowparkContainerJobOperator(BaseOperator):
                 if self.drop_on_completion:
                     self._drop_service()
                 raise TimeoutError(f"Job {self.job_name} did not reach a 
terminal status before the timeout.")
-            response = self._run_one(f"DESCRIBE SERVICE {self.job_name}", 
return_dictionaries=True)
-            status = response.get("status")
+            status = self._describe_status(self.job_name)
             if status in TERMINAL_STATUSES:
-                return status
+                # Persist DONE before _handle_final_status drops the service. 
Otherwise a retry after
+                # a crash post-drop sees NOT_FOUND and resubmits a job that 
already succeeded.
+                if (
+                    self.durable
+                    and status == SnowparkContainerJobStatus.DONE
+                    and (task_state_store := context.get("task_state_store")) 
is not None
+                ):
+                    task_state_store.set(
+                        self._job_done_marker_key, {self.job_name: 
SnowparkContainerJobStatus.DONE.value}
+                    )
+                self._handle_final_status(status=status)
+                self._poll_until_complete_ran = True
+                return
             if status not in NON_TERMINAL_STATUSES:
                 raise RuntimeError(f"Job {self.job_name} returned unexpected 
status: {status}")
             time.sleep(self.poll_interval)
 
+    def get_job_result(self, external_id: JsonValue, context: Context) -> None:
+        """Finalize the completed job."""
+        self.job_name = cast("str", external_id)
+        if self._poll_until_complete_ran:
+            return
+        # The mixin only reaches this path when the job is DONE, so the status 
is hardcoded.
+        self._handle_final_status(status=SnowparkContainerJobStatus.DONE)
+
     def _log_container_output(self, status: str | None) -> None:
         """Fetch and log container output for all replicas. Best-effort so it 
never blocks cleanup."""
         for instance_id in range(self.replicas):
-            sql = f"SELECT SYSTEM$GET_SERVICE_LOGS('{self.job_name}', 
{instance_id}, '{self.container_name}')"
+            sql = "SELECT SYSTEM$GET_SERVICE_LOGS(%(job_name)s, 
%(instance_id)s, %(container_name)s)"
+            parameters = {
+                "job_name": self.job_name,
+                "instance_id": instance_id,
+                "container_name": self.container_name,
+            }
             try:
-                response = self._run_one(sql)[0]
+                response = self._run_one(sql, parameters=parameters)[0]
             except Exception as e:
                 self.log.warning("Could not retrieve logs for instance_id %d: 
%s", instance_id, e)
                 continue
@@ -244,12 +334,16 @@ class SnowparkContainerJobOperator(BaseOperator):
     def _drop_service(self) -> None:
         """Best-effort drop of the job service."""
         try:
-            self._hook.run(f"DROP SERVICE IF EXISTS {self.job_name}")
+            self._hook.run(
+                "DROP SERVICE IF EXISTS IDENTIFIER(%(job_name)s)", 
parameters={"job_name": self.job_name}
+            )
         except Exception as e:
             self.log.error("Error dropping service %s: %s", self.job_name, e)
 
     def on_kill(self) -> None:
         """Drop the running service on task kill."""
+        if not self.cancel_on_kill:
+            return
         if self.job_name:
             self._drop_service()
 
@@ -268,11 +362,11 @@ class SnowparkContainerJobOperator(BaseOperator):
         if not self.spec_text and not (self.spec and self.spec_stage):
             raise ValueError("Must provide either 'spec_text' or both 'spec' 
and 'spec_stage'")
 
-        self.job_name = self._submit_job()
-
         if not self.wait_for_completion:
-            return self.job_name
+            return self.submit_job(context)
+
         if self.deferrable:
+            job_name = self.submit_job(context)
             # timeout and execution_timeout give the trigger two separate 
deadlines. timeout caps
             # how long the job is polled, and execution_timeout, when set, 
enforces the task-level
             # limit. The trigger times out on whichever is reached first.
@@ -290,7 +384,7 @@ class SnowparkContainerJobOperator(BaseOperator):
                 defer_timeout = self.execution_timeout + poll_buffer
             self.defer(
                 trigger=SnowparkContainerJobTrigger(
-                    job_name=self.job_name,
+                    job_name=job_name,
                     snowflake_conn_id=self.snowflake_conn_id,
                     poll_interval=self.poll_interval,
                     end_time=now + self.timeout,
@@ -299,13 +393,13 @@ class SnowparkContainerJobOperator(BaseOperator):
                     schema=self.schema,
                     role=self.role,
                     warehouse=self.warehouse,
+                    cancel_on_kill=self.cancel_on_kill,
                 ),
                 timeout=defer_timeout,
                 method_name="execute_complete",
             )
-        status = self._poll_for_status()
-        self._handle_final_status(status)
-        return self.job_name
+        self.execute_resumable(context)
+        return cast("str", self.job_name)
 
     def execute_complete(self, context: Context, event: dict[str, Any]) -> str:
         """Resume after the trigger fires."""
diff --git 
a/providers/snowflake/src/airflow/providers/snowflake/triggers/snowpark_containers.py
 
b/providers/snowflake/src/airflow/providers/snowflake/triggers/snowpark_containers.py
index 4b1c6e2d1be..d79c5e11cda 100644
--- 
a/providers/snowflake/src/airflow/providers/snowflake/triggers/snowpark_containers.py
+++ 
b/providers/snowflake/src/airflow/providers/snowflake/triggers/snowpark_containers.py
@@ -45,6 +45,8 @@ class SnowparkContainerJobTrigger(BaseTrigger):
     :param schema: (Optional) name of schema. (default: None)
     :param role: (Optional) name of role. (default: None)
     :param warehouse: (Optional) name of warehouse. (default: None)
+    :param cancel_on_kill: If True, drop the job service when the deferred 
task is killed.
+        (default: True)
     """
 
     def __init__(
@@ -58,6 +60,7 @@ class SnowparkContainerJobTrigger(BaseTrigger):
         schema: str | None = None,
         role: str | None = None,
         warehouse: str | None = None,
+        cancel_on_kill: bool = True,
     ) -> None:
         super().__init__()
         self.job_name = job_name
@@ -69,6 +72,7 @@ class SnowparkContainerJobTrigger(BaseTrigger):
         self.schema = schema
         self.role = role
         self.warehouse = warehouse
+        self.cancel_on_kill = cancel_on_kill
 
     def serialize(self) -> tuple[str, dict[str, Any]]:
         """Serialize SnowparkContainerJobTrigger arguments and class path."""
@@ -84,6 +88,7 @@ class SnowparkContainerJobTrigger(BaseTrigger):
                 "schema": self.schema,
                 "role": self.role,
                 "warehouse": self.warehouse,
+                "cancel_on_kill": self.cancel_on_kill,
             },
         )
 
@@ -158,6 +163,8 @@ class SnowparkContainerJobTrigger(BaseTrigger):
 
     async def on_kill(self) -> None:
         """Drop the job service when a deferred task is killed."""
+        if not self.cancel_on_kill:
+            return
         hook = self._get_hook()
         try:
             await asyncio.to_thread(hook.run, f"DROP SERVICE IF EXISTS 
{self.job_name}")
diff --git 
a/providers/snowflake/src/airflow/providers/snowflake/utils/snowpark_containers.py
 
b/providers/snowflake/src/airflow/providers/snowflake/utils/snowpark_containers.py
index 001446123b1..52719c85e32 100644
--- 
a/providers/snowflake/src/airflow/providers/snowflake/utils/snowpark_containers.py
+++ 
b/providers/snowflake/src/airflow/providers/snowflake/utils/snowpark_containers.py
@@ -18,6 +18,9 @@ from __future__ import annotations
 
 from enum import Enum
 
+NOT_FOUND_STATUS = "NOT_FOUND"
+OBJECT_NOT_EXIST_ERROR_CODE = 2003
+
 
 class SnowparkContainerJobStatus(str, Enum):
     """Statuses of a Snowpark Container Services job service."""
diff --git 
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
 
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
index e3abcc5e7b9..4b322808569 100644
--- 
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
+++ 
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
@@ -21,10 +21,18 @@ from datetime import UTC, datetime, timedelta
 from unittest import mock
 
 import pytest
+from snowflake.connector.errors import ProgrammingError
 
 from airflow.providers.common.compat.sdk import TaskDeferred
 from airflow.providers.snowflake.operators.snowpark_containers import 
SnowparkContainerJobOperator
 from airflow.providers.snowflake.triggers.snowpark_containers import 
SnowparkContainerJobTrigger
+from airflow.providers.snowflake.utils.snowpark_containers import (
+    NOT_FOUND_STATUS,
+    OBJECT_NOT_EXIST_ERROR_CODE,
+)
+
+from tests_common.test_utils.task_state import 
get_non_reserved_task_state_writes
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_3_PLUS
 
 TASK_ID = "test_spcs_job"
 COMPUTE_POOL = "test_pool"
@@ -35,6 +43,8 @@ SPEC_TEXT = "spec:\n  containers:\n  - name: main\n    image: 
/db/schema/repo/im
 JOB_NAME = "TEST_JOB"
 SNOWFLAKE_CONN_ID = "snowflake_default"
 MOCK_HOOK_PATH = 
"airflow.providers.snowflake.operators.snowpark_containers.SnowflakeHook"
+DROP_SQL = "DROP SERVICE IF EXISTS IDENTIFIER(%(job_name)s)"
+SUBMIT_RESPONSE = [f"Started Snowpark Container Services Job '{JOB_NAME}'."]
 
 
 def _make_operator(**kwargs):
@@ -49,6 +59,13 @@ def _make_operator(**kwargs):
     return SnowparkContainerJobOperator(**defaults)
 
 
+def _context(task_store=None):
+    ctx = {"ti": mock.MagicMock(spec=["stats_tags"], stats_tags={})}
+    if task_store is not None:
+        ctx["task_state_store"] = task_store
+    return ctx
+
+
 class TestSnowparkContainerJobOperator:
     def test_invalid_spec_combinations_at_init(self):
         with pytest.raises(ValueError, match=r"Cannot specify both"):
@@ -141,38 +158,42 @@ class TestSnowparkContainerJobOperator:
         assert "external_access_integrations" in op.template_fields
         assert hasattr(op, "external_access_integrations")
 
+    def test_external_id_key(self):
+        assert _make_operator().external_id_key == 
"snowpark_container_job_name"
+
     @mock.patch(MOCK_HOOK_PATH)
     def test_submit_job_parses_job_name(self, mock_hook_cls):
         mock_hook = mock_hook_cls.return_value
-        mock_hook.run.return_value = ["Started Snowpark Container Services Job 
'TEST_JOB'."]
+        mock_hook.run.return_value = SUBMIT_RESPONSE
         op = _make_operator()
-        result = op._submit_job()
+        result = op.submit_job(None)
         assert result == JOB_NAME
 
     @pytest.mark.parametrize(
         "status",
-        ("DONE", "FAILED", "CANCELLED", "INTERNAL_ERROR"),
+        ("FAILED", "CANCELLED", "INTERNAL_ERROR"),
     )
+    @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
     @mock.patch(MOCK_HOOK_PATH)
-    def test_poll_returns_terminal_status(self, mock_hook_cls, status):
+    def test_poll_raises_on_terminal_failure(self, mock_hook_cls, mock_log, 
status):
         mock_hook = mock_hook_cls.return_value
         mock_hook.run.return_value = {"status": status}
         op = _make_operator(poll_interval=0)
-        op.job_name = JOB_NAME
-        assert op._poll_for_status() == status
+        with pytest.raises(RuntimeError, match="finished with status"):
+            op.poll_until_complete(JOB_NAME, None)
 
     @mock.patch(MOCK_HOOK_PATH)
     def test_poll_raises_on_unexpected_status(self, mock_hook_cls):
         mock_hook = mock_hook_cls.return_value
         mock_hook.run.return_value = {"status": "UNKNOWN"}
         op = _make_operator(poll_interval=0)
-        op.job_name = JOB_NAME
         with pytest.raises(RuntimeError, match="unexpected status"):
-            op._poll_for_status()
+            op.poll_until_complete(JOB_NAME, None)
 
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
     @mock.patch("time.sleep")
     @mock.patch(MOCK_HOOK_PATH)
-    def test_poll_waits_through_pending_then_done(self, mock_hook_cls, 
mock_sleep):
+    def test_poll_waits_through_pending_then_done(self, mock_hook_cls, 
mock_sleep, mock_handle):
         mock_hook = mock_hook_cls.return_value
         mock_hook.run.side_effect = [
             {"status": "PENDING"},
@@ -180,9 +201,9 @@ class TestSnowparkContainerJobOperator:
             {"status": "DONE"},
         ]
         op = _make_operator(poll_interval=5)
-        op.job_name = JOB_NAME
-        assert op._poll_for_status() == "DONE"
+        op.poll_until_complete(JOB_NAME, _context())
         assert mock_sleep.call_count == 2
+        mock_handle.assert_called_once_with(status="DONE")
 
     @pytest.mark.parametrize(
         ("drop_on_completion", "drops"),
@@ -202,10 +223,10 @@ class TestSnowparkContainerJobOperator:
         op.job_name = JOB_NAME
 
         with pytest.raises(TimeoutError, match="did not reach a terminal 
status"):
-            op._poll_for_status()
+            op.poll_until_complete(JOB_NAME, None)
 
         mock_log.assert_called_once_with("RUNNING")
-        drop_call = mock.call(f"DROP SERVICE IF EXISTS {JOB_NAME}")
+        drop_call = mock.call(DROP_SQL, parameters={"job_name": JOB_NAME})
         if drops:
             assert drop_call in mock_hook.run.call_args_list
         else:
@@ -251,6 +272,20 @@ class TestSnowparkContainerJobOperator:
             op._log_container_output("DONE")
         assert mock_info.call_count == 3
 
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_log_container_output_binds_arguments(self, mock_hook_cls):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = ["logs"]
+        op = _make_operator()
+        op.job_name = JOB_NAME
+        op._log_container_output("DONE")
+        mock_hook.run.assert_called_once_with(
+            "SELECT SYSTEM$GET_SERVICE_LOGS(%(job_name)s, %(instance_id)s, 
%(container_name)s)",
+            parameters={"job_name": JOB_NAME, "instance_id": 0, 
"container_name": op.container_name},
+            handler=mock.ANY,
+            return_dictionaries=False,
+        )
+
     @mock.patch(MOCK_HOOK_PATH)
     def test_log_container_output_swallows_fetch_error(self, mock_hook_cls):
         mock_hook = mock_hook_cls.return_value
@@ -274,7 +309,15 @@ class TestSnowparkContainerJobOperator:
         op = _make_operator()
         op.job_name = JOB_NAME
         op.on_kill()
-        mock_hook.run.assert_called_once_with(f"DROP SERVICE IF EXISTS 
{JOB_NAME}")
+        mock_hook.run.assert_called_once_with(DROP_SQL, 
parameters={"job_name": JOB_NAME})
+
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_on_kill_skips_drop_when_cancel_on_kill_disabled(self, 
mock_hook_cls):
+        mock_hook = mock_hook_cls.return_value
+        op = _make_operator(cancel_on_kill=False)
+        op.job_name = JOB_NAME
+        op.on_kill()
+        mock_hook.run.assert_not_called()
 
     @mock.patch(MOCK_HOOK_PATH)
     def test_on_kill_logs_error_on_exception(self, mock_hook_cls):
@@ -306,60 +349,56 @@ class TestSnowparkContainerJobOperator:
         op = _make_operator()
 
         with pytest.raises(RuntimeError, match="Unexpected job submission 
response"):
-            op._submit_job()
+            op.submit_job(None)
 
     @mock.patch(MOCK_HOOK_PATH)
     def test_execute_no_wait(self, mock_hook_cls):
         mock_hook = mock_hook_cls.return_value
-        mock_hook.run.return_value = ["Started Snowpark Container Services Job 
'TEST_JOB'."]
+        mock_hook.run.return_value = SUBMIT_RESPONSE
         op = _make_operator(wait_for_completion=False)
         result = op.execute(context=None)
         assert result == JOB_NAME
         assert mock_hook.run.call_count == 1
 
-    @mock.patch(MOCK_HOOK_PATH)
     @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
-    @mock.patch.object(SnowparkContainerJobOperator, "_poll_for_status", 
return_value="DONE")
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
-    def test_execute_wait_success(self, mock_submit, mock_poll, mock_log, 
mock_hook_cls):
-        op = _make_operator()
+    @mock.patch.object(SnowparkContainerJobOperator, "poll_until_complete")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_execute_wait_success(self, mock_hook_cls, mock_submit, mock_poll, 
mock_log):
+        op = _make_operator(durable=False)
         result = op.execute(context=None)
         mock_submit.assert_called_once()
         mock_poll.assert_called_once()
         mock_log.assert_called_once_with("DONE")
         assert result == JOB_NAME
 
-    @mock.patch(MOCK_HOOK_PATH)
     @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
-    @mock.patch.object(SnowparkContainerJobOperator, "_poll_for_status", 
return_value="FAILED")
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
-    def test_execute_wait_failure_raises(self, mock_submit, mock_poll, 
mock_log, mock_hook_cls):
-        op = _make_operator()
-        with pytest.raises(RuntimeError, match="FAILED"):
-            op.execute(context=None)
-        mock_log.assert_called_once_with("FAILED")
-
-    @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
-    @mock.patch.object(SnowparkContainerJobOperator, "_poll_for_status", 
return_value="DONE")
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
     @mock.patch(MOCK_HOOK_PATH)
-    def test_execute_drops_service_on_completion(self, mock_hook_cls, 
mock_submit, mock_poll, mock_log):
+    def test_execute_drops_service_on_completion(self, mock_hook_cls, 
mock_submit, mock_log):
         mock_hook = mock_hook_cls.return_value
-        op = _make_operator(drop_on_completion=True)
+        mock_hook.run.side_effect = [
+            {"status": "DONE"},
+            None,
+        ]
+        op = _make_operator(drop_on_completion=True, poll_interval=0, 
durable=False)
         op.execute(context=None)
-        mock_hook.run.assert_called_once_with(f"DROP SERVICE IF EXISTS 
{JOB_NAME}")
+        assert mock.call(DROP_SQL, parameters={"job_name": JOB_NAME}) in 
mock_hook.run.call_args_list
 
     @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
-    @mock.patch.object(SnowparkContainerJobOperator, "_poll_for_status", 
return_value="DONE")
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
     @mock.patch(MOCK_HOOK_PATH)
-    def test_execute_skips_drop_when_disabled(self, mock_hook_cls, 
mock_submit, mock_poll, mock_log):
+    def test_execute_skips_drop_when_disabled(self, mock_hook_cls, 
mock_submit, mock_log):
         mock_hook = mock_hook_cls.return_value
-        op = _make_operator(drop_on_completion=False)
+        mock_hook.run.side_effect = [
+            {"status": "DONE"},
+        ]
+        op = _make_operator(drop_on_completion=False, poll_interval=0, 
durable=False)
         op.execute(context=None)
-        mock_hook.run.assert_not_called()
+        drop_call = mock.call(DROP_SQL, parameters={"job_name": JOB_NAME})
+        assert drop_call not in mock_hook.run.call_args_list
 
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
     def test_execute_defers_when_deferrable(self, mock_submit):
         op = _make_operator(deferrable=True)
         with pytest.raises(TaskDeferred) as exc:
@@ -368,7 +407,14 @@ class TestSnowparkContainerJobOperator:
         assert exc.value.trigger.job_name == JOB_NAME
         assert exc.value.method_name == "execute_complete"
 
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
+    def test_execute_defer_forwards_cancel_on_kill(self, mock_submit):
+        op = _make_operator(deferrable=True, cancel_on_kill=False)
+        with pytest.raises(TaskDeferred) as exc:
+            op.execute(context=None)
+        assert exc.value.trigger.cancel_on_kill is False
+
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
     def test_execute_defer_without_execution_timeout(self, mock_submit):
         op = _make_operator(deferrable=True, timeout=100, poll_interval=10)
         with pytest.raises(TaskDeferred) as exc:
@@ -376,7 +422,7 @@ class TestSnowparkContainerJobOperator:
         assert exc.value.trigger.execution_deadline is None
         assert exc.value.timeout == timedelta(seconds=100 + 10 + 60)
 
-    @mock.patch.object(SnowparkContainerJobOperator, "_submit_job", 
return_value=JOB_NAME)
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
     def 
test_execute_defer_uses_execution_timeout_for_deadline_and_buffer(self, 
mock_submit, time_machine):
         time_machine.move_to(1000, tick=False)
         context = {"ti": mock.Mock(start_date=datetime.fromtimestamp(1000, 
tz=UTC))}
@@ -400,7 +446,7 @@ class TestSnowparkContainerJobOperator:
         result = op.execute_complete(context=None, event={"status": "DONE", 
"job_name": JOB_NAME})
         assert result == JOB_NAME
         mock_log.assert_called_once_with("DONE")
-        mock_hook.run.assert_called_once_with(f"DROP SERVICE IF EXISTS 
{JOB_NAME}")
+        mock_hook.run.assert_called_once_with(DROP_SQL, 
parameters={"job_name": JOB_NAME})
 
     @mock.patch(MOCK_HOOK_PATH)
     @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
@@ -429,7 +475,7 @@ class TestSnowparkContainerJobOperator:
                 event={"status": status, "job_name": JOB_NAME, "message": 
"boom"},
             )
         if drops:
-            mock_hook.run.assert_called_once_with(f"DROP SERVICE IF EXISTS 
{JOB_NAME}")
+            mock_hook.run.assert_called_once_with(DROP_SQL, 
parameters={"job_name": JOB_NAME})
         else:
             mock_hook.run.assert_not_called()
         if logs:
@@ -457,3 +503,276 @@ class TestSnowparkContainerJobOperator:
             )
         mock_log.assert_called_once_with("timeout")
         mock_hook.run.assert_not_called()
+
+
[email protected](
+    not AIRFLOW_V_3_3_PLUS, reason="task_state_store (durable execution) 
requires Airflow 3.3+"
+)
+class TestSnowparkContainerJobOperatorDurable:
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_job_name_persists_to_task_state_store_on_fresh_submit(
+        self, mock_hook_cls, mock_submit_job, mock_handle
+    ):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = {"status": "DONE"}
+
+        op = _make_operator(poll_interval=0)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = None
+
+        op.execute(context=_context(task_store=task_store))
+
+        assert get_non_reserved_task_state_writes(task_store) == [
+            mock.call(op.external_id_key, JOB_NAME),
+            mock.call(op._job_done_marker_key, {JOB_NAME: "DONE"}),
+        ]
+        mock_handle.assert_called_once_with(status="DONE")
+
+    @mock.patch("time.sleep")
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job")
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_reconnects_to_running_job_without_resubmitting(
+        self, mock_hook_cls, mock_submit_job, mock_handle, mock_sleep
+    ):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.side_effect = [
+            {"status": "RUNNING"},
+            {"status": "DONE"},
+        ]
+
+        op = _make_operator(poll_interval=5)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = JOB_NAME
+
+        result = op.execute(context=_context(task_store=task_store))
+
+        assert get_non_reserved_task_state_writes(task_store) == [
+            mock.call(op._job_done_marker_key, {JOB_NAME: "DONE"})
+        ]
+        mock_submit_job.assert_not_called()
+        mock_handle.assert_called_once_with(status="DONE")
+        assert result == JOB_NAME
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "poll_until_complete")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job")
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_already_succeeded_completes_without_polling(
+        self, mock_hook_cls, mock_submit_job, mock_poll_until_complete, 
mock_handle
+    ):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.side_effect = [{"status": "DONE"}]
+
+        op = _make_operator(poll_interval=5)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = JOB_NAME
+
+        op.execute(context=_context(task_store=task_store))
+
+        mock_submit_job.assert_not_called()
+        mock_poll_until_complete.assert_not_called()
+        mock_handle.assert_called_once_with(status="DONE")
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "poll_until_complete")
+    @mock.patch.object(SnowparkContainerJobOperator, "get_job_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job")
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_resubmits_when_stored_job_in_terminal_error(
+        self, mock_hook_cls, mock_submit_job, mock_get_job_status, 
mock_poll_until_complete, mock_handle
+    ):
+        mock_get_job_status.return_value = "FAILED"
+        mock_submit_job.return_value = f"{JOB_NAME}_2"
+
+        op = _make_operator(poll_interval=0)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = JOB_NAME
+
+        op.execute(context=_context(task_store=task_store))
+
+        mock_submit_job.assert_called_once()
+        assert get_non_reserved_task_state_writes(task_store) == [
+            mock.call(op.external_id_key, f"{JOB_NAME}_2")
+        ]
+        mock_poll_until_complete.assert_called_once_with(f"{JOB_NAME}_2", 
mock.ANY)
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "poll_until_complete")
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job")
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_resubmits_when_stored_job_not_exist(
+        self, mock_hook_cls, mock_submit_job, mock_describe_status, 
mock_poll_until_complete, mock_handle
+    ):
+        mock_describe_status.side_effect = ProgrammingError(
+            msg="test job does not exist", errno=OBJECT_NOT_EXIST_ERROR_CODE
+        )
+        mock_submit_job.return_value = f"{JOB_NAME}_2"
+
+        op = _make_operator(poll_interval=0)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = JOB_NAME
+
+        op.execute(context=_context(task_store=task_store))
+
+        mock_submit_job.assert_called_once()
+        assert get_non_reserved_task_state_writes(task_store) == [
+            mock.call(op.external_id_key, f"{JOB_NAME}_2")
+        ]
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_handle_final_status")
+    @mock.patch.object(SnowparkContainerJobOperator, "submit_job", 
return_value=JOB_NAME)
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_durable_false_never_touches_task_state_store(self, mock_hook_cls, 
mock_submit_job, mock_handle):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = {"status": "DONE"}
+
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        op = _make_operator(durable=False)
+
+        op.execute(context=_context(task_store=task_store))
+
+        task_store.get.assert_not_called()
+        task_store.set.assert_not_called()
+
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_deferrable_does_not_persist_to_task_state_store(self, 
mock_hook_cls):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = SUBMIT_RESPONSE
+
+        op = _make_operator(deferrable=True)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+
+        with pytest.raises(TaskDeferred):
+            op.execute(context=_context(task_store=task_store))
+
+        task_store.get.assert_not_called()
+        task_store.set.assert_not_called()
+
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_no_wait_does_not_persist_to_task_state_store(self, mock_hook_cls):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = SUBMIT_RESPONSE
+
+        op = _make_operator(wait_for_completion=False)
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+
+        result = op.execute(context=_context(task_store=task_store))
+
+        assert result == JOB_NAME
+        task_store.get.assert_not_called()
+        task_store.set.assert_not_called()
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    def test_get_job_status_returns_status(self, mock_describe_status):
+        mock_describe_status.return_value = "DONE"
+        op = _make_operator()
+        status = op.get_job_status(context=_context(), external_id=JOB_NAME)
+        assert status == "DONE"
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    def test_get_job_status_returns_not_found_when_service_missing(self, 
mock_describe_status):
+        mock_describe_status.side_effect = ProgrammingError(
+            msg="test job does not exist", errno=OBJECT_NOT_EXIST_ERROR_CODE
+        )
+        op = _make_operator()
+        status = op.get_job_status(context=_context(), external_id=JOB_NAME)
+        assert status == NOT_FOUND_STATUS
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    def test_get_job_status_reraises_other_programming_errors(self, 
mock_describe_status):
+        mock_describe_status.side_effect = ProgrammingError(msg="syntax 
error", errno=1003)
+        op = _make_operator()
+        with pytest.raises(ProgrammingError, match="syntax error"):
+            op.get_job_status(context=_context(), external_id=JOB_NAME)
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    def test_get_job_status_returns_done_from_task_state_store(self, 
mock_describe_status):
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = {JOB_NAME: "DONE"}
+        op = _make_operator()
+        status = op.get_job_status(context=_context(task_store=task_store), 
external_id=JOB_NAME)
+        assert status == "DONE"
+        task_store.get.assert_called_once_with(op._job_done_marker_key)
+        mock_describe_status.assert_not_called()
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_describe_status")
+    def test_get_job_status_ignores_marker_not_tied_to_job_name(self, 
mock_describe_status):
+        mock_describe_status.return_value = "RUNNING"
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        task_store.get.return_value = "DONE"
+        op = _make_operator()
+        status = op.get_job_status(context=_context(task_store=task_store), 
external_id=JOB_NAME)
+        assert status == "RUNNING"
+        mock_describe_status.assert_called_once_with(JOB_NAME)
+
+    @pytest.mark.parametrize("external_id", [123, None])
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_get_job_status_rejects_non_string_stored_job_name(self, 
mock_hook_cls, external_id):
+        op = _make_operator()
+        with pytest.raises(TypeError, match="is not a string"):
+            op.get_job_status(external_id, _context())
+        mock_hook_cls.return_value.run.assert_not_called()
+
+    @pytest.mark.parametrize("external_id", ["DB.SCHEMA.TEST_JOB", '"my job"'])
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_get_job_status_binds_qualified_or_quoted_job_name(self, 
mock_hook_cls, external_id):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = {"status": "RUNNING"}
+        op = _make_operator()
+        status = op.get_job_status(external_id, _context())
+        assert status == "RUNNING"
+        mock_hook.run.assert_called_once_with(
+            "DESCRIBE SERVICE IDENTIFIER(%(job_name)s)",
+            parameters={"job_name": external_id},
+            handler=mock.ANY,
+            return_dictionaries=True,
+        )
+
+    @mock.patch.object(SnowparkContainerJobOperator, "_log_container_output")
+    @mock.patch(MOCK_HOOK_PATH)
+    def test_poll_persists_done_before_dropping_service(self, mock_hook_cls, 
mock_log):
+        mock_hook = mock_hook_cls.return_value
+        mock_hook.run.return_value = {"status": "DONE"}
+        task_store = mock.MagicMock(spec_set=["get", "set"])
+        manager = mock.Mock()
+        manager.attach_mock(task_store.set, "set")
+        manager.attach_mock(mock_hook.run, "run")
+
+        op = _make_operator()
+        op.poll_until_complete(JOB_NAME, _context(task_store=task_store))
+
+        assert manager.mock_calls[-2:] == [
+            mock.call.set(op._job_done_marker_key, {JOB_NAME: "DONE"}),
+            mock.call.run(DROP_SQL, parameters={"job_name": JOB_NAME}),
+        ]
+
+    @pytest.mark.parametrize(
+        ("status", "active", "succeeded"),
+        [
+            ("PENDING", True, False),
+            ("RUNNING", True, False),
+            ("DONE", False, True),
+            ("FAILED", False, False),
+            ("CANCELLING", False, False),
+            ("DELETING", False, False),
+        ],
+    )
+    def test_is_job_active_and_is_job_succeeded(self, status, active, 
succeeded):
+        op = _make_operator()
+        assert op.is_job_active(status) is active
+        assert op.is_job_succeeded(status) is succeeded
+
+    @pytest.mark.parametrize(
+        "kwargs",
+        [
+            pytest.param({"default_args": {"durable": False}}, 
id="default_args"),
+            pytest.param({"durable": False}, id="kwarg"),
+        ],
+    )
+    def test_durable_false_reaches_operator(self, kwargs):
+        op = _make_operator(**kwargs)
+        assert op.durable is False
diff --git 
a/providers/snowflake/tests/unit/snowflake/triggers/test_snowpark_containers.py 
b/providers/snowflake/tests/unit/snowflake/triggers/test_snowpark_containers.py
index f0e29e4515d..3e082588709 100644
--- 
a/providers/snowflake/tests/unit/snowflake/triggers/test_snowpark_containers.py
+++ 
b/providers/snowflake/tests/unit/snowflake/triggers/test_snowpark_containers.py
@@ -58,6 +58,7 @@ class TestSnowparkContainerJobTrigger:
             schema="sc",
             role="r",
             warehouse="wh",
+            cancel_on_kill=False,
         ).serialize()
         assert class_path == CLASSPATH
         assert kwargs == {
@@ -70,6 +71,7 @@ class TestSnowparkContainerJobTrigger:
             "schema": "sc",
             "role": "r",
             "warehouse": "wh",
+            "cancel_on_kill": False,
         }
 
     @mock.patch(HOOK, autospec=True)
@@ -195,6 +197,12 @@ class TestSnowparkContainerJobTrigger:
         await self._trigger().on_kill()
         mock_hook_cls.return_value.run.assert_called_once_with(f"DROP SERVICE 
IF EXISTS {JOB_NAME}")
 
+    @pytest.mark.asyncio
+    @mock.patch(HOOK, autospec=True)
+    async def test_on_kill_skips_drop_when_cancel_on_kill_disabled(self, 
mock_hook_cls):
+        await self._trigger(cancel_on_kill=False).on_kill()
+        mock_hook_cls.return_value.run.assert_not_called()
+
     @pytest.mark.asyncio
     @mock.patch(HOOK, autospec=True)
     async def test_on_kill_logs_error_on_failure(self, mock_hook_cls):

Reply via email to