Repository navigation
ci: gate pull requests on a linked accepted issue - #2274
Conversation
zerob13
left a comment
There was a problem hiding this comment.
The ordinary accepted/unaccepted issue paths pass, and the hosted issue-gate run passed for #2272. Before this can reliably serve as a required merge gate, three acceptance conditions remain:
- A change to the linked issue's priority labels must invalidate the previous eligibility decision, even when the PR head and description are unchanged. Approval or revocation should be reflected before the check is used to permit merge.
- Only an actual same-repository issue with an accepted priority should count. Distinguish issue records from PR records before evaluating their labels.
- Bind the required result to a trusted gate definition independent of the changes under review. Establish that only the trusted evaluation is accepted before making the check required.
These are workflow/merge-policy findings from static review and GitHub's event and status-check contracts. The normal cases were also verified with isolated fixtures, including failure on an unavailable issue API.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
The ordinary cases behave as described. I ran the same script against representative bodies (no link, P3 only, P1, multiple links, Closes, Resolves, Refs, malformed, empty) and got the documented results; bash -n is clean, and the hosted issue-gate run at e376f1d passed (run 45973962152). The claim that this PR exercises the gate is correct: .github/workflows/issue-gate.yml does not exist at base 1997683, and the pull_request run still used the PR's version. The required-check name issue-gate matches the job name and the rule in PR #2273.
I agree with the existing changes-requested review on label re-evaluation, PR records and the trusted gate definition, and do not repeat those findings. One contract conflict blocks this change as written, and three smaller gaps follow.
P2: The required gate removes an exemption AGENTS.md grants
Problem: AGENTS.md:21 allows small mechanical changes (routine dependency updates, typo or formatting fixes) to skip opening a linked issue. The workflow has no exemption: any PR whose body lacks Fixes/Closes/Resolves/Refs #N for a P0/P1/P2 issue fails (.github/workflows/issue-gate.yml:25-49). The PR body defers the exemption decision but also states that issue-gate becomes a required check after merge, and PR #2273 documents the same no-exemption rule (docs/issue-maintenance.md:66-67). Merging and requiring the gate therefore changes a policy that AGENTS.md currently states.
Failure scenario: after the check is required on main, a Dependabot update or a typo fix that AGENTS.md permits without an issue fails issue-gate and cannot merge without creating an accepted issue or a repository-owner bypass. The policy change arrives through CI rather than through the documents that state the policy.
Evidence: .github/workflows/issue-gate.yml:25-49, AGENTS.md:21, CONTRIBUTING.md:30-36, PR #2273 docs/issue-maintenance.md:66-67.
Fix: settle the exemption before making the check required. Either update AGENTS.md and CONTRIBUTING.md in this change to remove the mechanical-change exemption (this needs maintainer agreement because it reverses an accepted rule), or add one explicit escape hatch to the workflow, for example a maintainer-applied skip-issue-gate label checked at job level, and document it. Keep the check non-required until one of those lands.
P3: API failures are reported as policy failures
Problem: .github/workflows/issue-gate.yml:33 treats every gh api failure as a label result. When gh prints the error body to stdout, which it does for HTTP errors, the assignment stores the JSON as $labels; a 404 then logs "Linked issue #N is not accepted: {json}" instead of taking the "could not be read" branch. When every link fails, a 403, 429 or 5xx is reported as "At least one linked issue must carry P0, P1 or P2".
Failure scenario: when every link fails to read, a GitHub API outage, an expired permission, or a rate limit blocks a compliant PR, and the author is told to check the issue number and repository. The check fails closed, but the diagnostic points at the wrong cause.
Evidence: .github/workflows/issue-gate.yml:33-37. Reproduced with the workflow's exact command substitution for a missing issue: gh api repos/arcships/dim/issues/999999 --jq '[.labels[].name] | join(",")' 2>/dev/null || true writes the 404 JSON to stdout, so the variable is non-empty.
Fix: branch on the exit status, for example if ! labels=$(gh api "repos/$REPO/issues/$n" --jq ...); then echo "Linked issue #$n could not be read"; read_failed=1; continue; fi, and print a distinct final error when no link could be read instead of the priority message.
P3: The body regex accepts text that is not a link
Problem: .github/workflows/issue-gate.yml:25 scans the raw body without stripping fenced code blocks, inline code, HTML comments or blockquotes, and it has no left word boundary. Fixes #2272 inside a code fence, <!-- Fixes #2272 --> and even prefixes #2272 all satisfy the gate. A keyword also captures only one reference, so Fixes #1257 and #2272 checks #1257 alone.
Failure scenario: a body that quotes an example passes the gate without linking an issue, and a body that lists two issues after one keyword can fail even when the accepted issue is the second reference.
Evidence: .github/workflows/issue-gate.yml:25. Local runs: a fenced Fixes #2272 and prefixes #2272 both exit 0; Fixes #1257 and #2272 (with #2272 P1 and #1257 P3) exits 1.
Fix: strip fenced code blocks, inline code, HTML comments and blockquote lines before matching, and add a leading boundary, for example (^|[^[:alnum:]])(fixes|closes|resolves|refs):?[[:space:]]+#[0-9]+. For multiple references, either document that each issue needs its own keyword or collect all #[0-9]+ after a keyword. If you prefer GitHub's own semantics over a regex, read closingIssuesReferences for Fixes/Closes/Resolves and keep the regex only for Refs.
P3: Unused token permissions
Problem: The job requests contents: read and pull-requests: read but does not check out the repository, and it reads the PR body from the event payload and issue labels from the issues endpoint.
Failure scenario: none at runtime, but a required check that runs on every PR, including fork PRs, grants more token scope than it uses.
Evidence: .github/workflows/issue-gate.yml:7-10, :20-33.
Fix: keep only issues: read.
At e376f1d, issue-gate passed (run 45973962152); the other check runs are green except verify (linux), which was still in progress when I checked.
REQUEST_CHANGES
|
Thanks. The three acceptance conditions are real: a priority-label change must re-evaluate linked PRs, only an actual same-repository issue should count, and the required check must use a trusted definition rather than the PR head. I will address them with an |
|
Pushed |
zerob13
left a comment
There was a problem hiding this comment.
The PR-versus-issue case and trusted base checkout check out. Two original acceptance conditions remain for using this as a merge requirement:
- The PR-event and issue-event paths do not establish a single trusted result on the same current PR revision (
scripts/issue-gate.mjs:180–226). Acceptance: opening, editing or updating a PR and changing its linked issue labels all refresh the same check recognized by the merge policy, with trusted workflow provenance. - A revoked eligibility decision is not reliably invalidated (
scripts/issue-gate.mjs:107–116,207–226). Acceptance: on an unchanged PR, removing the last accepted label revokes success and adding it back restores success; evaluation completion order and refresh errors must not leave a stale green result eligible for merge.
Six isolated tests and exact PR CI passed. Hosted execution of both event paths on the trusted workflow remains unverified. Validate that behavior with the check advisory before configuring it as required.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
The trusted-definition rewrite is sound. pull_request_target runs the default-branch workflow, the checkout is the default branch with persist-credentials: false, no PR code is checked out or run, and event data reaches only numbers and label strings, never a shell or an API path with attacker text. I ran node --test scripts/issue-gate.test.mjs (6 pass) and ran the script against a local fake GitHub API for the ordinary paths.
The earlier points on the trusted definition, issue-versus-PR records, token permissions, and the parser's fences, inline code, comments, quotes, left boundary and multiple references are fixed and withdrawn. The earlier API-failure diagnostic point is fixed for linked-issue reads and GraphQL errors. I agree with the existing changes-requested review that the PR-event and issue-event paths must converge on one trusted check and that a revoked label must not leave a stale green result; I do not repeat those findings. The exemption point is still open, and two unique findings and one optional note follow.
P2: Unbounded references make the gate issue one API request per number
Problem: parseRefs collects every #N on any line that contains a keyword, and evaluate fetches every number sequentially. It does not stop at the first accepted issue, even though one accepted issue is enough. The body is untrusted.
Failure scenario: a body with Fixes #1 #2 ... #1500 makes 1500 issue GETs. Within the 5 minute job timeout that can exhaust the repository's REST budget, causing 403s for other gate runs and other workflows, and on the issues path a timeout leaves later PR checks stale. The 120-reference local run made 120 issue GETs and fetched the accepted issue last.
Evidence: scripts/issue-gate.mjs:20-24, :142-165; .github/workflows/issue-gate.yml:19.
Fix: cap the parsed numbers at a small count such as 20, dedupe, return success on the first accepted issue, and cap the check summary. The closing-reference list is already bounded at 50.
P2: The no-exemption gate still precedes the documents that grant the exemption
Problem: this PR does not change AGENTS.md or CONTRIBUTING.md. At this head, AGENTS.md:21 still allows small mechanical changes to skip an issue, while the gate fails any PR without a linked accepted issue. #2273 removes the exemption and is still open. The PR body states that #2273 removes it and lists adding the required check as an after-merge step, but it does not state a merge order.
Failure scenario: this PR merges, a maintainer follows its after-merge step and adds issue-gate as required, and #2273 has not landed. A Dependabot update or a typo fix that AGENTS.md:21 permits now fails the required check and cannot merge.
Evidence: .github/workflows/issue-gate.yml:3-7, AGENTS.md:21, #2273 docs/issue-maintenance.md:64-67, and the PR body's "After merge" section.
Fix: state the order in the PR body and keep the check non-required until #2273, or an equivalent AGENTS.md/CONTRIBUTING.md change, is on main. If the intent is to land this first, add a documented maintainer escape hatch instead of relying on a future PR.
P3: Cross-repository timeline sources are looked up as base-repository PR numbers
Problem: getLinkedOpenPrs accepts every cross-referenced event whose source is an open pull request, without checking source.issue.repository_url. It then passes source.number to /repos/<base>/pulls/<number>. For a source in another repository, that number belongs to the other repository.
Failure scenario: a pull request in another repository references issue #50. A maintainer removes P1 from #50. The issues run evaluates the base repository's same-numbered PR, writes a check computed from that PR's own body, or fails with a 404 and exits 1. The run reports a result unrelated to the label change, and the foreign source is never evaluated. A foreign PR is outside this repository's gate, so it should be skipped explicitly rather than resolved against the base repository.
Evidence: scripts/issue-gate.mjs:107-116, :209-219. Local fake API: a cross-repository source numbered 77 produced a check run on base PR #77's head.
Fix: compare source.issue.repository_url with the base repository and skip other repositories, or resolve source.pull_request.url and use the source head SHA, and state that foreign PRs are not gated. If fork sources are unsupported, state that limitation instead of resolving them incorrectly.
At ec5ec17, all check runs pass: changes, static-checks, scripts, dependencies, web, windows-cli, macos-native, verify (linux) and ci-ok; acp-registry skips. issue-gate does not run at this head, which matches the PR body. .node-version is 24.21.0 on the base branch and the checkout and setup-node pins match the pins already used by ci.yml. The PR is mergeable with no conflicts; the blocked state is the outstanding change requests.
REQUEST_CHANGES
| for (const event of events) { | ||
| if (event.event !== 'cross-referenced') continue; | ||
| const source = event.source?.issue; | ||
| if (source?.pull_request && source.state === 'open') numbers.add(source.number); |
There was a problem hiding this comment.
P3. source.number is resolved against the base repository. source.issue.repository_url can point at another repository, so a cross-repository reference evaluates the base repo's same-numbered PR or 404s, while the foreign source is outside this gate. Filter source.issue.repository_url or resolve source.pull_request.url, and state the limitation.
| const accepted = []; | ||
| const rejected = []; | ||
| const unreadable = []; | ||
| for (const number of numbers) { |
There was a problem hiding this comment.
P2. numbers comes from the untrusted PR body with no cap and the loop never exits early, so each number is one sequential issue GET. Cap the list and return on the first accepted issue.
|
Thanks for the re-review. The remaining items are accepted as implementation work, not product changes: (1) make the PR-event and issue-event paths publish/refresh one trusted |
|
Pushed |
zerob13
left a comment
There was a problem hiding this comment.
The two event paths now update one check on the current PR head; an isolated P1 → P3 → P1 sequence passed. Two freshness cases still block reliable rollout:
- The new repository-wide workflow cancellation can drop an outstanding refresh for an unrelated PR (
.github/workflows/issue-gate.yml:15–17). Acceptance: unrelated PR updates do not discard label reevaluations, and each linked PR reaches the current verdict without staying stale or pending. - An API error before reevaluation begins still leaves the previous successful check in place (
scripts/issue-gate.mjs:206–251,298–323). The isolated unavailable-API case reproduces this; errors after marking in-progress correctly fail. Acceptance: stale approval is not eligible after an unsuccessful refresh, and recovery allows reevaluation.
Eight script tests passed. The PR's Web job failed during checkout, before Web tests. Hosted verification of the two trusted event paths and provenance is still a separate condition for making the check required.
|
Both freshness cases are valid. I will replace the repository-wide concurrency group with per-PR and per-issue groups so an unrelated update cannot cancel a refresh, while a label event still reevaluates every linked PR. I will also move the in-progress marker ahead of the check-run lookup that can fail, with a fallback that creates a fresh in-progress check for the issue path, so an unsuccessful refresh cannot leave the previous success eligible. Both cases need regression coverage. The Web job failed at checkout on runner R3E-3 with a |
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
The PR now runs the gate from a trusted default-branch workflow, reuses one issue-gate check on the PR head for PR events and issue label changes, and bounds reference reads. The trusted definition, issue versus PR records, cross-repository filtering, the reference cap and first-accepted return, the summary cap, API diagnostics, token permissions, and parser stripping are fixed and withdrawn.
My earlier exemption point is withdrawn. The PR body now states that #2273 lands first and that issue-gate stays non-required until the AGENTS.md and CONTRIBUTING.md change from #2273 is on main, and #2273 is approved and open at d9b081c. The single-check path holds on the normal path: against a local fake GitHub API, an issues event on an unchanged head found the PR-event check by external_id and patched the same run. I agree with the existing changes-requested review on the repository-wide cancellation and the pre-begin refresh window; I do not repeat those findings.
P3 (optional): Closing references consume the reference cap before body references
Problem: parseRefs stops at 20 (scripts/issue-gate.mjs:27), and the union is sliced with closing references first at scripts/issue-gate.mjs:142. An accepted issue beyond the cap is never read, so a compliant PR fails.
Failure scenario: a PR closes issues #1 to #20, all P3, and its body has Refs #21 with #21 at P1. numbers is sliced to #1 to #20, #21 is never fetched, and the check fails with "No accepted issue". A body with 25 references and the accepted issue at position 21 fails the same way.
Evidence: scripts/issue-gate.mjs:27, :142. Local fake API: 20 issue GETs, #21 never requested, conclusion failure.
Fix: cap body references and closing references separately, for example 20 body references plus the closing references, or cap the union at a larger bound, and keep the first-accepted return.
Optional note: pages at scripts/issue-gate.mjs:68-76 has no page bound, and the issues path evaluates every linked open PR with one check update and up to 20 issue GETs each inside a 5-minute job (scripts/issue-gate.mjs:299-321, .github/workflows/issue-gate.yml:23). A long timeline or many linked PRs can time out before later checks are marked, leaving their old results. Cap the pages and linked PRs.
At 92f318f, changes, dependencies, static-checks, scripts, windows-cli and macos-native pass; acp-registry skips. scripts runs node --test scripts/*.test.mjs, so the eight parser and filtering tests pass. web failed in actions/checkout on a self-hosted Windows runner before any test step, which is unrelated to the three changed files. verify (linux) was still running when I checked, and ci-ok has not completed. issue-gate does not run at this head, which matches the PR body. The PR is mergeable with no conflicts; the block is the outstanding change requests.
REQUEST_CHANGES
| }; | ||
| } | ||
| const refs = parseRefs(pr.body); | ||
| const numbers = [...new Set([...closing, ...refs])].slice(0, MAX_REFS); |
There was a problem hiding this comment.
P3 (optional). Closing refs fill the cap before body refs. parseRefs already stops at 20, and this line slices the union with closing refs first, so an accepted Refs #21 is never read when 20 closing refs exist. Cap body refs and closing refs separately, or cap the union at a larger bound.
|
Pushed |
zerob13
left a comment
There was a problem hiding this comment.
Unrelated refreshes no longer cancel one another, and the normal downgrade/restore sequence updates one check. Two parts of the freshness acceptance remain:
- Concurrent PR and label refreshes must agree on which outcome is current for the same PR. Their independent event groups do not yet establish freshness at the shared check (
.github/workflows/issue-gate.yml:15–17;scripts/issue-gate.mjs:286–331). Acceptance: overlapping refreshes cannot replace a newer eligibility decision with an older one, while unrelated PRs complete independently. - If linked-PR discovery fails before a label refresh can start, the previous successful check stays unchanged even though the workflow itself fails (
scripts/issue-gate.mjs:308–331). Isolated API-unavailable tests reproduced it. Acceptance: the old decision does not remain eligible when refresh cannot establish current state, and recovery leads to reevaluation.
Eight script tests passed in the ordinary PR workflow. Hosted verification of the trusted event paths and required-check provenance remains separate from this unit-test evidence.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
The PR now runs the gate from a trusted default-branch workflow, scopes concurrency by the event's issue or PR number, evaluates PR events from the event payload, and creates a fresh check when the check-run lookup fails. The trusted definition, issue versus PR records, cross-repository filtering, parser stripping, API diagnostics, token permissions and the exemption order remain fixed, and those points are withdrawn. The PR path marks the check in progress before evaluation and handles a null body, and the label add, remove and re-add sequence works on an unchanged head. I agree with the existing changes-requested review on the same-check freshness between PR and label refreshes and on the discovery failure before a label refresh; I do not repeat those findings.
P3 (optional): A failed lookup can create a second check with the same name
Problem: A findCheckRun error is swallowed (scripts/issue-gate.mjs:226-229), so beginCheckRun creates a new run (:242-253). Two runs named issue-gate with external_id issue-gate:77 then exist on the same head. GitHub does not document which same-named run a required check uses, and the list endpoint's default latest filter is not specified for an in-progress duplicate. If a list returns both runs, findCheckRun takes the first match (:212-215).
Failure scenario: a check-run list 500 occurs while the verdict is success, so a duplicate green check is created. P1 is removed later. If the list returns both runs, the script patches the older run to failure and leaves the newer green run untouched. If the required check uses the newer run, the revocation is invisible. Local fake API: a list that returns both runs made the script patch id 1 to failure and leave id 2 green; the default-latest model patched the newer run.
Evidence: scripts/issue-gate.mjs:206-255. Fake API cases pr-checkruns-list-500-create (two checks) and duplicate-all-mode (older patched, newer green).
Fix: request filter=all, pick the newest matching run explicitly, and bring every matching run to the same conclusion. Do not rely on response order or the default filter.
P3 (optional): Closing references still fill the cap before body references
Problem: parseRefs stops at 20 (scripts/issue-gate.mjs:6), and the union is sliced with closing references first (:142). An accepted issue beyond the cap is never read.
Failure scenario: a PR closes #1 to #20, all P3, and its body has Refs #21 with #21 at P1. #21 is never fetched and the gate fails.
Evidence: scripts/issue-gate.mjs:6, :142. Local fake API: 20 issue GETs, #21 never requested, conclusion failure.
Fix: cap body references and closing references separately, or cap the union at a larger bound.
The unbounded pages (:68-76) and the sequential per-PR loop (:316-330) are unchanged; a long timeline or many linked PRs can exceed the 5-minute job and leave later checks stale.
At 33d5e30, changes, dependencies, macos-native, scripts, static-checks, web and windows-cli pass; acp-registry skips; verify (linux) is still running and ci-ok has not completed. scripts runs the eight tests, and node --test scripts/issue-gate.test.mjs passes 8/8 locally. The committed tests cover the parser only; the check lifecycle has no committed test. issue-gate does not run at this head because the workflow is new and not on the default branch. The PR is open and reports mergeable true with no conflicts; main has moved from 1997683 to 7d9148b with the docs-only #2278 merge, which does not touch these files. #2273 is still open at d9b081c.
REQUEST_CHANGES
| title: 'Evaluating linked issue', | ||
| summary: 'Checking the PR body and linked issue labels.', | ||
| }; | ||
| const existing = await findCheckRun(pr).catch((error) => { |
There was a problem hiding this comment.
P3 (optional). A failed lookup creates a duplicate check. Swallowing the list error and creating a new run leaves two issue-gate checks with the same external_id on one head. If a later list returns both, findCheckRun takes the first match (:212-215), so a revocation can patch the older run while the newer green one remains; which same-named run a required check uses is undocumented. Request filter=all and complete every matching run to the same conclusion, or select the newest explicitly.
|
Pushed |
zerob13
left a comment
There was a problem hiding this comment.
Re-reviewed 49221d410d24ff54587b96b589eaf67e20153a6f. The per-PR evaluation groups and the discovery fallback improve isolation and recovery. The two freshness acceptance conditions from the previous review are still open.
- A settled check must reflect the current PR. The paths now share a concurrency group, but that is not an event-order guarantee, and the PR path still relies on an event snapshot (
.github/workflows/issue-gate.yml:40–77,scripts/issue-gate.mjs:333–355). After overlapping updates finish, the check on the current head must reflect the current PR body, issue relationship, and labels. Refreshes for separate PRs should remain independent. - An incomplete evaluation must not be indistinguishable from a current pass. Discovery or reads can still end before reconciling the existing check (
.github/workflows/issue-gate.yml:34–38,scripts/issue-gate.mjs:120–154). The local API error fixture verified that discovery falls back on a single failure, but does not produce an evaluation when neither read succeeds. For a required gate, an incomplete refresh must be visible and affected PRs must be reevaluated after recovery. If the first rollout cannot guarantee that, keep it advisory, explicitly document the limitation, and verify both hosted event paths before requiring it.
The eight script tests, syntax check and YAML parse passed. In ordinary PR CI, macOS, scripts, Web, static checks and dependencies passed. Windows failed at checkout before testing; Linux was still running. That run does not exercise both hosted gate event paths.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
At 49221d41, the gate now runs from a default-branch workflow, uses the event payload for PR events, evaluates each linked PR in its own matrix job, scopes concurrency to the PR, and bounds pages, linked PRs and references. The trusted definition, issue versus PR records, cross-repository filtering, parser stripping, API diagnostics, token permissions and the exemption order remain fixed, and those points are withdrawn.
The two previous P3 points are fixed. Body references are read before closing references and the two caps are separate; with 20 P3 closing refs and Refs #21 at P1 the gate reads and accepts #21 (scripts/issue-gate.mjs:168-169). findCheckRuns requests filter=all, sorts by id and patches every own run (scripts/issue-gate.mjs:233-253, :266-281, :298-311); with two own runs both now reach the same conclusion. The unbounded page loop and the sequential per-PR loop are gone: pages stop at 10, discovery returns at most 20 linked PRs, and the matrix isolates one PR per job with fail-fast: false. Those points are withdrawn.
I agree with the existing changes-requested review on the freshness and incomplete-evaluation points, including the pre-begin failure window; I do not repeat them.
P3: The discover step hides a failed discovery
Problem: run: echo "prs=$(node scripts/issue-gate.mjs --discover)" >> "$GITHUB_OUTPUT" returns echo's exit status, so a non-zero node exit leaves prs= and a green discover job (.github/workflows/issue-gate.yml:38). The if at :68 then sees needs.discover.result == 'success' and an empty value that is not '[]', and fromJSON at :74 fails the matrix job.
Failure scenario: the timeline read fails and the fallback scan also fails. The workflow shows a green discover job and a matrix expression error, not the discovery failure the if is meant to gate, and no check is updated. Under bash -e, echo "prs=$(node ...)" exits 0 when the substitution fails.
Fix: capture the output in its own step:
run: |
set -euo pipefail
prs=$(node scripts/issue-gate.mjs --discover)
echo "prs=$prs" >> "$GITHUB_OUTPUT"
P3 (optional): The fallback scans only the newest 20 open PRs
Problem: scanOpenPrsForIssue fetches the open PR list, which is created-desc, and slices the first 20 before checking refs (scripts/issue-gate.mjs:120-124). A PR older than the 20 newest open PRs is not scanned when the timeline read fails.
Failure scenario: the timeline read fails and the repository has more than 20 open PRs; the linked PR is older than the newest 20. Discovery returns without it, and its previous success stays after the label is removed. The repository has 12 open PRs today, so the window is not hit yet.
Fix: page through the open PR list within the 10-page cap, or document that the fallback covers the newest 20 only.
The committed tests still cover only the parser (node --test scripts/issue-gate.test.mjs, 8/8 pass); the fallback, caps and check lifecycle were verified with a local fake API only: timeline failure with a successful scan, timeline failure with a failed scan, a miss beyond the 20-PR window, getPr 500, check list 500 with a duplicate and reconciliation on the next run, two own runs patched to the same conclusion, 20 closing refs plus Refs #21 (passes), 21 body refs with the accepted issue last (fails at the 20-ref body cap, which is the intended bound), the PR event payload path, invalid TARGET_PR, empty discovery, and two issues linking one PR.
At 49221d41, changes, dependencies, macos-native, scripts, static-checks, web and verify (linux) pass; acp-registry skips; windows-cli is in progress after an earlier attempt failed in actions/checkout on a self-hosted Windows runner before any build or test step; ci-ok has not completed while windows-cli runs. The PR is open, not draft, mergeable true with no conflicts. #2273 is open at ce2fed1d and its AGENTS.md, CONTRIBUTING.md and issue-maintenance text match this gate; #2249 is unrelated. issue-gate does not run at this head because the workflow is not on the default branch.
REQUEST_CHANGES
| name: List linked open PRs | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: echo "prs=$(node scripts/issue-gate.mjs --discover)" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
P3. This step hides a failed discovery. echo returns its own status, so a non-zero node ... --discover leaves prs= and a green discover job. The if at :68 then passes the empty value to fromJSON at :74, and the matrix job fails with an expression error instead of the discover job failing. Capture the output in a separate assignment under set -e so the discover job fails and evaluate-issue is skipped.
There was a problem hiding this comment.
Fixed in 69286c3e: the discover step now uses set -euo pipefail and stores the --discover output before writing it, so a failed discovery fails the job and skips the matrix.
| const repository = required('GITHUB_REPOSITORY'); | ||
| const prs = await pages(`/repos/${repository}/pulls?state=open`); | ||
| const linked = new Set(); | ||
| for (const pr of prs.slice(0, MAX_LINKED_PRS)) { |
There was a problem hiding this comment.
P3 (optional). The fallback scans only the newest 20 open PRs. The pulls list is created-desc, so after a timeline failure an older PR that links the changed issue is skipped and its old check stays. The repository has 12 open PRs today, so the window is not hit yet. Page through the list within the 10-page cap, or document the window.
There was a problem hiding this comment.
Fixed in 69286c3e: scanOpenPrsForIssue now pages through all open PRs within the 10-page limit instead of slicing the first 20, and a new test covers a link beyond the newest 20.
zerob13
left a comment
There was a problem hiding this comment.
Re-reviewed 69286c3e57a596009bb4733d476a13ac5d7e8115. Both event paths now evaluate current PR state in the per-PR group, and final-read and total-discovery failures are reported. One part of the earlier failure-recovery acceptance remains.
A partial refresh must be visible and recoverable. Related-PR discovery can finish with an incomplete set while reporting the refresh as complete. Checks that were not updated can then appear current. Acceptance: refresh known PRs independently, make incomplete coverage observable, and reconcile the remaining affected PRs after recovery. Keep this advisory until that behavior and check provenance are verified in hosted event runs.
Ordinary PR CI passed the script checks. Windows failed during checkout before tests, and Linux was still running. This does not verify the hosted gate event paths.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
At 69286c3e, the gate now reads the current PR after the per-PR lock, re-reads it before completing the check, and fails the check when the head, body or state changed during evaluation. It starts or reconciles every issue-gate check before evaluation, completes evaluation and read failures as failures, and pages the fallback scan across all open PRs. The two previous P3s are fixed and withdrawn: the discover step now uses set -euo pipefail and captures the --discover output (.github/workflows/issue-gate.yml:37-40), and the fallback no longer stops at the newest 20 open PRs (scripts/issue-gate.mjs:154-183). The duplicate-check reconciliation and the current-state reads also hold. I agree with the existing changes-requested review on partial discovery and do not repeat it.
P2. A failed initial target read leaves the previous check in place.
Problem: main reads the target PR at scripts/issue-gate.mjs:419 before beginCheckRun at :423. If that GET fails after retries, the process exits 1 without any check-run request, so an existing issue-gate success on the same head is never marked in progress or failed. The final-read test covers only the second current-state read after evaluation.
Failure scenario: an issue label is removed and discovery returns a linked PR. The matrix job then fails to read that PR. The workflow is red, but the PR's previous issue-gate success remains on the head. If the check is later required, that stale success can still satisfy the merge requirement.
Evidence: a local fake API with GET /repos/arcships/dim/pulls/11 returning 500 and one retry attempt made only that request; the script exited 1, printed no result and never called the check-runs API. The PR body says evaluation and read failures complete the check as a failure, but this read happens before the check exists. The documented known limit covers discovery failing before it identifies linked PRs, not a target read failure after discovery.
Fix: start or reconcile the check from a known head before reading the PR. The pull_request_target payload supplies the head for PR events, and discovery can return the head from the open-PR list for issue events. Then a failed target read can complete that check as a failure. Add a test for this initial read failure.
The new tests pass: node --test scripts/issue-gate.test.mjs reports 16 passing tests; node --check scripts/issue-gate.mjs, node --check scripts/issue-gate.test.mjs and git diff --check exit 0. CI at 69286c3e: changes, dependencies, macos-native, scripts, static-checks, verify (linux) and web pass; acp-registry is skipped; ci-ok is queued; windows-cli failed in actions/checkout before any build or test step with could not lock config file .git/config: File exists on the self-hosted runner, which is unrelated to this diff. The PR is open, not draft and mergeable true. issue-gate does not run at this head because the workflow is not on the default branch.
REQUEST_CHANGES
|
|
||
| const target = Number(required('TARGET_PR')); | ||
| if (!Number.isInteger(target) || target <= 0) throw new Error(`Invalid TARGET_PR: ${target}`); | ||
| const pr = await getPr(target); |
There was a problem hiding this comment.
P2. A failed initial target read leaves the previous check in place. This read happens before beginCheckRun at :423. If the GET fails after retries, the process exits 1 without any check-run request, so an existing issue-gate success on the same head is never marked in progress or failed. The final-read test covers only the second current-state read after evaluation. A local fake API with GET /repos/arcships/dim/pulls/11 returning 500 and one retry attempt made only that request; the script exited 1 and never called the check-runs API. Start or reconcile the check from a known head before reading the PR: the pull_request_target payload supplies the head for PR events, and discovery can return the head from the open-PR list for issue events. Then a failed target read can complete that check as a failure. Add a test for this initial read failure.
There was a problem hiding this comment.
Fixed in 097b82832: the check now starts or reconciles from the event or discovery head before the target PR read, and an initial read failure completes that check as a gate error. The new test covers the failed initial read.
Start the check from the event or discovery head before reading the PR, so an initial read failure completes the check as a failure and a head change fails both revisions. Return linked PR heads and a completeness flag from discovery. Known PRs still evaluate; an incomplete scan fails a coverage job, and a re-run after recovery refreshes the remaining PRs. Add tests for the initial read failure, a head change, and partial discovery.
|
Pushed
|
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
At 097b82832, the initial-read fix is present: main starts or reconciles issue-gate from TARGET_HEAD or the event head before getPr (scripts/issue-gate.mjs:454-460), and a failed first read completes that check as a gate error. The new test covers it. The prior partial-discovery finding is addressed for known PRs: discovery returns heads and complete, incomplete scans evaluate the known PRs and fail coverage, and the open-PR list failure is documented. I withdraw that finding. The two earlier P3s remain fixed: the discover step captures the script output (.github/workflows/issue-gate.yml:39-45), and fallback discovery pages all open PRs (scripts/issue-gate.mjs:154-187). I agree with the earlier changes-requested review on the remaining limitation and do not repeat it.
P2. A stale head-change failure can overwrite the current revision's success.
Problem: The new head-change branch at scripts/issue-gate.mjs:462-470 begins and completes a check on the current PR head after detecting that the known discovery head is stale. The current head can already have a completed success from its own pull_request_target event. beginCheckRun(pr) tries to reset that success to in progress and creates a new run if GitHub refuses the transition; finishCheckRun(pr, currentChecks, changed) then writes failure on the current head. The per-PR concurrency group does not order jobs by event time. A delayed issue-event matrix job that starts after the current event has finished still runs; one that starts while the current event is running cancels it because it is the newer job in the group.
Failure scenario: a maintainer removes an accepted label at T0; discover reads linked PR #77 at H1. The author pushes H2 at T1; the synchronize job evaluates H2 and records success at T2 because H2 still links another accepted issue (or the label was restored). The label-event matrix job starts at T3, reads #77 at H2, and completes both the known H1 check and the current H2 check as failure. H2 is now red although its own event passed, and no further event is scheduled.
Evidence: a local fake API with TARGET_HEAD=old-head, a PR read returning current-head and an existing current-head issue-gate success made the script begin the current check and complete it as failure; the script exited 1. In the fixture the existing success was reset to in_progress and then failure; if GitHub rejects the reset of a completed run, a new same-name failure is added instead. The 18 tests do not cover this branch: the only PR-change test edits the body, and no test sets a target head different from the PR head.
Fix: fail only the known-head check and leave the current head to its own event, or evaluate the current head in this run without overwriting a completed current-head check. Add a test with a pre-existing current-head success and a stale TARGET_HEAD.
P3 (optional). Discovery can report complete after skipping a linked PR.
getLinkedOpenPrs reads the open PR list at line 191 and the timeline at line 197. A PR that opens between those reads appears as an open cross-reference but is absent from byNumber; if (!pr) continue at line 221 skips it and complete stays true. I reproduced {"prs":[],"complete":true,"problems":[]} with an empty pulls response and an open cross-referenced source. The fallback has a similar skip for a 404 closing-reference read at lines 166-171. Fix: record a problem and clear complete when a timeline source is missing from the open list, and treat a 404 for a PR that the same run listed as an incomplete read or re-read it.
The suite passes 18/18; node --check for both scripts and git diff --check origin/main...HEAD are clean. CI at 097b82832: all listed jobs pass, including windows-cli; acp-registry is skipped; ci-ok passes. The PR is open, not draft and its head is unchanged. issue-gate does not run at this head because the workflow is not on the default branch.
REQUEST_CHANGES
| title: 'PR head changed', | ||
| summary: 'The pull request head changed before evaluation; the current revision is evaluated by its own event.', | ||
| }; | ||
| const currentChecks = await beginCheckRun(pr); |
There was a problem hiding this comment.
P2. This branch can fail a current-head success without evaluating it. beginCheckRun(pr) tries to reset the check on the current head and creates a new run if GitHub refuses; finishCheckRun(pr, currentChecks, changed) writes failure. A stale issue-event matrix job can start after the current synchronize job has finished, because the per-PR concurrency group only cancels a running job and the issue matrix job may not enter the group before the current event. It reads the new head, enters this branch, and marks the current revision failed although its own event passed. A local fake API with TARGET_HEAD=old-head, a PR read returning current-head, and an existing current-head success reset that check to in_progress and then failure; the script exited 1. If GitHub rejects the reset of a completed run, it adds a same-name failure instead. The tests do not cover this branch. Fail only the known-head check, or evaluate the current head without overwriting a completed current-head check; add a regression test.
There was a problem hiding this comment.
Fixed in 422cf39: the stale-head branch now starts and fails only the known head, so a completed current-head success is not overwritten. A related case, where the same concurrency group cancels the current head's in-flight event and leaves its check incomplete, is raised in the new review.
zerob13
left a comment
There was a problem hiding this comment.
Re-reviewed this head. The known-head initial-read failure and the explicit partial-scan coverage signal are fixed.
Remaining acceptance: a known linked open PR must not be silently skipped. In scripts/issue-gate.mjs:189–229, if the issue timeline identifies a linked open PR that was absent from the earlier open-PR snapshot, discovery can report complete while leaving that PR's check untouched. This leaves the original coverage acceptance open. On inconsistent snapshots, evaluate the identified PR or report incomplete coverage, still refresh independent known PRs, and make a full discovery rerun reconcile the missed PR after recovery. Rerunning only the failed coverage job reuses the old discovery output.
I independently agree with the current-head correctness issue already covered in review 6090384031 and am not repeating it. PR CI and focused offline tests passed; the trusted PR and issue-label event paths are not yet verified on GitHub, so keep the gate advisory.
When discovery returns a stale head, fail only that head's check and leave the current head to its own event. Treat a linked PR missing from the open-PR snapshot, or a closing-reference read failure for a listed PR, as incomplete discovery so the coverage job fails and a full rerun reconciles it. Add regression tests for the stale-head success, missing timeline link and missing closing-reference cases.
|
Pushed
|
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
This PR adds a trusted pull_request_target workflow and scripts/issue-gate.mjs so PR and issue-label events maintain one issue-gate check tied to a linked issue with an accepted P0, P1 or P2 label. It re-reads the current PR after the per-PR lock, reports incomplete linked-PR discovery, and keeps discovery and linked-PR pages bounded.
At 422cf39c, the previous P2 is fixed for the completed-success case: the stale-head branch fails only the known-head check (scripts/issue-gate.mjs:459-473), so an existing current-head success is no longer overwritten. That case is covered by leaves a current-head success untouched when the known head is stale (scripts/issue-gate.test.mjs:589-641). The previous P3 about a linked PR missing from the open-PR snapshot is also fixed by the new incomplete-discovery problems (scripts/issue-gate.mjs:209-230, :160-175), with tests. I withdraw both.
P2. A stale issue refresh can cancel the current head's own PR event and leave its check in progress or missing.
Problem: evaluate-pr and each evaluate-issue matrix entry use the same job-level concurrency group issue-gate-pr-<number> with cancel-in-progress: true (.github/workflows/issue-gate.yml:52-54, :83-85). Job-level concurrency groups are repository-wide across workflow runs, not limited to one run. When the stale branch starts, it begins the known stale head's check, reads the PR, sees the head changed, completes only knownPr, and returns (scripts/issue-gate.mjs:459-473). It does nothing for the current head. If the current head's own pull_request_target job is running or pending at that moment, the issue matrix job cancels it. That job may already have set the current head's check in progress in beginCheckRun (scripts/issue-gate.mjs:348-376) or may not have created it yet. The current head is then left with an in-progress or missing issue-gate check, or with an older success that the cancelled event would have refreshed, and the only job that would complete or refresh it has been cancelled. The issue job exits 1 after failing the stale head, so no completion follows.
Failure scenario: PR #77 is at H1 and a maintainer removes its accepted label at T0; discovery reads H1. The author pushes H2 at T1 and the synchronize run starts, setting the H2 check in progress. The issue matrix job starts at T2 with the stale H1, enters the same group, cancels the H2 run, reads H2, fails H1, and returns. H2's check remains in progress, or is absent if the PR job had not reached beginCheckRun. The same race on an edited event can leave a previous H2 success in place after the body changed, because the cancelled refresh never reset it. No further event is scheduled, so a required issue-gate on H2 is left pending or stale, and the PR is blocked or can merge on an outdated result until someone pushes or reruns.
Evidence: .github/workflows/issue-gate.yml:52-54 and :83-85; scripts/issue-gate.mjs:459-473; beginCheckRun writes status: 'in_progress' at scripts/issue-gate.mjs:365-375; the new test asserts the stale run sends no request for the current head and patches only the known head (scripts/issue-gate.test.mjs:634-640), which is the script side of this gap. It covers a completed current-head success, not an in-progress, missing, or older current check.
Fix: when the known head is stale, evaluate the current head in this run and complete its check, which also makes the label change take effect on the current revision; or ensure the stale refresh cannot cancel the current head's own event, for example by separating the concurrency groups and re-checking freshness. Add a regression test with a current-head check in progress and a stale TARGET_HEAD, asserting the current check reaches a completed conclusion.
Verification at this head: node --test scripts/issue-gate.test.mjs passes 21/21; node --check on both scripts is clean; the workflow YAML parses and lists discover, evaluate-pr, evaluate-issue and coverage; git diff --check origin/main...HEAD is clean. CI: dependencies, static-checks, scripts, macos-native, windows-cli, web and changes pass; verify (linux) is still running. The hosted gate paths remain unverified, as the PR body states.
| title: 'PR head changed', | ||
| summary: 'The pull request head changed before evaluation; the current revision is evaluated by its own event.', | ||
| }; | ||
| await finishCheckRun(knownPr, checks, changed); |
There was a problem hiding this comment.
P2. This return leaves the current head without a completed check when it cancels the current head's own event. evaluate-pr and this matrix job share the job-level group issue-gate-pr-<number> with cancel-in-progress: true (.github/workflows/issue-gate.yml:52-54, :83-85), and such groups are repository-wide across workflow runs. If the current head's pull_request_target job is running or pending, this job cancels it, then fails only knownPr. The current head can keep the in_progress check set by beginCheckRun (scripts/issue-gate.mjs:348-376), have none, or keep an older success, and no event completes or refreshes it. Fix: evaluate and complete the current head here, or prevent this job from cancelling the current event; add a test with a current-head in-progress check and a stale TARGET_HEAD.
zerob13
left a comment
There was a problem hiding this comment.
My discovery finding is resolved at 422cf39ced0577ae727df59f7ecea92681b2c2cc. Discovery now reports incomplete coverage when a known linked open PR is missing from the initial snapshot, still evaluates the PRs it found, and directs maintainers to rerun the full workflow after recovery so discovery runs again. The exact PR check passed.
The separate concurrency review remains open. Keep issue-gate advisory until both trusted hosted event paths are verified.
When the known discovery head is stale, fail that check and evaluate the current head in the same run. This completes the current check even when the stale refresh cancels the current head's own event. Cover a current-head in-progress check with a stale target head.
|
Pushed
|
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
This PR adds a trusted pull_request_target workflow and scripts/issue-gate.mjs so PR and issue-label events maintain one issue-gate check tied to a linked P0, P1 or P2 issue. It scopes concurrency per PR, re-reads the current PR and issue labels after the lock, reports incomplete linked-PR discovery, and bounds pages and references.
At 31cd4341 the round-8 P2 is fixed. When discovery returns a stale head, the stale check is failed and then the current head is started, evaluated and completed in the same run (scripts/issue-gate.mjs:463-478). The shared job-level concurrency group can still cancel the current head's own PR event, but the current check is no longer left in progress or missing: beginCheckRun(pr) reconciles it and finishCheckRun(pr, checks, result) completes it. The catch path now fails checkedPr, so failures after the switch complete the current head rather than the stale one (scripts/issue-gate.mjs:484-486). The test starts with an in-progress current-head check and a stale TARGET_HEAD, and asserts the stale check fails while the current check completes as success (scripts/issue-gate.test.mjs:589-641). I withdraw the round-8 P2. Earlier rounds' points remain fixed and withdrawn.
I found no new P0-P2. The workflow and script still agree on check identity, per-PR concurrency, event paths, permissions, trusted base checkout, bounded discovery and incomplete-discovery reporting. Hosted execution of both event paths remains a rollout condition recorded in the PR body, so issue-gate should stay advisory for now.
Verification at this head: node --test scripts/issue-gate.test.mjs passes 21 tests; node --check is clean on both scripts; the workflow YAML parses with discover, evaluate-pr, evaluate-issue and coverage; git diff --check origin/main...HEAD is clean. CI: static-checks, dependencies, macos-native, windows-cli, scripts and changes pass; verify (linux) is in progress; web fails in actions/checkout with a Windows .git/config lock before any test runs, which is unrelated to this PR and needs a rerun.
zerob13
left a comment
There was a problem hiding this comment.
The discovery fix still holds, and the new fixture confirms that a stale refresh settles the current head when both check updates succeed.
New regression in the current-head settlement path: the stale-head branch waits for the obsolete check update before starting evaluation of the current head. If GitHub rejects just that obsolete update, the run exits without settling the current revision, even when its own job has been canceled and its API calls would succeed. Please evaluate and settle the current head from the current PR and issue facts when its calls are available, and report the obsolete update failure separately. This is a static reliability finding, not the Web checkout failure.
The exact scripts job is green. The trusted hosted paths remain unverified, so keep issue-gate advisory.
Evaluate and complete the current head first when discovery is stale, then fail the obsolete known-head check best-effort. A rejected stale update no longer prevents the current revision from settling. Cover a stale-head update failure while the current head still completes.
|
Pushed
|
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
This PR adds a trusted pull_request_target workflow and scripts/issue-gate.mjs so PR and issue-label events maintain one issue-gate check tied to a linked P0, P1 or P2 issue. It scopes concurrency per PR, re-reads the current PR and labels after the lock, reports incomplete linked-PR discovery, and bounds pages and references.
At 581ab925, the existing changes-requested finding on stale settlement is fixed. When discovery returns a stale head, the current head is now started, evaluated and completed first (scripts/issue-gate.mjs:459-486); the obsolete known-head check is completed best-effort in a finally block, and a rejected update is logged instead of preventing the current revision from settling (scripts/issue-gate.mjs:479-485). The new test rejects the stale-head completion while the current in-progress check still completes as success (scripts/issue-gate.test.mjs:646-700), and the earlier stale/current test still asserts the current check completes (scripts/issue-gate.test.mjs:589-644). I withdraw my earlier points and do not repeat the other open review.
No new P0-P2. One API-outage limit remains: if the initial check start or the target read fails after the stale refresh has canceled the current event, the current check can stay in progress until a later event or rerun. The run fails visibly and the gate stays advisory, so I do not block on it.
The workflow and script still agree on check identity, per-PR concurrency, event paths, permissions, trusted base checkout, bounded discovery and incomplete-discovery reporting. Hosted execution of both event paths remains a rollout condition.
Verification at this head: node --test scripts/issue-gate.test.mjs passes 22 tests; node --check is clean on both scripts; the workflow YAML parses with discover, evaluate-pr, evaluate-issue and coverage; git diff --check origin/main...HEAD is clean. CI: static-checks, dependencies, macos-native, windows-cli, scripts, web and changes pass; verify (linux) is in progress at review time.
zerob13
left a comment
There was a problem hiding this comment.
The remaining finding is resolved at 581ab9257f83efb35c01a6bb3c85f899736a54fb. The current head now settles from current facts even when the obsolete check update is rejected, and the workflow reports that failure separately. The exact scripts job passed the relevant regression and discovery tests. I found no remaining review blocker. Keep issue-gate advisory until the two hosted event paths are verified; this approval is separate from the remaining required PR checks.
There was a problem hiding this comment.
Duplicate approval. A concurrent DimAgent session approved this head first (review 6095934247). I independently reviewed the delta 31cd434…581ab925 and reached the same conclusion: the stale-head cleanup no longer blocks current-head settlement, the regression test reproduces the old failure, and node --test scripts/issue-gate.test.mjs passes 22/22. No remaining blocker. No source files were modified.
Fixes #2272
Summary
scripts/issue-gate.mjsandscripts/issue-gate.test.mjs.issue-gatecheck throughexternal_id.pull_request_targetevent payload. The settled check therefore reflects the current PR revision.issue-gaterun reaches the same conclusion.coveragejob so missing refreshes are visible. Re-run the full workflow after recovery to reconcile the remaining PRs; rerunning only thecoveragejob reuses the old discovery result.closingIssuesReferencesforFixes/Closes/Resolves; parseRefsafter stripping fences, inline code, HTML comments, blockquotes and cross-repository refs.issue-gatestays non-required until the docs: define issue maintenance rules #2273 AGENTS/CONTRIBUTING change is onmain.Verification
node --test scripts/issue-gate.test.mjs: 22 tests pass, covering the parser, current-state reads, duplicate reconciliation, evaluation failures, initial and final read failures, a stale known head with an in-progress current check, a rejected stale-head update, fallback discovery beyond 20 PRs, partial discovery that still refreshes known PRs, and missing timeline or closing-reference links.node --check scripts/issue-gate.mjsandnode --check scripts/issue-gate.test.mjsare clean;git diff --checkis clean.pull_request_targetdefinition checks out the base branch only; no PR code is checked out or run.Rollout
issue-gateadvisory until both hosted event paths are verified: PR events, and aP1->P3->P1label change on an unchanged PR head.coveragejob fails, and checks for the PRs that could not be discovered remain until the full workflow is re-run after recovery.issue-gateto themainruleset's required status checks.