Skip to content

feat(pr-triage): take the caller's token grant and accept a dispatch for bot PRs - #278

Merged
bketelsen merged 5 commits into
mainfrom
lucilla/pr-triage-grant-dispatch
Nov 18, 2026
Merged

bketelsen merged 5 commits into
mainfrom
lucilla/pr-triage-grant-dispatch

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #227. Closes #233.

#227: the caller grants the triage token (ADR-0086, amends ADR-0021 in part)

  • pr-triage.yml has no permissions key (top level and job). A called workflow can only reduce the token that the calling job passes (GitHub: reusing workflow configurations), so a fixed grant with checks: read and statuses: read would ask for more than the existing callers grant (34 repositories with a caller: the inventory in docs/design/pull-request-target-policy.md, read on 2026-11-09). With no key, a private caller adds the 2 reads to its own job, and the readiness step reads the checks instead of getting HTTP 403. A public caller needs no change.
  • Core's caller risk-paths-caller.yml grants contents: read, pull-requests: write, checks: read, statuses: read.
  • Guard: npm run check:fleet fails a job that calls pr-triage.yml without its own permissions mapping, with a string grant (write-all, read-all), or with a scope or value outside contents: read, pull-requests: write, checks: read|none, statuses: read|none (triageCallerGrantGaps in scripts/lib/fleet-conventions.mjs). A workflow-level grant does not count: GitHub gives a calling job without its own grant the default token. The check parses the workflows with the yaml package (2.9.1, exact pin, no dependencies) instead of 1 more hand-written YAML reader.
  • Baseline row B5: pr-triage.yml is the 1 exception to the top-level permissions: {} rule. test/repository-baseline.test.mjs pins the exemption list to exactly that file, which must exist, have only the workflow_call trigger and no permissions line.

#233: dispatch for bot PRs (ADR-0087)

  • pr-triage.yml takes the input pr (string, default ""). On workflow_dispatch, the levels step refuses a value that does not match ^[1-9][0-9]*$ or is not a safe integer, before any API call. It reads GET /pulls/{number}; a PR that is not open gets the outcome not-open and no label change. The base SHA comes from that answer. Then the step labels as on pull_request_target. The step does not read head.sha: it needs only the base SHA and the file list.
  • On pull_request_target, a non-empty pr fails the step. Another event name fails it.
  • readiness, the Dependabot metadata step and shadow now also need github.event_name == 'pull_request_target' in their if:, so a dispatch runs only the scripts step and levels.
  • The spec (rule A2) gives the dispatch caller .github/workflows/pr-triage-dispatch.yml and the bot job step (gh workflow run ... -f pr="$PR_NUMBER", actions: write). It is a separate file because the Actions event policy for the caller paths is an allowlist of events.

The callers' PRs (private callers add the 2 reads; bot repositories add the dispatch caller) come after a core commit with this change is pinned. None is opened here.

Risk tier

Risk tier: 3 — risk:high. Matched paths in .github/risk-paths.json, and why the change is safe:

  • .github/workflows/** (L2): pr-triage.yml and risk-paths-caller.yml.
    • pr-triage.yml loses its own permission blocks. Its token is now the calling job's grant. In core that grant is 4 scopes, 3 read and pull-requests: write, the same write scope as before. In other repositories, check:fleet fails a caller job without a narrow grant (enabled declarations; the spec states the rule for all callers). The job still checks out nothing and runs no PR code.
    • The new pr input reaches the script only through env: (PR_TRIAGE_PR), never inside run:, and the script accepts digits only.
    • The 3 added github.event_name == 'pull_request_target' conditions only narrow when a step runs.
  • scripts/lib/pr-triage.mjs (L2): the levels step accepts workflow_dispatch. The readiness and shadow code is unchanged and still refuses any event but pull_request_target.
  • The embedded copy in pr-triage.yml was rewritten only by npm run sync:risk-paths-workflow; check:risk-paths passes.

Docs housekeeping

  • New docs started from their category's TEMPLATE.md (ADR-0086, ADR-0087)
  • Every new doc indexed in docs/README.md
  • Cross-links added in both directions (ADRs ↔ specs/pr-triage.md, specs/risk-paths.md, specs/repository-baseline.md, design/pull-request-target-policy.md; ADR-0021 gets the "Amended in part by" line)
  • New significant decision recorded as an ADR first, in this PR
  • New/edited ADRs are fact-only

Decision trail: the maintainer chose option A on #227 (caller grant plus a fleet guard) and option A on #233 (dispatch with a PR number, levels only).

Verification

  • make ci at 3b644cd: 1039 tests, 1039 pass, 0 fail (0149919 adds 1 blank line in ADR-0086: check:docs and CI green there); check:docs, check:risk-paths green.
  • GITHUB_TOKEN=… node scripts/check-fleet-conventions.mjs: ok for all 7 enabled repositories (clix, core, firn, frostmarks, hearth, std, updex), 32 workflow files read.
  • YAML is read with a real parser (yaml); the tests still cover flow and block mappings, quoting, comments, anchors and aliases, duplicate keys, BOM, CRLF, an empty file and no final newline.
  • Workflows: actions SHA-pinned; risk-paths-caller.yml keeps permissions: {}; pr-triage.yml is the ADR-0086 exception. ci.yml: the fleet-conventions job now runs npm ci before npm run check:fleet (the guard imports yaml); a test pins that order.
  • Revert test: in a scratch worktree at e3ee192, scripts/lib/pr-triage.mjs and both workflows restored to the base, and triageCallerGrantGaps stubbed to return [], then node --test test/pr-triage.test.mjs test/fleet-conventions.test.mjs test/repository-baseline.test.mjs: 28 triage/workflow tests fail (for example levels dispatch reads the live base SHA and shares the label ratchet, levels dispatch refuses invalid pr input "7\n" before any API call, workflow_dispatch runs only the scripts and levels; ..., B5: every workflow pins its actions by SHA, ...) and 28 guard tests fail (for example triageCallerGrantGaps requires own job permissions despite top-level "permissions: write-all\n", checkFleetConventions reports a triage caller without its own job permissions), all on assertions. The npm ci test fails with the ci.yml line reverted.
  • CI green at 0149919 (docs-gate, fleet-conventions, scaffold-e2e, pr-triage).

Cross-review

Reviewer github-copilot/claude-sonnet-5.5; coder openai/gpt-6.1-sol (code, tests, spec and design edits), the 2 ADRs from an Anthropic model. Base 602caf9bba57e0f354b9e5484f488ab8cd9afe34.

  • Initial review in 2 batches. Batch 1 (code and tests) at e3ee192: 1 blocking point, the fleet-conventions job ran check:fleet without npm ci, so the new yaml import failed on a clean runner (also seen in run 44208991438). Fixed in a36ad0f with a guard test and the correction record .memory/corrections/2026-11-18-pr-278-fleet-job-npm-ci.json. 5 low points: a constant assertion (replaced by a check derived from disk), a stale comment in workflow-triggers.mjs, 3 missing YAML shapes (flow-mapping job, quoted keys, << fails closed: tests added), npm ci in the doc commands (added), and a regex that can also match a foreign owner (accepted: extra gaps only).
  • Batch 2 (docs) and re-review 1 at f680088: Ready, no blocking point. 5 non-blocking doc points: fixed in 3b644cd (the GitHub default-token claim is quoted and hedged, and the guard ignores workflow-level permissions either way; counts name their source and date; ADR-0087 names the bot workflows and tokens, and incus is left out because it opens its sync PRs with a PAT; the review rubric names the exception; the spec lists the grants by scope).
  • Re-review 2 at 3b644cd: Ready; 1 low point (a missing paragraph break), fixed in 0149919.
  • Re-review 3 at 01499193fa662e2b394928b78e14081da4f4c0fb: Ready, Blocking: none.

Follow-ups (after a core commit with this change is pinned; not opened here)

  • frostyard/apt-publisher, bketelsen/fleet (private callers): add checks: read and statuses: read to the pr-triage job and bump the pin.
  • frostyard/bootc-debian, frostyard/omarchy-apps: add .github/workflows/pr-triage-dispatch.yml (spec rule A2) and a dispatch step in check-dependencies.yml.
  • frostyard/snosi: the same, while its WORKFLOW_PAT secret is not set.
  • frostyard/incus: no dispatch caller needed (sync-upstream.yml uses the PAT UPSTREAM_SYNC_TOKEN).

Not tested: no live run on GitHub. The dispatch path and a private caller's grant are covered by unit tests with a fake API only. After merge, the core caller's next PR run shows the grant at work in a public repository.

…for bot PRs

pr-triage.yml sets no permissions, so its job gets the calling job's
grant. A private caller can grant checks: read and statuses: read, and
the readiness step then reads the checks instead of getting HTTP 403
(ADR-0086, amends ADR-0021 in part). check:fleet fails a job that calls
pr-triage.yml without its own narrow permissions mapping; it reads the
workflows with the yaml parser.

pr-triage.yml takes the input pr. On workflow_dispatch only the levels
step runs: it refuses a pr value that is not digits only, reads the PR
and its base SHA from the pulls API, and labels the PR as on
pull_request_target. A repository whose workflows open PRs with
GITHUB_TOKEN adds the dispatch caller of the spec (ADR-0087).

Closes #227
Closes #233
@github-actions github-actions Bot added level:L2 Read the diff risk:high Touches a path in .github/risk-paths.json labels Nov 18, 2026
scripts/lib/fleet-conventions.mjs now imports the yaml package, and the
fleet-conventions job ran check:fleet without npm ci (ERR_MODULE_NOT_FOUND).
A test pins npm ci before npm run check:fleet in that job.
The B5 test derives the files without top-level permissions: {} from
disk, the guard tests cover flow-mapping jobs, quoted keys and the YAML
1.2 merge key (fails closed), and the docs say to run npm ci before
check-fleet-conventions.mjs in a core checkout. Adds the correction
record for the fleet-conventions job that ran without npm ci.
…urces

ADR-0086 quotes the GitHub sentence on a calling job without its own
grant and says the guard ignores workflow-level permissions, so it holds
whatever GitHub takes as the default. The caller and private counts name
the inventory table and its date; ADR-0087 names the bot workflows and
their tokens (incus opens its sync PRs with a PAT). The review rubric
names the pr-triage.yml exception, and the spec lists the 4 grants by
scope.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 18, 2026
@bketelsen
bketelsen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 57f3b9b Nov 18, 2026
7 checks passed
@bketelsen
bketelsen deleted the lucilla/pr-triage-grant-dispatch branch November 18, 2026 01:07
This was referenced Nov 22, 2026
This was referenced Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L2 Read the diff ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json

Projects

None yet

2 participants