Skip to content

Allow loop gates to add human-readable decisions - #74806

Merged
kaxil merged 4 commits into
apache:mainfrom
astronomer:task-loops-decision-reason
Oct 16, 2026
Merged

kaxil merged 4 commits into
apache:mainfrom
astronomer:task-loops-decision-reason

Conversation

@ashb

@ashb ashb commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

As it landed on main, a loop's gate only recorded a go/no-go decision for
the next iteration, meaning the UI could show that a loop stopped after N
iterations, but a user would have to go to the logs to find out why,
exactly, the loop ended when it did.

This adds a LoopDecision object that lets an until callable include
human-readable text to show alongside its decision.

As well as introducing this new type, it also changes how the decision
makes it to the server. Prior to this change, the decision was shipped to
the API server via a specially named XCom value, in a normal SetXCom
request, which was then read when the gate's TISuccessState request
arrived. That "worked", but was inherently fragile: a separate write
with its own locking, validation and cleanup on every non-success path.

The decision now travels on the gate's terminal state update. The server
acts on it in the transaction that marks the gate finished, so the
stop/continue signal never needs storing. A gate that fails because until
stayed false at max_iterations sends its reason with the failure, which is
when an explanation helps most.

Only the reason is persisted, as an XCom on the gate's attempt that the
server writes in that same transaction. Keying it to the attempt means
each try keeps its own reason, and a cleared or retried gate starts with
none, so no clear path has to remember to delete a stale one. Task state
was considered instead, but it is keyed by the iteration rather than the
attempt, so a reason outlived the clears and tries it described, and
clear_on_success and retention could remove it. The server writes the
XCom directly to the metadata DB (not to a configured backend, so the UI
can always show it), and the reserved _airflow_loop_ prefix stops users
and tasks forging it. The XCom list endpoint leaves those keys out when
asked, which the UI does.

Some (cropped) screenshots of how this currently shows it.

compare-1-loop-page compare-2-gate-task-iteration-2 compare-3-body-task-iteration-2

Long decision handling:

compare-1-loop-page
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.

@ashb ashb added this to the Airflow 3.4.0 milestone Oct 15, 2026
@ashb ashb added the backport-to-v3-4-test Backport to v3-4-test label Oct 15, 2026
@boring-cyborg boring-cyborg Bot added area:API Airflow's REST/HTTP API area:go-sdk area:task-sdk area:ts-sdk area:UI Related to UI/UX. For Frontend Developers. kind:documentation labels Oct 15, 2026
@ashb
ashb force-pushed the task-loops-decision-reason branch from 9085e7f to 318af82 Compare October 15, 2026 16:21
@bbovenzi

Copy link
Copy Markdown
Contributor

UX makes sense to me. We may surface this in more places later. Let'e see

@bbovenzi bbovenzi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

UI lgtm

ashb added 3 commits October 15, 2026 20:35
As it landed on main, a loop's gate only recorded a go/no-go decision for
the next iteration, meaning the UI could show that a loop stopped after N
iterations, but a user would have to go to the logs to find out why,
exactly, the loop ended when it did.

This adds a `LoopDecision` object that lets an `until` callable include
human-readable text to show alongside its decision.

As well as introducing this new type, it also changes how the decision
makes it to the server. Prior to this change, the decision was shipped to
the API server via a specially named XCom value, in a normal SetXCom
request, which was then read when the gate's TISuccessState request
arrived. That "worked", but was inherently fragile: a separate write
with its own locking, validation and cleanup on every non-success path.

The decision now travels on the gate's terminal state update. The server
acts on it in the transaction that marks the gate finished, so the
stop/continue signal never needs storing. A gate that fails because until
stayed false at max_iterations sends its reason with the failure, which is
when an explanation helps most.

Only the reason is persisted, as an XCom on the gate's attempt that the
server writes in that same transaction. Keying it to the attempt means
each try keeps its own reason, and a cleared or retried gate starts with
none, so no clear path has to remember to delete a stale one. Task state
was considered instead, but it is keyed by the iteration rather than the
attempt, so a reason outlived the clears and tries it described, and
clear_on_success and retention could remove it. The server writes the
XCom directly to the metadata DB (not to a configured backend, so the UI
can always show it), and the reserved `_airflow_loop_` prefix stops users
and tasks forging it. The XCom list endpoint leaves those keys out when
asked, which the UI does.
A finished loop's page shows the reason its final iteration gave, and every
task instance in an iteration shows that iteration's reason. The iteration
pickers are left alone because their rows are one-line labels.
A reason can run to 512 bytes over several lines, which pushed the header
stats around, so the headers cut it to one line and the tooltip shows it
in full.
@ashb
ashb force-pushed the task-loops-decision-reason branch from eef3f94 to 5f3379b Compare October 15, 2026 20:02
Comment thread airflow-core/pyproject.toml Resolved
@kaxil
kaxil merged commit 4c4bab0 into apache:main Oct 16, 2026
164 checks passed
@kaxil
kaxil deleted the task-loops-decision-reason branch October 16, 2026 11:25
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-4-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-4-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 4c4bab0 v3-4-test

This should apply the commit to the v3-4-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

ashb added a commit that referenced this pull request Oct 17, 2026
As it landed on main, a loop's gate only recorded a go/no-go decision for
the next iteration, meaning the UI could show that a loop stopped after N
iterations, but a user would have to go to the logs to find out why,
exactly, the loop ended when it did.

This adds a `LoopDecision` object that lets an `until` callable include
human-readable text to show alongside its decision.

