Skip to content

Add a POST /xcoms/{dag_id}/{run_id}/{task_id}/keys execution API endpoint#70223

Open
dabla wants to merge 7 commits into
apache:mainfrom
dabla:feature/add-xcoms-keys-route
Open

Add a POST /xcoms/{dag_id}/{run_id}/{task_id}/keys execution API endpoint#70223
dabla wants to merge 7 commits into
apache:mainfrom
dabla:feature/add-xcoms-keys-route

Conversation

@dabla

@dabla dabla commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Add a POST /xcoms/{dag_id}/{run_id}/{task_id}/keys execution API endpoint that
accepts a list of XCom keys and returns all matching values in a single database
query. Use it in XComIterable to reduce iteration from N round-trips to one.

Motivation

XComIterable (introduced in AIP-104 Task Iteration) stores per-index results
under distinct keys (return_value_0, return_value_1, …) with the same
map_index. The existing GET …/slice endpoint cannot be reused because it
ranges over map_index for a single key — the inverse structure. Iterating or
slicing a 1000-item result previously issued 1000 separate XCom.get_one calls.

Changes

  • New endpoint POST /xcoms/{dag_id}/{run_id}/{task_id}/keys — accepts
    {"keys": [...]}, returns values in request-key order (null for missing
    keys), filtered by map_index query param (default -1)
  • has_xcom_access simplified: reads the optional key from
    request.path_params instead of requiring a {key} path segment, so a
    separate router/dependency is no longer needed
  • XComKeysRequest Pydantic model added to execution API data models
  • GetXComByKeys comms message, XComOperations.get_by_keys client method,
    handle_get_xcom_by_keys supervisor handler, and processor dispatch wiring
  • XComIterable.__iter__ and __getitem__ slice now use GetXComByKeys
    — one round-trip for full iteration, deserialization kept lazy via generator
    expression in __iter__
  • Tests for the new endpoint (TestGetXComByKeys) and for XComIterable
    (TestXComIterable)

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

Claude Sonnet 4.6 (GitHub Copilot CLI)


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

dabla and others added 2 commits July 22, 2026 10:56
… XCom fetch

Fetching XCom results from XComIterable (which stores per-index values as
distinct keys return_value_0, return_value_1, ... under the same map_index)
required one API round-trip per element.  The existing GetXComSequenceSlice
endpoint cannot be reused because it ranges over map_index for a single key --
the inverse structure.

Add a dedicated POST route that accepts a list of keys and returns all values
in one database query, preserving key order in the response.  The full
wiring -- comms message, client method, supervisor request handler, and route
registration -- is included so the endpoint is usable end-to-end once
XComIterable is updated to call it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@amoghrajesh amoghrajesh 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.

I haven't followed up closely with AIP 104, but I have some qns from an initial look.

Comment thread task-sdk/src/airflow/sdk/execution_time/schema/schema.json
Comment thread task-sdk/src/airflow/sdk/execution_time/lazy_sequence.py
Comment thread airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
Comment thread airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py
@dabla dabla added this to the Airflow 3.4.0 milestone Jul 22, 2026
@dabla
dabla force-pushed the feature/add-xcoms-keys-route branch from 5258e09 to dbf25d5 Compare July 22, 2026 14:10
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