airflow icon indicating copy to clipboard operation
airflow copied to clipboard

With multi-team on, two teams' identical asset watchers end up on one team's trigger

Open seanghaeli opened this issue 2 weeks ago • 4 comments

With [core] multi_team on, an asset watcher's trigger gets the team of the Dag that declares it, and only that team's triggerer runs it (#67605). The lookup that reuses an existing trigger ignores the team, so when two teams' Dags declare the same watcher on the same asset, both use the first team's trigger. The second team's asset gets events only while the first team's triggerer runs it: once that team stops scheduling on the asset and stops its triggerer, the trigger shows as orphaned and the other team's asset gets no more events, even though its own triggerer is up.

The same gap shows up in a few other ways:

  • Identical watchers on different assets of two teams share a trigger when no Fernet key is set. With one set, the lookup never matches across Dag files, because it compares encrypted kwargs.
  • When one team declares the watcher and another only schedules on the asset, each of the second team's parses removes the watcher and the first team's adds it back, so the asset gets a new trigger every parse and never fires.
  • A watcher created before multi-team was turned on keeps no team, so no team's triggerer runs it.

Suggestion: with multi-team on, have a Dag file's parse only reuse, add and remove its own team's watchers, and let another team's identical watcher stand in only while that team still schedules on the asset.

seanghaeli avatar Nov 12 '26 21:11 seanghaeli

@ramitkataria this is the issue you raised regarding triggers belonging to multiple teams. Tracking it here as a follow-up for later

seanghaeli avatar Nov 12 '26 21:11 seanghaeli

Hi, I'd like to work on this. My read of the fix direction from the report: with multi-team on, make the trigger-reuse lookup team-aware, and scope each parse's add/remove of watchers to its own team (with the cross-team stand-in only while that team still schedules on the asset). I'll start with a failing test reproducing the two-team shared-watcher case and post my plan here before the PR. (Previously contributed the SparkSubmitHook masking fix, #71711.)

divyanshus2404 avatar Nov 13 '26 14:11 divyanshus2404

As promised, findings before/with the PR — all four failure modes trace to add_asset_trigger_references in dag_processing/collection.py:

  1. The reuse lookup matches on (classpath, encrypted_kwargs) with no team filter, so the second team's parse adopts the first team's trigger row.
  2. With a Fernet key set, encrypt_kwargs is non-deterministic, so that SQL equality never matches at all — which is why sharing only shows up without a Fernet key.
  3. The add/remove diff compares against all of AssetModel.triggers (every team's), so a team that only schedules on the asset computes the owning team's watcher into the remove set each parse, and the owning team re-adds it on its next parse.
  4. A pre-multi-team trigger has team_name NULL, which no team's lookup matches.

Opened #77026: scopes reuse/diff/removal to the parsing team (gated on multi_team), and switches the reuse match to classpath + trigger-hash comparison in Python so it's Fernet-safe. Includes a regression test for the two-team shared-watcher case that fails on main.

divyanshus2404 avatar Nov 13 '26 15:11 divyanshus2404

Go for it

seanghaeli avatar Nov 20 '26 09:11 seanghaeli