Skip to content

Block merging on fork CI once a PR is moved to project CI - #76672

Merged
potiuk merged 1 commit into
apache:mainfrom
shahar1:fork-ci-project-ci-label-blocks-merge
Nov 12, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
shahar1:fork-ci-project-ci-label-blocks-merge

Conversation

@shahar1

@shahar1 shahar1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes one of the bugs that Ash raised on AIP-120: adding the use project ci label did not stop a PR from merging on the fork CI result (dev list), as happened in #76536.
With this change, the next Fork CI monitor run after the label sets CI passed back to pending, and the PR cannot merge until project CI passes on the head commit.
The monitor does the revoke (no pull_request_target), so the fork result still counts for up to one monitor cycle (about 15 minutes) after the label.

AI Summary

Why

The main and release-branch rulesets require the CI passed and CI run started contexts. They accept these contexts from any source.

For a PR that runs CI in a fork, the Fork CI monitor sets the CI passed commit status from the fork run.

The use project ci label sends the PR to project CI. But the label did not remove the success that the fork run gave. Thus, a maintainer or auto-merge could merge the PR on the fork result before project CI ran.

This occurred on #76536:

Time Event
13:34 The monitor set CI passed to success from the fork run
13:36:52 A maintainer added use project ci
13:36:55 The maintainer closed and opened the PR again
13:37:01 Project CI went into the queue
13:38:29 The PR merged on the fork result. Project CI was then cancelled

The AIP-120 [VOTE] thread gives more data: https://lists.apache.org/thread/hh5p3j9cj66767lj3gpotfz8rgvkt0oh

How

When a PR has use project ci, a fork run cannot set its CI passed status. The status stays pending until the CI passed job of project CI is successful on the head commit. Then the status changes to success.

The GitHub documentation says: "If a check and a commit status have the same name, both must pass when that name is required." (source) Thus, a pending status blocks the merge, also when the project CI check run is successful.

When a maintainer adds the label

  • No workflow reacts to the label. This PR does not use pull_request_target, because that trigger will be disabled for the repository.
  • The next monitor run releases the PR to project CI. In the same run, it changes a CI passed success from a fork run to pending ("Waiting for project CI (use project ci)").
  • The monitor reads the labels from the PR itself, not from the label search. The search index can show a new label some minutes late.
  • A success with the description "Project CI passed for this commit" stays. Thus, a release that runs again does not remove a result that project CI gave.

At the start of each monitor run

  • The monitor finds the head commits of all open PRs with use project ci.
  • The main loop does not write CI passed on these commits. report_project_ci_passed controls them.
  • A status is on a commit, not on a PR. Thus, this step also covers a second PR from the same branch.

Before the monitor sets a fork success

  • The search index can show a new label some minutes late. Thus, the monitor does not use search for this step.
  • The monitor reads the PR directly (GET pulls/{n}). It also reads the open PRs from the same head branch.
  • The monitor does not set the success if one of these PRs now has the label, or if the head commit changed.

At the end of each monitor run

  • report_project_ci_passed writes only if the head commit already has a CI passed status. If there is no status, the project CI check run decides alone. Thus, the monitor never leaves a pending status on a PR that did not have one.
  • It looks at the newest project CI run on the head commit. All files in PROJECT_CI_WORKFLOW_FILES are accepted.
  • The exact CI passed check run of a run gives the result. These runs do not count, and they do not hide an older result:
    • a run that has only CI passed (run cancelled) or CI passed (project CI not run)
    • a run that was cancelled before its jobs started. Such a run has no check runs.
  • A re-run keeps its check suite. Thus, a marker from the first attempt does not hide the result of the re-run.
  • If the CI passed check run is successful, the monitor sets success. If not, it removes a success.
  • Sometimes the GraphQL search does not show the head commit, for example after a rebase that keeps old commit dates. Then the monitor uses REST.
  • The per-run limit on status writes applies only to success, and only after a write is successful. Changes to pending have no limit.
  • An error on one PR does not stop the work on other PRs.
  • If the search for labelled PRs fails, the monitor sets no fork success in that run. It still changes statuses to pending.

When a maintainer removes the label

  • The change updates the PR. Thus, the monitor finds the PR again in its next run.
  • If the PR is gated, the monitor sets the fork result again when the fork run is green.
  • If the PR is not gated, or its base branch has no gate, the monitor examines the CI passed status that the monitor wrote. When the project CI check run is successful, the monitor sets success. Thus, a pending status does not stay on the PR.
  • This also works when the GraphQL search does not show the head commit.
  • The monitor finds only PRs that changed in the last 24 hours. If project CI passes later and nothing else changes on the PR, the status stays pending until the PR changes again.

Limits of this change

  • The protection is not immediate, and it is not atomic. A fork success that was set before the label stays until the next monitor run is complete. During this time, the PR can merge on the fork result.
    • The monitor runs each 15 minutes. The time is longer when GitHub delays or drops a scheduled run, or when a run fails.
    • One more cycle is necessary when the label arrives after a run read the PR.
    • A maintainer who adds the label to a PR with a green fork run must wait for pending before the merge or auto-merge. As an alternative, the maintainer can start the monitor manually (workflow_dispatch).
    • A shorter monitor interval makes the time shorter. Then the write limits for each run must change with it.
    • A strict block at merge time needs a required check from one fixed source. That is not in this PR.
  • Project CI does not start automatically. A maintainer must close and open the PR again, or the contributor must push. GitHub does not start workflow runs for events that GITHUB_TOKEN causes, except workflow_dispatch and repository_dispatch. A labeled trigger in ci-amd.yml would start CI for each label and cancel runs in progress.
  • The merge waits for the monitor. After project CI is successful, a PR with a pending status stays blocked until the next monitor run sets success. This can take approximately 15 minutes.
  • Known gaps, also in the documentation:
    • The direct read does not find a duplicate PR from a different branch at the same commit.
    • The rulesets accept CI passed from any source. Thus, a PR that changes workflows can make its own CI passed check run. This gap is not new, and it applies to all PRs that use project CI. Reviewers must still examine changes to CI files.

Verification

Check Result
uv run --project dev/breeze pytest dev/breeze/tests/test_fork_ci_reconcile.py dev/breeze/tests/test_fork_ci_messages.py dev/breeze/tests/test_fork_ci_gate.py -q 545 passed
prek commit hooks on the changed files (ruff, mypy, markdownlint) Passed. The lychee-docker link check did not run locally (no Docker socket)
No workflow uses pull_request_target; .github/zizmor.yml and .github/fork-ci-gate.toml are the same as on main Confirmed with git grep and git diff
GraphQL fields and REST fields (check_runs[].check_suite.id, check_suite_id of a workflow run), read-only queries on live apache/airflow commits The fields are there and agree
checkRuns(filterBy: {checkName}) on a commit with a re-run Gives only the latest attempt (checked for the earlier revision)
pulls?state=open&head=<owner>:<branch> Shows fork PRs. commits/{sha}/pulls and associatedPullRequests do not show them, so this PR does not use them
Two independent reviews of this revision (gate correctness; review comment and documentation) Both GO. Open minor points: the revoke is written after the comment writes in apply_plan, so an error there delays the revoke by one run; the project CI GraphQL query costs approximately 151 points for each page
Earlier revisions: Opus, Codex and Copilot reviews Findings fixed

Simulation on a copy of the repository

I tested this revision on a copy of apache/airflow that is not in its fork network, with a contributor fork. The copy has a minimal ci-amd.yml (gate, build-info, one quick job, ci-passed), the monitor without Slack, and the same rules as main. It has no pull_request_target workflow. I started each monitor run with workflow_dispatch.

Step Result
Fork CI green, monitor ran CI passed success ("Fork CI passed for this commit"), merge CLEAN
use project ci added, before the next monitor run CI passed stays success, merge CLEAN. This is the limit written above
Next monitor run CI passed changes to pending ("Waiting for project CI (use project ci)"), merge BLOCKED
Close and reopen, project CI runs Merge BLOCKED
Project CI check passes, before the next monitor run Still BLOCKED: the pending status must also pass
Next monitor run "Project CI passed for this commit", merge CLEAN
Two more monitor runs No writes. The status stays success
New push to the labelled PR, fork run green, project run cancelled The monitor sets no CI passed status, merge BLOCKED. After project CI passes on the new head commit, merge CLEAN with no monitor run
Second PR: label added after the fork run is green and before a monitor run The monitor never sets a fork success, merge BLOCKED
Label removed, fork run green The monitor sets the fork result again, merge CLEAN

The earlier revision showed the bug on the same copy without this PR: after the label, the merge state was UNSTABLE, and the PR could merge on the fork result while project CI ran.

Not tested:

  • apache/airflow itself and the full CI. These tests used the copy and the minimal CI.
  • Scheduled monitor runs.
  • A label that arrives during a monitor run.
  • Two PRs on the same head commit.
  • A project CI run that fails.

