Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions .github/workflows/ipr-agreement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ permissions:
pull-requests: write
statuses: write

concurrency:
# Per-repo serialization for adcp's own signature writes. GitHub Actions
# concurrency is scoped per-repo, so this does NOT cross-serialize against
# downstream AAO repos using the cross-repo callable workflow — that
# contention is handled by the rebase-retry loop in
# `scripts/ipr/check-and-record.mjs`.
group: adcp-ipr-signature-write
cancel-in-progress: false
# cancel-in-progress: false alone still permits only one pending run, so a
# burst evicts pending checks for unrelated PRs. `queue: max` keeps up to
# 100 pending runs so each PR's check still runs.
# GitHub added this option on 2026-05-07; older validators may not know it.
# https://github.blog/changelog/2026-05-07-github-actions-concurrency-groups-now-allow-larger-queues/
# https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency#example-queueing-multiple-pending-runs
queue: max
# Concurrency is set per job, not per workflow.
#
# `check` (pull_request_target) only reads the ledger and posts the
# `IPR Policy / Signature` status; it never writes. It gets a per-PR group so
# a newer push cancels a superseded check, and unrelated PRs run in parallel.
# It used to share the repo-wide write group, so every PR's check waited behind
# every other PR's check *and* its runner wait. On 2026-10-15 that queue
# completed one check every 20-45 minutes and blocked every merge for hours.
#
# `record` (sign-phrase comments) writes `signatures/ipr-signatures.json` and
# keeps the repo-wide `adcp-ipr-signature-write` group. Only comments that can
# contain the sign phrase start that job, so other PR comments no longer queue
# in the group. A check that races a signature is resolved in
# `scripts/ipr/check-and-record.mjs`: the check re-reads origin/main after
# posting pending, and the write re-marks the latest PR head after its push.
#
# GitHub Actions concurrency is scoped per repo, so neither group serializes
# against downstream AAO repos using the cross-repo callable workflow. The
# rebase-retry loop in `scripts/ipr/check-and-record.mjs` handles that
# contention.

jobs:
check:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
# Skip issue comments that can't contain the sign phrase. The script
# re-validates the exact match; this just avoids spinning up the runner for
# every unrelated comment.
if: >-
github.event_name == 'pull_request_target' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, 'I have read the IPR Policy'))
concurrency:
group: adcp-ipr-check-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
# The default GITHUB_TOKEN authenticates as github-actions[bot], which
# is not in the IPR-signatures ruleset bypass list — pushes to main get
# rejected by branch protection (GH013). The aao-ipr-bot App is in the
# bypass list, so we mint an installation token from it and use that
# for both the checkout's persisted credentials (git push) and the
# for both the checkout's persisted credentials (git fetch/push) and the
# script's API calls. Same pattern as ipr-check-callable.yml.
- name: Mint AAO IPR Bot installation token
id: app-token
Expand All @@ -67,6 +68,55 @@ jobs:
with:
node-version: '24'

- name: Check IPR signature
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: node scripts/ipr/check-and-record.mjs

record:
# Skip issue comments that can't contain the sign phrase. The script
# re-validates the exact match; this keeps unrelated comments from starting
# a runner. Because the group is on this job rather than the workflow, a
# comment that fails this `if` is skipped instead of waiting in the group.
if: >-
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, 'I have read the IPR Policy')
runs-on: ubuntu-latest
concurrency:
group: adcp-ipr-signature-write
cancel-in-progress: false
# cancel-in-progress: false alone still permits only one pending job, so
# a burst evicts pending signature writes. `queue: max` keeps up to 100
# pending. GitHub added this option on 2026-05-07; older validators may
# not know it.
# https://github.blog/changelog/2026-05-07-github-actions-concurrency-groups-now-allow-larger-queues/
# https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency#example-queueing-multiple-pending-runs
queue: max
steps:
# See the `check` job for why this uses the aao-ipr-bot App token.
- name: Mint AAO IPR Bot installation token
id: app-token
uses: actions/create-github-app-token@v3.2.0
with:
app-id: ${{ secrets.IPR_APP_ID }}
private-key: ${{ secrets.IPR_APP_PRIVATE_KEY }}
owner: adcontextprotocol
repositories: adcp

- name: Checkout default branch
uses: actions/checkout@v7.0.1
with:
ref: main
fetch-depth: 1
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true

- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: '24'

- name: Check and record IPR signature
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
Expand Down
88 changes: 67 additions & 21 deletions .github/workflows/ipr-check-callable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,24 @@ on:
required: true
description: 'PEM private key for the AAO IPR Bot (org-level secret)'

# Per-repo serialization. GitHub Actions concurrency is scoped per-repo, so
# this group only serializes signatures landing from THIS caller repo. The
# rebase-retry loop in `scripts/ipr/check-and-record.mjs` handles contention
# across sibling AAO repos pushing to the same JSON file.
concurrency:
group: adcp-ipr-signature-write
cancel-in-progress: false
# cancel-in-progress: false alone still permits only one pending run, so a
# burst evicts pending checks for unrelated PRs. `queue: max` keeps up to
# 100 pending runs so each PR's check still runs.
# GitHub added this option on 2026-05-07; older validators may not know it.
# https://github.blog/changelog/2026-05-07-github-actions-concurrency-groups-now-allow-larger-queues/
# https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency#example-queueing-multiple-pending-runs
queue: max
# Concurrency is set per job, mirroring adcp's own ipr-agreement.yml (see the
# comment there for the incident that motivated it):
# - `check` (pull_request_target) only reads the ledger and posts the status.
# It gets a per-PR group so unrelated PRs never wait behind each other.
# - `record` (sign-phrase comments) writes the ledger and keeps the per-repo
# `adcp-ipr-signature-write` group.
# GitHub Actions concurrency is scoped per-repo (the caller's repo here), so
# the write group only serializes signatures landing from THIS caller repo.
# The rebase-retry loop in `scripts/ipr/check-and-record.mjs` handles
# contention across sibling AAO repos pushing to the same JSON file.

