Skip to content

ADR-3551: Anchor edited pull-request aggregator runs at ready-for-review

  • Status: Accepted
  • Date: 2026-11-15
  • Deciders: Project maintainer
  • Tags: ci, fork-local

Context

.github/workflows/rule-enforcement.yml triggers on [opened, edited, synchronize, reopened, ready_for_review], while .github/workflows/required-aggregator.yml triggered on [opened, synchronize, reopened, ready_for_review]. Editing a pull request's title or body after Required Checks Aggregator succeeded re-ran the governance gates (Deliverables Checklist, docs/state.md Gate, DCO Sign-off, and sibling jobs in rule-enforcement.yml) without re-running the aggregator (issue 3459). A gate turned red by that edit left the single required status check (ADR-0313) green, leaving the pull request UNSTABLE instead of BLOCKED.

Adding edited to required-aggregator.yml without adjusting its freshness window fails healthy pull requests. The aggregator computed minCreatedMs = runCreatedMs - 2 * 60 * 1000 from its own workflow run to drop draft-era GitHub Actions check runs. Because build, lint, and test workflows do not trigger on edited, their check runs on the unchanged head SHA predate the edited aggregator run and would be ignored as absent, failing every owed context under ADR-3293. Conversely, anchoring minCreatedMs at ready_for_review alone keeps earlier rule-enforcement.yml (Rules) check runs on the same head SHA inside the window: when the aggregator polls before the current edit's Rules run registers its gate jobs behind CI tier (Rules), newestByName would otherwise pick the earlier green gate runs and pass before the edit's gate fails.

Decision

Add edited to on.pull_request.types in .github/workflows/required-aggregator.yml ([opened, edited, synchronize, reopened, ready_for_review]), leaving workflow permissions: (actions: read authorises workflow-run reads; pull-requests: read authorises issue timeline reads) and ref-scoped concurrency: (cancel-in-progress: true off master) unchanged.

