hussein-awala opened a new issue, #77669:
URL: https://github.com/apache/airflow/issues/77669
### Under which category would you file this issue?
Airflow Core
### Apache Airflow version
main (678e3e08d2); the code path is the same in 3.3.x
### What happened and how to reproduce it?
A `RollupMapper` whose window uses `direction=Window.Direction.BACKWARD`
never creates a Dag run, even after every upstream key the window expects has
arrived.
```python
PartitionedAssetTimetable(
assets=hourly_asset,
default_partition_mapper=RollupMapper(
upstream_mapper=StartOfDayMapper(),
window=DayWindow(direction=Window.Direction.BACKWARD),
),
)
```
For downstream key `2024-03-13`, `RollupMapper.to_upstream` expects the
hourly keys `2024-03-12T01:00:00` through `2024-03-13T00:00:00`. Produce
exactly those 24 events: only `2024-03-13T00:00:00` is linked to the
`2024-03-13` pending run. The other 23 go to the `2024-03-12` pending run, and
neither run is ever satisfied.
Cause: `AssetManager._queue_partitioned_dags` routes each event with
`mapper.to_downstream`. `RollupMapper.to_downstream` delegates to the upstream
mapper, which routes a key to the period that contains it. A BACKWARD window
holds `(previous period start, period start]`, so routing and expected set
disagree. The scheduler (`_resolve_asset_partition_status`) only counts
`PartitionedAssetKeyLog` rows linked to each pending run. This breaks the
invariant documented on `Window`: `upstream_key in window.to_upstream(D) ⇔ D in
mapper.to_downstream(upstream_key)`.
The same happens for `HourWindow`, `DayWindow`, `WeekWindow`, `MonthWindow`,
`QuarterWindow` and `YearWindow`, each paired with its `StartOf*Mapper`.
FORWARD rollups and BACKWARD fan-outs behave as documented.
### What you think should happen instead?
Either rollups honor `direction`, or a BACKWARD rollup is rejected instead
of silently never firing. `direction` was added for `FanOutMapper` (#65761,
#67475). The rollup claim came later, in the docs (#68889), with no test. A
docs PR that references this issue points rollup users to FORWARD until this is
decided.
Choosing the fix needs a decision:
1. **Route rollup events by the window's own member set.** Add a core-only
`Window` hook that returns the next period start. In
`RollupMapper.to_downstream`, a BACKWARD key that is not in its own period's
expected set goes to the next period. This keeps the window maths and fan-out
unchanged. A BACKWARD daily rollup for `2024-03-13` would then wait for
`2024-03-12T01:00:00` … `2024-03-13T00:00:00`, which may not be what users
expect.
2. **Give BACKWARD rollups "previous period" semantics.** The `2024-03-13`
rollup would wait for `2024-03-12T00:00:00` … `2024-03-12T23:00:00`, as the old
docs described. This needs window maths specific to rollups, or a change to the
shared BACKWARD maths. The latter changes fan-out behavior shipped in 3.3.0.
3. **Reject BACKWARD windows in `RollupMapper` at Dag-parse time.** This
turns the silent hang into an error, but Dags that parse today would stop
parsing.
### Operating System
N/A (scheduler logic, reproduced in unit tests)
### Deployment
Other
### Anything else?
It happens every time. With `MinimumCount(1)`, the run fires as soon as the
anchor key arrives, counting events mostly outside the window (worked out from
the code, not run).
A DB-backed scheduler test that reproduces this for all six windows is ready
on a local branch. It becomes the regression test for whichever option is
chosen.
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @hussein-awala before posting
--
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]