Skip to content

Conversation

@guan404ming
Copy link
Member

Why

  • task group page is lack of support of hitl currently

How

  • add the tab like other pages
image

tested with this example

from __future__ import annotations

# [START hitl_tutorial]
import datetime

import pendulum

from airflow.providers.standard.operators.hitl import (
    ApprovalOperator,
    HITLBranchOperator,
    HITLEntryOperator,
    HITLOperator,
)
from airflow.sdk import DAG, Param, task
from airflow.sdk.definitions.taskgroup import TaskGroup

with DAG(
    dag_id="aip_90_dag",
    start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
    catchup=False,
    tags=["example", "HITL"],
) as dag:
    # [START howto_task_group_input_collection]
    with TaskGroup("input_collection", tooltip="Collect user inputs and options") as input_collection:
        # [START howto_hitl_entry_operator]
        wait_for_input = HITLEntryOperator(
            task_id="wait_for_input",
            subject="Please provide required information: ",
            params={"information": Param("", type="string")},
        )
        # [END howto_hitl_entry_operator]

        # [START howto_hitl_operator]
        wait_for_option = HITLOperator(
            task_id="wait_for_option",
            subject="Please choose one option to proceed: ",
            options=["option 1", "option 2", "option 3"],
        )
        # [END howto_hitl_operator]
    # [END howto_task_group_input_collection]

    # [START howto_task_group_validation]
    with TaskGroup("validation", tooltip="Validate collected inputs and options") as validation:
        # [START howto_hitl_approval_operator]
        valid_input_and_options = ApprovalOperator(
            task_id="valid_input_and_options",
            subject="Are the following input and options valid?",
            body="""
* Input: {{ task_instance.xcom_pull(task_ids='input_collection.wait_for_input', key='return_value')["params_input"]["information"] }}
* Option: {{ task_instance.xcom_pull(task_ids='input_collection.wait_for_option', key='return_value')["chosen_options"] }}
            """,
            defaults="Reject",
            execution_timeout=datetime.timedelta(minutes=1),
        )
        # [END howto_hitl_approval_operator]

        # [START howto_hitl_branch_operator]
        choose_a_branch_to_run = HITLBranchOperator(
            task_id="choose_a_branch_to_run",
            subject="You're now allowed to proceeded. Please choose one task to run: ",
            options=["task_1", "task_2", "task_3"],
        )
        # [END howto_hitl_branch_operator]

        valid_input_and_options >> choose_a_branch_to_run
    # [END howto_task_group_validation]

    # [START howto_task_group_execution]
    with TaskGroup("execution", tooltip="Execute selected tasks") as execution:
        # [START howto_hitl_workflow]
        @task
        def task_1(): ...

        @task
        def task_2(): ...

        @task
        def task_3(): ...

        [task_1(), task_2(), task_3()]
        # [END howto_hitl_workflow]
    # [END howto_task_group_execution]

    # Define task group dependencies
    input_collection >> validation >> execution

# [END hitl_tutorial]

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Aug 10, 2025
@guan404ming guan404ming changed the title Add Required Actions tab in group task page Add Required Actions tab in group task page Aug 10, 2025
Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

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

Looks good in my view!

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Really nice.

Unfortunately we will need some backend change I think before we can implement this feature. More details in my comment bellow.

Comment on lines +54 to +57
const tabs = [
{ icon: <MdOutlineTask />, label: translate("tabs.taskInstances"), value: "" },
{ icon: <FiUser />, label: translate("tabs.requiredActions"), value: "required_actions" },
];
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to create the full list to then filter it again.

Example:

    ...(Boolean(taskId)
    ? []
    : [
        {
          accessorKey: "task_id",
          enableSorting: true,
          header: translate("common:taskId"),
          meta: {
            skeletonWidth: 10,
          },
        },
      ]),

Copy link
Member Author

@guan404ming guan404ming Aug 13, 2025

Choose a reason for hiding this comment

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

Yes, it does make the code more clear and more efficient. I would update it.

{
dagId,
dagRunId: runId,
taskIdPattern: groupId,
Copy link
Member

Choose a reason for hiding this comment

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

Using taskIdPattern to retrieve 'group related' HILT will not work in every case. While this is true that task from a same group tend to share the same prefix, it also mean that any task outside the group that also maches the pattern will get returned wrongly in here and displayed in the group actions.

For instance, based on your example, I added a TI, outside all groups, and since the name matches the 'validation' prefix, this will end up like this in the UI

    validation_single_task = HITLBranchOperator(
        task_id="validation_single_task",
        subject="This is the validation for the single task",
        options=["1", "2", "3"],
    )
Screenshot 2025-08-12 at 17 16 02

We need to add a backend filter on group_id I think. To be sure to only retrieve 'group' related TIs.

Copy link
Member Author

@guan404ming guan404ming Aug 13, 2025

Choose a reason for hiding this comment

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

Thanks for clear example that makes sense to me. Let me mark this as draft to wait the backend update.

@guan404ming
Copy link
Member Author

Close since it seems no needed currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants