anishgirianish commented on code in PR #60855:
URL: https://github.com/apache/airflow/pull/60855#discussion_r2791187801


##########
task-sdk/src/airflow/sdk/execution_time/supervisor.py:
##########
@@ -1007,9 +1007,23 @@ def _on_child_started(
             ti_context = self.client.task_instances.start(ti.id, self.pid, 
start_date)
             self._should_retry = ti_context.should_retry
             self._last_successful_heartbeat = time.monotonic()
-        except Exception:
+        except Exception as e:
             # On any error kill that subprocess!
             self.kill(signal.SIGKILL)
+
+            # Handle broker redelivery: task already running on another worker
+            if isinstance(e, ServerResponseError) and e.response.status_code 
== 409:
+                # FastAPI wraps HTTPException detail in {"detail": {...}}
+                detail = e.detail
+                if isinstance(detail, dict) and "detail" in detail:
+                    detail = detail["detail"]
+                if (
+                    isinstance(detail, dict)
+                    and detail.get("reason") == "invalid_state"
+                    and detail.get("previous_state") == "running"
+                ):

Review Comment:
   Thanks for the feedback. Moved the 409 handling into 
TaskInstanceOperations.start() in client.py, following the same pattern as 
DagRunOperations.trigger(). The supervisor now catches  TaskAlreadyRunningError 
with no dict parsing at all.                                                    
                                                                                
       
   Also fixed ServerResponseError.from_response() to properly handle dict-type 
detail values previously, it fell through to a raw msgspec.json.decode 
fallback, which caused double-wrapping and required callers to unwrap 
e.detail["detail"]. That's no longer needed.



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