From 7e5ea0c27998b2ac0d68eb808f6c0577391f8b35 Mon Sep 17 00:00:00 2001 From: kriti-sc Date: Mon, 6 Oct 2025 14:06:34 -0700 Subject: [PATCH 1/5] change 404 to 410 --- .../api_fastapi/execution_api/routes/task_instances.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py index f2f8fc8e11565..18109d41da23f 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py @@ -605,12 +605,12 @@ def ti_heartbeat( "Retrieved current task state", state=previous_state, current_hostname=hostname, current_pid=pid ) except NoResultFound: - log.error("Task Instance not found") + log.error("Task Instance not found in Task Instance, might have moved to the Task Instance History table") raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, + status_code=status.HTTP_410_GONE, detail={ "reason": "not_found", - "message": "Task Instance not found", + "message": "Task Instance not found, might have moved to the Task Instance History table", }, ) From 607574a7ac663825499425866097d206c0a08a57 Mon Sep 17 00:00:00 2001 From: kriti-sc Date: Mon, 6 Oct 2025 14:34:09 -0700 Subject: [PATCH 2/5] change 404 to 410 --- .../api_fastapi/execution_api/routes/task_instances.py | 4 ++-- .../execution_api/versions/head/test_task_instances.py | 6 +++--- task-sdk/src/airflow/sdk/execution_time/supervisor.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py index 18109d41da23f..5bbfd67000720 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py @@ -577,7 +577,7 @@ def ti_skip_downstream( "/{task_instance_id}/heartbeat", status_code=status.HTTP_204_NO_CONTENT, responses={ - status.HTTP_404_NOT_FOUND: {"description": "Task Instance not found"}, + status.HTTP_410_GONE: {"description": "Task Instance not found, might have moved to the Task Instance History table"}, status.HTTP_409_CONFLICT: { "description": "The TI attempting to heartbeat should be terminated for the given reason" }, @@ -605,7 +605,7 @@ def ti_heartbeat( "Retrieved current task state", state=previous_state, current_hostname=hostname, current_pid=pid ) except NoResultFound: - log.error("Task Instance not found in Task Instance, might have moved to the Task Instance History table") + log.error("Task Instance not found in Task Instance table, might have moved to the Task Instance History table") raise HTTPException( status_code=status.HTTP_410_GONE, detail={ diff --git a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py index 66ce18e2d3554..88932b49a1df0 100644 --- a/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py +++ b/airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py @@ -1264,7 +1264,7 @@ def test_ti_heartbeat( assert response.json()["detail"] == expected_detail def test_ti_heartbeat_non_existent_task(self, client, session, create_task_instance): - """Test that a 404 error is returned when the Task Instance does not exist.""" + """Test that a 410 error is returned when the Task Instance does not exist.""" task_instance_id = "0182e924-0f1e-77e6-ab50-e977118bc139" # Pre-condition: the Task Instance does not exist @@ -1275,10 +1275,10 @@ def test_ti_heartbeat_non_existent_task(self, client, session, create_task_insta json={"hostname": "random-hostname", "pid": 1547}, ) - assert response.status_code == 404 + assert response.status_code == 410 assert response.json()["detail"] == { "reason": "not_found", - "message": "Task Instance not found", + "message": "Task Instance not found, might have moved to the Task Instance History table", } @pytest.mark.parametrize( diff --git a/task-sdk/src/airflow/sdk/execution_time/supervisor.py b/task-sdk/src/airflow/sdk/execution_time/supervisor.py index 01e3094cb5929..ebad19e5493b6 100644 --- a/task-sdk/src/airflow/sdk/execution_time/supervisor.py +++ b/task-sdk/src/airflow/sdk/execution_time/supervisor.py @@ -1099,7 +1099,7 @@ def _send_heartbeat_if_needed(self): # Reset the counter on success self.failed_heartbeats = 0 except ServerResponseError as e: - if e.response.status_code in {HTTPStatus.NOT_FOUND, HTTPStatus.CONFLICT}: + if e.response.status_code in {HTTPStatus.GONE, HTTPStatus.CONFLICT}: log.error( "Server indicated the task shouldn't be running anymore", detail=e.detail, From 80542b5a6c14d3390127385d4dabb6c46c2cde82 Mon Sep 17 00:00:00 2001 From: Kriti Kathuria <38242933+kriti-sc@users.noreply.github.com> Date: Sun, 9 Nov 2025 13:33:54 +0530 Subject: [PATCH 3/5] Update airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py Co-authored-by: Amogh Desai --- .../airflow/api_fastapi/execution_api/routes/task_instances.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py index 5bbfd67000720..9d703bcb92dbb 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py @@ -577,7 +577,7 @@ def ti_skip_downstream( "/{task_instance_id}/heartbeat", status_code=status.HTTP_204_NO_CONTENT, responses={ - status.HTTP_410_GONE: {"description": "Task Instance not found, might have moved to the Task Instance History table"}, + status.HTTP_410_GONE: {"description": "Task Instance no longer exists, it may have moved to the Task Instance History table"}, status.HTTP_409_CONFLICT: { "description": "The TI attempting to heartbeat should be terminated for the given reason" }, From 32f289c9a8a52265c2a1e9b73226073cab8c8654 Mon Sep 17 00:00:00 2001 From: Kriti Kathuria <38242933+kriti-sc@users.noreply.github.com> Date: Sun, 9 Nov 2025 13:34:02 +0530 Subject: [PATCH 4/5] Update airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py Co-authored-by: Amogh Desai --- .../airflow/api_fastapi/execution_api/routes/task_instances.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py index 9d703bcb92dbb..91e4f63b70192 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py @@ -610,7 +610,7 @@ def ti_heartbeat( status_code=status.HTTP_410_GONE, detail={ "reason": "not_found", - "message": "Task Instance not found, might have moved to the Task Instance History table", + status.HTTP_410_GONE: {"description": "Task Instance no longer exists, it may have moved to the Task Instance History table"}, }, ) From 734109117c96680f2f433a33877b9d9927af662f Mon Sep 17 00:00:00 2001 From: Kriti Kathuria <38242933+kriti-sc@users.noreply.github.com> Date: Sun, 9 Nov 2025 13:35:13 +0530 Subject: [PATCH 5/5] Update airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py Co-authored-by: Amogh Desai --- .../airflow/api_fastapi/execution_api/routes/task_instances.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py index 91e4f63b70192..7efbc8767afd2 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py @@ -605,7 +605,7 @@ def ti_heartbeat( "Retrieved current task state", state=previous_state, current_hostname=hostname, current_pid=pid ) except NoResultFound: - log.error("Task Instance not found in Task Instance table, might have moved to the Task Instance History table") + status.HTTP_410_GONE: {"description": "Task Instance no longer exists, it may have moved to the Task Instance History table"}, raise HTTPException( status_code=status.HTTP_410_GONE, detail={