Skip to content

[v3-4-test] Allow loop gates to add human-readable decisions (#74806) - #74932

Merged
ashb merged 1 commit into
v3-4-testfrom
backport-74806-v3-4-test
Oct 18, 2026
Merged

ashb merged 1 commit into
v3-4-testfrom
backport-74806-v3-4-test

Conversation

@ashb

@ashb ashb commented Oct 17, 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.

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


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 commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Based on top of #74931, should be automatically repointed when that gets merged to v3-4-test

Base automatically changed from backport-74671-v3-4-test to v3-4-test October 17, 2026 20:01
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
ashb force-pushed the backport-74806-v3-4-test branch from ac5c178 to ebee2b9 Compare October 17, 2026 20:14
@ashb
ashb marked this pull request as ready for review October 17, 2026 20:17
@ashb
ashb merged commit d5d6080 into v3-4-test Oct 18, 2026
178 of 187 checks passed
@ashb
ashb deleted the backport-74806-v3-4-test branch October 18, 2026 03:45
@github-actions github-actions Bot added this to the Airflow 3.4.1 milestone Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.4.1 based on: merged to version branch
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants