diff --git a/.github/AGENTS.md b/.github/AGENTS.md new file mode 100644 index 0000000000000..e7689490f687d --- /dev/null +++ b/.github/AGENTS.md @@ -0,0 +1,38 @@ + + + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [The `.github` folder — Agent Instructions](#the-github-folder--agent-instructions) + - [Keep the CI-minutes estimates in sync with the workflows](#keep-the-ci-minutes-estimates-in-sync-with-the-workflows) + + + +# The `.github` folder — Agent Instructions + +## Keep the CI-minutes estimates in sync with the workflows + +`breeze ci approve-workflow-runs` (run by `workflows/auto-approve-workflow-runs.yml`) decides whether +to approve an external contributor's CI runs from an estimate of the job-minutes they take. The +numbers live in `dev/breeze/src/airflow_breeze/utils/ci_minutes_estimate.py` and are medians +measured on recent `Tests (AMD)` PR runs on public runners. + +After you change the CI workflows in a way that adds, removes, splits or resizes jobs (new test +groups, a changed matrix, new composite workflows, a move between runner types), refresh the +estimates once the change has run on enough PRs, and in any case about once a month: + +1. Run `uv run dev/calibrate_ci_minutes_estimates.py --since ` + from the repository root with an authenticated `gh` CLI. Pick a date that covers at least a + week of runs after the workflow change. +2. Copy the medians and fits it prints into the constants of `ci_minutes_estimate.py`, and update + the "Last calibrated" line next to them. +3. When you add a new job group to the workflows, add a matching group to both + `ci_minutes_estimate.py` (with the selective-check output that turns it on) and the + `JOB_GROUPS` patterns of the calibration script. Unmatched jobs fall into the base group. +4. Run `uv run --project dev/breeze pytest dev/breeze/tests/test_ci_minutes_estimate.py + dev/breeze/tests/test_workflow_run_approval.py -xvs`. + +The estimates cover public runners only. Self-hosted (RunsOn) runners need their own set once there +is enough data from them. diff --git a/.github/fork-ci-gate.toml b/.github/fork-ci-gate.toml index c80593d221c43..6119f610ef2d8 100644 --- a/.github/fork-ci-gate.toml +++ b/.github/fork-ci-gate.toml @@ -29,6 +29,16 @@ enabled_since = 2026-01-01T00:00:00Z # Days without any fork CI activity after which a gated pull request is closed. close_after_days = 7 +# Report each job of a gated pull request's fork run as its own commit status. Set to false when +# the fork CI monitor exceeds GitHub's rate limits (see dev/AGENTS.md); the `Fork CI / Tests (AMD)` +# status is posted either way. +job_statuses = true + +# Cancel the unfinished `pull_request` runs of pull requests that have already merged, of any +# author, so they stop using GitHub-hosted minutes and self-hosted runners for a result nobody +# reads. The fork CI monitor does it on its schedule. +cancel_merged_runs = true + # Organisations exempted under AIP-120 §2.2. Keys are display names used in comments, # values are GitHub logins. Changes go through a reviewed pull request. [allowlist] diff --git a/.github/workflows/auto-approve-workflow-runs.yml b/.github/workflows/auto-approve-workflow-runs.yml new file mode 100644 index 0000000000000..61d86be7a64fb --- /dev/null +++ b/.github/workflows/auto-approve-workflow-runs.yml @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +--- +# Approves the waiting workflow runs of external contributors' PRs to main when the change is safe to +# run without a maintainer's look, and labels the others "need workflow approval". A PR whose CI runs +# in the contributor's fork (AIP-120) is approved unless it changes CI definition files, and then gets +# a comment saying why its runs wait. The rules are in +# dev/breeze/src/airflow_breeze/utils/workflow_run_approval.py and documented in +# contributing-docs/05_pull_requests.rst. +# +# This workflow runs only trusted code from main. It reads the PR's metadata, changed-file list and +# git objects, and never checks out or runs the PR's code. Approving with GITHUB_TOKEN starts the +# approved runs right away, and workflow_run workflows that follow them still trigger. +name: Auto approve workflow runs +on: # yamllint disable-line rule:truthy + schedule: + - cron: '*/15 * * * *' + workflow_dispatch: + inputs: + report-only: + description: "Only report the decisions and estimates, without approving or labelling" + type: boolean + default: false +permissions: + # Approving workflow runs. + actions: write + # Adding and removing the "need workflow approval" label, and commenting on a fork CI PR whose + # CI change keeps its runs waiting. + pull-requests: write + contents: read +concurrency: + group: auto-approve-workflow-runs + cancel-in-progress: false +jobs: + approve-workflow-runs: + name: "Approve workflow runs of external contributors" + runs-on: ubuntu-latest + if: github.repository == 'apache/airflow' + timeout-minutes: 20 + steps: + - name: "Checkout main" + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: main + - name: "Install Breeze" + uses: ./.github/actions/breeze + - name: "Approve workflow runs" + env: + GITHUB_TOKEN: ${{ github.token }} + GITHUB_REPOSITORY: ${{ github.repository }} + REPORT_ONLY: ${{ inputs.report-only && 'true' || 'false' }} + run: breeze ci approve-workflow-runs diff --git a/.github/workflows/ci-amd.yml b/.github/workflows/ci-amd.yml index c5f24e5937bd6..4e6de3a5a8df1 100644 --- a/.github/workflows/ci-amd.yml +++ b/.github/workflows/ci-amd.yml @@ -233,7 +233,6 @@ jobs: PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }} PR_CREATED_AT: ${{ github.event.pull_request.created_at }} - PR_EVENT_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} # A base branch with neither gate file predates the gate (the pull request adding it, # or a release branch cut before it) and keeps running project CI. With only one of # them present, the missing file fails the job instead of opening the gate. diff --git a/.github/workflows/fork-ci-monitor.yml b/.github/workflows/fork-ci-monitor.yml index ec34b9615b028..278787be5af74 100644 --- a/.github/workflows/fork-ci-monitor.yml +++ b/.github/workflows/fork-ci-monitor.yml @@ -41,8 +41,8 @@ jobs: name: "Reconcile pull requests gated to fork CI" if: github.repository == 'apache/airflow' permissions: - # Listing the runs and jobs of the gate tampering check, and deleting the runs that only - # gated a pull request to fork CI. + # Listing the runs and jobs of the gate tampering check, deleting the runs that only gated a + # pull request to fork CI, and cancelling the unfinished runs of merged pull requests. actions: write contents: read # Labels, comments and closing of gated pull requests. diff --git a/contributing-docs/05_pull_requests.rst b/contributing-docs/05_pull_requests.rst index c7fee6d267771..593180aba6fbe 100644 --- a/contributing-docs/05_pull_requests.rst +++ b/contributing-docs/05_pull_requests.rst @@ -242,6 +242,47 @@ is the PMC private list — see the ``private@airflow.apache.org``. That document also covers the further steps the project may take when the same behaviour persists across PRs. +CI workflow runs of external contributors +----------------------------------------- + +GitHub does not start the CI workflows of a PR from a fork until a maintainer approves them, +for the contributors that the repository's approval setting covers. To keep you from waiting +for a maintainer on every push, a scheduled workflow checks the waiting runs every 15 minutes +and approves them automatically when all of these hold: + +* The PR targets ``main``. PRs to release branches, such as ``v3-4-test``, always wait for a + maintainer. +* The PR does not change anything under ``.github/``, ``dev/breeze/`` or ``scripts/ci/``. Those + files define the CI workflows and choose the runners they use. +* The change does not need the full set of tests, does not change dependencies (``pyproject.toml``, + lock files, ``package.json``, ``go.mod``, Gradle build files) and does not add a new provider. +* The CI jobs your change selects are estimated to take at most 310 job-minutes, about a quarter of + a full CI run. Changes to documentation, to the UI, to the Helm chart, to the language SDKs, to + one area of Airflow core or to a small provider usually stay under it. Changes to large providers + such as Amazon or Google, to several providers, or to the Task SDK (which runs the tests of all + providers) usually do not. +* The PR changes at most 100 lines of source code. Tests (including end-to-end tests), + documentation, newsfragments, translations and lock files are not counted, so a fix with + thorough tests still qualifies. Larger changes are usually new features, and a maintainer looks + at them first. + +If your PR's CI runs in your fork (it carries the ``fork ci required`` label), the CI run in +``apache/airflow`` only checks that, so none of the rules above apply. Its runs are approved +automatically unless the PR changes files that define CI: anything under ``.github/``, +``dev/breeze/``, ``scripts/ci/``, ``scripts/docker/`` or ``scripts/in_container/``, a ``Dockerfile`` +or ``.pre-commit-config.yaml``. Then the runs wait for a maintainer and a comment on the PR explains +why. CI in your fork runs either way. + +Each new push is checked again, because approval applies to one commit. Only runs started in the +last 24 hours are considered, so older waiting runs stay with maintainers. If your PR does not +qualify, it gets the ``need workflow approval`` label and a maintainer approves the runs after +looking at the change. That can take a while, so please do not ping maintainers about it; it is +not a judgement of your PR. The label is removed when a later commit is approved automatically. + +Maintainers can see each decision, the CI jobs selective checks expect to run and their estimated +time in the summary of the ``Auto approve workflow runs`` workflow. The rules are described in +more detail in `CI workflows <../dev/breeze/doc/ci/05_workflows.md>`__. + Gen-AI Assisted contributions ----------------------------- diff --git a/contributing-docs/25_maintainer_pr_triage.md b/contributing-docs/25_maintainer_pr_triage.md index e5f5313c5b770..e3f6909194c94 100644 --- a/contributing-docs/25_maintainer_pr_triage.md +++ b/contributing-docs/25_maintainer_pr_triage.md @@ -238,6 +238,7 @@ The triage workflow uses the following labels and states: | Label / State | Meaning | |---|---| | `ready for maintainer review` | PR has passed Stage 1 and is queued for human review. Applied only after the skill has verified that no workflow runs are awaiting approval. | +| `need workflow approval` | The PR's CI workflow runs wait for a maintainer, because the `Auto approve workflow runs` workflow did not approve them: a PR to a branch other than `main`, a change to CI definition files, a full-tests or dependency change, a change whose CI jobs are estimated at more than 310 job-minutes, or a change of more than 100 lines of source code (see [Pull Requests](05_pull_requests.rst)). For a PR whose CI runs in the contributor's fork, only a change to CI definition files keeps its runs waiting, and the workflow comments on the PR to say so. The workflow also tries to add the label when processing the PR failed; its run then fails too. Approve the runs after looking at the diff. The workflow removes the label when a later commit is approved automatically. | | `closed because of multiple quality violations` | PR was closed because the author has multiple open PRs with quality issues. | | `suspicious changes detected` | PR (and all open PRs by the same author) was closed because the diff contained suspicious patterns (secret exfiltration, malicious CI modifications, etc.). | | `closed because of open PR limit` | PR was closed in the one-time closure that introduced the [open PR limit](32_open_pull_request_limit.rst). Applied by `dev/close_prs_over_open_pr_limit.py`, never by the triage skill. If the author reopens the PR, triage it like any other. | diff --git a/dev/AGENTS.md b/dev/AGENTS.md index 947e0ac9e8e42..313c786018397 100644 --- a/dev/AGENTS.md +++ b/dev/AGENTS.md @@ -7,6 +7,7 @@ - [dev/ directory guidelines](#dev-directory-guidelines) - [Scripts](#scripts) + - [Fork CI job statuses and GitHub's rate limits](#fork-ci-job-statuses-and-githubs-rate-limits) @@ -42,3 +43,19 @@ uv run dev/my_script.py [args...] ``` Document `uv run` (not `python`) as the invocation method in READMEs and instructions. + +## Fork CI job statuses and GitHub's rate limits + +The fork CI monitor (`breeze ci fork-ci-reconcile`, run by `.github/workflows/fork-ci-monitor.yml`) +reports every job of a gated pull request's fork run as its own commit status. Those writes are the +largest share of what the monitor does with the repository's `GITHUB_TOKEN`, whose rate limits every +workflow of `apache/airflow` shares (see "Write budget" in +`dev/breeze/doc/ci/08_fork_ci_for_external_contributors.md`). + +If the budget is exceeded, turn the job statuses off: set `job_statuses = false` in +`.github/fork-ci-gate.toml`. Signs that it is exceeded are the monitor's Slack note that job +statuses "did not fit in the budget" persisting across runs, rate-limit retries ("GitHub rate limit, +retrying") or "still rate limited" errors in the monitor's run log or its Slack messages, or other +workflows of the repository failing on secondary rate limits. The aggregate `Fork CI / Tests (AMD)` +status and `CI passed` are posted either way, so turning job statuses off loses detail, not gating. +Lowering `MAX_JOB_STATUSES_PER_RUN` in `fork_ci_reconcile.py` is the softer alternative. diff --git a/dev/breeze/doc/08_ci_tasks.rst b/dev/breeze/doc/08_ci_tasks.rst index ca16b4483febc..7d00e36ee3292 100644 --- a/dev/breeze/doc/08_ci_tasks.rst +++ b/dev/breeze/doc/08_ci_tasks.rst @@ -188,7 +188,8 @@ Pull requests from external contributors can run their CI in the contributor's f gated pull requests ``fork ci required``, keeps them in draft until the fork run is green, maintains one state comment and a ``Fork CI / Tests (AMD)`` commit status linking to the run in the fork, closes pull requests without fork CI activity for a week, closes gated pull requests that made project CI run -by changing workflows, and writes everything it could not classify to a Slack message. With +by changing workflows, and writes everything it could not classify to a Slack message. It also cancels +the unfinished workflow runs of pull requests, of any author, that have already merged. With ``--dry-run`` it prints the changes instead of applying them. See `Fork CI for external contributors `_ for the design. @@ -199,6 +200,26 @@ These are all available flags of ``fork-ci-reconcile`` command: :width: 100% :alt: Breeze ci fork-ci-reconcile +Approving workflow runs of external contributors +------------------------------------------------ + +The ``auto-approve-workflow-runs`` workflow runs ``approve-workflow-runs`` every 15 minutes. It approves +the waiting workflow runs of external contributors' PRs to ``main`` whose CI jobs are estimated at no more +than 310 job-minutes, that change at most 100 lines of source code and that do not touch CI definition files, and labels the other PRs ``need workflow approval``. PRs whose CI runs in +the contributor's fork (AIP-120) only run the fork CI gate in ``apache/airflow``, so their runs are +approved whatever their size unless they change CI definition files; such a PR also gets a comment +explaining that its CI change needs a maintainer. For every PR it also +estimates the CI jobs selective checks will run and how long they take, and writes them to the job +summary. Use ``--report-only`` to see the decisions without approving runs or changing labels. The rules +are described in `CI workflows `_. + +These are all available flags of ``approve-workflow-runs`` command: + +.. image:: ./images/output_ci_approve-workflow-runs.svg + :target: https://raw.githubusercontent.com/apache/airflow/main/dev/breeze/images/output_ci_approve-workflow-runs.svg + :width: 100% + :alt: Breeze ci approve-workflow-runs + ----- Next step: Follow the `Release management tasks <09_release_management_tasks.rst>`_ guide to learn how diff --git a/dev/breeze/doc/ci/05_workflows.md b/dev/breeze/doc/ci/05_workflows.md index 7ec7871993cb8..a03452145c4db 100644 --- a/dev/breeze/doc/ci/05_workflows.md +++ b/dev/breeze/doc/ci/05_workflows.md @@ -98,6 +98,68 @@ whose CI runs in the contributor's fork (AIP-120), the gate skips `build-info` a everything after it, so the run finishes in seconds; see [Fork CI for external contributors](08_fork_ci_for_external_contributors.md). +### Approval of pull request runs + +GitHub holds the runs of a fork PR in `action_required` until someone with write access approves +them, for the contributors the repository's approval setting covers. The +`auto-approve-workflow-runs.yml` workflow runs every 15 minutes on `main` and calls +`breeze ci approve-workflow-runs`, which approves the waiting runs of a commit when all of these hold: + +- the PR targets `main`; PRs to release branches (`v3-4-test`, `airflow-ctl/v0-1-test`, ...) run those + branches' own workflows and always wait for a maintainer +- the PR changes nothing under `.github/`, `dev/breeze/` or `scripts/ci/`, which define the workflows + and choose the runners +- the PR changes no dependency manifest or lock file (`pyproject.toml`, `uv.lock`, `package.json`, + `pnpm-lock.yaml`, `go.mod`, Gradle build files, ...) and adds no new provider (selective checks + run from `main`'s tree and do not know it) +- selective checks for the PR's merge commit succeed, and do not need the full set of tests, all Python + and database versions, a canary build or upgraded dependencies (the estimate does not model them) +- the jobs selective checks select are estimated at no more than 310 job-minutes on public runners + (about 23% of a full-tests run, just above the cluster of single core areas and the Helm chart) +- the PR changes at most 100 lines of source code; tests (including e2e tests), docs, newsfragments, + translations, lock files and images are not counted + +A PR to `main` whose CI runs in the contributor's fork (AIP-120: the `Fork CI gate` job would skip +project CI for it) is decided by one rule instead, because its `Tests (AMD)` run only executes the +gate: its runs are approved whatever its size, cost or dependency changes, unless it changes a file +the fork CI reconciler counts as CI-defining (`.github/`, `dev/breeze/`, `scripts/ci/`, +`scripts/docker/`, `scripts/in_container/`, `Dockerfile*`, `.pre-commit-config.yaml`). Such a PR gets +the `need workflow approval` label and one comment telling the author that the CI change needs a +maintainer; see +[Approving gated runs](08_fork_ci_for_external_contributors.md#approving-gated-runs). + +Only runs created in the last 24 hours (`--max-run-age-hours`) are considered, so the workflow never +approves a backlog of older waiting runs at once; those stay with maintainers. A commit that is the +head of several open PRs is never approved automatically, because its runs cannot be told apart by +PR, and only runs started after the PR was opened and after its base branch last changed are +approved (retargeting a PR does not start new runs). A run selects its jobs from the labels the PR +had when it started, while the decision uses the current labels, so for PRs that run project CI a +run started before a label that changes which tests run was added or removed +(`full tests needed`, `all versions`, `default versions only`, `latest versions only`, `canary`, +`upgrade to newer dependencies`, `area:e2e-tests`, `area:kubernetes-tests`) is left for a +maintainer, since it still runs the selection it started with; the next push is decided afresh. +For a PR whose CI runs in the fork neither the selection nor the labels a run started with matter: +the gate reads the current labels when the run starts and fails when it cannot, so a run started +before `use fork ci` or `use project ci` was added or removed is approved too. Other PRs get the +`need workflow approval` label and wait for a maintainer. When processing a PR fails (for example on +a GitHub API error), the workflow tries to add the label to it and the workflow run fails, so the +failure stays visible even if the label could not be added. The label is removed when a later commit +of the PR is approved automatically. + +The workflow uses only `main`'s code. It reads the PR's metadata and fetches its merge commit as git +objects to list the changed files; it never checks out or runs the PR's code. The merge commit must +have been built from the head commit whose runs get approved, so a push after the check cannot slip +into an approved run. Approving with the workflow's `GITHUB_TOKEN` starts the runs right away, and +`workflow_run` workflows that follow them still trigger. + +The estimate comes from `dev/breeze/src/airflow_breeze/utils/ci_minutes_estimate.py`, which turns the +selective-check outputs into job groups with job-minutes and a wall-clock estimate, weighting +providers by the size of their test suites. The job summary lists every waiting PR with its decision, +the expected job groups and the estimated time. The numbers are medians of recent `Tests (AMD)` PR +runs on public runners; refresh them with `dev/calibrate_ci_minutes_estimates.py`, as +`.github/AGENTS.md` describes. Run `breeze ci approve-workflow-runs --report-only` (or dispatch the +workflow with `report-only`) to see the decisions without approving or labelling anything. + ## Fork push run These runs are triggered by a push to any branch of a contributor's fork in which the 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 1b2bd742f90ac..004c097be9130 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 @@ -310,9 +310,11 @@ directly with the runner's `python3` without installing breeze. The reconciler i full project CI as `base_without_gate`. 2. For pull requests, one read-only API call for the current labels (`gh api repos/apache/airflow/pulls/ --jq '.labels[].name'`), so override labels added - after the event are seen on a re-run. If that call fails, the gate uses the labels of the - event payload instead. It never falls back to running project CI: anyone able to exhaust - the shared token quota would otherwise switch the gate off for every pull request. + after the event are seen on a re-run. If that call fails, the gate job fails and nothing + after it runs; re-running the job decides again. It falls back neither to running project + CI, since anyone able to exhaust the shared token quota would otherwise switch the gate off + for every pull request, nor to the labels of the event payload, since runs started before + `use fork ci` was added are approved automatically (see "Approving gated runs"). 3. `python3 dev/breeze/src/airflow_breeze/utils/fork_ci_gate.py` with the event payload fields and the labels passed as environment variables. It writes `project-ci=true|false` and `reason=...` to `GITHUB_OUTPUT`. A base branch with neither file skips the script and @@ -337,6 +339,50 @@ where `*` is any characters except `/`). The `check-ci-workflows-in-sync` prek hook allowlist is extended to permit the `gate` job and the `build-info` dependency to exist only in the AMD workflow. +### Approving gated runs + +GitHub holds the `pull_request` runs of a fork pull request in `action_required` until someone with +write access approves them, for the contributors the repository's approval setting covers. Until +then the gate job does not run either. A gated pull request would stay in the maintainers' approval +queue even though its project CI run only executes the gate, and the reconciler could not delete a +gated run that never ran. + +`breeze ci approve-workflow-runs`, run every 15 minutes by `auto-approve-workflow-runs.yml` (see +[CI workflows](05_workflows.md#approval-of-pull-request-runs)), handles them. For a pull request to +`main` it calls `fork_ci_gate.decide` with the configuration of its own `main` checkout and the +pull request's author, association, creation time, head repository and current labels, the inputs +the gate job of the waiting run uses. When the reason is gated (`external`, `pilot` or +`label_fork_ci`), the rules for pull requests that run project CI (estimated job-minutes, lines of +source code, dependency files, full tests) do not apply, because none of those jobs run. One rule +applies instead: + +- The waiting runs of the head commit are approved when the pull request's merge commit changes no + file that the reconciler counts as CI-defining: `.github/`, `dev/breeze/`, `scripts/ci/`, + `scripts/docker/`, `scripts/in_container/`, `Dockerfile*` and `.pre-commit-config.yaml` (see + "Trusting a green fork run"). The approved `ci-amd.yml` run executes only the gate, and the other + `pull_request` workflows (CodeQL for the changed languages, the newsfragment check, dependency + review) run on GitHub-hosted runners. +- Otherwise the runs wait for a maintainer, the pull request is labelled `need workflow approval`, + and the workflow posts one comment explaining that the change to the listed CI files needs a + maintainer to review it and approve the runs. The comment starts with the marker + `` and is posted once per pull request; only comments by + `github-actions[bot]` with the marker count. A change to `.github/` can remove the gate or add a + workflow that does run, so such a run must not start without a review. + +A run started before `use fork ci` or `use project ci` was last added or removed is approved too, +so a committer can add `use fork ci` after the PR's first runs were created and before they are +approved. The gate decides from the labels the PR has when the run starts, never from those of the +run's event, and fails when it cannot read them. + +Both rules use the same list as "Trusting a green fork run", so a gated pull request whose runs are +approved automatically is also one whose green fork run is trusted, and one that changes CI is both +left waiting for approval and labelled `needs project ci` once its fork run is green. The gate +tampering check still applies to every run a maintainer approves by hand. + +The approval reads only API metadata and the git objects of the merge commit; it never checks out or +runs the pull request's code. Pull requests to other branches keep the rules for project CI, which +leave them to a maintainer. + ## Fork mode CI ### Trigger @@ -661,6 +707,87 @@ Commit statuses were chosen over check runs because a check run created with the token is attached to the creating workflow's check suite and its details link then opens the monitor run rather than `details_url`. A status honours `target_url`. +### Job statuses + +Next to the aggregate status, each job of the fork run is reported as its own commit status, so +the pull request shows which jobs run, failed or passed, each linking to the job in the fork. +The run is the one `Fork CI / Tests (AMD)` reports (its `databaseId` is fetched with the check +suites); its jobs come from `GET /repos//actions/runs//jobs?filter=latest`. + +- The context is `Fork CI job / `, with non-printable characters replaced and the name + shortened to 100 characters. Job names come from the workflow of the contributor's commit, so + the prefix is what keeps a job from posting `Fork CI / Tests (AMD)`, from which the reconciler + reads its decisions back, or `CI passed`, which the merge ruleset requires. Jobs that share a + context, which GitHub compares case-insensitively, are reported as the worst of them. +- A queued or running job is `pending` ("Running in the fork"), a successful one `success`, and a + failed, timed-out, cancelled or unstartable one `failure`. Skipped and neutral jobs, and the jobs + every run has (`Fork CI gate`, `Check if the run is needed`, `Platform: AMD` and `CI passed`), are + not reported. Queued and running share one status so that starting a job costs no write. +- The desired statuses are compared with the head commit's current ones + (`GET /repos/apache/airflow/commits//status`), and only differences are posted, failures + first. GraphQL has no mutation for commit statuses (`createCheckRun` exists, but see above for + why check runs do not fit), so each one is a REST call, and they count towards GitHub's limits on + content-creating requests: a reconciler run posts at most `MAX_JOB_STATUSES_PER_RUN` (60) of + them, each write charged as it is made. What does not fit is posted by the next run, and once + the budget is spent no further pull request's jobs or statuses are read in that run. A run that + defers job statuses adds a note to the Slack message, with fixed wording so it is posted once + while deferrals persist; the run log lists the pull requests. +- Commit statuses cannot be deleted and have no neutral state. When a run has completed, a job + context posted for an earlier run of the same commit that the completed run does not have, or + skipped, is overwritten with `success` and the description "Not in the latest fork run - see + Fork CI / Tests (AMD)", so it no longer shows as running or failed. +- Once every job of a completed run is reported, the run is recorded in the marker as + `jobs: "::"` (`runAttempt` is fetched with the check suites), so + later runs do not read its jobs again. A run in progress is read on every run, and a re-run in + the fork is read again because its attempt changes, even when it ends with the same conclusion. +- Reporting job statuses is caught on its own: when it fails, the failure is listed with the + unknown items for Slack, and the pull request is still classified, so for example a `CI passed` + that no longer holds is still revoked. + +The job statuses are informational. Merging still depends on `CI passed`, and the state machine +on `Fork CI / Tests (AMD)`; a job status never changes either. + +`job_statuses = false` in `.github/fork-ci-gate.toml` turns them off; the reconciler then posts +only `Fork CI / Tests (AMD)` and `CI passed`, as before. Statuses already posted stay on their +commits. Turn them off when the fork CI monitor's runs hit GitHub's rate limits (rate-limit +retries in the run log, or "still rate limited" errors in Slack); `dev/AGENTS.md` records this for +agents. + +#### Write budget + +Measured on 2026-10-25 from `apache/airflow`'s own `Tests (AMD)` pull request runs (the same +workflow runs in the forks; `GET /repos/apache/airflow/actions/runs//jobs?filter=latest`, +jobs whose conclusion is not `skipped`, minus the four jobs that are not reported): + +| Pull request | Run | Started jobs | Reported job statuses | +|---|---|---|---| +| Breeze test fix | [40138784120](https://github.com/apache/airflow/actions/runs/40138784120) | 11 | 7 | +| Documentation fix | [40169750323](https://github.com/apache/airflow/actions/runs/40169750323) | 16 | 12 | +| Google provider change | [40158907296](https://github.com/apache/airflow/actions/runs/40158907296) | 43 | 39 | +| CI change (full tests) | [40207881565](https://github.com/apache/airflow/actions/runs/40207881565) | 131 | 127 | + +`apache/airflow` had 1898 `Tests (AMD)` pull request runs from 2026-10-18 to 2026-10-24, about 270 a +day or 11 an hour. Each reported job costs at most two writes (running, then its result) and one +when it starts and finishes between two reconciler runs; a fork run of 30-60 minutes spans two to +four of them, so most jobs cost two. + +The limits that matter are GitHub's documented ones for the `GITHUB_TOKEN` of `apache/airflow`, +shared by every workflow of the repository: 1000 REST requests an hour, and 80 content-creating +requests a minute and 500 an hour. Assuming about 35 reported jobs for an average push: + +- **Contributor pilot**, a few gated pushes a day: about 70 writes a push, under 20 an hour, under + 5% of the content-creating limit. +- **Gate enabled**, assuming about half of the pull request runs come from gated pull requests + (about 5-6 pushes an hour): about 400 writes an hour without a cap, 80% of the content-creating + limit and more at peaks. The cap of 60 writes a run, four runs an hour, holds job statuses to at + most 240 an hour: 48% of the content-creating limit and 24% of the REST limit, plus two reads per + pull request with a run in progress. Job statuses then lag behind at busy times, the aggregate + status does not. + +These are estimates: the share of gated runs, the jobs per push and the pushes per pull request +are assumptions, not measurements. Watch the monitor's call counts in its run log after enabling +the gate, and turn `job_statuses` off if they approach the limits. + ### Relationship to the triage skill The `pr-management-triage` skill described in `contributing-docs/25_maintainer_pr_triage.md` @@ -706,6 +833,36 @@ name within its time limit, and its run is the evidence. A re-run is kept too: d deletes every attempt, and an earlier attempt may have run project CI. Nothing is deleted for a pull request in the `gate_bypassed` state. A dry run only reports the deletions. +### Cancelling runs of merged pull requests + +Merging a pull request does not stop its `pull_request` runs. They keep using `apache/airflow`'s +capacity, GitHub-hosted minutes from the ASF's allocation and the self-hosted runners, for a +result nobody reads once the change is on its target branch. This is not specific to fork CI; the +monitor does it because it already runs every 15 minutes with `actions: write`. + +Each monitor run lists the `pull_request` runs of `apache/airflow` that are `queued`, +`in_progress`, `waiting`, `pending` or `requested`, and looks up the pull requests of their head +branches in one GraphQL query per 25 branches, paging through every pull request of a branch: a +common branch name such as `main` has pull requests from many forks, and an open one with the +run's head must not be missed. A run is cancelled when: + +- a merged pull request has the run's head repository, branch and commit (runs of pull requests + from forks do not list their pull request, so they are matched this way); +- no open pull request has the same head, since a branch can be reused for a new pull request; +- the run was created before the merge. A workflow triggered by the merge itself, such as one + on the `closed` event, is meant to run. + +It applies to the pull requests of every author, not only gated ones. A run is cancelled with +`POST /repos/apache/airflow/actions/runs//cancel`; one still `in_progress` 30 minutes after the +merge, for example because a step ignores the cancellation, is force-cancelled +(`.../force-cancel`). A run that finished in the meantime (HTTP 409) is not a problem; any other +failure is reported to Slack with the pull request, and a failure of the whole pass is reported +as a note, without affecting the reconciliation of gated pull requests. A dry run only reports +the cancellations. `cancel_merged_runs = false` in `.github/fork-ci-gate.toml` turns it off. + +Only runs of the merged head commit are matched. A run of an earlier commit of the pull request is +normally cancelled by the workflow's concurrency group when the next commit is pushed. + ### Far behind the base branch A fork run tests the pushed commit as it is, while project CI tests it merged with the base @@ -760,7 +917,10 @@ Per run, with ~700 gated pull requests: ~28 GraphQL calls for pass 2, ~14 for fo calls for the recent `pull_request` runs, one REST call per base branch for its workflow files, a jobs call and a compare call only per long `ci-amd.yml` run of a gated pull request, one changed-files call per head commit that turns green, plus one mutation per actual state -change. Well inside +change. Cancelling runs of merged pull requests adds five paginated run listings, one GraphQL +query per 25 head branches with unfinished runs, and one mutation per cancelled run. Job statuses add a jobs call and a status call per pull request with a fork run in +progress or a completed run not yet reported, and up to two status mutations per job, at most +`MAX_JOB_STATUSES_PER_RUN` per run; see "Write budget". Well inside the `GITHUB_TOKEN` limits at a 15-minute cadence. The reconciler logs its call counts so the budget stays observable. @@ -906,6 +1066,11 @@ as a failed check rather than a crash. workflow files on the base branch. - A green fork run is trusted only for pull requests that do not change what fork CI runs; see "Trusting a green fork run". +- Job statuses carry names from the contributor's workflow under their own `Fork CI job / ` + prefix, so they cannot post the reconciler's own contexts or `CI passed`; see "Job statuses". +- Workflow runs of a gated pull request are approved without a maintainer only when it changes no + CI-defining file, so a pull request that edits the gate away still waits for a maintainer before + any run starts; see "Approving gated runs". - The reconciler runs on `main` with `pull-requests: write` and never checks out or executes pull request content. Its inputs are API data; its comment templates are static. - Fork runs get the fork's `GITHUB_TOKEN` only. Nothing in project CI trusts a fork run's diff --git a/dev/breeze/doc/images/output_ci.svg b/dev/breeze/doc/images/output_ci.svg index 7158eac2e10d3..d175e86af7b1f 100644 --- a/dev/breeze/doc/images/output_ci.svg +++ b/dev/breeze/doc/images/output_ci.svg @@ -1,4 +1,4 @@ - +