fix(actions): coalesce redundant queued current-head runs - #1645
Conversation
📝 WalkthroughWalkthrough동일한 PR 현재 head에 대한 중복 queued GitHub Actions 실행을 식별하고, 라이브 상태를 재검증한 뒤 취소하는 Python CLI와 Changes현재 PR 헤드 실행 병합
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: 🟠 High · up to This PR adds privileged automation that coalesces duplicate workflow runs, but its current implementation can execute attacker-controlled branch metadata and may cancel a run after it has started. That could disrupt unrelated repository Actions runs, so the PR is not safe to merge until the shell boundary and cancellation race are fixed. Sequence Diagram(s)sequenceDiagram
participant PR as GitHub PR
participant Workflow as current-head-run-coalescer.yml
participant Coalescer as coalesce
participant Actions as GitHub Actions API
PR->>Workflow: opened, synchronize 또는 reopened 이벤트
Workflow->>Coalescer: 저장소, PR 번호, head 정보 전달
Coalescer->>Actions: PR 및 활성 실행 조회
Coalescer->>Actions: 후보 실행과 라이브 상태 재조회
Coalescer->>Actions: 중복 queued 실행 취소
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 2 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Minimum-safe queue-saturation admission record for exact head |
|
Fresh evidence immediately before integration:
Ordinary admission therefore depends on scarce queue capacity that this exact repair is designed to recover. No failing test, security finding, meaningful CHANGES_REQUESTED, provenance defect, or merge conflict is being bypassed. Integration will use the exact expected head SHA; after merge protected |
Root cause
Live exact-head evidence showed duplicate queued sets of the same expensive workflows can survive for one unchanged PR branch/head after PR recreation or draft-state changes. The existing live-ref queue hygiene protects newly pushed authoritative heads, but multiple queued runs with the same workflow identity can still consume scarce hosted capacity while all remain superficially current.
This is causal for downstream repositories including
ContextualWisdomLab/accounting-information-platform, where exact-head Accounting Foundation/reviewer lanes remain queued while repository-owned security/SAST lanes can already be terminal.Repair boundary
This PR adds a trusted
pull_request_targetcurrent-head coalescer foropened,synchronize,reopened,ready_for_review, andconverted_to_draft. It checks out only trustedContextualWisdomLab/.github@github.workflow_shawith persisted credentials disabled, grants only the Actions/contents/PR reads-writes needed for ordinary queued-run cancellation, and never executes PR-head code.Cancellation authority is deliberately narrow: exact head repository/ref/SHA, exact base repository/ref/SHA, PR association, stable numeric
workflow_id, and live queued status must agree. Different open PRs never donate evidence. A closed predecessor may participate only when its live head/base identities exactly equal the successor. The implementation re-fetches active siblings, related PR state and the candidate immediately before ordinary/cancel; it never callsforce-cancel. GitHub exposes no conditional queued-only cancel precondition, so the final GET→POST status race remains an explicitly documented platform limit rather than a claimed atomic guarantee.Current repair state — 2026-09-02
Exact writer head at this refresh:
f6b7e07eb38d5cd7db147d5e506a3e6e0f4bcae7on protectedmain@7683f1da91f1fc9e046660169f1f7ac4aabcc3c6.Current review exposed and the branch has now source-fixed a real normalization defect: workflow-run
pull_requests[*].head.repo/base.repoassociations can use GitHub's minimal embedded repository shape (id,name, canonical APIurl) and omitfull_name, while the live pull-request endpoint supplies the fuller repository object. The old_head_tuple()/_base_tuple()therefore could assign an empty repository identity to otherwise valid Actions associations and preserve duplicate runs indefinitely.TDD lineage is explicit. RED commits first reproduced the minimal Actions representation for both
pull_requestandpull_request_targetand added malformed-host/scheme/query/path fail-closed cases. Production commit74cf4989bd305a76ab18fa85acee73fc7b80d9c3adds_repository_full_name(): a validatedfull_nameis accepted directly; otherwise only a canonicalhttps://api.github.com/repos/{owner}/{repo}URL with no query/fragment is parsed and revalidated._head_tuple(),_base_tuple(), and ordinary workflowhead_repositorymatching use the same normalization. Current doctoring records the two GitHub REST shapes and the bounded normalization contract.The original inline finding is now outdated and has an exact-head source/test reply, but fresh reviewer resolution and exact-head workflow results remain authoritative. Do not treat an outdated thread or queued check as implicit success.
Earlier review convergence retained
Already-addressed current-branch findings include exact-base/open-PR isolation,
pull_request_targetassociation semantics, ready/draft transition triggers, final candidate status re-fetch, refreshed authoritative sibling state, explicitGH_TOKENuse, per-request timeout, shell-injection-safe workflow inputs, and accurate documentation of the unavoidable cancel API race. Those repairs remain subject to revalidation on the final unchanged head.Exact-head evidence boundary
The ordinary security, SAST, CodeQL, Python Security, Secret Scan, SBOM, Scorecard and OSV workflows for the current lineage are queued/non-passing under the same saturated Actions fleet this PR is intended to de-amplify. Predecessor results do not transfer. Integrate only when all substantive findings are resolved and ordinary protected admission on one unchanged head permits it.
No self-approval, synthetic status, force push, destructive rebase, required-check suppression, predecessor-evidence transfer, or generalized administrator bypass is authorized.