A GitHub App for a factory
A factory acts on GitHub as one identity: it labels, comments, pushes branches and opens pull requests. That identity is a GitHub App, one app for everything this factory does. A machine user (a second GitHub account with a personal access token) is not used: GitHub can suspend a user account that automation drives hard, and then everything the account wrote is hidden and every poll fails. That happened to tehas-tehas on 2026-10-24.
An app is not a user. Its installation tokens last one hour, reach only the
repositories it is installed on, and its writes show as <slug>[bot]. tehas
makes and renews the tokens itself: nothing on the host holds a long-lived
GitHub token. The factory is named by one setting, TEHAS_GITHUB_APP_ID. The
installation and the bot's login are looked up at GitHub and kept in
~/tehas/state/github; they are not settings.
Make the app with tehas setup
tehas setup --new-app
Setup prints one link. Open it in a browser signed in to the account that
should own the app: GitHub shows the app's name and permissions, filled in.
Press Create GitHub App. GitHub then opens a page whose address ends in
?code=...&state=.... Paste that address (or the code alone) at setup's
prompt. Setup turns the code into the app, writes the key to
~/.config/tehas/github-app.pem (mode 600) and the app's ID to instance.env
as TEHAS_GITHUB_APP_ID, keeps the app's client id and client secret beside
the key for the plugins' sign-in, and prints the install link. Install the app on the
product repository, and on the repository review findings go to if it is
another one. Setup waits up to 10 minutes for that, then goes on.
--app-owner <login> sets the organisation or user that owns the app (the
repository's owner by default) and --app-name <name> its name
(<repository>-factory by default; the slug of the name becomes the bot's
login). The code lasts an hour and works once. Run tehas setup again to
start over.
To use an app you already have, give its ID and key:
tehas setup --app-id <App ID> --app-key-file <downloaded>.private-key.pem
The client, for the plugins' sign-in
A plugin's view is served only to a person GitHub says has access to the
repository, who signs in through the app's web flow
(the gate of the views). That needs
two things of the app: a callback URL and a client secret. tehas setup --new-app sets the callback in the manifest when instance.env has
TEHAS_DOMAIN, and keeps the client id and secret GitHub returns in
~/.config/tehas/github-app.client-id and github-app.client-secret, mode
600. With TEHAS_EDGE_ONE_LEVEL=on the name is plugins-<sub>.<domain>.
An app made before has neither. On the app's settings page, General:
- Under Callback URL, add
https://plugins.<domain>/_auth/callbackand save. - Note the Client ID.
- Under Client secrets, press Generate a new client secret and copy it into a file. GitHub shows it once.
Then, as the tehas user:
tehas setup --app-client-id <Client ID> --app-secret-file <file>
Setup checks the rest as on any run, then writes the two files, mode 600. Remove the file you copied the secret into. Plugins are still being built in this release: nothing reads the two files until the gate runs.
tehas setup lists every step. Setup ends with
tehas github check.
Make the app by hand
Do this on a host that was set up before the wizard, or to see what the wizard asks for. In the organisation (or account) that owns the product repository: Settings, Developer settings, GitHub Apps, New GitHub App.
| Field | Value |
|---|---|
| GitHub App name | <product>-factory, for example. Its slug becomes the bot's login, <slug>[bot] |
| Homepage URL | The product repository's URL. Nothing calls it |
| Callback URL | https://plugins.<domain>/_auth/callback, with the instance's TEHAS_DOMAIN, for the plugins' sign-in. Empty without a domain |
| Setup URL | Empty |
| Expire user authorization tokens | Leave on. tehas uses installation tokens, which always last one hour |
| Request user authorization (OAuth) during installation | Off |
| Enable Device Flow | Off |
| Webhook, Active | Off. tehas polls; it needs no public address |
| Where can this GitHub App be installed? | Only on this account |
Repository permissions, everything else "No access":
| Permission | Access | What tehas does with it |
|---|---|---|
| Contents | Read and write | Push cycle branches, read the code and releases |
| Issues | Read and write | Labels, comments, issue edits, closing |
| Pull requests | Read and write | Open, edit and ready pull requests |
| Metadata | Read-only | Required by GitHub |
| Actions | Read-only | Read CI runs |
| Checks | Read-only | Read a pull request's checks |
| Commit statuses | Read and write | Read a pull request's statuses; a plugin's hook posts one (plugins) |
Leave Workflows at "No access" on purpose: with it off, no cycle can push a
change to .github/workflows/. No organisation or account permissions, and
subscribe to no events.
Create the app. On its General page note the App ID, and under
Private keys generate one: a .pem file downloads. Keep it secret; it is
the app's only credential. Install the app (Install App, then Install
next to the organisation) on the product repository, and on the repository
review findings go to if it is another one.
Then give the app to the host with tehas setup --app-id <App ID> --app-key-file <key>, or by hand as the tehas user:
install -m 600 <downloaded>.private-key.pem ~/.config/tehas/github-app.pem
and one line in the instance's instance.env:
TEHAS_GITHUB_APP_ID=<App ID>
The key stays in ~/.config/tehas, outside the instance directory, and is
never given to a cycle's container. The installation ID and the bot's login
are not written down: the first command that needs them asks GitHub with the
app's key and keeps the answers in ~/tehas/state/github/installation and
~/tehas/state/github/login. If the app is not installed on TEHAS_REPO,
every command says which repository and gives the install link.
Commits a cycle makes are authored as the tehas user's git identity. tehas setup sets it to the app. By hand, the bot's user ID is
gh api 'users/<slug>[bot]' --jq .id:
git config --global user.name '<slug>[bot]'
git config --global user.email '<user id>+<slug>[bot]@users.noreply.github.com'
Then check it:
. ~/tehas/env.sh
tehas github check
It prints the app, the installation, the bot's login, when the token runs out
and whether the installation reaches TEHAS_REPO, and never the token itself.
command -v gh now answers ~/tehas/shim/gh.
Moving a host that used a token
GH_TOKEN in ~/.config/tehas/env, GH_CYCLE_TOKEN and TEHAS_CYCLE_LOGIN
are refused: any command stops with exit 78 and says
<NAME> is no longer used: the factory acts as a GitHub App. Take them out,
make or give the app as above, and run any command again.
TEHAS_GITHUB_APP_INSTALLATION, TEHAS_BOT_LOGIN and
TEHAS_MILLWRIGHT_LOGIN are not settings: the installation is looked up and
both logins are the one in ~/tehas/state/github/login. Since tehas 1.0 a
line that sets one stops every command with exit 78; take them out too.
tehas setup --token-file and --app-installation are unknown options (exit 64).
What tehas does with it
tehasbot github-tokensigns a short JSON Web Token with the key, exchanges it for an installation token, and keeps that in~/tehas/state/github/token(mode 600) until fewer than 10 minutes are left.env.shputs~/tehas/shimfirst onPATH. Itsghasks for the token at every call, so a command that runs for hours never holds an expired one; git's github.com credential helper asks the samegh. The dispatcher's poll is the one caller that asks once: it takes the token at its start, gives it to everyghof the poll asTEHAS_GH_TOKEN, and gives it totidy,statusandhealthwhen the poll runs them, so theghof none of them asks again (#938, #965). The poll keeps it in memory only - never in a log, a file, or the poll's record.- A cycle's container is never given the app's own token. It gets a second
token from the same app, narrowed to the product repository with Contents
and Pull requests write and Issues read (#1814):
tehasbot github-token --cyclemakes it and keeps it in~/tehas/state/github-cycle. The container is given that directory read-only, and the token as its firstGH_TOKEN. The cycle's pull request and comments carry the app's<slug>[bot]login, so no user account is behind a cycle and none can be suspended. Without the narrowed token no cycle starts. A planning turn's and a manual session's container is given a token of the same body, made when the command starts, renewed every 5 minutes while the container runs (tehasbot github-token --session) and kept in~/tehas/state/github-session, read-only, never the key or the app's own token, and the image's ownghreads the token there at every call. Neither token can label an issue or comment on one: the issue writes of a container are not made with it. A cycle'sgh issue create,gh issue editandgh issue commentgo to the host instead, through the cycle's relay directory (<workspace>.state/relay,/run/tehas/relayin the container):tehas workruns them with the app's token, asked for each one, and only with a title, a body and an issue number. A comment goes only on the cycle's own issue or on one the cycle created through the relay, and an edit only on an issue the cycle created during that cycle. A cycle has at most 50 such writes. A label, an assignee, a milestone, a project, a state, another repository, a body over 1 MiB, a link in place of a file, and a title or body with<!-- tehas:in it, in any letter case and with any white space after<!--, are refused with the reason. A planning turn and a session have no relay.tehas workrenews the cycle's token every 5 minutes while the cycle runs. A failed renewal is one line in the cycle's work log, never a token, and is tried again after 30 seconds, so two failures in a row no longer let the token run out. One renewal that runs past 60 seconds is stopped, with what it started, and counts as a failed one, so a hung call to GitHub neither stops the renewals nor holds the end of the cycle. The renewer istehas-cycle renew(console/cycle/src/renew.rs). It ends within a second of atehas workthat was killed outright, so it does not keep the issue's lock after its cycle is gone. - The dispatcher, the refresh and the Protolab take the bot's login from
~/tehas/state/github/login, because an installation token cannot ask GitHub who it is. The millwright is that same login (see the millwright's grant). - When a new token finds the app renamed (see
the commands page), the bot's user id in
~/tehas/state/account-idsis recorded under the new login before~/tehas/state/github/loginis rewritten; the old pair stays. If that record cannot be written, the old login is kept and the next token tries again. The dispatcher knows the bot's comments by that user id, and by login only when none is recorded, so a question asked before the rename is still found.
The shim's gh keeps an account of what the factory writes. A call that writes
to GitHub - a comment, a label, an api call that posts, patches, puts or
deletes, a GraphQL mutation - appends one tab-separated line to
~/tehas/state/github-writes.log before it hands gh's own output back: the
time in UTC, the kind (api POST, issue comment, ...), the repository, the
issue or PR number, gh's exit status, and 403 or 429 when gh's error stream
says so, else -. It holds nothing else: not the token, not a body, not a
field value. Reads are not logged and run as they always did. gh api graphql
always sends POST, a query among them, so the shim reads its method for
nothing: it reads the first word of the query instead, and logs the call only
when that word is mutation. An idle poll asks GitHub nothing but queries, and
so adds no line. Which call is a write, and the line, are decided by
console gh, which the shim execs; a read goes on to gh at once. A host whose
console is missing or cannot be run still has a working gh, with the token,
and logs nothing until the console is repaired. The poll line of tehas status counts it, and tehas github writes shows the last day by hour and
by its busiest minute against GitHub's limits. A write GitHub refuses for a
rate limit is sent once more after a minute, and only that call
(the commands page).
The commands page has the details.
What a container's token may do
A cycle's, a planning turn's and a session's container get the narrowed token, never the app's own. It has these permissions on the product repository and on nothing else:
| Permission | Access |
|---|---|
| Contents | write |
| Pull requests | write |
| Issues | read |
| Metadata | read |
GitHub lets a token with Pull requests write manage the repository's labels: create, rename and delete them. GitHub's tables list Issues write or Pull requests write for those calls. So a container can rename a label, though it cannot apply one to an issue or comment on one with this token. The dispatcher does not take a label's name as proof of what it is: it pins each granting label, as the next section says.
Label pins
The dispatcher keeps the GitHub node id of each label whose application
grants work (tehas:ready, tehas:plan, tehas:refine, tehas:finish,
tehas:blocked, tehas:lean and tehas:classic) in ~/tehas/state/labels,
one <name><tab><id> line each. The first page of each poll reads the
repository's tehas: labels with their ids, and the label events read from
GraphQL carry the id of their label:
tehas labels, whichinstall.shruns andtehas updateruns when the table of labels changes, makes the labels and then pins them, and printspinned the label <name> as <id>. With no file yet it pins every granting label it finds, so a host that ran it at install has a pin for each. Once the file exists it pins only a label it made itself, one that did not exist before it ran: a label that was already there with no pin could be another label renamed to the name, so it is named (not pinned: ... was there before with no pin) and the command exits 1. The one exception is a label GitHub says was created within a minute of a label that is pinned and still that label: the sametehas labelsrun made both, so it is pinned (pinned the label <name> as <id> in state/labels: it was made with the pinned labels). A renamed label keeps its creation time, so this does not take one. This is howtehas:blocked, pinned from 1.0, gets its pin on a host from before.- A host with no file, one from before the pins, is pinned by its first poll that reads the labels: each granting label it finds, and the file is written even when it finds none. A dry run says what it would pin and writes nothing. From then on the poll pins nothing.
- A granting label with no line in the file grants nothing: its applications
count as nobody's and the poll logs
refused: the label <name> (<id>) has no pin. A label that was missing when the pins were made therefore cannot be brought in by renaming another label to its name. - An application whose label id is not the pinned one counts as nobody's:
it starts nothing, and the label is taken off as one applied by an
account that is not allowed. The poll logs
refused: ...with the label's name, the pinned id and the event's id. When the label that now carries a granting name is not the pinned one, no application of it counts that poll, and the log saysrefused: the label <name> is not the one pinned. - The log names such an application's account
unknown. It is no account: it counts as nobody's even whenTEHAS_ALLOWED_LABELERSnames a GitHub account calledunknown, whose own application of a pinned label counts as any listed account's does. The same holds for a millwright app calledunknown. - A pinned label the poll's read of the labels did not name (deleted, or
pushed off the read's page of 100 by other
tehas:labels), and every pinned label when the labels could not be read, grants nothing that poll: label events read from REST carry no label id, so they could not be told from another label renamed to the name. - A refused
tehas:blockedstarts nothing, but it still holds: an issue that carries it waits as it would for an allowed account's, on the marked comment or on the label alone. A refused pin never lets an issue start sooner.
tehas labels pins tehas:prototype the same way, and the
Protolab publishes no ticket while the
label under that name is not the pinned one. The dispatcher does not act on
it.
A label renamed into a granting name, for example a person's bug renamed to
tehas:ready, therefore grants nothing: its old applications carry the id of
the old label.
To delete and recreate a tehas: label, remove its line from
~/tehas/state/labels and delete the label, then run tehas labels: it makes
the label and pins it. To pin a label that is there and has no pin, after
checking on GitHub that it is the label it should be, add its line
(<name><tab><id>, the id tehas labels printed) to the file by hand.
tehas labels never changes a pin that is there. Until a label is pinned its
applications count for nothing.
The relay is a security channel
The relay is the one way a cycle's container reaches GitHub's issues with
more than read access, so it is a host channel and is held to the rule that
nothing may widen what a container is given (the mounts and variables of
tehas work are pinned by console/cycle/tests/work_container.rs). The container gets a
directory to leave requests in. It gets no token for it and no way to ask for
anything but the three commands. The host reads each request, checks it and
runs it. It refuses, with the reason written back to the cycle:
- a command other than
gh issue create,gh issue editandgh issue comment; - a label, an assignee, a milestone, a project, a state change and another repository;
- a comment on an issue other than the cycle's own and the ones it created;
- an edit of an issue the cycle did not create during that cycle;
- a body over 1 MiB, a link in place of a file, and any text containing
<!-- tehas:, in any letter case and with any white space after<!--; - the 51st write of a cycle.
A title and a body that pass are posted masked as the console masks a log:
tokens, keys, passwords, private addresses and the host's names are taken
out. Every @ mention gets a zero-width space after the @, so a cycle's
text notifies nobody.
The host also takes the marker apart where it quotes an agent's text itself, in its own comments and in the plan, so a marker an agent wrote cannot come back as the factory's.
Things seen on the first app
- A token's answer for a repository says
"push": false. That field is a user's access and is not filled for an app; Contents write is what lets it push. - GitHub names the app
<slug>[bot]in REST answers and<slug>in GraphQL andgh --json. tehas drops the[bot]where it compares the two. - Moving an existing factory from a machine user to an app: comments the old
account wrote stay where they are, but if that account is suspended they are
hidden, and the dispatcher cannot see a question it asked there
(
skip #N: its question is not among the last 100 comments; tehas:question is set and no comment carries the question, so the issue waits until its open points are answered or the label is taken off). Taketehas:questionoff and applytehas:readyortehas:refineagain to go on with such an issue. A question on record that is there but was written by another account than the bot is said asskip #N: its question was written by 'X', not the bot 'Y'.