Skip to content

Reload Dag bundle configuration without restarting processors - #74915

Open
samraj2k wants to merge 37 commits into
apache:mainfrom
samraj2k:sameer.raj/reload-dag-bundle-config
Open

samraj2k wants to merge 37 commits into
apache:mainfrom
samraj2k:sameer.raj/reload-dag-bundle-config

Conversation

@samraj2k

@samraj2k samraj2k commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Devlist discuss thread: https://lists.apache.org/thread.html/860cv5t71v5mnq59b50fk5891lv5nh26
Lazy consensus thread: https://lists.apache.org/thread.html/jm76cmcr6gofw8xq4rlp8k5q10sqz2h6

Dag processors currently read the bundle list only at startup. A deployment must restart them to add or remove a bundle. In a large deployment, these restarts are difficult when bundles are added frequently.

This PR adds the capability of hot reload using the existing dag_bundle_config_list. The Dag processor checks for changes at the existing bundle_refresh_check_interval. The configuration source returns the complete list of bundles.

A deployment can supply the list through Airflow's existing _CMD or _SECRET configuration mechanism. For example, a command can read a file or call an internal API:

export AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST_CMD='cat /opt/airflow/bundles.json'

Existing literal environment variables and airflow.cfg values keep their startup behavior. Users do not need to rename their environment variables unless they want to enable reload. The ordinary environment variable takes precedence over _CMD and _SECRET.

Behavior

For example, a deployment can publish these lists without restarting the Dag processor:

[finance]        -> Start processing finance
[finance, risk]  -> Start processing risk; continue finance
[risk]           -> Stop processing finance and mark its Dags stale
[]               -> Remove all bundles
  • A missing bundle is marked inactive by an unfiltered processor. The existing stale-Dag scan marks its Dags stale.
  • A successful read containing [] removes all bundles. Blank output is treated as a failed read, so a command must report a failure rather than return [].
  • Failed commands, unavailable secrets, malformed configuration, and an invalid new classpath keep the last accepted list in that process. An update is accepted as a complete list.
  • A fresh process has no previous list to use. Invalid or unavailable configuration prevents startup. A valid [] starts with no bundles.
  • Use a new bundle name when changing its definition, such as its classpath or repository. Existing bundle instances are reused, and failed construction of a new bundle is retried.
  • Processors using --bundle-name stop parsing removed bundles locally, but never deactivate missing bundles globally. An unfiltered processor is needed for global deactivation.

Note: For v1, hot reload is supported only for database backed Dag processors. HTTP-backed Dag processors (recently added feature) can continue using a literal dag_bundle_config_list. If _CMD or _SECRET is configured with an HTTP-backed processor, it will fail at startup with a clear error. HTTP-mode reload is outside the scope of this PR

Multiple Dag processors

The approach allows eventual convergence. Processors may see a change at different times. For example:

  1. Processor A still sees [finance].
  2. Processor B sees [] and marks finance inactive.
  3. Processor A marks finance active again, then stops permanently.

Each unfiltered processor reconciles bundle active state with the database on every check, even when its local list has not changed. Processor B can therefore repair that stale write. The state converges when surviving processors see the same list and continue processing; the change is not immediate across all hosts.

Finish existing Dag runs before removing a bundle if those runs need to complete. Tasks and callbacks can still need its definition.

This PR is based on main and can be reviewed independently of #73209 and #73217. It adds no public source class, new configuration option, database migration.

This PR adds an optional bundle_config field to DagFileParseRequest and the internal StartLangSDKRuntime message. This is required to carry the accepted importer settings and team ownership, so parsingprocess do not read the bundle configuration source again.

The configuration key is marked sensitive to support _CMD and _SECRET, so configuration views that hide sensitive values will also hide this value.

Test Plan

Along with the OSS unit tests, also performed integration testing in local

Case: Bundle discovery and removal

Screenshot 2026-10-21 at 11 30 32 PM Screenshot 2026-10-21 at 11 31 45 PM

Case: source failure keeps the accepted list

Screenshot 2026-10-21 at 11 32 53 PM

API server:
Screenshot 2026-10-21 at 11 33 40 PM

Case: Construction and database synchronization retry

Screenshot 2026-10-21 at 11 34 24 PM
Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-6)

Generated-by: Codex (GPT-6) following the guidelines


@shahar1 shahar1 added this to the Airflow 3.5.0 milestone Oct 17, 2026
@samraj2k
samraj2k force-pushed the sameer.raj/reload-dag-bundle-config branch 6 times, most recently from 4b1de2c to 8881392 Compare October 18, 2026 16:16
@samraj2k
samraj2k requested a review from uranusjr as a code owner October 18, 2026 16:16
@samraj2k
samraj2k force-pushed the sameer.raj/reload-dag-bundle-config branch 7 times, most recently from 52db297 to 8b6bae0 Compare October 21, 2026 17:13
@samraj2k samraj2k changed the title Reload Dag bundle configuration without restarting processors reload dag bundle configuration without restarting processors Oct 21, 2026

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

