Skip to content

[improvement](workflow) Keep only latest code review per PR - #67119

Open
hello-stephen wants to merge 2 commits into
apache:masterfrom
hello-stephen:codex/code-review-latest-only
Open

[improvement](workflow) Keep only latest code review per PR#67119
hello-stephen wants to merge 2 commits into
apache:masterfrom
hello-stephen:codex/code-review-latest-only

Conversation

@hello-stephen

@hello-stephen hello-stephen commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:

Several high-frequency PR workflows can keep obsolete jobs queued or running after a newer event arrives for the same PR. This wastes GitHub-hosted runner capacity and increases queue latency.

This PR applies per-PR latest-run concurrency to all five measured workflows:

  • Code Review Runner
  • License Check
  • FE Code Style Checker
  • Code Formatter
  • Gitleaks PR Check

Each eligible PR job uses the PR number as its concurrency key and enables cancel-in-progress. The concurrency is job-scoped, so skipped jobs and unrelated events cannot cancel an active PR check. License Check push runs use the unique run id and remain independent.

Code Review Runner additionally requires a first workflow attempt. A failed or canceled review is retried with a fresh /review, preventing a manual rerun of an older workflow from replacing a newer logical review request.

Measured effect

The sample covers the last three complete workdays in CST: 2026-08-20, 2026-08-21, and 2026-08-24.

Methodology:

  • count only jobs that were assigned a real GitHub-hosted runner;
  • bind Code Review Runner issue-comment runs to the exact PR using the eligible /review comment actor and timestamp;
  • group pull-request workflows by their source repository and branch because historical Actions list responses usually omit the pull_requests array;
  • treat an old job as cancellable only when a newer event for the same PR key was created before that job completed;
  • estimate saved runner time from the newer run creation time to the older job completion time, or the full execution time when the old job was still queued.
Workflow Runs/jobs Later same-PR runs Overlapping old jobs Reclaimable runner time
Code Review Runner 213 / 214 102 11 214.5 min
License Check 465 / 465 211 10 11.7 min
FE Code Style Checker 466 / 466 212 13 31.8 min
Code Formatter 466 / 466 212 11 9.8 min
Gitleaks PR Check 330 / 330 150 6 8.2 min
Total 1,940 / 1,941 887 51 276.0 min

Most later same-PR runs were sequential checks after the preceding job had completed and are intentionally not counted as waste. The 51 actual overlaps would have reclaimed approximately 276 runner minutes (4.60 hours).

One overlapping old Code Review workflow was manually rerun and consumed another 37.8 minutes. Requiring a fresh /review removes that stale-rerun path, raising the modeled total to 313.8 minutes (5.23 hours) for this sample.

The long Code Review jobs account for most of the direct runner-time saving. The four shorter checks mainly avoid queued obsolete jobs during bursts, which reduces queue pressure even though their direct minute saving is smaller.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test
      • Parsed all five workflow files with Ruby/Psych.
      • Ran actionlint; findings are limited to the same four Code Review shellcheck findings and the same CheckStyle actions/checkout@v3 warning present on origin/master.
      • Verified all five PR-number concurrency groups and cancel-in-progress policies.
      • Verified non-PR License Check runs fall back to the unique run id.
    • No need to test or manual test.
  • Behavior changed:

    • No.
    • Yes. A newer PR event cancels older jobs from these five workflows for the same PR. Code Review retry requires a new /review request.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary: Cancel an older Code Review Runner job when a newer review is requested for the same PR. Keep concurrency at job scope so unrelated skipped issue comments do not cancel active reviews, and require a fresh review request instead of rerunning an older workflow attempt.

### Release note

None

### Check List (For Author)

- Test: Manual test
  - Parsed the workflow with Ruby/Psych
  - Ran actionlint and confirmed only the four pre-existing shellcheck findings remain
  - Verified the PR-keyed concurrency and first-attempt policy assertions
- Behavior changed: Yes. Only the latest review request for a PR keeps running.
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor Author

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#67119

Problem Summary: Extend per-PR latest-run concurrency from Code Review Runner to License Check, FE Code Style Checker, Code Formatter, and Gitleaks PR Check. PR jobs share a stable PR-number group, while non-PR License Check runs use a unique run id and remain independent.

### Release note

None

### Check List (For Author)

- Test: Manual test
  - Parsed all five workflows with Ruby/Psych
  - Ran actionlint and confirmed only existing baseline findings remain
  - Verified all five PR-number concurrency groups and cancel-in-progress policies
- Behavior changed: Yes. New PR runs cancel older jobs from these workflows for the same PR.
- Does this need documentation: No
@hello-stephen
hello-stephen marked this pull request as ready for review August 25, 2026 11:40
@hello-stephen

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor Author

skip buildall

@github-actions github-actions Bot 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.

Request changes. I reviewed all five workflow changes, every declared trigger/guard, the Code Review Runner finalization tail, the status-sync workflow, recent rerun/dispatch behavior, and a concrete canceled runner execution. Two review rounds converged with no new findings; all candidates were adjudicated, and the six accepted issues are covered by five inline threads.

