Skip to content

fix(ci): 同一 PR 新提交自动取消旧 CI,保留作者双队列 - #73

Closed
efeire wants to merge 3 commits into
mainfrom
codex/cancel-stale-pr-ci
Closed

efeire wants to merge 3 commits into
mainfrom
codex/cancel-stale-pr-ci

Conversation

@efeire

@efeire efeire commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

变更说明 / Change Description

同一个 PR 推送新提交后,取消其旧提交尚未结束的主 CI,避免旧任务继续占用作者队列。现有 ci.yml 完全不变,保留按作者和 PR 编号奇偶划分的两个队列;最新提交仍按原规则排队。

PR synchronize → 独立取消任务 → 核对当前 PR / HEAD → 取消同 PR 的旧 CI
  • 新增一个单 job workflow,仅监听面向 main 的 pull_request_target: synchronize。
  • 只调用 GitHub API,不 checkout、不执行 PR 代码;权限限定为 actions: write 和 pull-requests: read。
  • 优先使用运行的 PR 关联;fork 运行缺少关联时,仅在来源仓库和分支的全部 PR 历史唯一时确认归属。
  • 每次取消前重读当前 PR;迟到事件退出,保护新 HEAD、其他 PR、其他 workflow 和 main push。取消冲突只有在读回已完成时才忽略。

变更类型 / Change Type

  • Bug 修复 / Bug fix
  • CI / 构建 / CI or build

涉及前端 / Frontend Changes

不涉及前端。

验证 / Validation

  • 新增 9 项 Node 行为测试,直接执行 workflow 内联脚本,仅模拟 GitHub API;覆盖分页、空 PR 关联、历史分支复用、连续推送、身份保护和取消竞态。
  • 现有 ci-workflow.test.mjs 33 项测试通过,作者双队列规则保持不变。
  • actionlint 1.7.12 校验新 workflow 通过;git diff --check 通过。
  • 对上游 PR feat(jobs): add native Oracle, OceanBase and Dameng job management t8y2/dbx#13201 的实时 API 做只读回放:实际生产脚本仅选择旧 run 39903908234,保留最新 HEAD 49331b5;取消端点替换为记录器,未取消真实任务。
  • 独立规范与需求审查通过;分支复用误归属回归先失败、修复后通过。
  • Fork PR fix(ci): 同一 PR 新提交自动取消旧 CI,保留作者双队列 #73 的 CI 在 0f601794da 通过:6 个 job 成功、18 个按变更范围跳过,完整 job/step 核对无失败;自动安全审查完成且无发现。
  • 上游 PR fix(ci): 同一 PR 新提交自动取消旧 CI,保留作者双队列 t8y2/dbx#13259 的 CI 对应同一 0f601794da,当前仍在作者队列等待,尚无 job 开始;上游自动审查尚无结论。
  • 在线自动取消验收:workflow 进入默认分支且仓库允许该事件后,需用真实新提交确认旧 run 取消、最新 run 与其他 PR 保留。PR CI 通过不代表该 workflow 已启用。

限制与回退

同一来源分支曾用于多个 PR,且运行缺少 PR 关联时,保留无法确认归属的旧 CI,避免误取消其他 PR。普通取消请求异步生效,不强制终止,也不删除运行记录。撤销新增 workflow 可停止后续自动取消;已经取消的 CI 需要手动重跑。

GitHub 可能出于安全原因不对类似 SHA 的分支名触发 pull_request_target;这些分支不在此单触发器方案的覆盖范围。已核对 自动审查意见 和 官方限制:保留约定的最小单触发器方案,不增加替代触发路径。

关联 Issue / Related Issue

未关联独立 Issue。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T06:12:15.861713Z 0f60179 PR opened
🔒 Security Review ✅ Completed 2026-10-23T06:09:27.414471Z 0f60179 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f601794da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

name: Cancel superseded PR CI

on:
pull_request_target:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cover branches suppressed by pull_request_target

When a fork uses a SHA-like head branch name, GitHub may deliberately suppress pull_request_target runs, as documented in Events that trigger workflows. Because this is the only trigger for the cancellation job, synchronizing such a valid PR leaves its superseded ci.yml run active and queues the new run behind it; add a trusted cancellation path based on an event that is not subject to this branch-name restriction.

Useful? React with 👍 / 👎.

@efeire efeire closed this Oct 25, 2026
@efeire
efeire deleted the codex/cancel-stale-pr-ci branch October 25, 2026 23:53
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.

2 participants