Derive the check-run freshness anchor in windowAnchorMs and exclude stale edited-rerun workflow suites:

  • When context.eventName === 'pull_request' && context.payload.action === 'edited', read github.rest.issues.listEventsForTimeline (per_page: 100, capped at 10 pages, wrapped in withApiBackoff) and anchor at created_at of the latest ready_for_review timeline event. When the timeline contains no ready_for_review event (the pull request was never a draft), anchor at context.payload.pull_request.created_at.
  • On every other event, anchor at the aggregator workflow run's own created_at, unchanged.
  • Compute minCreatedMs = anchorMs - 2 * 60 * 1000 (runTimestampMs >= minCreatedMs counts; < minCreatedMs is excluded), log the selected anchor source via core.info, and fail closed without judging checks if the timeline call fails or the anchor timestamp cannot be derived. Non-Actions github-advanced-security checks retain their any-age rule (ADR-3539).
  • Declare editedRerunWorkflows = ['.github/workflows/rule-enforcement.yml'] for workflows whose pull_request trigger includes edited and that report required checks, and require every listed workflow to declare a top-level run-name starting with "[${{ github.event.pull_request.updated_at }}] " before any author-controlled text (run-name: "[${{ github.event.pull_request.updated_at }}] ${{ github.event.pull_request.title }}" in .github/workflows/rule-enforcement.yml, enforced statically by the sync guard in scripts/ci/tests/test_aggregator_edited_window.py). Keep literal ${{ syntax out of required-aggregator.yml's actions/github-script script: scalar (and enforce GitHub's 21,000-character ParseScalar expression limit across all workflow scalars in scripts/ci/check-workflow-size.py) so the runner does not wrap the embedded script into an oversize format(...) expression. On an edited event, require a non-empty context.payload.pull_request.updated_at (failing closed via core.setFailed naming pull_request.updated_at if missing). On each edited-event poll, list workflow runs for the head SHA via github.rest.actions.listWorkflowRunsForRepo (reusing the 10-page listWorkflowRunsForSha pager under withApiBackoff) and classify each listed workflow's runs in classifyEditedRerunSuites: a run matches the current edit stamp when its display_title starts with '[' + context.payload.pull_request.updated_at + '] ', and every other run of that workflow is stale. If any workflow in editedRerunWorkflows has more than one run (in any status, including cancelled or completed) matching the current edit-stamp prefix (ambiguousWorkflows), fail closed at once via core.setFailed naming the workflow(s) and stamp and instructing the author to edit the pull request again (any title or body change re-stamps it) or push a commit. Otherwise add every stale run's check_suite_id to excludedSuites in newestByName, log the excluded stale-suite count via core.info, keep polling through registrationGraceDeadline while any workflow in editedRerunWorkflows has no current run, and fail closed with core.setFailed naming the workflow file (the Rules workflow did not start for this edit) if still absent past the grace. Even when a single edit-stamped run is already green, do not exit the edited poll loop until a listWorkflowRunsForRepo listing started after registrationGraceDeadline (editedListingStartMs > registrationGraceDeadline), logging the grace wait via core.info meanwhile, so a later same-second duplicate run that registers within the 2-minute grace is listed and fails closed as ambiguous.

Alternatives considered

Option Pros Cons Why not chosen
Option a: trigger on edited, anchor at latest ready_for_review or pull_request.created_at, and correlate editedRerunWorkflows suites by run-name edit-stamp prefix Re-judges current-edit governance gates alongside ready-head build checks; correlates each edited aggregator run with the Rules run of the same edit; preserves draft-era exclusion One extra aggregator run, one timeline API query, and one workflow-runs listing per edited-event poll; Rules run titles start with the edit stamp Chosen; satisfies branch protection without re-running build matrices or admitting earlier Rules results
Option b: reuse the previous aggregator verdict and re-check only rule-enforcement.yml gates Avoids reading the issue timeline when a prior completed verdict exists Ref-scoped cancel-in-progress cancels an in-progress aggregator when an edit lands mid-run, leaving no completed verdict to reuse Rejected: cancel-in-progress leaves no verdict to reuse
Option c: leave required-aggregator.yml triggers as is Zero extra aggregator runs on PR edits Title or body edits turning governance gates red leave the required check green (UNSTABLE, not BLOCKED), allowing forge-button merge Rejected: forge-button merge on UNSTABLE
Option d: disable minCreatedMs on edited runs No timeline API call required Admits skipped or stale draft-era GitHub Actions check runs from before the pull request became ready for review Rejected: re-opens the draft-era masking gap
Option e: anchor only, no stale-suite exclusion Avoids listing workflow runs on edited-event polls Earlier rule-enforcement.yml runs on the same head SHA remain inside the ready_for_review window; if the aggregator polls before the edit's Rules run registers its gate jobs, stale green gate runs satisfy newestByName before the edit's gate fails Rejected: race re-opens the UNSTABLE merge gap
Option f: 60-second creation floor (created_at >= ownCreatedMs - 60 s) Correlates editedRerunWorkflows runs without setting run-name on rule-enforcement.yml Two edits less than 60 seconds apart place the earlier edit's Rules run inside the floor; if its gates finish green before the later edit's Rules run registers, missingWorkflows is empty and the aggregator passes on the superseded PR text (PR 3466 review) Rejected: two edits inside the margin admit the earlier edit's suite (PR 3466 review)

Consequences

  • Positive: editing a pull request's title or body re-runs Required Checks Aggregator; a red Deliverables Checklist, docs/state.md Gate, or DCO Sign-off check turns the required context red (BLOCKED), stale Rules suites from earlier events or rapid consecutive edits on the same head SHA cannot satisfy or mask the edit, same-second duplicate stamps fail closed instead of admitting an earlier edit's checks, and a valid edit counts earlier ready-head build and test runs and stays green. Draft-era GitHub Actions check runs older than ready_for_review minus two minutes remain excluded, and timeline errors, workflow-runs API errors, missing timestamps or edit stamps, ambiguous same-second stamps, or an unstarted Rules run fail closed.
  • Negative: every pull-request title or body edit, including automated bot body edits, triggers one extra Required Checks Aggregator polling run, one paginated timeline API read (listEventsForTimeline), and one paginated workflow-runs API read (listWorkflowRunsForRepo) per edited-event poll. Rules workflow run titles start with the "[<updated_at>] " edit stamp, and because pull_request.updated_at has one-second resolution, two edits within the same second share a stamp: when more than one run of a workflow in editedRerunWorkflows (in any status, including cancelled or completed) carries the current edit-stamp prefix, the aggregator fails closed immediately rather than guessing which run judged the latest PR text, requiring another pull-request edit (any title or body change re-stamps it) or a commit push to clear; revisit this fail-closed rule when GitHub exposes a sub-second timestamp or per-event edit id on workflow runs. Every edited aggregator run also polls for at least the 2-minute registration grace before trusting an edit-stamped run, while a same-second duplicate run that registers only after registrationGraceDeadline is not seen by that aggregator run; its own Rules checks still report on the head commit.
  • Neutral / follow-ups: push, workflow_dispatch, opened, synchronize, reopened, and ready_for_review runs keep their existing own-run anchor, 2-minute registration grace, tier exemptions, and ADR-3539 external-app handling with no extra workflow-runs API calls. scripts/ci/required_aggregator_harness.py and scripts/ci/tests/test_aggregator_edited_window.py cover edited pass/fail paths, rapid two-edit correlation and masking, same-second duplicate-stamp fail-closed rejection, the edit-stamp prefix boundaries, missing own updated_at, static editedRerunWorkflows trigger and run-name sync, draft-era exclusion, multiple ready_for_review transitions, pagination, and transient/permanent API failures, while scripts/ci/check-workflow-size.py and scripts/ci/tests/test_check_workflow_size.py guard workflow YAML scalars against actions/runner's 21,000 UTF-16 code-unit expression limit after .NET Char.IsWhiteSpace expression trimming.

References