Skip to content

Add event-driven PR workflow labels - #3786

Open
wasphin wants to merge 12 commits into
apache:masterfrom
wasphin:add-pr-workflow-labels
Open

wasphin wants to merge 12 commits into
apache:masterfrom
wasphin:add-pr-workflow-labels

Conversation

@wasphin

@wasphin wasphin commented Nov 29, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

Open PRs need a filterable indication of their next action so authors,
reviewers, AI agents and maintainers can hand work back and forth without
losing track of pending reviews or decisions.

Implements the workflow discussed in
#3719 using ordinary GitHub Actions,
without a hosted AI triage service, shared personal AI token or per-PR command.

What is changed and the side effects?

Changed:

  • Define six next-action status labels in a portable review skill and document
    them in CONTRIBUTING.md. Add an interactive agent entry point for the skill.
  • Synchronize lifecycle events, formal review notifications and author replies
    using deterministic API checks. Maintainers retain semantic review decisions
    and final merge readiness; the workflow never approves or merges a PR.
  • Receive fork review notifications through a read-only relay. Label writes use
    default-branch code and do not execute PR code or consume workflow artifacts.
  • Track the head accepted as ready to merge and revoke stale readiness after a
    head change or an unmet required merge condition.
  • Rotate through at most 20 PRs per batch. Skip PRs without workflow labels
    after 90 days without updates, configurable through PR_WORKFLOW_IDLE_DAYS.
    Existing workflow states, direct events and explicit PR requests bypass this
    age filter.
  • Add 40 functional regression cases and a dedicated workflow to run them.

Side effects:

  • The status workflow needs the built-in token's pull-requests write permission
    to manage labels and readiness bookkeeping comments. Semantic interpretation,
    AI review scheduling and abandoned-review detection remain manual.
  • Performance effects: Adds event-driven Actions and a half-hourly bounded
    reconciliation batch; no impact on the brpc runtime.
  • Breaking backward compatibility: None for brpc APIs or runtime behavior.

Check List:

Track the next PR action with ordinary GitHub events instead of hosted
AI triage and a shared personal token. Keep semantic review and merge
acceptance with reviewers and maintainers.

Use default-branch code for label writes, relay fork review notifications
without privileged PR execution, and invalidate readiness when the head
or required merge conditions change.
Default batch enrollment to PRs updated within 90 days, configurable via
PR_WORKFLOW_IDLE_DAYS. Keep existing workflow states under observation
and always process direct events and explicit PR requests.
Upgrade github-script to v8 to avoid the Node.js 20 deprecation warning
seen in the demo workflow. Keep the runtime update separate from PR
eligibility changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can leave the ready-to-merge label in place despite outside or unauthorized feedback and can abort classification of non-collaborator reviews.

4 open issues
What changed in this PR