related: #76536


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5 and Fable 5.2, with subagents)

Generated-by: Claude Code (Opus 5.5 and Fable 5.2) following the guidelines

@potiuk potiuk left a comment

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.

The monitor-side fix is sound: heads carrying use project ci no longer get a fork success, and report_project_ci_passed moves them to pending until project CI passes. The new pull_request_target workflow is the part I'd like changed, because that trigger is going away for us.

Blocking — pull_request_target is about to be disabled (.github/workflows/fork-ci-project-ci-label.yml:31)

  pull_request_target:  # zizmor: ignore[dangerous-triggers]
    types: [labeled, synchronize, reopened]

pull_request_target will be disabled for us soon, so this workflow (the immediate revoke when use project ci is added, on synchronize and on reopened) would silently stop running. The monitor-side changes in fork_ci_reconcile.py do not depend on it: the monitor no longer posts a fork success for heads carrying the label, and report_project_ci_passed turns an existing fork success into pending on its next run. Could you drop this workflow, together with its entry in the gate-protected file set, the zizmor.yml comment change and the tests of its shell logic, and rely on the monitor for the revoke? The window of up to one monitor cycle would then belong under "Limits of this change". If that window matters, a shorter monitor interval keeps us off pull_request_target.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. After you've
addressed the points above and pushed an update, an Apache Airflow
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them 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 marked this pull request as draft November 9, 2026 19:53
@shahar1

shahar1 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Drafting until I test the new approach

@shahar1
shahar1 force-pushed the fork-ci-project-ci-label-blocks-merge branch from db96a8b to bed8d8a Compare November 11, 2026 19:14
@shahar1
shahar1 marked this pull request as ready for review November 11, 2026 19:30
@shahar1
shahar1 requested a review from potiuk November 11, 2026 19:30
@shahar1

shahar1 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@potiuk Could you please take another look? thank you!

The rulesets require the `CI passed` context from any source, and the Fork CI
monitor posts it from the fork run. Adding `use project ci` did not withdraw
that success, so a pull request could merge on the fork result before project
CI ran, as happened on apache#76536.

The revoke is done by the monitor and not by an event-driven workflow, because
`pull_request_target` is about to be disabled for this repository. The fork
result therefore stays until the next monitor run that completes; the design
document records that window as a limit.
@shahar1
shahar1 force-pushed the fork-ci-project-ci-label-blocks-merge branch from bed8d8a to 801890c Compare November 12, 2026 06:00

@potiuk potiuk left a comment

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.

The revoke now lives entirely in the monitor and pull_request_target is gone, which resolves my earlier blocking point. The rest also holds up:

  • The release run sets CI passed to pending and keeps a success that project CI earned.
  • No fork success is posted on a commit shared with a labelled pull request, or when that list can't be read.
  • The live read of the pull request and its same-branch siblings closes the gap left by the slow label search.
  • Both ways of reading the project CI result skip cancelled and not-run runs.

The 15-minute window and the 24-hour recovery limit are documented as known limits.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

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

@potiuk
potiuk merged commit e17ceca into apache:main Nov 12, 2026
152 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

potiuk pushed a commit that referenced this pull request Nov 12, 2026
…#76672) (#76981)

The rulesets require the `CI passed` context from any source, and the Fork CI
monitor posts it from the fork run. Adding `use project ci` did not withdraw
that success, so a pull request could merge on the fork result before project
CI ran, as happened on #76536.

The revoke is done by the monitor and not by an event-driven workflow, because
`pull_request_target` is about to be disabled for this repository. The fork
result therefore stays until the next monitor run that completes; the design
document records that window as a limit.
(cherry picked from commit e17ceca)

Co-authored-by: Shahar Epstein <[email protected]>
vatsrahul1001 pushed a commit that referenced this pull request Nov 27, 2026
…#76672) (#76981)

The rulesets require the `CI passed` context from any source, and the Fork CI
monitor posts it from the fork run. Adding `use project ci` did not withdraw
that success, so a pull request could merge on the fork result before project
CI ran, as happened on #76536.

The revoke is done by the monitor and not by an event-driven workflow, because
`pull_request_target` is about to be disabled for this repository. The fork
result therefore stays until the next monitor run that completes; the design
document records that window as a limit.
(cherry picked from commit e17ceca)

Co-authored-by: Shahar Epstein <[email protected]>
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.

2 participants