Thanks for working through the earlier points. All four are addressed at 821aa2b: the forced read for unknown names is throttled, teams are checked before any rows are written, the body is corrected, and template signing is retried. The reload design and the tests read well. One new minor point is inline, about the per-check import-error cleanup.

Smaller observations

  • See the inline comment on airflow-core/src/airflow/dag_processing/bundles/manager.py:615.
  • Process: the backport-to-v3-4-test label is still on the PR. As potiuk noted, this is a new feature that changes the unreleased 2027-02-28 supervisor schema version, and the Task SDK on main now requires apache-airflow-core>=3.5.0. It should ship in 3.5 only. I'll remove the label.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

@shahar1 shahar1 removed the backport-to-v3-4-test Backport to v3-4-test label Nov 8, 2026
With configuration reload enabled, every check deleted import errors again
for each bundle ever removed, so the cleanup grew with every removal and
repeated every few seconds. Errors published after a bundle is deactivated
by a processor that has not seen the removal are left until an unfiltered
Dag processor restarts.
@uranusjr

uranusjr commented Nov 8, 2026

Copy link
Copy Markdown
Member

My concern is how "reload mode" is put into the code. The code makes it a condition that call sites check, not a thing that is modelled. I would prefer it be done by modelling the source as an object and giving consumers a resolved context. Add a private interface with two implementations (static vs reloadable) as mentioned in the inline comment. The source is chosen once per process and owns the accepted snapshot, the throttle and the miss cache.

DagBundlesManager asks the source and never builds another manager. Consumers get one typed per-bundle object, e.g. BundleParseContext(importer_registry, team_name). The same model goes over the wire as bundle_config, so the Go and TS schemas get a real type instead of additionalProperties: true. The mode checks become polymorphic dispatch, and the "nothing passed" fallbacks go away.

samraj2k and others added 2 commits November 9, 2026 19:20
Reload mode was a condition that call sites checked, and the cached
configuration was mutated in place, so a second cache entry could drift
with its own throttle and run the command again. A source chosen once per
process now owns the accepted list, the throttle and the cache of missing
names, and parsing processes receive a typed per-bundle context that the
Go and TypeScript schemas can describe. The Dag processor also parses at
startup only the bundles it has written to the database.

Co-authored-by: Cursor <[email protected]>
…ag-bundle-config

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	airflow-core/src/airflow/dag_processing/bundles/manager.py
#	airflow-core/tests/unit/dag_processing/bundles/test_dag_bundle_manager.py
samraj2k and others added 2 commits November 9, 2026 20:31
Celery workers run the stale bundle version cleanup for their whole life, but a new DagBundlesManager only copies the bundle list the process already holds and never reads the command or secret again. Bundles added after the worker started were never cleaned up.

Co-authored-by: Cursor <[email protected]>
When no importer registry was cached, for example for a removed bundle, the callback and parse checks fell back to the Task SDK registry, which reads dag_bundle_config_list directly. Now that the key honours _cmd and _secret, a failing command ran on every callback regardless of bundle_refresh_check_interval, and a successful one could build importers from a list the Dag processor had not accepted.

Co-authored-by: Cursor <[email protected]>
Comment on lines +287 to +289
def is_bundle_config_reload_enabled() -> bool:
"""Return whether this process reads the bundle configuration again from a command or secrets backend."""
return isinstance(_get_bundle_config_source(), _ReloadingBundleConfigSource)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don’t think we need to send a context in static mode (and change the parsing path). We can add parse_context(name) -> BundleParseContext | None to the source. The static source returns None, so the static path stays exactly as it is today. The reloading source returns the accepted context. The same goes for the HTTP-mode guard and _reconcile_bundles (source.reconcilable). The call sites then ask the source what to do, instead of what it is, and is_bundle_config_reload_enabled can go. I'd rather this land in this PR than in a follow-up since the follow-up would touch the same call sites again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks, I have done as mentioned.

Comment on lines +141 to +156
def _get_bundle_config_reload_option() -> tuple[str, str] | None:
section, key = "dag_processor", "dag_bundle_config_list"
env_key = "AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST"
if env_key in os.environ:
return None
for suffix in ("cmd", "secret"):
env_option = f"{env_key}_{suffix.upper()}"
if env_option in os.environ:
return suffix, os.environ[env_option]
if ConfigParser.has_option(conf, section, key):
return None
for suffix in ("cmd", "secret"):
option = f"{key}_{suffix}"
if ConfigParser.has_option(conf, section, option):
return suffix, ConfigParser.get(conf, section, option)
return None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is still a copy from AirflowConfigParser. Expose a supported helper in the shared configuration module that returns the _cmd/_secret source for an option, and build the reloading source from that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the copy. Now, get_dynamic_option_reader() and _get_bundle_config_source() builds the reloading source

