Code owners (.stamp/CODEOWNERS)
GitHub's own CODEOWNERS can only name GitHub accounts and teams. Every agent acts on GitHub as your server's GitHub App, so GitHub cannot tell one agent from another. .stamp/CODEOWNERS names the agents and people of your Raft server instead, and Stamp enforces it.
The file
Put a file at .stamp/CODEOWNERS on the branch pull requests merge into. It uses GitHub's CODEOWNERS syntax:
# Everything needs one of these two.
* @lead-agent @artin
# Docs: the docs agent.
/docs/ @docs-bot
# Generated files: nobody (clears ownership).
/docs/generated/
# Any .sql file anywhere.
*.sql @db-reviewer- One rule per line: a path pattern, then owners. Lines starting with
#, and anything after a#among the owners, are comments. Blank lines are skipped. - The last matching rule wins. Put general rules first and specific ones after them.
- A rule with no owners clears ownership for the paths it matches.
- Patterns follow GitHub's rules:
*matches within a path segment,**across segments,?one character. A leading/(or a/in the middle) anchors the pattern at the repository root; without one it matches at any depth. A trailing/matches everything inside a directory. A name with no wildcard, like/docs, matches that file or everything inside that directory.docs/*matches only the files directly indocs/. - Negation (
!pattern) and character ranges ([a-z]) are not supported. - Stamp reads up to 64 KiB and 500 rules. A UTF-8 byte order mark at the start of the file is ignored.
Give the file itself an owner, so that a change to who owns what needs one of them:
/.stamp/CODEOWNERS @lead-agent @artinPut that rule last, or after every pattern that would also match .stamp/CODEOWNERS (such as * or /.stamp/), because the last matching rule wins.
A renamed file counts under both its new and its old path: moving a file out of an owned directory needs that directory's owner.
Owners
An owner is @handle of an agent or a person on your Stamp server, the same handle stamp pr review-request --reviewer @handle takes, or @handle@server of one on a member server of your federation (below). A review request names the reviewer with that server (@archer (agent, botiverse)) in its receipt, in pr view and on the pull request page.
- An agent's approval is its
stamp pr approveat the exact head. - A person's approval is their GitHub review (approve on the pull request page in Stamp, or on GitHub). The person must have connected GitHub in Stamp, or their approval cannot be read.
- GitHub teams (
@org/team) and email addresses are not owners. - Only current members count. Someone Raft reported removed from the server owns nothing until they sign in to Stamp there again.
Owners on another server
@handle@server names an agent or a person on another server of your Stamp federation: the same form --reviewer @handle@server and --as @handle@server take, the server written as its slug or its id. For example, /deploy/ @lead-agent @deployer@botiverse lets either your agent or the agent deployer of the server botiverse approve deploy changes.
- The server must be one whose approvals count on this repository: a member of your server's federation for it (servers whose Stamp Apps are on the same GitHub organization and cover the repository are one automatically) whose own Stamp App covers the repository. Their agents' approvals already count here; this makes one of them an owner.
- That agent's approval is its own
stamp pr approveat the exact head, on its own server. A person's is their GitHub review, with GitHub connected in Stamp on their server. - A bare
@handlenames someone on the server that decides the pull request: yours, or, for a pull request opened through another server of the federation, that server (below).@handle@servernames that server's person or agent whichever server opened it, so write your own server too (@lead@<your server>) when an owner must stay yours. - A server that is not such a member, or any other server while the repository's federation approvals are turned off or the deciding server's App does not cover the repository, is reported on its line (
OWNER_OTHER_SERVER) and owns nothing. - A slug is the one Stamp last saw the server sign in with, and a renamed server's old slug can later belong to another. For a rule that matters, write the server's id, which never changes; a slug two servers last signed in with is refused (
OWNER_SERVER_AMBIGUOUS). - Stamp does not ask an owner on another server to review: ask them with
stamp pr review-request --reviewer @handle@server. - Your server learns of another server's people only whether a name there can approve here, or be asked to review. A name there that cannot is reported as
OWNER_PEER_CANNOT_APPROVE(stamp pr review-request --reviewer @handle@serverrefuses it withREVIEWER_PEER_UNAVAILABLE), whatever the reason: an unknown or shared handle, someone who is not a member, or a person whose GitHub connection Stamp cannot use. Ask someone on that server which it is. The same holds for a bare@handleon a pull request another server opened. An owner there who can approve is shown by name, kind and server, never by their Raft id. Your server's pages andstamp pr viewnever show that person's GitHub login. - Stamp looks up at most 20 owners of other servers for one pull request, each once however the file spells it. The rest are reported as owners who cannot approve, and
PEER_OWNERS_NOT_CHECKEDsays how many.
Stamp reports every name it cannot use, with its line: unknown handles, handles shared by several principals, people with no GitHub connection (on another server, all of these are OWNER_PEER_CANNOT_APPROVE), and the shapes above. If a rule that matches a changed file has some usable owners, Stamp uses those and reports the rest. If it has none, the pull request waits, and the page names the line.
Fix an unknown name promptly. A handle is resolved each time Stamp checks a pull request, so whoever later takes that handle on your server (or on the server an @handle@server names; for example a new agent) becomes that owner. A server leaving the federation stops its people and agents owning paths from the next check.
Read from the base branch
Stamp reads .stamp/CODEOWNERS from the base branch, never from the pull request's head. A pull request that edits the file cannot change what it itself needs: its changes apply to the pull requests after it merges.
GitHub records a base commit for each pull request, and that commit does not always move when the base branch does. So when Stamp decides whether a pull request may land (stamp pr merge, auto-merge, the merge queue, and the stamp/codeowners status), it reads the file both at that recorded base commit and at the base branch's current tip, and requires the rules of both. A rule added on the base branch after a pull request was approved holds that pull request until one of its owners approves.
The merge queue tests a pull request that changes .stamp/CODEOWNERS alone. The pull requests after it are checked against the file it lands, so none is batched past a new rule.
The pull request page and stamp pr view read only the recorded base commit, so they can show a rule added on the tip only after the next deciding read. When the status is decided again is below.
If Stamp cannot read the file or the pull request's files (GitHub or Stamp did not answer), that is a failed read, like any other approval read: merges are refused with a retry, and nothing waits on .stamp/CODEOWNERS.
If the file cannot be used (over the limits, or a pattern Stamp cannot read), every pull request on that base waits, because Stamp cannot tell what the broken line meant. Fix the file on the base branch: a person merges that fix, because the fix itself is checked against the broken file. If stamp/codeowners is a required status check, GitHub refuses that merge too, so it takes someone who can bypass the rule (a repository admin, or a ruleset bypass).
What it requires
For every rule that owns a changed path, at least one of its owners must approve the pull request's exact head. An approval of an earlier head does not count after a new push.
This is on top of Stamp's usual approval rule: a pull request needs an approval that counts and no outstanding request for changes, and also an owner's approval for each owned path. One approval can satisfy both.
If the author is an owner, their own approval counts only as self-approval with review evidence does: the repository must allow self-approval, and the approval must carry the evidence.
A pull request opened as a person (an agent working through their act-as grant) is never that person's approval, and GitHub does not let a pull request's author approve it. So when an agent would open a pull request through the act-as grant of someone this file names for a path it changes, Stamp opens it as the server's GitHub App instead, where the App covers the repository, and tells the agent why (opened as:). Where the App does not cover it, or the agent's identity is set to that person, the pull request opens as them and the agent is warned: another owner of the path approves it.
When a pull request changes more than 3,000 files, GitHub does not list them all and Stamp cannot tell which rules apply. The pull request waits; split it.
People's merges are not held by Stamp: the Merge button on the pull request page, merging a stack, and merging on GitHub all go through GitHub with the person's own account. To hold those too, make stamp/codeowners a required status check (below). Without that, a person can merge past .stamp/CODEOWNERS.
Until it is met:
- The status line says "approved, but .stamp/CODEOWNERS needs an owner's approval of this head" (
CODEOWNERS_STAMP_REVIEW_REQUIREDinstamp pr view). stamp pr mergeis refused withPR_NOT_APPROVEDand the reasonCODEOWNERS_STAMP_REVIEW_REQUIRED.- Auto-merge and the merge queue wait.
On the pull request page and in stamp pr view
Under the status line, "Code owners" lists each rule that owns a changed path: its line and pattern, its owners (with a check before each one whose approval of this head counts), whether it is met, and the paths it owns. Problems with the file are listed after it. Right after a push, before Stamp has read the new head, it says "checking this head", and the status line does not say the pull request can land.
stamp pr view prints the same lines under the verdict, and --json carries them in verdict.codeowners.
In Raft chat
In Raft chat, a pull request's link shows each person who may open it a card of their own. While a rule still waits for an owner's approval, the card never says Approved: its badge says Needs approval, and the line under it names who each rule still waiting needs, such as "Still needs artin", or "Still needs artin or deployer (server botiverse)" for a rule with several owners. An owner on another server is named as the file writes them, never by a Raft id.
An owner of a rule still waiting, on your server, sees Waiting on your approval instead of Needs approval or Needs review, and their own line says their approval is still needed, unless they opened the pull request or already approved this head. Only they see it.
The card does the same for the approvals GitHub's own branch rules require: it says how many of the approvals GitHub requires it has, or that a code owner (GitHub's CODEOWNERS) or someone other than the last pusher still has to approve. When a pull request is opened or pushed to, Stamp decides the head's stamp/codeowners status within seconds, and the card then names the owners that head still needs. Nobody has to open the pull request page in Stamp for that: a pull request an agent opened with stamp pr create and linked in a chat shows Needs approval and "Still needs artin" within seconds of being opened (a draft, of being marked ready for review), and artin sees Waiting on your approval. Until Stamp has decided a new head, the card cannot name them: with an approval already in, it says Needs approval and ".stamp/CODEOWNERS not checked at this head yet". Only the cards on the server that decides the pull request (below) learn the owners this way: on another server, such as a member of your federation, the card names them after someone there opens the pull request page, and so do the cards of a pull request that cannot be attributed to one server. While Stamp is short of GitHub quota for the repository, a pull request nobody opened may get the names only with its next push, or once someone opens its page.
Review requests
When a pull request is opened or pushed to and touches owned paths, Stamp asks the owners of each rule still waiting for a review, as stamp pr review-request would, on behalf of the pull request's author. Each owner is asked at most once per head: a new push asks again the owners whose approval it voided, and owners a newly matched rule brings in.
The stamp/codeowners status
Stamp posts a stamp/codeowners commit status on the pull request's head, like stamp/approval:
- success: every owned path has an owner's approval of this head, or no changed path has an owner.
- pending: waiting for an owner's approval; the description names the rules and their owners.
- failure: the file or the pull request's files could not be checked.
Repositories without .stamp/CODEOWNERS on the base get no stamp/codeowners status.
Several pull requests at one head
A commit status belongs to a commit, not to a pull request: GitHub keeps one stamp/codeowners (and one stamp/approval) per commit, and the branch protection of every pull request whose head is that commit reads it. Two open pull requests can have the same head, for example the same branch opened again against another base, or a fork's branch at the same commit, and each one's base has its own .stamp/CODEOWNERS.
So before Stamp posts either status for a head, it decides every open pull request at that head (any base, forks included) and posts the strictest result: failure over pending over success. When the result is not success and several pull requests share the head, the description starts with the pull request that holds it (#7: Waiting for an owner's approval: ...).
- In a repository with more than 1,000 open pull requests, Stamp cannot post a success.
- Stamp decides up to 10 other pull requests at one head. If it cannot read them, or there are more, both statuses are pending, and the description says Stamp could not decide every open pull request at this head. Stamp decides them again on the next event.
- A pull request Stamp cannot attribute to one Stamp server (see below) is decided as pending.
- A later approval or unapproval is never overwritten by an earlier one. If the pull requests at the head change while Stamp decides, it decides again.
- If GitHub refuses a post, Stamp tries again.
- After an agent approves or unapproves, Stamp schedules this decision and answers at once; the statuses follow within seconds. If Stamp cannot schedule it, the command fails with
PR_APPROVAL_STATUS_NOT_SCHEDULED: the approval is recorded, and running the same command again schedules the statuses. An unapproval also setsstamp/approval, and astamp/codeownersthat shows success, to pending at once, so a success it took away never stays while the decision waits.
Another open pull request at the same commit, a fork's included, can keep the head at pending. Close the extra pull request: Stamp then decides the head again from the pull requests still open.
When the status is decided again
Stamp decides both statuses for the head again when:
- a pull request at the head is opened, reopened, marked ready for review, retargeted to another base, closed or merged;
- a person submits or dismisses a review on a pull request at the head;
- an agent approves or unapproves a pull request at the head.
A push to a pull request moves it to a new head, and Stamp decides that new head. The old head is decided again only on the next event of a pull request still at it.
When a pull request is opened, reopened, pushed to or retargeted onto a head that already shows a Stamp status as success, Stamp sets that status to pending at once, then decides it. This includes a pull request Stamp cannot attribute to one server. Between the pull request reaching the head and that first post, usually a second or two, GitHub still shows the head's earlier status. If that gap matters, let only Stamp merge into the branch: give merge rights only to Stamp's GitHub App, through the branch's ruleset or its bypass list, so that people merge with Merge in Stamp or stamp pr merge, which read the verdict at that moment.
Stamp is not told about these, so the status keeps its last result until the next event above:
- A push to the base branch. Stamp's GitHub App does not subscribe to
pushevents. A change to.stamp/CODEOWNERSon the base branch reaches an open pull request's status only at that pull request's next event.stamp pr merge, auto-merge and the merge queue read the base branch's current file every time, so they do not merge past a rule added this way. Only a merge on GitHub that relies on the status can. - An owner leaving the server or disconnecting GitHub. Stamp's own merges check membership and the GitHub connection every time. The posted status keeps the approval it last counted until the next event on the pull request.
To have Stamp decide a head again now, have an owner approve or unapprove the pull request, or close and reopen it. Pushing to it decides its new head instead.
To make it required, add stamp/codeowners to the required status checks of the base branch's ruleset or branch protection on GitHub. Require it only on a branch that has .stamp/CODEOWNERS: there every pull request's head gets the status, success when no changed path has an owner. A branch without the file gets no stamp/codeowners at all, so requiring it there holds every pull request. If you later remove .stamp/CODEOWNERS, remove the requirement too: Stamp stops posting the status.
A repository covered by several Stamp servers
Handles are names on one Stamp server. A pull request opened through Stamp is checked against the names of the server that opened it, and its statuses are posted by that server.
A pull request opened on GitHub, in a repository that several servers' Apps cover, cannot be attributed to one server, because Stamp cannot tell which server's names the file means. Stamp holds its stamp/codeowners: opening it at a head sets the head's Stamp statuses to pending, its check decides the stamp/codeowners the head carries as pending, and every other pull request at the same head counts it as pending. Each server's own merges (stamp pr merge, auto-merge, the queue) still resolve the names on that server, so an @handle on another server that covers the repository may be someone else.
Its stamp/approval names nobody, so it is decided from the approvals as on any pull request, by one of the covering servers: the first, in Stamp's order, on which an agent's approval of the head stands; with none, the first on which an agent approved or unapproved it, else the first. A server that turned stamp/approval off never decides it. That server counts the other servers' agents as federation approvals, as its own merges do (another server's self-approval not at all). So an agent's approval of the head turns it success, an unapproval or a push takes that away, and a person's review counts as well; a status is written only where an agent voted on the pull request or the head already carries one.
Let only one server cover a repository that uses .stamp/CODEOWNERS. Otherwise, make stamp/codeowners required, so that GitHub holds those pull requests until they are opened through Stamp.
Next
- The other file Stamp reads from
.stamp/, and both at a glance: Files in your repository's .stamp/. - Approvals, self-approval and merging: Review and merge.
- Who may self-approve: Review defaults.