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

   Killing a running common.ai task (LLMOperator, AgentOperator, or an operator 
deriving
   from them) used to absorb the SIGTERM grace window. No operator implemented 
on_kill, so
   the pydantic-ai run kept issuing model requests and its toolsets never 
unwound, leaving a
   provisioned sandbox running until SIGKILL, where it leaked.
   
   The operators now hold the run's pydantic-ai CancellationToken and cancel it 
from
   on_kill, so a killed run stops and tears down cleanly within the grace 
window instead of
   running dead until SIGKILL. The cancel is issued from a short-lived thread, 
because
   on_kill runs in the Task SDK's SIGTERM handler on the same thread that 
drives run_sync,
   where an inline cancel does not interrupt the blocked run (it only takes 
effect once the
   in-flight await returns). Requires pydantic-ai 2.26.0 for first-party run 
cancellation.
   
   This does not change the SIGKILL case. A task killed with SIGKILL runs no 
Python, so a
   sandbox killed that way still depends on the backend's own backstop.
   
   ##### Test plan
   
   Manual end-to-end (not covered by CI): on a breeze start-airflow stack, 
trigger a
   common.ai agent/LLM task and, while it is running, mark it failed or clear 
it from the UI.
   The task log shows on_kill firing and the run raising RunCancelled within 
the grace
   window. Verified for AgentOperator (live UI) and LLMOperator (RunCancelled 
~1ms after
   on_kill, versus running dead to SIGKILL without the change).
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes, Claude Code (Opus 4.8)
   
   Generated-by: Claude Code (Opus 4.8) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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