As well as introducing this new type, it also changes how the decision
makes it to the server. Prior to this change, the decision was shipped to
the API server via a specially named XCom value, in a normal SetXCom
request, which was then read when the gate's TISuccessState request
arrived. That "worked", but was inherently fragile: a separate write
with its own locking, validation and cleanup on every non-success path.

The decision now travels on the gate's terminal state update. The server
acts on it in the transaction that marks the gate finished, so the
stop/continue signal never needs storing. A gate that fails because until
stayed false at max_iterations sends its reason with the failure, which is
when an explanation helps most.

Only the reason is persisted, as an XCom on the gate's attempt that the
server writes in that same transaction. Keying it to the attempt means
each try keeps its own reason, and a cleared or retried gate starts with
none, so no clear path has to remember to delete a stale one. Task state
was considered instead, but it is keyed by the iteration rather than the
attempt, so a reason outlived the clears and tries it described, and
clear_on_success and retention could remove it. The server writes the
XCom directly to the metadata DB (not to a configured backend, so the UI
can always show it), and the reserved `_airflow_loop_` prefix stops users
and tasks forging it. The XCom list endpoint leaves those keys out when
asked, which the UI does.

* Show loop decision reasons in the UI

A finished loop's page shows the reason its final iteration gave, and every
task instance in an iteration shows that iteration's reason. The iteration
pickers are left alone because their rows are one-line labels.

A reason can run to 512 bytes over several lines, which pushed the header
stats around, so the headers cut it to one line and the tooltip shows it
in full.

(cherry picked from commit 4c4bab0)
ashb added a commit that referenced this pull request Oct 18, 2026
…#74932)

As it landed on main, a loop's gate only recorded a go/no-go decision for
the next iteration, meaning the UI could show that a loop stopped after N
iterations, but a user would have to go to the logs to find out why,
exactly, the loop ended when it did.

This adds a `LoopDecision` object that lets an `until` callable include
human-readable text to show alongside its decision.

As well as introducing this new type, it also changes how the decision
makes it to the server. Prior to this change, the decision was shipped to
the API server via a specially named XCom value, in a normal SetXCom
request, which was then read when the gate's TISuccessState request
arrived. That "worked", but was inherently fragile: a separate write
with its own locking, validation and cleanup on every non-success path.

The decision now travels on the gate's terminal state update. The server
acts on it in the transaction that marks the gate finished, so the
stop/continue signal never needs storing. A gate that fails because until
stayed false at max_iterations sends its reason with the failure, which is
when an explanation helps most.

Only the reason is persisted, as an XCom on the gate's attempt that the
server writes in that same transaction. Keying it to the attempt means
each try keeps its own reason, and a cleared or retried gate starts with
none, so no clear path has to remember to delete a stale one. Task state
was considered instead, but it is keyed by the iteration rather than the
attempt, so a reason outlived the clears and tries it described, and
clear_on_success and retention could remove it. The server writes the
XCom directly to the metadata DB (not to a configured backend, so the UI
can always show it), and the reserved `_airflow_loop_` prefix stops users
and tasks forging it. The XCom list endpoint leaves those keys out when
asked, which the UI does.

* Show loop decision reasons in the UI

A finished loop's page shows the reason its final iteration gave, and every
task instance in an iteration shows that iteration's reason. The iteration
pickers are left alone because their rows are one-line labels.

A reason can run to 512 bytes over several lines, which pushed the header
stats around, so the headers cut it to one line and the tooltip shows it
in full.

(cherry picked from commit 4c4bab0)
vatsrahul1001 pushed a commit that referenced this pull request Oct 20, 2026
…#74932)

As it landed on main, a loop's gate only recorded a go/no-go decision for
the next iteration, meaning the UI could show that a loop stopped after N
iterations, but a user would have to go to the logs to find out why,
exactly, the loop ended when it did.

This adds a `LoopDecision` object that lets an `until` callable include
human-readable text to show alongside its decision.

As well as introducing this new type, it also changes how the decision
makes it to the server. Prior to this change, the decision was shipped to
the API server via a specially named XCom value, in a normal SetXCom
request, which was then read when the gate's TISuccessState request
arrived. That "worked", but was inherently fragile: a separate write
with its own locking, validation and cleanup on every non-success path.

The decision now travels on the gate's terminal state update. The server
acts on it in the transaction that marks the gate finished, so the
stop/continue signal never needs storing. A gate that fails because until
stayed false at max_iterations sends its reason with the failure, which is
when an explanation helps most.

Only the reason is persisted, as an XCom on the gate's attempt that the
server writes in that same transaction. Keying it to the attempt means
each try keeps its own reason, and a cleared or retried gate starts with
none, so no clear path has to remember to delete a stale one. Task state
was considered instead, but it is keyed by the iteration rather than the
attempt, so a reason outlived the clears and tries it described, and
clear_on_success and retention could remove it. The server writes the
XCom directly to the metadata DB (not to a configured backend, so the UI
can always show it), and the reserved `_airflow_loop_` prefix stops users
and tasks forging it. The XCom list endpoint leaves those keys out when
asked, which the UI does.

* Show loop decision reasons in the UI

A finished loop's page shows the reason its final iteration gave, and every
task instance in an iteration shows that iteration's reason. The iteration
pickers are left alone because their rows are one-line labels.

A reason can run to 512 bytes over several lines, which pushed the header
stats around, so the headers cut it to one line and the tooltip shows it
in full.

(cherry picked from commit 4c4bab0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:go-sdk area:task-sdk area:ts-sdk area:UI Related to UI/UX. For Frontend Developers. backport-to-v3-4-test Backport to v3-4-test kind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants