Defer Cadwyn import to keep FastAPI off the Task SDK worker path#69016
Merged
jason810496 merged 1 commit intoJun 26, 2026
Merged
Conversation
The Task SDK supervisor imports the execution-time schema package on every worker, and that package imported cadwyn at module load. cadwyn pulls in FastAPI, Starlette and Jinja2, which are only needed on the foreign-language-SDK schema-migration path and never for a pure-Python worker. Because the supervisor is imported lazily after the Celery prefork, each pool worker paid this import in private (non copy-on-write) pages, raising worker memory on Python 3.14. Defer the cadwyn import behind a cached bundle accessor and into _versioned_class so importing the schema package no longer loads FastAPI. The foreign-SDK path is unchanged; a regression test asserts the worker import graph stays cadwyn-free.
1 task
shahar1
approved these changes
Jun 26, 2026
amoghrajesh
approved these changes
Jun 26, 2026
jason810496
added a commit
that referenced
this pull request
Jun 26, 2026
…er path (#69016) (#69029) The Task SDK supervisor imports the execution-time schema package on every worker, and that package imported cadwyn at module load. cadwyn pulls in FastAPI, Starlette and Jinja2, which are only needed on the foreign-language-SDK schema-migration path and never for a pure-Python worker. Because the supervisor is imported lazily after the Celery prefork, each pool worker paid this import in private (non copy-on-write) pages, raising worker memory on Python 3.14. Defer the cadwyn import behind a cached bundle accessor and into _versioned_class so importing the schema package no longer loads FastAPI. The foreign-SDK path is unchanged; a regression test asserts the worker import graph stays cadwyn-free. (cherry picked from commit 85aa9b6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Airflow 3.2.2 in Python 3.13.concurrency=10(linear scale).Why
The execution-time
schemapackage importedcadwyn(pulling in FastAPI/Starlette/Jinja2) at module load, butcadwynis only needed on the Multi-Lang task execution path. Imported lazily after the Celery prefork, every pool worker paid this in private pages, raising worker memory on Python 3.14.What
VersionBundlelazily behind afunctools.cachedget_bundle(), with thecadwynimport inside it.generate_versioned_modelsintoSchemaVersionMigrator._versioned_class, the only path that needs it.from ...schema import bundleworking via module-level__getattr__, socadwynloads only whenbundleis accessed.cadwyn/fastapi-free, and that accessingbundleloadscadwyn.Was generative AI tooling used to co-author this PR?