Skip to content

Fail LLMOperator approval at parse time on Airflow cores older than 3.1 - #73261

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:llm-require-approval-3-1-guard
Sep 17, 2026
Merged

kaxil merged 1 commit into
apache:mainfrom
astronomer:llm-require-approval-3-1-guard

Conversation

@kaxil

@kaxil kaxil commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Human-in-the-loop review needs Airflow 3.1+, but require_approval=True was never gated on it. The provider floors apache-airflow>=3.0.0, so a 3.0.x core is a supported install, and there the Dag imported cleanly and the failure landed mid-task. execute calls agent.run_sync() before defer_for_approval, and defer_for_approval imports HITLTrigger, which raises on import below 3.1, and airflow.sdk.execution_time.hitl, which does not exist before 3.1. So the model call was paid for, the task then died on an import that could never have succeeded, and every retry paid for it again.

__init__ now rejects the parameter the way AgentOperator already rejects enable_hitl_review, so the Dag fails to import instead.

Why __init__ rather than execute. Failing before the spend is the whole point, and a guard in execute would still sit downstream of agent.run_sync(), reporting the problem after the cost it exists to avoid. Placement within __init__ matters too: the check sits below the on_approval_timeout literal validation and above the combination rule, so a typo keeps its own precise message, while on an old core the core version is reported rather than a combination error that would send the user to drop an argument that was never the problem.

Verified against a real Airflow 3.0.6 core with the provider installed from source:

before after
Dag import succeeds fails with AirflowOptionalProviderFeatureException: require_approval=True needs Airflow 3.1+.
agent.run_sync() called, then the task fails never reached

Airflow 3.0.6 Dag Import Errors dialog showing AirflowOptionalProviderFeatureException: require_approval=True needs Airflow 3.1+

The four @task.llm* decorator tests that build an operator with require_approval=True now carry a 3.1 skip, matching the existing gate on the equivalent AgentOperator test. Without it they error on the 3.0.6 row of the providers-compatibility job rather than passing.

One caveat, noted in llm.rst: a dynamically mapped task (.expand()) is only constructed when it runs, so there the same error surfaces as a task failure rather than an import error, still before the model is called.

Related to #72157, which adds this kind of guard for approval_assigned_users. This covers the parent parameter that knob depends on.

@guan404ming guan404ming left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Small nit: the six-line comment above the guard restates the PR body, and the two ordering tests already pin the placement. I think "Checked before the combination rule so an old core reports the core version rather than a wrong knob." would be good.

Human-in-the-loop review needs Airflow 3.1+, but require_approval=True had no
version guard. On a 3.0.x core, which apache-airflow>=3.0.0 supports, the Dag
imported fine and the task ran the model call before defer_for_approval failed
on an import that cannot succeed there. Every retry paid for the call again.

Reject the parameter in __init__ instead, matching how AgentOperator already
gates enable_hitl_review.
@kaxil
kaxil force-pushed the llm-require-approval-3-1-guard branch from ba844f1 to 012e4f3 Compare September 17, 2026 11:48
@kaxil
kaxil merged commit d318d54 into apache:main Sep 17, 2026
83 checks passed
@kaxil
kaxil deleted the llm-require-approval-3-1-guard branch September 17, 2026 13:04
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.

3 participants