andreahlert opened a new pull request, #61631:
URL: https://github.com/apache/airflow/pull/61631

   Closes: #53140
   
   When a running Task Instance is cleared, `prepare_db_for_next_try()` 
archives the current try to the Task Instance History (TIH) table and assigns a 
new UUID. This means heartbeats from the old process will fail with a 404 "Not 
Found" because the UUID no longer exists in the TI table. However, a generic 
404 is misleading since the TI did exist - it was just cleared.
   
   This PR adds a TIH lookup in the `NoResultFound` handler of the heartbeat 
endpoint:
   - If the UUID is **not** in TI but **is** in TIH: return **410 Gone**, 
indicating the TI was cleared/moved
   - If the UUID is **not** in TI and **not** in TIH: return **404 Not Found** 
(unchanged behavior)
   
   This gives the task SDK supervisor a more specific signal and matches HTTP 
semantics (410 means "the target resource is no longer available at the origin 
server and this condition is likely to be permanent").
   
   Changes:
   - `execution_api/routes/task_instances.py`: Added TIH existence check in the 
heartbeat `NoResultFound` handler; added 410 to OpenAPI response schema
   - `execution_time/supervisor.py`: Added `HTTPStatus.GONE` to the set of 
status codes that the supervisor treats as "stop heartbeating" (alongside 
NOT_FOUND and CONFLICT)
   - `test_task_instances.py`: Added test using `prepare_db_for_next_try()` to 
properly simulate a cleared TI and verify the 410 response
   
   Previous attempt: #56443 (closed as stale). This PR addresses the review 
feedback from that PR by actually checking the TIH table rather than blindly 
changing 404 to 410.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to