Critical checkpoint conclusions:

  • Goal and proof: Canonical, normally ordered first-attempt jobs do coalesce, but the change does not guarantee that the newest logical request or current-head validation survives. YAML parsing and the PR's green checks prove basic syntax/execution only.
  • Scope: The diff is small and focused, but Code Review Runner cancellation necessarily reaches unchanged failure, status, telemetry, session, and credential finalizers; those interactions are part of the feature's correctness.
  • Concurrency: GitHub Actions scheduling is the concurrency source; PR reviews/comments/statuses and shared OSS auth are the mutable state. There are no Doris process threads or locks here. Historical reruns, reverse first-attempt admission, raw group keys, and mixed status ownership leave six correctness/lifecycle gaps.
  • Lifecycle and error handling: Expected supersession is treated as a genuine failure, and optional finalizers can consume the forced-cancellation window before required auth persistence. Input/head/base mismatches otherwise fail loudly.
  • Parallel paths and conditions: All four validation workflows, issue comments, manual dispatch, reusable-call scope, skipped events, and License master pushes were checked. Unique prefixes and run-ID fallbacks safely isolate unrelated paths; the accepted issues cover the remaining exceptions.
  • Tests and results: All five YAML files parse, and current checks are green. There is no end-to-end coverage for overlapping same-PR runs, historical attempts, cancellation cleanup, noncanonical manual input, mixed status ownership, or reversed admission.
  • Compatibility, persistence, and data: No Doris runtime configuration, FE/BE propagation, storage/protocol, transaction/EditLog, or data-write behavior changes. GitHub status/comment/review state and OSS auth persistence are the relevant external state and are covered inline.
  • Performance and observability: Supersession can save runner time, but optional cleanup may hold cancellation for nearly five minutes, and the permanent false failure comment is misleading observability. Existing run IDs/logs are otherwise sufficient.

No additional user-provided review focus was supplied. Review status: complete and converged after Round 2.

runs-on: ubuntu-latest
concurrency:
group: fe-code-style-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

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.

[P1] Keep historical reruns out of the current-PR group

These groups are keyed only by PR number, so rerunning an older workflow attempt after head B's check starts lets the old attempt join the same group and cancel (or replace while pending) B's validation. GitHub reruns retain the original GITHUB_SHA/GITHUB_REF, so the replacement still checks head A and cannot restore validation for B. The same issue is present in the new Clang Formatter, Gitleaks, and License Check blocks. Please isolate github.run_attempt > 1 with a run-unique group such as github.run_id; changing only cancel-in-progress does not protect a pending current-head job because the default queue replaces an existing pending member.

runs-on: ubuntu-latest
concurrency:
group: code-review-${{ inputs.pr_number || github.event.issue.number || github.run_id }}
cancel-in-progress: true

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.

[P1] Make expected supersession cancellation-safe

Once a running review has resolved its inputs, a newer request cancels the review step, but the existing always() path treats steps.review.outcome == 'cancelled' as a genuine error. Canceled Doris run 31655483365 concretely posted "Review step was cancelled" to PR 66473 and reset the status to pending. The same run then spent the rest of GitHub's five-minute cancellation window in Litefuse and was killed before session or refreshed-auth sync began; commit 296b8f2bc0d explicitly requires that auth write-back after unrelated review failure because Codex may already have refreshed the credential. Please exclude cancellation from genuine-failure reporting and give refreshed auth a strictly bounded early persistence path (or cooperative/external handoff) before optional telemetry/session work.

jobs:
code-review:
runs-on: ubuntu-latest
concurrency:

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.

[P1] Preserve status ownership across manual supersession

This shared group includes issue-comment runs, which always manage the code-review status, and manual dispatches where manage_status can be set to false. A false-status dispatch can cancel /review after it posts pending, complete its own review, and skip both terminal status writes; code-review-sync-result.yml has no review-completion trigger to repair the stranded status. Please require every replacement admitted to this group to take over status management, or isolate non-status-managing runs until there is an explicit ownership handoff.

code-review:
runs-on: ubuntu-latest
concurrency:
group: code-review-${{ inputs.pr_number || github.event.issue.number || github.run_id }}

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.

[P2] Canonicalize the PR number before admission

inputs.pr_number is a raw string here, and GitHub accepts equivalent forms such as 67119, 067119, and 00067119 for the same pull request. Those supported dispatch/call inputs create different group names, so they can run in parallel with each other or with /review instead of coalescing per PR. Please strictly canonicalize and validate the numeric identifier in a prerequisite resolver, then key this job from its canonical output.

# the latest review for the same PR.
if: >-
inputs.pr_number != '' ||
github.run_attempt == 1 &&

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.

[P1] Fence by logical request order, not concurrency admission order

run_attempt == 1 excludes historical reruns, but two fresh requests still both pass. GitHub documents that concurrency is ordered by when a job starts waiting for the group, not workflow dispatch/event time, and ordering is not guaranteed. If older request A reaches this job after newer B, A becomes the latest entrant and cancels B, preserving A's older focus or explicit head/base inputs. Please add a monotonic latest-request ownership check/fence rather than treating scheduler admission order as request freshness.

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.

1 participant