Repository navigation
fix(ci): promote fork PRs' issues, and fail the run when a label write is refused (#2767) - #2769
Conversation
…e is refused (#2767) `issue-status-on-merge.yml` ran on `pull_request`, where a PR opened from a FORK gets a read-only `GITHUB_TOKEN`. Every label write was refused with "Resource not accessible by integration", the issue stranded in `status-in-progress` with its fix already on `dev` — and the run reported SUCCESS, because the refusal was a `core.warning`. It only ever bit external contributors, i.e. exactly the PRs nobody is watching the label on (observed 2026-09-14: #2752 merged, #2106 relabelled by hand). Two changes. **`pull_request_target`**, which runs in the base repo's context and so carries the write token the `permissions:` block already asks for. That trigger is the standard privilege-escalation footgun, so the reasoning is written next to it rather than left implicit: the escalation always takes the form "check out the stranger's code, then execute it", and this workflow does neither — no `actions/checkout`, no `run:` steps, and the only untrusted values (`pull_request.title` / `.body`) reach exactly one regex that extracts `\d+`. The residual capability is bounded to what the feature does anyway — a MERGED PR names which issue numbers get relabelled — and `pull_request_target` runs the base branch's copy of the workflow, so a fork cannot edit this file to widen that. **A refused write now fails the job.** Failures are collected rather than thrown at the first miss, so one unlabelable issue cannot strand the others, and `core.setFailed` runs after the loop naming every issue that still needs a manual fix. A `removeLabel` 404 stays a non-failure — an issue that was never picked up simply has no label to remove. `tests/unit/test_2767_issue_status_fork_prs.py` guards both safety properties in the shape of `test_1896_integration_nightly_workflow.py`. Mutation-tested, each caught: reverting the trigger, adding an `actions/checkout`, adding a `run:` step, and downgrading `setFailed` back to `warning`. Note for reviewers of the test: the guards strip comment lines before asserting. Without that, a comment saying "there is NO actions/checkout" satisfies the checkout check and "collected, not thrown" satisfies the throw check — the guard would pass because of the sentence claiming the property instead of the property. Both bit me while writing it. Fixes #2767 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q19uRCksdn4DiRAJ55rfpZ
Review:
|
| Category | Status | Notes |
|---|---|---|
| Lane | C | .github/workflows/ — correctly the highest tier |
| Base branch | ✅ | dev |
| Closing keyword | ✅ | Fixes #2767, same-repo, so the automation this PR fixes will promote its own issue |
| PR size | ✅ | 2 files, +225/−5 |
| Security greps | ✅ | clean |
| Build/config packaging | ➖ | no new env var, no new backend package |
| Test adequacy | ✅ | mutation-tested 4 ways, each caught |
| Merge gate | 🟡 | 9 pass / 9 pending at time of writing, 0 fail |
ui label |
➖ | no frontend diff |
/review — structural
Critical: none.
Verified rather than assumed:
pull_request_targetsafety — the parsed step list contains noactions/checkoutand norun:; the only API calls areissues.addLabels/issues.removeLabel; untrustedtitle/bodyreach one\d+regex. The escalation shape (fetch fork code → execute it) is structurally absent.- Action pinning — I expected to flag
actions/github-script@v9as unpinned under a write token, and it is not a defect: the repo SHA-pins every third-party action (tailscale/,pypa/,google-github-actions/,docker/,dependabot/) and tags first-partyactions/*throughout (27×checkout@v7, 6×github-script@v9). This conforms. Raising it would have been a false finding from not reading the convention. - No double-run —
pull_requestis removed, not supplemented. - Scope creep — none; the diff is the workflow plus its guard.
[I1] A typo'd issue number now turns the post-merge run red — undifferentiated from the bug being fixed (Confidence: 8/10)
.github/workflows/issue-status-on-merge.yml — the addLabels catch:
} catch (e) {
failures.push(`#${num}: could not add status-in-dev — ${e.message}`);
continue;
}This collects on any status. The issue asked to fail when a write is refused — a 403 "Resource not accessible by integration". A 404 is a different fact: the issue does not exist, i.e. someone typed Fixes #99999. That now reds the run too.
Two reasons it is worth a deliberate decision rather than leaving as-is:
- The sibling call already discriminates. Nine lines down,
removeLabelspecial-casese.status === 404as a non-failure with a comment explaining why. Within one script, one call distinguishes 404 and the other does not — a reader will trip on that asymmetry and not know which is intentional. - The two need different messages. "could not add status-in-dev" for a 403 means the automation is broken, an issue is stranded; for a 404 it means fix the typo in the PR body. Same red, opposite action.
Not arguing it should be silent — a typo'd reference is worth surfacing, and the run is post-merge so red is a notification, not a block. Just that it should say which of the two it is. Smallest version:
failures.push(e.status === 404
? `#${num}: no such issue — check the reference in the PR body`
: `#${num}: could not add status-in-dev — ${e.message}`);[I2] permissions is file-scoped where the repo's other pull_request_target workflow scopes per job (Confidence: 6/10)
permissions:
issues: write
pull-requests: readEquivalent today — there is exactly one job. But integration-nightly.yml, the repo's only other pull_request_target workflow, deliberately uses top-level permissions: {} with per-job grants (discover/test get contents: read, only comment gets issues: write). On a pull_request_target workflow that difference is not stylistic: a second job added later silently inherits issues: write here, and inherits nothing there. Worth matching the stricter neighbour while the file has one job and the change is free.
[I3] pull-requests: read is dead (Confidence: 8/10)
The script's only API calls are issues.addLabels and issues.removeLabel; PR data comes from context.payload.pull_request, not the API. So the pull-requests: read grant is never exercised. Harmless, but on the one workflow in the repo carrying a write token for a stranger's PR, "the permissions block lists exactly what is used" is a property worth keeping true — it is what makes the next reviewer's audit cheap.
On the tests
The guards strip comment lines before asserting, and that is load-bearing rather than tidy: my first two attempts passed because of my own comments — the sentence "there is NO actions/checkout" satisfied the checkout check, and "collected, not thrown" satisfied the throw check. A guard that passes on prose claiming the property is worse than no guard, because it reports green. Following test_1896's _commands() precedent fixed it; the helper carries the reason in its docstring so the next person does not re-introduce it.
Mutation results, re-run for this review:
| mutation | outcome |
|---|---|
trigger → pull_request |
🔴 1 failed |
add actions/checkout of PR head |
🔴 1 failed |
add run: echoing the PR title |
🔴 1 failed |
setFailed → warning |
🔴 2 failed |
| unmutated | 🟢 10 passed |
Caveat on verification
actionlint is not installed locally, so my syntax checking was YAML-parse level only (all 28 workflow files still parse). GitHub's own parser is the real gate, and a pull_request_target trigger cannot be exercised until the file is on dev — the fix is unobservable until it lands, by construction. The first fork PR merged after this is the actual proof.
🤖 Generated with Claude Code · https://claude.ai/code/session_01Q19uRCksdn4DiRAJ55rfpZ
vybe
left a comment
There was a problem hiding this comment.
merge-train: batch validated on train/20260914-1332
…he divergence, record the accepted delays (#2814) (#2816) `Issue Status on PR Merge` has not run since #2769 changed its trigger to `pull_request_target`: zero runs across six merges, three carrying a valid `Fixes #N`, every one of those issues left in `status-in-progress` until a human moved it. Not red — absent. GitHub executes the base branch's copy of a `pull_request_target` workflow but REGISTERS the trigger from the default branch, and `main` still says `pull_request`. Neither copy can start a run, and the change is inert until the next release cut. Decided (2026-09-15): wait for the release rather than hotfix `main`. This PR therefore ships the guard for the class, not the trigger: - tests/unit/test_2814_workflow_trigger_parity.py — for every workflow, each default-branch-registered event declared here must also be declared by `main`'s copy, or the delay is recorded in ACCEPTED_UNTIL_RELEASE with a reason. Reads `main` via `git show`, falls back to a `--depth=1` fetch (proven from a CI-shaped clone), skips loudly if unreachable. A stale allowlist entry fails too, so the record is pruned when the gap closes. First run found three MORE unrecorded divergences (`workflow_dispatch` on deploy-dev, alembic-head-watch, publish-images) beside the two `schedule` ones whose files already said "main only" in their own comments. - issue-status-on-merge.yml — the comment that said "runs the file as it exists on the BASE branch" now also says it is registered from `main`, since reading the first as the second is the inference that shipped this. - docs/memory/learnings.md — the class, stated once. Backfill (AC#2): #2730 (merged via #2731 at 15:15 UTC 2026-09-14) had never been promoted — now `status-in-dev`; #2794/#2795 had a stale `status-ready` beside their hand-added `status-in-dev` — stripped. Related to #2814 (AC#1 closes at the release cut, not here) Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: sim <[email protected]>
…om `main` (Abilityai#2822) `issue-status-on-merge.yml` has produced zero runs since Abilityai#2769 moved it to `pull_request_target` on 2026-09-14. Seventeen PRs have merged into `dev` since, ten of them carrying a closing keyword for eleven issues, and every one of those issues was relabelled by hand. Neither trigger could start a run, for opposite reasons. GitHub reads a `pull_request` workflow from the PR's merge ref, which resolves against `dev` -- and `dev`'s copy no longer declared it. It reads a `pull_request_target` workflow from the repository's DEFAULT branch (`GITHUB_REF` is the default branch, `GITHUB_SHA` its last commit) -- and `main` receives release cuts only, so `main`'s copy still says `pull_request`. The trigger that decides whether a run starts was being read from a branch the PR never touches, which is why the failure was absent rather than red. `push` is read from the ref being pushed, explicitly including workflows that are not merged into the default branch, so a trigger change to this file takes effect on the merge that lands it and cannot go dark until a release cut again. That is Abilityai#2822's fourth acceptance criterion, not merely a way to restore today's promotion. It keeps Abilityai#2767's fix by a safer route: a push to `dev` is a base-repo event whatever the merged PR's origin, so the token carries the declared `permissions:` and a fork author's issue is promoted like anyone else's -- without handing a write token to an event a stranger can start. A push payload carries no pull request, so the merged PR is resolved from the pushed commits with `listPullRequestsAssociatedWithCommit`, which needs `pull-requests: read` and nothing more. Only PRs that merged INTO the pushed branch are read: a commit on `dev` is also in the head of the open `dev` -> `main` release PR, whose body closes every issue in the release. Still no `actions/checkout` and no `run:` step. Closes Abilityai#2822
…om `main` (#2822) (#2825) * fix(ci): promote on the push to `dev`, not on a trigger registered from `main` (#2822) `issue-status-on-merge.yml` has produced zero runs since #2769 moved it to `pull_request_target` on 2026-09-14. Seventeen PRs have merged into `dev` since, ten of them carrying a closing keyword for eleven issues, and every one of those issues was relabelled by hand. Neither trigger could start a run, for opposite reasons. GitHub reads a `pull_request` workflow from the PR's merge ref, which resolves against `dev` -- and `dev`'s copy no longer declared it. It reads a `pull_request_target` workflow from the repository's DEFAULT branch (`GITHUB_REF` is the default branch, `GITHUB_SHA` its last commit) -- and `main` receives release cuts only, so `main`'s copy still says `pull_request`. The trigger that decides whether a run starts was being read from a branch the PR never touches, which is why the failure was absent rather than red. `push` is read from the ref being pushed, explicitly including workflows that are not merged into the default branch, so a trigger change to this file takes effect on the merge that lands it and cannot go dark until a release cut again. That is #2822's fourth acceptance criterion, not merely a way to restore today's promotion. It keeps #2767's fix by a safer route: a push to `dev` is a base-repo event whatever the merged PR's origin, so the token carries the declared `permissions:` and a fork author's issue is promoted like anyone else's -- without handing a write token to an event a stranger can start. A push payload carries no pull request, so the merged PR is resolved from the pushed commits with `listPullRequestsAssociatedWithCommit`, which needs `pull-requests: read` and nothing more. Only PRs that merged INTO the pushed branch are read: a commit on `dev` is also in the head of the open `dev` -> `main` release PR, whose body closes every issue in the release. Still no `actions/checkout` and no `run:` step. Closes #2822 * fix(ci): name the real reason both PR filters are needed, measured `listPullRequestsAssociatedWithCommit` documents that for a commit "not present in the default branch" -- which every `dev` commit is until a release cut -- it returns "merged AND open pull requests associated with the commit". Measured on `b8a790b2`: six PRs come back, one merged and five OPEN, and every one of them is `base: dev`, because any branch cut from `dev` after that commit contains it. So the release PR was the smaller half of the story: `merged_at` is what stops one merge promoting the close list of every open PR in flight, and `base.ref` is what excludes the `dev` -> `main` release PR. The comment said only the second; both are now stated with the measurement behind them, and each has its own test. * fix(ci): prune the issue-status-on-merge allowlist entry this PR makes stale test_2814_workflow_trigger_parity::test_every_accepted_entry_names_a_real_divergence fails once this branch stops declaring pull_request_target on issue-status-on-merge.yml: the ACCEPTED_UNTIL_RELEASE entry recording that divergence no longer matches anything, which is exactly what that guard is for. The entry existed because the promotion was accepted as broken until the next release cut. Moving the trigger to push: branches: [dev] removes the need to wait for a release at all, so the record goes with it.
Fixes #2767
Both halves of the "Done when"
Fixes #Nrelabels without manual intervention1.
pull_request_targetA fork PR's
GITHUB_TOKENis read-only, so every label write was refused and the issue stranded instatus-in-progresswith its fix already ondev.pull_request_targetruns in the base repo's context and carries the write token thepermissions:block already asks for.That trigger is the standard privilege-escalation footgun, so the argument is written next to it in the file, not left implicit. The escalation always takes one form — check out the stranger's code, then execute it. This workflow does neither:
actions/checkoutrun:stepstitle/body\d+The residual capability is bounded to what the feature does anyway: a merged PR (
if: merged == true) names which issue numbers get relabelled. Labels only, maintainer-gated, recorded in the issue timeline.And
pull_request_targetruns the base branch's copy of the workflow, never the PR's — so a fork cannot edit this file to widen any of the above. That is what makes the three properties sufficient rather than merely true today.permissionsis unchanged (issues: write,pull-requests: read) — escalating the trigger must not quietly escalate the scopes.2. A refused write fails the job
The defect wasn't only the read-only token; it was that the refusal was a
core.warningon a successful run, so a green check sat next to a mislabelled issue.Failures are now collected, not thrown at the first miss — one unlabelable issue must not strand the others — and
core.setFailedruns after the loop naming every issue that still needs a manual fix. AremoveLabel404 remains a non-failure: an issue never picked up simply has no label to remove.Guards
tests/unit/test_2767_issue_status_fork_prs.py, in the shape oftest_1896_integration_nightly_workflow.py. Mutation-tested — each caught:pull_requestactions/checkoutof the PR headrun:echoing the PR titlesetFailed→warningA note on the tests themselves
The guards strip comment lines before asserting. Without that, a comment reading "there is NO
actions/checkout" satisfies the checkout check, and "collected, not thrown" satisfies the throw check — the guard passes because of the sentence claiming the property rather than the property. Both bit me while writing this, which is why the stripping is a named helper with the reason in its docstring rather than an inlinesplitlines().Verification
test_1896+test_2280)actionlintis not installed locally, so the syntax check here is YAML-level only — GitHub's own parser is the real gate on merge🤖 Generated with Claude Code
https://claude.ai/code/session_01Q19uRCksdn4DiRAJ55rfpZ