Skip to content

GitHub merge check

The merge check is the last of Zentri’s three catches. It asks the coordinator whether a pull request may merge, and fails when the pull request breaks the coordination rules. It is the only catch that a shell write, a skipped commit hook, or an agent without hooks cannot get past, provided branch protection requires it.

The check comes in two forms. Both send the same request and read the same verdict.

Form Where it runs Status name State
The Action A job in the repository’s own workflow zentri merge check Tested end to end against a local coordinator and a fake GitHub API.
The GitHub App A server you run outside the repository zentri/merge-check No App exists yet. The code is tested only against fakes.

The design is in ADR-0008, section 4. The decision rule comes from ADR-0009. The repository’s docs/architecture/merge-check.md describes the internals.

  1. GitHub tells the check about a pull request.
  2. The check lists the pull request’s changed files through the GitHub API.
  3. It sends the branch and the files to POST /v1/projects/{project_id}/merge-check.
  4. The coordinator reads its own state in one read-only snapshot and returns a verdict: success or failure, a Markdown summary, and the findings.
  5. The Action fails its job, or the App sets its check run to failure, when any rule holds.

The coordinator decides from its own records. The caller sends only the branch, the base, the head commit, the pull request number, and the paths. A rename sends both its old and its new path.

A session branch is named zentri/<slug>-<id8>, where <id8> is the end of the session ID. zt start creates it.

Rule Fails when Applies to
session A zentri/ branch names no session of the project, or more than one, or does not have that shape. Session branches
unclaimed The session never claimed a changed file. Released and expired claims count as claimed. Session branches
held Another session holds a live claim on a changed file. Every branch
duplicate The session’s intent was registered as a duplicate, ran anyway, and the intent it matched is still active. Session branches
decision The session has a high-risk decision that is still proposed, or was rejected and no accepted decision of the same session supersedes it. Session branches

A branch outside zentri/, such as one a person pushed, is checked for held only, and the summary says so. A coordinator error fails the check. It never passes it.

  • Any user of the organization, or an integration token with the checks:read scope.
  • A session token gets 403. An agent cannot probe its own gate.
  • The call writes nothing in Zentri.
  1. Have a Zentri admin create an integration token with the checks:read scope. It is the only scope the check needs. The token belongs to the organization, so one token serves every project.

    Terminal window
    umask 077
    printf 'Authorization: Bearer %s\n' "$(cat ~/zentri-admin-token)" >admin.headers
    curl -sS -H @admin.headers -H 'Content-Type: application/json' \
    -d '{"label":"github-merge-check","scope":"checks:read"}' \
    https://zentri.example.com/v1/integration-tokens | jq -r .token >check-token
    rm admin.headers

    The header file keeps the admin token out of the process list.

  2. In the repository’s settings, under Secrets and variables, then Actions, add these:

    Kind Name Value
    Secret ZENTRI_CHECK_TOKEN The zt_i_ token from step 1.
    Variable ZENTRI_URL The coordinator’s base URL, such as https://zentri.example.com.
    Variable ZENTRI_PROJECT_ID The project’s ID, from GET /v1/projects.
  3. Add the workflow below to the default branch.

  4. In the branch protection rule or ruleset for each protected branch, require the status check zentri merge check.

Save this as .github/workflows/zentri-merge-check.yml. Pin the action to a full commit SHA.

name: zentri merge check
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
# The job reads the pull request's file list and nothing else.
permissions:
pull-requests: read
concurrency:
group: zentri-merge-check-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check:
name: zentri merge check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: zentri-repo/zentri/integrations/github-check@<full commit sha>
with:
url: ${{ vars.ZENTRI_URL }}
project-id: ${{ vars.ZENTRI_PROJECT_ID }}
token: ${{ secrets.ZENTRI_CHECK_TOKEN }}

The job’s name is the status you require in step 4.

Input Required Meaning
url Yes The coordinator’s base URL. It must be https, or http on a loopback host.
project-id Yes The Zentri project ID.
token Yes The checks:read integration token. Pass it from a secret.
github-token No A token that can read the pull request’s files. Defaults to the job’s GITHUB_TOKEN, which is enough with pull-requests: read.

