Skip to content

Distinguish OpenAI batch timeout and cancellation in deferrable tasks - #72149

Draft
Lee-W wants to merge 2 commits into
apache:mainfrom
astronomer:openai-batch-termination-reason
Draft

Distinguish OpenAI batch timeout and cancellation in deferrable tasks#72149
Lee-W wants to merge 2 commits into
apache:mainfrom
astronomer:openai-batch-termination-reason

Conversation

@Lee-W

@Lee-W Lee-W commented Aug 27, 2026

Copy link
Copy Markdown
Member

A deferred OpenAITriggerBatchOperator reported every non-success outcome as the
same OpenAIBatchJobException, so a task that merely ran out of patience looked
identical to a batch that failed, and neither could be handled separately. The
synchronous path has always raised OpenAIBatchTimeout for the same condition.
The trigger now reports why it stopped, and the resuming task picks the matching
exception from that field rather than from the message text.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Lee-W added 2 commits August 27, 2026 20:47
A deferred OpenAITriggerBatchOperator reported every non-success outcome as the
same OpenAIBatchJobException, so a task that merely ran out of patience looked
identical to a batch that failed, and neither could be handled separately. The
synchronous path has always raised OpenAIBatchTimeout for the same condition.
The trigger now reports why it stopped, and the resuming task picks the matching
exception from that field rather than from the message text.
The synchronous path cancels the batch before raising a timeout, but the
deferrable path only failed the task and left the batch running and billing on
OpenAI's side. A deferred timeout now requests cancellation with the batch id
carried by the trigger event. Cancellation is asynchronous, so the batch
reports "cancelling" for a while before it settles; a cancel that fails is
logged and never masks the timeout.

Deliberately not cancelling on a polling_error: batches.cancel is
irreversible, and the failure mode there is unknown and often a transient,
Airflow-side error rather than a real batch problem. OpenAI's batch has a
24-hour completion window that bounds it on its own, so leaving it alone costs
a bounded amount; wrongly cancelling it is unrecoverable data loss. Anthropic
cancels on its equivalent error branch, but its session has no such natural
end point, so that precedent does not apply here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant