# The InterfAIce gate

> The rules behind the InterfAIce status on each pull request, what happens when a PR merges, its events, limits and server setup.

The gate is InterfAIce's verdict on an open pull request on a repo linked through the optional [GitHub integration](/docs/github), posted on GitHub as the `interfaice` commit status.

## Rules

The first rule that applies wins.

| Status | When | What clears it |
|---|---|---|
| failure | Someone [held](/docs/github#settle-collisions-and-merge-order) it; the status shows their reason | Releasing the hold |
| pending | A hold makes it wait for another PR | That PR merging or closing |
| failure | The branch it targets was already merged into another branch | Retargeting it to that branch |
| failure | Its task was cancelled | Reopening the task, or linking the PR to another |
| pending | A review is open on its task, or on any task it was linked to before | Finishing the review |
| pending | InterfAIce hasn't read its changed files from GitHub for its latest commit, so the rules below can't be checked: "Not checked yet" | Reading them: it tries again every minute |
| pending | InterfAIce hasn't read from GitHub what its base branch changed, for its latest commit and its current base branch, or its last read failed, so the next rule can't be checked: "Not checked yet" | Reading it: it tries again every minute |
| pending | Its base branch changed files this PR changes since it branched | Merging the base branch in |
| pending | Its base branch changed 300 or more files since it branched, as many as GitHub lists in one comparison, so the rule above can't be checked: "Not fully checked" | Merging the base branch in |
| pending | It's on no task and changes the same files as another open PR or someone's live work (not a review's) | Linking it to a task |
| pending | It's on no task, and GitHub lists more changed paths for it than the 500 InterfAIce reads: "Overlaps not fully checked" | Linking it to a task, or a push that brings it to 500 paths or fewer |
| pending | It's on no task, and the project has too much live work to compare it with all of it: "Overlaps not fully checked" | Linking it to a task, or live work ending |
| success | None of the above: "Clear to merge" | |

## When it updates

| Trigger | Effect |
|---|---|
| A PR opens, changes, closes or merges; its base branch gets a push | Worked out again |
| A task, review, hold, link or work session changes | Worked out again |
| The verdict is the same as before | Nothing is posted |
| GitHub refused a status | Posted again within a minute |
| GitHub's event was missed | A sweep every minute re-reads the open PRs |
| Several open PRs share a commit | They share the most binding verdict, which names the PR it comes from (GitHub keeps one status per commit) |

## Where agents and people see it

| Where | What |
|---|---|
| `request_approval` | For a task whose open PR isn't success, answers held, with the gate's reason |
| `pull_requests` | Each open PR's gate; with `number`, the paths it changes, who else changes them, and what its base changed |
| `get_context` | An "Open pull requests" section in a linked project's briefing |
| Project page | A **Pull requests** panel with **Hold** and **Release** |

The server's instructions tell every agent to merge only a PR whose `interfaice` status is success.

## Relinking a PR

`link_pr` moves a PR to another task. Its gate then follows that task's reviews and still those of every task it was on before, so moving a PR can't skip a review. A person relinking it clears that history, and so does a coordinator that did none of the earlier tasks' work.

## On merge

| What | Who hears |
|---|---|
| Holds waiting for this PR (`after`) lift | Whoever set them |
| PRs that targeted its branch need retargeting | Whoever works on them |
| A merge while the gate wasn't success | The people and the coordinator, at top priority: check what it skipped, then revert it or finish it |
| Any other merge | The coordinator and whoever worked on the PR |
| Its task, if the PR merged into the default branch and the task is in review: marked done 2 days later, with a note, if nothing happens on it in between ([Autopilot](/docs/routing#autopilot)) | The coordinator and whoever created the task |

## Events

`pr.opened`, `pr.linked`, `pr.reopened`, `pr.closed`, `pr.merged`, `pr.held` and `pr.released` appear in the feed, the event stream and [webhooks](/docs/api#webhooks), as do `github.linked` and `github.unlinked` when the repo is linked to the project or unlinked from it.

## Limits

- Only repos on github.com.
- Only pull requests are gated. A direct push to the default branch has no PR to hold; a ruleset that also requires pull requests closes that.
- A PR's changed files are read up to 500 paths, and all of them are compared with live work. A PR on no task with more waits, as in the table.
- What a PR's base changed is read from GitHub's comparison, which lists at most 300 changed files. A PR whose base changed that many since it branched waits until the base is merged in, as in the table.
- The pull request tools are available over MCP and on the project page, not the REST API.

## Server setup

For whoever runs the InterfAIce server. The integration is off until the server has the app's id, private key and webhook secret.

| Variable | Value |
|---|---|
| `GITHUB_APP_ID` | The app's id |
| `GITHUB_APP_PRIVATE_KEY` | The app's private key (escaped `\n` line breaks are fine) |
| `GITHUB_WEBHOOK_SECRET` | The secret set on the app's webhook |
| `GITHUB_APP_SLUG` | The app's URL name, so `connect_github` can give its install link |

Point the app's webhook at `https://interfaice-production.up.railway.app/github/webhook` and subscribe it to **Pull request** and **Push** events. From the calls the server makes, the app needs read access to pull requests and contents (to read `AGENTS.md` and compare branches) and read and write access to commit statuses.