jobs:
check:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
# Skip issue comments that can't contain the sign phrase. Same filter as
# adcp's own workflow — avoids spinning up a runner for every comment.
if: >-
github.event_name == 'pull_request_target' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, 'I have read the IPR Policy'))
concurrency:
group: ipr-check-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
# SECURITY: do not add a checkout of the caller repo to this job. The
# App token + caller's GITHUB_TOKEN both live in this job's env; a step
# that runs PR-head code (e.g. `npm ci`, build scripts, anything that
Expand Down Expand Up @@ -103,3 +96,56 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LEDGER_DIR: ${{ github.workspace }}/.ipr-ledger
run: node ${{ github.workspace }}/.ipr-ledger/scripts/ipr/check-and-record.mjs

record:
# Skip issue comments that can't contain the sign phrase. Same filter as
# adcp's own workflow — avoids spinning up a runner for every comment, and
# because the group is on this job, unrelated comments never wait in it.
if: >-
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(github.event.comment.body, 'I have read the IPR Policy')
runs-on: ubuntu-latest
concurrency:
group: adcp-ipr-signature-write
cancel-in-progress: false
# cancel-in-progress: false alone still permits only one pending job, so
# a burst evicts pending signature writes. `queue: max` keeps up to 100
# pending. GitHub added this option on 2026-05-07; older validators may
# not know it.
# https://github.blog/changelog/2026-05-07-github-actions-concurrency-groups-now-allow-larger-queues/
# https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency#example-queueing-multiple-pending-runs
queue: max
# SECURITY: same constraint as `check` — never check out or run caller-repo
# code in this job.
steps:
- name: Mint AAO IPR Bot installation token (scoped to adcp)
id: app-token
uses: actions/create-github-app-token@v3.2.0
with:
app-id: ${{ secrets.IPR_APP_ID }}
private-key: ${{ secrets.IPR_APP_PRIVATE_KEY }}
owner: adcontextprotocol
repositories: adcp

- name: Checkout central IPR ledger
uses: actions/checkout@v7.0.1
with:
repository: adcontextprotocol/adcp
ref: main
token: ${{ steps.app-token.outputs.token }}
path: .ipr-ledger
fetch-depth: 1
persist-credentials: true

- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: '24'

- name: Check and record IPR signature
env:
# See the `check` job for which token is used for what.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LEDGER_DIR: ${{ github.workspace }}/.ipr-ledger
run: node ${{ github.workspace }}/.ipr-ledger/scripts/ipr/check-and-record.mjs
9 changes: 7 additions & 2 deletions governance/ipr-bot-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ The `.pem` file should not be checked into any repo. After generation, paste its

### `adcp` — local flow

`.github/workflows/ipr-agreement.yml` runs in adcp on PR + comment events. It checks out `main` with the default `GITHUB_TOKEN`, runs `scripts/ipr/check-and-record.mjs`, and commits + pushes signature updates back to adcp. No App involvement.
`.github/workflows/ipr-agreement.yml` runs in adcp on PR + comment events. It mints an AAO IPR Bot installation token (the default `GITHUB_TOKEN` is not in the ledger ruleset's bypass list), checks out `main` with it, and runs `scripts/ipr/check-and-record.mjs`. It has two jobs:

- `check` (`pull_request_target`) reads the ledger and posts the `IPR Policy / Signature` status. It never writes, so it uses a per-PR concurrency group that cancels superseded checks. PRs never wait behind each other.
- `record` (comments containing the sign phrase) records new signatures and pushes them to adcp. It keeps the repo-wide `adcp-ipr-signature-write` group.

A push that races a signature is resolved in the script. The check re-reads `origin/main` after posting `pending`, and the write re-marks the PR's latest head after its push. Whichever finishes last, the head ends up `success`. A failed re-read leaves the status `pending` (fail closed).

### Downstream — cross-repo flow

Expand All @@ -67,7 +72,7 @@ Each downstream repo has a tiny caller workflow (~15 lines) that invokes the reu
3. Runs `scripts/ipr/check-and-record.mjs` with `LEDGER_DIR=.ipr-ledger`. The script reads/writes signatures there; `git push` from inside the directory uses the installation token configured by the checkout step.
4. API calls back to the event repo (comments, status check) use the caller repo's default `GITHUB_TOKEN` — no cross-repo write required for those.

Per-repo concurrency groups (`adcp-ipr-signature-write` in each repo) serialize signature writes within each repo. GitHub Actions concurrency is scoped per-repo, so the cross-repo race is handled by a rebase-retry loop in the script — when a push fails because adcp's main moved, the script pulls with `--rebase` and retries up to 5 times.
The callable uses the same `check` / `record` split as adcp's own workflow. Per-repo concurrency groups (`adcp-ipr-signature-write` in each repo, on the `record` job only) serialize signature writes within each repo. GitHub Actions concurrency is scoped per-repo, so the cross-repo race is handled by a rebase-retry loop in the script — when a push fails because adcp's main moved, the script pulls with `--rebase` and retries up to 5 times.

## Rotation

Expand Down
Loading
Loading