The action is a composite step that runs check.sh. The inputs reach the script as ZENTRI_URL, ZENTRI_PROJECT_ID, ZENTRI_TOKEN, and GITHUB_TOKEN in its environment, never in the script text.

While the Zentri repository is private, a workflow in another repository can use the action only after the owner allows access in the repository’s Actions settings. You can instead copy action.yml and check.sh into your repository, check out the base branch with actions/checkout, add contents: read, and use the local path.

The verdict goes to the job summary. On success the log ends with:

Zentri merge check passed.

On failure the job exits 1 and logs this annotation, and the summary lists each finding:

The merge check failed. The job summary lists why.

The job also exits 1 when the check cannot run, for example when the coordinator does not answer.

The Action fails without asking the coordinator in three cases: the pull request comes from a fork but its branch is under zentri/, it changes more than 3000 files, or GitHub lists fewer files than the pull request counts.

The job needs the secret. GitHub gives secrets to pull_request_target runs, even for forks, and such a run uses the workflow and the action from the base branch, not from the pull request. So a pull request cannot change the check that judges it.

That holds only while the workflow never runs code from the pull request. Do not add actions/checkout with the pull request’s ref, and do not run its scripts. The action reads the event and calls two APIs. It never checks out the pull request.

The trust ends at the base branch. Anyone who can push to it, or merge a pull request that edits the workflow, can weaken the check. Protect the workflow file with CODEOWNERS, or use the App, which lives outside the repository.

The App, zentri-github-check, is a webhook server that runs outside the repository. It is the stronger gate: a person who can push to the base branch can edit a workflow, but not the App. It creates a check run named zentri/merge-check.

Register the App under the organization that owns the repositories with these settings:

  • Webhook URL. https://<host>/webhook, served through a TLS proxy.
  • Webhook secret. At least 16 bytes. Make one with openssl rand -hex 32.
  • Repository permissions. Checks: read and write. Pull requests: read. Metadata: read. Nothing else.
  • Events. Pull request only.

Install it on the repositories to check, have an admin create one checks:read integration token, and require the status check zentri/merge-check in branch protection.

Every setting is a flag or an environment variable. A flag wins. Secrets come only from files that others cannot read, never from a variable’s value.

Variable Default Meaning
ZENTRI_GITHUB_APP_ID none The App ID.
ZENTRI_GITHUB_APP_PRIVATE_KEY_FILE none The App’s PEM private key, RSA of 2048 bits or more.
ZENTRI_GITHUB_WEBHOOK_SECRET_FILE none The webhook secret, on one line.
ZENTRI_SERVER none The coordinator URL.
ZENTRI_INTEGRATION_TOKEN_FILE none The zt_i_ integration token with checks:read.
ZENTRI_GITHUB_REPO_MAP_FILE none The repo map.
ZENTRI_GITHUB_API_URL https://api.github.com The REST API base. Use https://<host>/api/v3 for GitHub Enterprise Server.
ZENTRI_GITHUB_CHECK_ADDR 127.0.0.1:8090 The address to listen on.

The repo map names each repository and its Zentri project:

{
"repositories": {
"acme/api": "0b5c4f3e-8d0a-4b8e-9a43-2f1f1f6f6c11"
}
}

A pull request in a repository the map does not name gets no check run. If branch protection requires the check there, the pull request stays blocked.

The App serves POST /webhook and GET /healthz. It checks the webhook signature before it parses the body, answers 202, and runs the check in the background. It runs at most 4 checks at once and answers 503 past that. It never sets the check to neutral, because GitHub counts a neutral check as passing.

  • A verdict is a snapshot. A pull request that passed stays green after another session claims one of its files, until the next push or a re-run. A pull request that failed because another session held a file passes only after that session ends and the check runs again. Push a commit or re-run the job.
  • The App’s Re-run button does nothing. The App does not handle check_run events. Push a commit or redeliver the webhook.
  • The base branch is trusted. Whoever can change the workflow on the base branch can weaken the Action.
  • At most 3000 changed paths, 100 findings in the reply (the rest are counted), and a 60000-byte summary.
  • No real GitHub run. The Action ran in scripts/e2e-m4.sh against a fake GitHub API. No App has been registered.