Adds an event-driven GitHub Actions workflow for tracking pull-request next actions through standardized status/* labels while keeping review interpretation and merge decisions with maintainers.

Changes:

  • Documents six workflow states, handoff rules, and triage guidance.
  • Adds trusted lifecycle, review-signal, readiness, and reconciliation workflows.
  • Implements deterministic synchronization with regression tests.
File Description
CONTRIBUTING.md Documents the six PR workflow labels and review handoff rules in English and Chinese.
.github/​workflows/​pr-workflow-checks.yml Runs regression tests for the PR workflow implementation.
.github/​workflows/​pr-status-label.yml Coordinates lifecycle, review, CI, scheduled, and manual synchronization using trusted default-branch code.
.github/​workflows/​pr-review-signal.yml Relays pull-request review activity without privileged permissions or pull-request code execution.
.github/​skills/​pr-workflow/​SKILL.md Defines workflow states, review handoffs, and GitHub usage guidance.
.github/​scripts/​pr-status-label.test.cjs Provides functional regression coverage for lifecycle, review, readiness, concurrency, batching, and security behavior.
.github/​scripts/​pr-status-label.cjs Implements PR selection, label transitions, review handling, readiness tracking, and merge-condition checks.
.github/​agents/​pr-triage.agent.md Adds a read-only interactive entry point for PR workflow triage.

Review effort: Lite

Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Require write, maintain or admin permission before recording the head
accepted as ready to merge. A triage-only labeler must hand the decision
to a maintainer. Treat missing collaborators as untrusted and propagate
other permission lookup failures.
Return a ready PR to maintainer evaluation after a new COMMENT review
or outside changes request. Preserve readiness after optional positive
reviews; trusted unanswered changes requests still route to the author.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Fork-controlled relay titles can manipulate another PR’s handoff or readiness, while missing check/status read permissions can prevent reliable readiness verification.

3 open issues
8 previously missed issues

In code that hasn't changed since last review

Medium severity Treat BEHIND as a reason to revoke merge readiness

.github/​scripts/​pr-status-label.cjs:204

When branch protection requires an up-to-date branch, a base-branch update can produce BEHIND while the current head's checks and approvals still pass. This condition preserves status/ready-to-merge despite that unmet merge requirement. Include BEHIND among the states that return the PR to awaiting-maintainer.

Medium severity Preserve authorized readiness labels during label swaps

.github/​scripts/​pr-status-label.cjs:228

A label swap can run its unlabeled job before the readiness labeled job, so this missing-tracker branch removes a maintainer decision that has not been recorded yet. The same loss occurs when the readiness event first encounters conflicting labels at line 147. Recover the authorized label application and its accepted head before treating a missing tracker as stale, while still rejecting unauthorized or superseded readiness.

Medium severity Ignore author replies that predate the active handoff

.github/​scripts/​pr-status-label.cjs:240

A queued author comment can run after a newer awaiting-author handoff and incorrectly clear its unanswered feedback; the review-signal path also reuses historical replies at line 298. Compare response timestamps with the active handoff or changes request before transitioning, rather than checking only author identity or whether any reply exists.

Medium severity Requeue superseded review handoffs after a head update

.github/​scripts/​pr-status-label.cjs:256

If the current review finishes on the old head after a push, this return discards its completion, while the push handler and routine scans retain review-in-progress. The revised PR can then remain outside the review queue although that handoff has ended. Track the head covered by the active review and return only superseded handoffs to ready-for-review, preserving any newer accepted review.

Medium severity Do not treat edits to old reviews as current review completion

.github/​scripts/​pr-status-label.cjs:263

The relay runs for edits as well as submissions, so workflow_run.created_at can make an old submitted review look newer than the current handoff. Editing that old COMMENT review can then end a newly accepted review by moving review-in-progress to awaiting-maintainer. Preserve and validate the review-event action, then distinguish edited feedback from completion of the current review while retaining dismissal handling.

Medium severity Detect review-thread replies as author responses

.github/​scripts/​pr-status-label.cjs:284

Author review-thread replies are not returned by issues.listComments, so answered feedback stays in or returns to awaiting-author. Include those replies in response detection, and relay pull_request_review_comment through the read-only notification workflow (.github/workflows/pr-review-signal.yml:25) so the handoff runs when they arrive.

Medium severity Validate review withdrawals against the active blocking request

.github/​scripts/​pr-status-label.cjs:290

An approval on a revised head leaves awaiting-author set because currentReviews omits that reviewer's previous changes request. Conversely, any dismissal is considered a withdrawal, so dismissing an unrelated approval clears a newer author handoff. Determine withdrawal from the prior formal opinion and the blocking request behind the current handoff, using dismissal history when needed.

Medium severity Prevent concurrency from dropping unprocessed PR events

.github/​workflows/​pr-status-label.yml:85

cancel-in-progress: false still allows a newer job to replace an older pending job in this group. A CI completion can therefore discard a review, author-reply, or readiness-label event, while routine scans preserve explicit states and never recover its handoff. Keep per-PR writes serialized, but reconcile unprocessed activity from durable API history or use a queue that does not drop these events.

4 resolved since last review

Review effort: Max (adaptive)

Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/workflows/pr-status-label.yml Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Allow pending per-PR jobs to queue rather than replacing one another.
Grant the sync token the check and status read permissions required by
its merge-readiness query.
Use GitHub-owned PR associations only to select work. Relay titles and
run times must not authenticate review activity or replay old feedback.
Reconcile reviews, dismissals and author replies against label history
so scheduled scans can recover missed notifications.

Record accepted review heads, preserve newer tasks and account for label
swap ordering without inventing a head accepted for merge. Keep author
self-reviews separate from independent reviews and enforce strict branch
update requirements only when branch protection or rulesets enable them.
@wasphin

wasphin commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Addressed the latest review in 2b740e3 and 5ccc570. The three inline findings have individual replies. For the eight additional findings in the review summary:

  1. BEHIND: readiness is revoked when legacy branch protection or a ruleset requires an up-to-date branch. A loose policy does not block an otherwise ready PR solely because it is behind.
  2. Label swaps: an authorized ready-label event records its exact head even during a transient label conflict. If the other swap job runs first, an authorized application gets up to ten minutes for that record; an unconfirmed application then returns to maintainer. A push cannot borrow this grace period, and required merge conditions are still checked while waiting.
  3. Old author replies: replies must postdate the active author handoff. Edits to old replies do not make them new responses. Historical answers can still prevent unrelated later feedback from incorrectly reopening the same request.
  4. Superseded review heads: accepted review labels record the exact head and label-event ID. A changed head requeues that recorded task; a newer acceptance is preserved. Existing labels without a trustworthy head record remain for human judgment rather than guessing their scope.
  5. Edited reviews: the relay no longer subscribes to review edits. Reconciliation uses original submission timestamps and GitHub dismissal history, not workflow creation time, so old edits cannot complete a newer task.
  6. Thread replies: the read-only relay now also wakes on new review-thread comments. Reconciliation reads thread comments and recognizes fresh author responses as requests for verification.
  7. Withdrawals: cross-head approvals and dismissal history are checked against the prior trusted blocking opinion. Unrelated approval dismissals do not clear author work, remaining unanswered requests stay with the author, and manually assigned author questions are preserved.
  8. Dropped pending jobs: per-PR concurrency uses queue: max. Periodic reconciliation also processes API activity newer than the current handoff, recovering missed notifications without replaying older activity.

All 57 functional tests pass locally, along with JavaScript syntax, workflow YAML and skill validation. The added branch-protection GraphQL fields and branch-rules endpoint were also checked read-only. These commits are pushed; live execution of the new privileged synchronization path has not yet been verified.

Comment thread .github/workflows/pr-status-label.yml Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
Comment thread .github/scripts/pr-status-label.cjs Resolved
ASF disables pull_request_target, so manual label and close events were
not received by pr-status-label.yml. Split PR lifecycle notifications
into zero-permission pull_request signal workflows (PR label signal and
PR activity signal) that wake the default-branch workflow_run receiver,
and skip non-status label runs to avoid unnecessary runner usage.
Address PR apache#3786 review feedback and modularize pr-status-label.cjs:
- Resolve fork PRs on workflow_run via head branch/SHA across open and
  closed PRs, and verify PR label signal definitions via 3-way merge-base
  blob comparison so un-rebased PRs still confirm labels safely.
- Bind ready-to-merge confirmations to specific label event IDs, keep
  delayed review-in-progress heads for requeueing (including triage
  reviewers), and tolerate minor PR updated_at timestamp drift.
- Combine merge-readiness checks and review classification into a single
  state decision, prefer populated test-merge check rollups, classify
  existing current-head reviews before requeuing superseded heads, and
  exclude dismissed-only reviews.
- Match thread replies to their owning review via in_reply_to_id, guard
  null review/PR user identities, preserve concurrent manual handoffs on
  post-write readback, and refactor sync() into focused helpers with
  regression tests.
Update .github/skills/pr-workflow/SKILL.md to document the read-only
signal workflows, merge-base signal definition verification, fork PR
association lookup, label-event-bound readiness records, test-merge check
precedence, per-review thread replies, and post-write conflict rollback.
Fix two edge cases in pr-status-label.cjs:
- Verify the target base branch's pr-label-signal.yml blob before
  accepting a matching head blob, so a modified non-default base branch
  cannot supply an untrusted merge result.
- Keep current-head formal opinions from being overwritten by a later
  approval or dismissal targeting an older commit, while preserving
  cross-head withdrawals submitted on the current head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +136 to +137
const prs = await github.paginate(github.rest.pulls.list,
{ owner, repo, state: 'open', per_page: 100 });
}
return !(behindRequired || notPassing
|| ['CHANGES_REQUESTED', 'REVIEW_REQUIRED'].includes(merge.reviewDecision)
|| ['BLOCKED', 'DIRTY'].includes(merge.mergeStateStatus));
const state = current[0];
if (state === BLOCKED) return; // Only its owner can interpret the unblock condition.
const setStatus = async next => {
if (state === next || !unchanged(pr, await readPr())) return;
Comment on lines +400 to +402
const latest = await readPr();
if (!active(latest) || latest.head.sha !== pr.head.sha || statusOf(latest).length) return;
await github.rest.issues.addLabels({ ...args, labels: [next] });
const replyNeedsVerification = allAuthorReplies.some(reply => reply.created_at > boundary);
const unanswered = requests.some(review => !allAuthorReplies.some(reply =>
reply.created_at > review.submitted_at
&& (reply.thread ? reply.reviewId === review.id : requests.length === 1)
Comment on lines +483 to +484
&& (reply.thread ? reply.reviewId === review.id : requests.length === 1)
&& (state !== AUTHOR || reply.created_at > boundary)));

jobs:
notify:
if: github.event_name != 'pull_request' || github.event.action != 'unlabeled' || startsWith(github.event.label.name, 'status/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants