ADR-0019: Contributor automation knows rather than guesses, and runs no pull request content where it can write
Status: Accepted Date: 2026-09-30
Context
Contributors need to know three things:
- which gate failed, and why;
- the exact command that reproduces or fixes it;
- where they stand on the way to a merge.
One maintainer cannot answer every one of those by hand. Automation that answers them has to talk to pull requests from forks and write to branches. That is where CI systems are most often attacked, and this package's own ledger lives in the Actions cache (ADR-0007).
The maintainer wants as much automation as static analysis allows, and no
AI anywhere in the workflows. Every word the bot posts must come from a
table in main, or from a tool's structured output validated against one.
What the design rests on, read at source, in GitHub's documentation, and by probes on 2026-09-30:
The repository's settings give workflows a write token by default, let Actions approve pull requests, and require workflow approval from first-time contributors only.
main's protection:- strict required checks;
- signed commits;
- squash only, with the PR title as subject and the PR body as message;
- linear history.
Every merge therefore leaves open pull requests behind
main.ci.ymlruns onpull_request(opened, synchronize, reopened) only, so editing a PR's title re-runs nothing.GITHUB_TOKENstarts no workflow. An event it causes starts no workflow run, exceptworkflow_dispatchandrepository_dispatch. A pull request it opens or updates gets runs in an approval-required state. A GitHub App's token starts workflows as a person's does.Commits made through the API are signed. A commit made with
createCommitOnBranchor the git-data REST endpoints, as an App or withGITHUB_TOKEN, and with no custom author or committer, is signed by GitHub. A server-side rebase of a pull request's branch makes unsigned commits.Which triggers carry what.
pull_requestfrom a fork gets a read-only token and no secrets.pull_request_target,issue_commentandworkflow_runrun the default branch's workflow with a token that can write, and with secrets.The cache probe.
issue_commentandpull_request_targetrun with a read-only Actions cache, and a save fails whateverpermissionssays.workflow_runruns with a writable cache even underpermissions: {}, and saves asrefs/heads/main, the scopemain's ledger is restored from.workflow_runand forks. It is the only event raised when another workflow finishes. For a fork's pull request, itspull_requestsfield is empty.Pushing to a fork. "Allow edits by maintainers" lets users with push access push to a fork's branch.
GITHUB_TOKENcannot push there.The tools report in structured form:
- PHPStan (
--error-format=json); - Pint (
--format=json); - Rector (
--output-format=json); - Pest (
--log-junit); - typos, lychee, actionlint, gitleaks (redacted) and osv-scanner (JSON);
- the gate itself (its JSON report, ADR-0009).
- PHPStan (
OIDC roles and
ref. Every job a workflow runs on the default branch, whatever its trigger, carriesref: refs/heads/mainin its OIDC token. An OIDC role that trusts a barereftherefore trusts all of them.
Decision
Foundations
The bot lives in this repository, is written in Python's standard library, and uses no model.
- Its workflows are
.github/workflows/bot-*.yml, and its scripts live in.github/scripts/. Each script has an I/O half and a pure deciding half, ascommit_lint.pydoes. - The deciding halves are unit-tested with
python3 -m unittestin a required CI job,scripts. - A privileged job installs nothing: no Composer, no pip, no npm.
- No language model is called anywhere. Every sentence the bot posts is
text from
main, filled with values validated againstmain.
- Its workflows are
Two identities:
GITHUB_TOKEN, and an App of our own.GITHUB_TOKEN, with per-job permissions, comments and re-runs jobs.- The App,
mutation-gate-bot, is installed on this repository only, with Contents and Pull requests set to read and write. It makes the writes that must start CI: the/fixcommits and the release pull request. - The App's private key lives in a GitHub environment,
bot, whose deployment-branch policy allowsmainonly. - Tokens are minted per job with
actions/create-github-app-token, pinned by SHA and narrowed with itspermission-*inputs. - Every commit the App makes goes through
createCommitOnBranchwith no custom author, so GitHub signs it and CI starts on it.
The rules every bot workflow keeps.
workflow_runhandles no pull request data. It writes the default branch's cache (the probe), so its one job is the relay of numbers.issue_commentandpull_request_targetrun no tool over pull request content. They carry a write token and secrets, so they read a pull request only as data: through the API, or from git objects at a pinned SHA, which also defeats planted symlinks. They never check it out as a working tree, install it or load it.- No pull request or comment string appears inside
${{ }}in arun:. It passes throughenv:and is handled by the script. - Every write names the head SHA it acted on (
expectedHeadOid,expected_head_sha). A push in between fails the write. permissions: {}at the workflow level, and each job asks for exactly what it writes.- Commands count only from
createdcomments. Comments by bots are ignored, except the App's own relay marker.concurrencyis set per pull request. - A test reads every workflow and fails when a job started by
pull_request_target,issue_commentorworkflow_runhas a step other than a checkout ofmain, the stdlib scripts, and the pinned token action. - CodeQL's
actionsanalysis stays on, and zizmor joinshygiene. - Three repository settings change:
- the default workflow token becomes read;
- Actions may not approve pull requests;
- workflow approval is required for all outside contributors.
A relay of numbers carries "CI finished" out of
workflow_run.- What it reads. On
workflow_run(completed) forci, one job reads the run's id (an integer), itshead_sha(validated as 40 hex) and itsconclusion. It finds the pull request whose head SHA equals the run's. For a fork, it looks it up by head repository and requires the SHA to match. - What it ignores. It reads no string the pull request controls, downloads no artifact, checks nothing out and installs nothing.
- How it hands off. As the App, it sets the pull request's sticky
comment to an explaining… state that carries
<!-- mutation-gate-bot: run=<id> sha=<sha> -->. A comment written by the App starts workflows. - Where the work happens. Evidence parsing and posting run on
issue_comment(edited), whose cache is read-only. They act only on the App's own comment carrying the marker, and read the run again by its id. - One more job. The re-run of infrastructure failures runs in the relay too, because it reads only job metadata.
- What it reads. On
What the bot knows
Every CI job leaves structured evidence.
- Each job in
ci.ymlasks its tool for machine-readable output. - A stdlib converter turns that output into
evidence/<job>.json, withformat,job,toolandfindings: [{path, line, rule, detail}]. - Where the fix is mechanical, the job adds
fix.patch. - All of it is uploaded as the artifact
evidence. - A test fails when a job in
ci.ymlhas no evidence producer.
- Each job in
Evidence is as untrusted as the pull request that produced it.
- A
pull_requestrun takes its workflow and scripts from the pull request, so the evidence can say anything. - The pipeline downloads it through the API and unpacks it in memory, with only the expected file names, a size cap per file and in total, and no paths taken from the archive.
- Each file is parsed against its schema, and a file that fails is dropped whole.
- Only these reach a comment:
path: it must be a file the pull request changed, checked against the API's list at the run's head SHA;line: an integer;rule: it must be inmain's vocabulary.
- Free text from evidence, such as a PHPStan message or an assertion message, is never rendered by the bot. The pull request's own job shows it, as an annotation it writes itself with no privilege.
- A rule outside the vocabulary is shown as unrecognised (see the job's annotations), and counted.
- A
The words come from tables in
main.Table Holds Source of each explanation .github/gates.jsonPer ci.ymljob: what it checks, the command that reproduces it, the command that fixes it where one exists, and its troubleshooting slug (ADR-0018)Written in this repository ARCHITECTURE.mdThe package's own rules ( C5,H3, …)Its rule rows .github/bot/rules/phpstan.jsonPHPStan identifiers One line per identifier, and phpstan.org's page for it .github/bot/rules/rector.jsonRector rule classes One line per rule, and its page in Rector's rule reference .github/bot/rules/pint.jsonphp-cs-fixer fixers One line per fixer, and its page in the fixer reference .github/bot/rules/markdownlint.jsonmarkdownlint rules ( MD013, …)One line per rule, and its page in markdownlint's docs .docs/guide/troubleshooting.mdThe gate's own statuses and message slugs Its sections (ADR-0018) - A test fails when a job has no
gates.jsonentry, or an entry has no job. - A test fails when a rule met in the recorded evidence fixtures has no entry.
- Each job in
ci.ymlalso ends with anif: failure()step that writes itsgates.jsonentry to the step summary and as an::error::annotation. That needs no privilege, and works for forks.
- A test fails when a job has no
What the bot does
It explains each failure exactly, and fixes what is mechanical.
What each gate shows. The sticky comment lists, per failed gate, its cause from
main's tables, at the validatedpath:line, with the rule's explanation and link.Gate Shown Mechanical fix checks: Pinteach file and fixer composer lint:fixchecks: Rectoreach file and rule composer refactor:fixchecks: PHPStanpath:line, identifier, its line and link, or theARCHITECTURE.mdrownone checks: normalize, validatethe file composer normalizetests and coveragethe failing test from JUnit at path:linenone coverageuncovered lines of changed files none rules,the rules refuse violationsthe rule and its ARCHITECTURE.mdrownone hygiene / typospath:lineand the typoproposed only; a corrected word inside an identifier can be wrong hygiene / markdownpath:lineand the rulemarkdownlint-cli2 --fixcommitlintthe commit or the title, and the rule none; history is the author's the mutation verdict a link to the gate's own comment (survivors, hints, reproduce,stub)none How the fix is made. When
checksormarkdownfails, that job itself runs the fix commands and addsfix.patchto its evidence.Always proposed. The comment shows the patch as suggested changes for hunks inside the diff, and as a collapsed patch for the rest.
Committed only on
/fix, and only for a branch in this repository. Every hunk must touch a file the pull request already changes (orcomposer.json, for normalize), under a size cap. The App makes one commit,style: apply the fixes CI computed, whose body names the run and its SHA.A fork only gets the suggestions. The author's own "commit suggestion" makes the commit.
The bot runs no tool. The bytes are the pull request's own CI's, committed only to that pull request's branch, where its author could push them anyway.
Infrastructure failures are re-run once.
- This applies when the failed step is checkout,
setup-php,composer-installor an artifact download, or when the runner was lost. The relay reads that from the run's job and step metadata, never from logs. - It runs once per job per head SHA, with
actions: writeonGITHUB_TOKEN. - The comment says what was re-run, and why.
- This applies when the failed step is checkout,
A first pull request is walked through by its state.
- The checklist. The sticky comment holds one, updated on every
event:
- waiting for a maintainer to start CI (the run's
action_requiredstatus); - title conventional;
- every gate green, each red one explained;
- new code tested (the gate's comment);
- a
Spec:line, when the pull request touches a path the spec map covers; - ready for review.
- waiting for a maintainer to start CI (the run's
- When
.github/changes, it adds: this pull request changes CI itself, so a maintainer reviews that before any check here means anything. - The welcome. A
pull_request_target(opened) job, with no checkout andpull-requests: write, opens the comment forFIRST_TIME_CONTRIBUTOR,FIRST_TIMERandNONE. The welcome text comes frommain: setup, the local gates, CI waiting for approval, and the title rule. - Ticked items collapse.
- The checklist. The sticky comment holds one, updated on every
event:
Missing tests are the gate's to report, and it reports them early.
- The gate's own sticky comment (ADR-0009) gains a
planned state, posted by the
planjob. It holds:- the units to be mutated;
- the estimate (ADR-0017);
- the changed lines no test runs, which the coverage map the plan already holds says.
- It is posted minutes before the verdict replaces it.
- This is a feature of the gate for every user, and the bot links it.
- The gate's own sticky comment (ADR-0009) gains a
planned state, posted by the
Pull request text is checked on edit, and helped, never rewritten.
- The
prworkflow. It runs onpull_request(opened, edited, synchronize, reopened), reads only metadata and runs no PHP.commitlintmoves there fromci.yml, under the same job name, so a fixed title or body is checked at once.- Every
Spec:number in the body must be an ADR in.docs/decisions, because the body becomesmain's commit message. - A title with
!needs a Migration section.
- The comment shows:
- the changelog preview: the exact line and section ADR-0018's
git-cliff run will write, computed in the
prjob and carried as evidence; - when the title fails, a suggestion. The type comes from the changed
paths (
.docs/only →docs,tests/only →test,.github/only →ci), and the scope from the top directory undersrc/(src/Adapter/Pest/→pest); - with no
Spec:line, a suggestion from.github/spec-map.json, which maps globs to ADR numbers. A test fails when a glob matches nothing or names a missing ADR.
- the changelog preview: the exact line and section ADR-0018's
git-cliff run will write, computed in the
- The bot never edits a title or a body.
- There is no changelog-entry check: the title is the changelog line.
- The
The commands, and who may use them.
Command Does Who /fixCommits the mechanical fix's patch write access, or the pull request's author /updateGitHub merges the base into the head (update-branch, merge method, with the expected head SHA). GitHub makes and signs the merge commit, commitlintexempts subjects that start with "Merge", and the squash erases it./rebasedoes the same and says whywrite access, or the pull request's author /retestRe-runs the failed jobs of the latest CI run on the current head, never one awaiting approval, at most three times per head SHA write access, or the pull request's author /docs <words>Searches a heading index generated from .docs/, and replies with at most three links and no prose. The words are reduced to[a-z0-9]+tokensanyone - The pull request's author is matched by user id, read from the API's pull request, never from the comment's text.
- Anyone else is checked against the collaborator-permission endpoint,
which must answer
write,maintainoradmin.author_associationis not read:MEMBERnames any member of the organisation, andCOLLABORATORincludes read and triage roles. - Anyone refused gets one reply naming who may run the command.
Duplicate issues are matched by message slug.
- An
issues(opened, edited) job, withissues: write, finds slugs (ADR-0018) in the body by pattern, and keeps only slugs that exist inmain's troubleshooting page. - It replies once, with the other issues carrying the same slug, open and closed, and the section's link.
- An
A release is drafted by the bot and signed by the maintainer.
- Drafting. On
workflow_dispatchby the maintainer, a job computes the next version from the commits since the last tag:featis a minor,fixandperfa patch, and!a major, or a minor while the major is 0; the first version is given by hand (ADR-0018). It writes that version'sCHANGELOG.mdsection with git-cliff, pinned by version and checksum, and opens or updatesrelease/vX.Y.Zas the App. - Signing. The maintainer edits and merges that pull request, runs
git tag -s vX.Y.Zon the squash commit, and pushes the tag. - Publishing.
release.yml, on the tag push:- checks the tag's signature against
.github/allowed_signers, and that the tag points at a commit onmain; - runs the gate in
mode: full(ADR-0011); - publishes the GitHub release with that section as its notes;
- moves the tag of the release's line:
vMAJOR.MINORwhile the major is 0 (v0.1), andvMAJORfrom 1.0.0 (ADR-0011).
- checks the tag's signature against
- A tag ruleset lets only the maintainer create
v*tags.
- Drafting. On
The ledger's OIDC roles
- An OIDC role that can write a ledger never trusts a bare
ref.- Where the ledger's store is reached through an OIDC role (S3, as the
approved S1 setup does, and the
gcsandazurestores, whose only credential is a federated one: ADR-0028), the role that can write the default branch's prefix trusts either:- a GitHub environment whose deployment-branch policy allows the default branch only, and which only the verdict job uses; or
- the
job_workflow_refof the workflow that runs the verdict, at the default branch.
- A bare
ref: refs/heads/maincondition is refused, because every job a workflow runs on the default branch carries it. That includes this bot's jobs, and anything started byissue_comment,workflow_runor a schedule.
- Where the ledger's store is reached through an OIDC role (S3, as the
approved S1 setup does, and the
Alternatives considered
| Option | Why it lost |
|---|---|
| A language model that explains failures and answers questions | The maintainer wants no AI in the workflows. It would also cost per call, give different words each run (ADR-0009 rejected model-written hints for that reason), need a second credential, and read text that pull request code writes, which is an injection surface. |
| Parsing raw job logs | Console text changes with every tool release, and pull request code writes it. Structured output does not change with the release. |
| Rendering the tools' own messages, escaped | Escaping Markdown completely is a known trap. The job's own annotations already show those messages on the diff. |
Parsing evidence and posting from workflow_run | workflow_run writes the cache main's ledger is restored from. |
Handing off through repository_dispatch | Its cache mode is unprobed and may be writable, as workflow_dispatch's is. |
A pull_request_target job that polls until CI finishes | It holds a runner idle for every CI run on every push. |
Running Pint from main inside a privileged workflow | It rests on a per-tool claim ("never loads the code it reads") that an upgrade can break, and it could not cover Rector. |
| Committing fixes automatically | It pushes to someone's branch unasked, and their next local push fails as non-fast-forward. |
| Pushing fixes to forks | GITHUB_TOKEN cannot, and an App token scoped to this repository is not expected to. Suggestions let the author commit. |
GITHUB_TOKEN only | Every fix commit and release pull request would wait for a maintainer to approve its CI. |
| The App for everything | Its key would sit in every bot job, not two. |
| A personal access token | The bot would act as the maintainer, with a long-lived credential and the maintainer's reach. |
| A hosted bot (Mergify, a Probot app run by someone else) | A third party with write access, and CI behaviour that changes with no commit here, against ADR-0011's "the package stands alone". |
actions/github-script | Logic in YAML strings that nothing tests. |
| The bot in PHP with Composer | Every privileged job would run composer install, a large supply chain beside a write token. |
A server-side rebase for /rebase | GitHub cannot sign rebased commits. |
| The bot rebasing and re-creating each commit | Every commit's author would become the bot. |
| Write access only for commands | Contributors would wait for the one maintainer for every update and reformat. |
| Anyone may run any command | Drive-by comments would spend CI minutes and cause writes. |
| Duplicates by word similarity or embeddings | Wrong matches on a small tracker cost more goodwill than they save, and an exact message slug is the same failure. |
| The bot rewriting titles and bodies | Its edits would conflict with the author's next edit, and the body is where the author states intent. |
| A required changelog entry or fragment | A second place for what the conventional title already says (ADR-0018). |
| Labelling by area, by type or by path | One maintainer. The conventional scope names the area, and the notes come from commits. |
| Closing stale issues and pull requests | Real reports would close unanswered. The backlog is read by a person. |
| Predicting which gates a pull request will trip | The fast gates report within minutes, sooner than a prediction could be read. The one slow answer worth having early is the gate's planned state. |
| release-drafter | It needs labels, its autolabeler runs under pull_request_target, and it ignores conventional commits. |
| release-please | The bot would create the tag, unsigned, which ADR-0011 refuses. |
OIDC roles trusting ref: refs/heads/main | Every default-branch job would be trusted, including ones that read pull request data. |
Consequences
A contributor learns the cause, the place and the fix of every red gate
without asking. The words are main's, the numbers are validated, and
nothing is guessed.
No pull request content runs anywhere that can write. The one job in
the cache scope main restores from handles only numbers.
Mechanical failures cost a comment, /fix, on a branch in this
repository, or a click on a suggestion from a fork.
Releases stay the maintainer's act: a signed tag, verified before anything is published.
Three repository settings and one environment change, and an App and a tag ruleset are created, once, by the maintainer.
Related
- ADR-0007: the ledger's scopes, and the OIDC roles that write them
- ADR-0009: the sticky comment's planned state, and why the reports stay free of generated prose
- ADR-0011: the CI table, signed commits, releases and the reusable workflow's permissions
- ADR-0017: the estimate in the planned state
- ADR-0018: the message slugs, the changelog and the release notes