This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch fork-ci-time-based-status-budget in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 654602a1cc69471a120d91fea942165eb351d58a Author: Jarek Potiuk <[email protected]> AuthorDate: Sun Nov 15 23:43:52 2026 +0900 Count a monitor re-run from its previous attempt Counting from when the run was created credited each later attempt with the time earlier attempts already had. Generated-by: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01NyQq9U7i5HhjDgrQ9qd3gq --- .../doc/ci/08_fork_ci_for_external_contributors.md | 5 +- .../src/airflow_breeze/utils/fork_ci_reconcile.py | 18 ++++-- dev/breeze/tests/test_fork_ci_reconcile.py | 71 +++++++++++----------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md b/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md index 71c4a648a45..09c935aaf21 100644 --- a/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md +++ b/dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md @@ -1006,8 +1006,9 @@ not one twelfth of it. Both are read from the monitor's runs (`GET /repos/apache/airflow/actions/workflows/fork-ci-monitor.yml/runs`, runs still waiting in its concurrency group left out), so they are the same boundary of each run, setup included, and not from the record the monitor carries between runs, which a failed run or a failed Slack post leaves -unchanged although that run may have posted statuses. A re-run counts from when its run was -created, so the time its first attempt had is not credited again. GitHub +unchanged although that run may have posted statuses. A re-run counts from its previous +attempt's start (`GET /repos/apache/airflow/actions/runs/<id>/attempts/<n>`), so the time earlier +attempts had is not credited again. GitHub starts scheduled workflows later than their cron: on 2026-11-15 the 5-minute monitor ran every 9 to 10 minutes, so a fixed 13 writes a run (160 an hour at the cron's cadence) posted only about 82 an hour, and four full-matrix fork runs at once took about six hours to catch up. Runs queued diff --git a/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py b/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py index 010edf8e05d..49cc0167f99 100644 --- a/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py +++ b/dev/breeze/src/airflow_breeze/utils/fork_ci_reconcile.py @@ -2839,8 +2839,7 @@ def find_time_since_previous_monitor_run( Both starts are read from GitHub, so they are the same boundary of each run, setup included, and a failed run or a failed Slack post, which leave the record the monitor carries between runs - unchanged, still counts. A re-run of this run counts from when the run was created, the earliest - its first attempt can have posted. + unchanged, still counts. A re-run of this run counts from its previous attempt's start. """ match = re.search(r"/actions/runs/(\d+)", run_url) if match is None: @@ -2865,10 +2864,17 @@ def find_time_since_previous_monitor_run( for start in [parse_github_datetime(run.get("run_started_at"))] if start is not None and start <= started ] - if (current.get("run_attempt") or 1) > 1: - created = parse_github_datetime(current.get("created_at")) - if created is not None: - boundaries.append(created) + attempt = current.get("run_attempt") or 1 + if attempt > 1: + try: + previous_attempt = client.rest_get(f"repos/{repo}/actions/runs/{run_id}/attempts/{attempt - 1}") + except Exception as e: + console_print(f"[warning]Could not read the previous attempt of this run: {e}[/]") + return None + previous_start = parse_github_datetime(previous_attempt.get("run_started_at")) + if previous_start is None: + return None + boundaries.append(previous_start) if not boundaries: return None return started - max(boundaries) diff --git a/dev/breeze/tests/test_fork_ci_reconcile.py b/dev/breeze/tests/test_fork_ci_reconcile.py index 7c850503798..fb50f20fb23 100644 --- a/dev/breeze/tests/test_fork_ci_reconcile.py +++ b/dev/breeze/tests/test_fork_ci_reconcile.py @@ -3462,14 +3462,8 @@ def test_job_status_budget_after_a_gap_is_capped(): MONITOR_RUN_URL = "https://github.com/apache/airflow/actions/runs/100" -def _monitor_run(run_id, started, status="completed", attempt=1, created=None): - return { - "id": run_id, - "status": status, - "run_started_at": started, - "run_attempt": attempt, - "created_at": created or started, - } +def _monitor_run(run_id, started, status="completed", attempt=1): + return {"id": run_id, "status": status, "run_started_at": started, "run_attempt": attempt} @pytest.mark.parametrize( @@ -3485,35 +3479,6 @@ def _monitor_run(run_id, started, status="completed", attempt=1, created=None): timedelta(minutes=7), id="previous-started-run", ), - pytest.param( - [ - _monitor_run(101, "2026-11-10T11:59:00Z"), - _monitor_run( - 100, - "2026-11-10T12:05:00Z", - status="in_progress", - attempt=2, - created="2026-11-10T11:58:00Z", - ), - _monitor_run(99, "2026-11-10T11:51:00Z"), - ], - timedelta(minutes=6), - id="re-run-after-a-later-run", - ), - pytest.param( - [ - _monitor_run( - 100, - "2026-11-10T12:05:00Z", - status="in_progress", - attempt=2, - created="2026-11-10T11:58:00Z", - ), - _monitor_run(99, "2026-11-10T11:51:00Z"), - ], - timedelta(minutes=7), - id="re-run-counts-from-its-first-attempt", - ), pytest.param([_monitor_run(100, "2026-11-10T11:58:00Z")], None, id="first-run"), pytest.param([_monitor_run(99, "2026-11-10T11:51:00Z")], None, id="this-run-not-listed"), ], @@ -3527,6 +3492,38 @@ def test_find_time_since_previous_monitor_run(client, runs, expected): ) [email protected]( + ("previous_attempt_start", "expected"), + [ + pytest.param("2026-11-10T12:03:00Z", timedelta(minutes=3), id="counts-from-the-previous-attempt"), + pytest.param("2026-11-10T11:50:00Z", timedelta(minutes=6), id="later-run-in-between"), + ], +) +def test_find_time_since_previous_monitor_run_for_a_re_run(client, previous_attempt_start, expected): + def rest_get(path): + if path.endswith("/actions/runs/100/attempts/2"): + return {"id": 100, "run_attempt": 2, "run_started_at": previous_attempt_start} + return { + "workflow_runs": [ + _monitor_run(100, "2026-11-10T12:06:00Z", status="in_progress", attempt=3), + _monitor_run(99, "2026-11-10T12:00:00Z"), + ] + } + + client.rest_get.side_effect = rest_get + + assert find_time_since_previous_monitor_run(client, REPO, run_url=MONITOR_RUN_URL) == expected + + +def test_find_time_since_previous_monitor_run_when_the_previous_attempt_cannot_be_read(client): + client.rest_get.side_effect = [ + {"workflow_runs": [_monitor_run(100, "2026-11-10T12:06:00Z", status="in_progress", attempt=2)]}, + GitHubError("gh api failed: HTTP 502"), + ] + + assert find_time_since_previous_monitor_run(client, REPO, run_url=MONITOR_RUN_URL) is None + + def test_find_time_since_previous_monitor_run_without_a_run_id(client): assert find_time_since_previous_monitor_run(client, REPO, run_url="https://run") is None client.rest_get.assert_not_called()
