kaxil commented on code in PR #73235:
URL: https://github.com/apache/airflow/pull/73235#discussion_r4042141010


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py:
##########
@@ -61,34 +61,37 @@ def upsert_hitl_detail(
     1. If a HITLOperator task instance does not have a HITLDetail,
        a new HITLDetail is created without a response section.
     2. If a HITLOperator task instance has a HITLDetail but lacks a response,
-       the existing HITLDetail is returned.
+       the request part is refreshed from the payload and the HITLDetail is 
returned.
        This situation occurs when a task instance is cleared before a response 
is received.
     3. If a HITLOperator task instance has both a HITLDetail and a response 
section,
-       the existing response is removed, and the HITLDetail is returned.
+       the request part is refreshed, the existing response is removed, and 
the HITLDetail is returned.
        This happens when a task instance is cleared after a response has been 
received.
        This design ensures that each task instance has only one HITLDetail.
     """
+    request_part = {
+        "options": payload.options,
+        "subject": payload.subject,
+        "body": payload.body,
+        "defaults": payload.defaults,
+        "multiple": payload.multiple,
+        "params": payload.params,
+        "assignees": [user.model_dump() for user in payload.assigned_users],
+    }
     hitl_detail_model = 
session.scalar(select(HITLDetail).where(HITLDetail.ti_id == task_instance_id))
     if not hitl_detail_model:
-        hitl_detail_model = HITLDetail(
-            ti_id=task_instance_id,
-            options=payload.options,
-            subject=payload.subject,
-            body=payload.body,
-            defaults=payload.defaults,
-            multiple=payload.multiple,
-            params=payload.params,
-            assignees=[user.model_dump() for user in payload.assigned_users],
-        )
-        session.add(hitl_detail_model)
-    elif hitl_detail_model.response_received:
-        # Cleanup the response part of HITLDetail as we only store one 
response for one task instance.
-        # It normally happens after retry, we keep only the latest response.
-        hitl_detail_model.responded_by = None
-        hitl_detail_model.responded_at = None
-        hitl_detail_model.chosen_options = None
-        hitl_detail_model.params_input = {}
-        session.add(hitl_detail_model)
+        hitl_detail_model = HITLDetail(ti_id=task_instance_id, **request_part)
+    else:
+        if hitl_detail_model.response_received:

Review Comment:
   The two other writers of this row lock TaskInstance then HITLDetail before 
reading `response_received` (`execution_api/routes/task_instances.py:746-754` 
for the park transition, `core_api/routes/public/hitl.py:168-184` for the human 
response, each commented as matching the other), while the SELECT on line 80 
takes neither. That was harmless while this branch wrote nothing, but now a 
response committing between the read and the flush skips the wipe and still 
replaces the request columns, so the row ends up carrying the new attempt's 
subject and options under the approval a reviewer gave the previous one, and 
the park handler resumes straight onto it (`task_instances.py:754-765`). The 
cross-attempt response itself predates this PR; what is new is that the row 
stops recording the mismatch, so would taking the same two locks in the same 
order here be worth it?



##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py:
##########
@@ -61,34 +61,37 @@ def upsert_hitl_detail(
     1. If a HITLOperator task instance does not have a HITLDetail,
        a new HITLDetail is created without a response section.
     2. If a HITLOperator task instance has a HITLDetail but lacks a response,
-       the existing HITLDetail is returned.
+       the request part is refreshed from the payload and the HITLDetail is 
returned.
        This situation occurs when a task instance is cleared before a response 
is received.
     3. If a HITLOperator task instance has both a HITLDetail and a response 
section,
-       the existing response is removed, and the HITLDetail is returned.
+       the request part is refreshed, the existing response is removed, and 
the HITLDetail is returned.
        This happens when a task instance is cleared after a response has been 
received.
        This design ensures that each task instance has only one HITLDetail.
     """
+    request_part = {
+        "options": payload.options,
+        "subject": payload.subject,
+        "body": payload.body,
+        "defaults": payload.defaults,
+        "multiple": payload.multiple,
+        "params": payload.params,
+        "assignees": [user.model_dump() for user in payload.assigned_users],

Review Comment:
   `created_at` sits in the same `# User Request Detail` block as these seven, 
on the model (`models/hitl.py:146-154`) and in the public schema 
(`core_api/datamodels/hitl.py:56-64`), but it is not in `request_part`, and its 
`default=timezone.utcnow` only fires on insert, so a re-run request keeps the 
first attempt's timestamp. The review drawer prints it next to the try number 
as an absolute plus a relative age (`HITLReviewDetailSummary.tsx:70-71`) and 
the list route offers it as a sort key and a range filter 
(`core_api/routes/public/hitl.py:319`, `:353`), so regenerated content still 
reads as days old and falls outside a recent-`created_at` filter. Add it to the 
refresh set?



-- 
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