PCTEJA opened a new pull request, #77533:
URL: https://github.com/apache/airflow/pull/77533
Large XCom values stall the Execution API event loop because pydantic
re-validates and re-serializes every element of a `JsonValue` on each pass
through the request and response models. A value arriving from the API is
already decoded JSON, and a value read back comes from a JSON store, so those
checks cannot fail. This PR annotates the XCom request body and response models
with `DecodedJsonValue`, a `JsonValue` that passes the value through unchanged
while publishing the same JSON schema.
closes #77502
## What changes
* `airflow-core/src/airflow/api_fastapi/common/types.py`: adds
`DecodedJsonValue`, defined exactly as in #77113 so the two PRs converge on one
definition.
* `airflow-core/src/airflow/api_fastapi/execution_api/datamodels/xcom.py`:
`XComResponse.value`, `XComSequenceIndexResponse.root` and
`XComSequenceSliceResponse.root` use `DecodedJsonValue`.
* `airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py`: the
`set_xcom` request body uses `DecodedJsonValue`.
## Scope relative to #77113
#77113 covers the state-store models (`task_state_store`,
`asset_state_store`) and explicitly leaves the XCom models out ("Not in this
PR: The XCom models ... I will open follow-ups"). This PR covers exactly that
leftover scope: the XCom models and the `set_xcom` request body. It does not
touch the state-store models, the asset models, or the public API XCom models.
## Benchmarks
Measured with the real Execution API app and SQLite, a 688,890-byte value
(100,000-element integer array), 10 requests per run, median of 3 alternating
runs each. The small-value control is unchanged, so the machine was quiet.
| Route | Base (ms) | This PR (ms) | Change |
| --- | --- | --- | --- |
| POST XCom (set) | 123.0 | 81.5 | -41.5 ms (-34%) |
| GET XCom | 142.2 | 58.2 | -84.0 ms (-59%) |
| POST small value (control) | 40.1 | 39.9 | no change |
| GET small value (control) | 19.5 | 19.5 | no change |
Model level, same 689 KB value: `XComResponse` validation 19.61 ms to 0.03
ms, JSON serialization 22.13 ms to 3.29 ms. The Cadwyn migration overhead
(about 50 ms over plain FastAPI at any version) is unchanged by this PR; the
remaining cost is JSON parsing, the database write, and response encoding.
## Tests
* New
`airflow-core/tests/unit/api_fastapi/execution_api/datamodels/test_xcom.py` (9
tests): validation returns the decoded value unchanged, serialization skips the
`JsonValue` checks, and the published schema matches plain `JsonValue`. 6 of
the 9 fail on the base commit for the expected reason; all 9 pass with the fix.
* Relevant set (new tests, `test_types.py`, head `test_xcoms.py`,
`v2025_04_28/test_xcom.py`): 210 passed, run twice with identical results.
* The served OpenAPI spec for the XCom paths and schemas is byte-identical
between base and this PR, so no `VersionChange` and no Task SDK model
regeneration are needed. The `generate-tasksdk-datamodels` prek hook passes
with no diff.
* Ruff format and check are clean; `mypy-airflow-core` passes.
## Notes
* No newsfragment: this is a performance improvement with no behavior change
for JSON values.
* Edge case, same as #77113: a custom XCom backend returning a non-JSON
object such as a datetime previously got a 500 on response validation. It is
now serialized by pydantic inferring its type, as for an `Any` field.
* Two tests in head `test_xcoms.py` (`test_xcom_access_denied`, get and set)
error at setup in this VM because `airflow_shared` is not importable here;
`test_app.py` fails to collect for the same reason, identically on the base
commit. The served-spec comparison above covers what `test_app.py` checks for
this change.
* The pre-push Codex review could not run on this VM: it failed with 401
Unauthorized ("Missing bearer basic authentication"), no Codex auth here. The
review was not silently skipped; it could not run.
* No live MySQL or Postgres run here (no Docker on this VM); SQLite only. CI
is authoritative for those.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Muse Spark
Generated-by: Muse Spark following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
---
* Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#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](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
* When adding dependency, check compliance with the [ASF 3rd Party License
Policy](https://www.apache.org/legal/resolved.html#category-x).
* For significant user-facing changes create newsfragment:
`{pr_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
You can add this file in a follow-up commit after the PR is created so you
know the PR number.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]