Comment on lines +2356 to +2357
if is_bundle_config_reload_enabled():
bundle_config = self._dag_bundle_manager.get_bundle_parse_context(dag_file.bundle_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

get_bundle_parse_context() still raises ValueError for a name that isn't configured. If a callback file for a bundle removed in that check is still queued, the main loop crashes here. Purge _callback_to_execute for removed bundles, or handle the error, and add a test either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this was an good fine, I missed it.
Also added specific tests so not miss in future


bundles = list(DagBundlesManager().get_all_dag_bundles())
manager = DagBundlesManager()
manager.get_all_bundle_names()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is too unobvious. Give the manager an explicit refresh() instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, i was reluctant on previously adding explicit refresh as public, but as per your shared model, I have refactored into interface and classes, and replaced this

…-bundle-config

# Conflicts:
#	task-sdk/src/airflow/sdk/coordinators/_subprocess.py
#	task-sdk/src/airflow/sdk/execution_time/schema/versions/v2027_02_28.py
Duplicating AirflowConfigParser lookup precedence in the Dag bundle manager risked drifting from shared configuration semantics, while boolean reload checks forced call sites to inspect the source type instead of delegating behavior. Implicitly refreshing inside get_all_bundle_names() also hid side effects from callers, and queued callbacks for bundles removed during reconciliation could still raise ValueError in the parsing loop.
Avoid adding new public classes or methods to AirflowConfigParser and DagBundlesManager where an internal shared configuration helper and the private bundle config source already cover every production caller.
A bad reload must leave running processors on the last adopted configuration without exposing sensitive input or making parsers and health probes depend on another read. Keep maintenance work bounded so bundle removal does not hold the processor loop.
class _StaticBundleConfigSource:
"""The bundle configuration of this process, read from ``dag_bundle_config_list`` on first use."""

reconcilable: ClassVar[bool] = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This now decides a lot of things. I’m thinking we can do it somehow like this

class _BaseLifecycle:
    def __init__(self, processor: DagFileProcessorManager) -> None: ...
    def check_supported(self) -> None: ...
    def reconcile(self, known_files: dict[str, set[DagFileInfo]]) -> None: ...
    def cleanup(self) -> None: ...

class _BaseBundleConfigSource:
    lifecycle_class: ClassVar[type[_BaseBundleLifecycle]]
    def parse_context(self, name: str) -> BundleParseContext | None: ...
    def get_bundle_teams(self) -> dict[str, str | None]: ...

class _StaticBundleConfigSource(_BaseBundleConfigSource):
    class lifecycle_class(_BaseLifecycle): ...
    # Implementat methods...

class _ReloadingBundleConfigSource(_BaseBundleConfigSource):
    class lifecycle_class(_BaseLifecycle): ...
    # Implementat methods...

this would gather logic all onto the bundle config source classes instead of scattered around with a flag check. It’s also clearer that the static and reloading sources are two separate things, reloading does not subclass (“is kind of”) static.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, this is inline with interface and then multiple impl in future. I have followed the model in the PR. _BaseBundleConfigSource is the base with two impl, one static and one dynamic.
One diff is that, in the impl, the lifecycle classes are module level classes that lifecycle class refers to, rather than nested classes.

…-bundle-config

# Conflicts:
#	airflow-core/src/airflow/api/common/airflow_health.py
#	airflow-core/src/airflow/dag_processing/manager.py
#	go-sdk/pkg/execution/genmodels/models.gen.go
#	scripts/ci/prek/check_security_doc_constants.py
Review feedback asked for reload mode to be modelled rather than checked
at each call site. The configuration source is chosen once per process,
so the Dag processor, health checks and parsing can ask it what to do
instead of testing whether reload is enabled.
The bundle lifecycle only needs to decide whether a processor reconciles
bundles and sweeps import errors. Leaving the reconciliation and the
import-error sweep on the Dag processor keeps each algorithm in one
place, next to the queues it updates, and keeps processor maintenance
out of the bundle configuration module.
A bundle whose constructor fails is not parsed, but the periodic sync
still stored it as active. Health checks and other readers of the
active bundle rows then counted a bundle that no Dag processor was
processing, unlike startup, which never records such a bundle.
Restricting new bundle rows to constructed bundles could not cover a
re-added bundle, because stored rows must stay reactivatable for Dag
processors to repair each other's active state. It also stopped
filtered processors from storing hot-added bundles as they do at
startup. Health in reload mode reads active rows as the declared
bundles, so a configured bundle stays active while it is retried.
Health in reload mode now counts only the bundles the deployment declares, as with a
static list. A failed command reports its exit status so operators can find the cause,
while its command, output and errors stay hidden.
@samraj2k

Copy link
Copy Markdown
Contributor Author

My concern is how "reload mode" is put into the code. The code makes it a condition that call sites check, not a thing that is modelled. I would prefer it be done by modelling the source as an object and giving consumers a resolved context. Add a private interface with two implementations (static vs reloadable) as mentioned in the inline comment. The source is chosen once per process and owns the accepted snapshot, the throttle and the miss cache.

DagBundlesManager asks the source and never builds another manager. Consumers get one typed per-bundle object, e.g. BundleParseContext(importer_registry, team_name). The same model goes over the wire as bundle_config, so the Go and TS schemas get a real type instead of additionalProperties: true. The mode checks become polymorphic dispatch, and the "nothing passed" fallbacks go away.

Thanks for detailed review. I have addressed this comment, and now bundle type lifecycle is managed properly through base class, and assosiated impls

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants