06 Operations
Status: Current Last verified: 579de4b
Runbooks for the deployed system. A self-hosted machine (deploy/selfhost) is run with its ghb command: deploy/selfhost/README.md.
Deploy
| Deployment | How a release goes out |
|---|---|
| The self-hosted machine | sudo ghb update (built images: git pull the checkout, then deploy its commit) or sudo ghb deploy <tag> (pulled images): dump the database, run migrate --roles, start the release and wait until every container is healthy and stays up. On a failure it starts the previous release again, unless the failed one migrated the database; ghb rollback --restore then restores the dump made before the migration and starts the last good release. |
| A worker | make update on each machine rebuilds and reinstalls it; a scheduled run of an older worker refuses a database migrated by a newer release. |
Deploy the API, the dashboard, the Observatory and the MCP server of one release together. A migration that is not additive needs every service of the new release before its old shape is removed. When a release adds an endpoint the other services call, the API goes out first: since B6 the MCP server and the Observatory record fixes through the API's POST /api/fixes.
Migrate
- Back up first:
ghb deploydumps the database before it migrates; elsewhere,pg_dumpthe database. - Apply:
ghb deploydoes it on the self-hosted machine. Elsewhere,github-backup-api migratewithMIGRATE_DATABASE_URLset to a direct connection (the runner's lock does not survive a transaction-mode pooler), ormake migratefrom a machine with the database URL, or let the API apply them at startup. Use the owner's URL: a service role may not change the schema.--rolesalso creates the service roles that are missing (ghb deploypasses it). Migration000019moves every table: it waits up to 30 s for a moment when no session uses them, then takes all their locks at once and holds them for well under a second. If it gives up, nothing changed: run it again, and stop the worker first if a backup run keeps the tables busy. - Start the release. With
MIGRATE_ON_START=falsethe API refuses to start until the migrations are applied, and names the missing ones.
A migration that fails rolls back completely (one transaction). Rules for writing them: 03 data ownership.
Database roles
Each service can connect as its own role (03 schemas and roles). Turning them on, once:
- Create the roles:
github-backup-api migrate --roles(orgithub-backup-worker migrate --roles) with the owner's URL. They start without a login. Create them only this way: migrate stops on a service role withSUPERUSER,CREATEROLE,CREATEDB,BYPASSRLS,REPLICATIONor another role's membership. Drop such a role (DROP OWNED BY ghb_api; DROP ROLE ghb_api;) and runmigrate --rolesagain. It also stops when a role another role created needs a group the owner may not grant (noADMIN OPTION); the error names the role and the group. - Give each login role a password in
psql, so it stays out of the server's logs:ALTER ROLE ghb_api LOGIN;then\password ghb_api. The same forghb_observatoryandghb_worker. Generate the password (openssl rand -base64 24). - Set each service's database URL to its role (with Compose
IDENTITY_DATABASE_URLforghb_identity_svc,RUNS_DATABASE_URLforghb_runs_svc,INSIGHTS_DATABASE_URLforghb_insights_svc,NOTIFY_DATABASE_URLforghb_notify_svc,BILLING_DATABASE_URLforghb_billing_svc, each falling back toAPI_DATABASE_URLand thenDATABASE_URL, andOBSERVATORY_DATABASE_URL), and the self-hosted worker'sDATABASE_URLtoghb_worker, with the owner's URL asMIGRATE_DATABASE_URLin the root.envforgithub-backup-worker migrateandmake migrate.
To go back, point the URLs at the owner again; nothing else changes. A login role you don't use can stay without a login; if one is dropped, migrate grants the others and logs that it is missing (--roles creates it again, without a login). The self-hosted stack connects as the owner today (ADR 0019).
ghb_mcp is retired: since B6 the MCP server has no database URL, and migrate strips the grants of the role. Once no MCP server of an older release connects with it, drop it: DROP OWNED BY ghb_mcp; DROP ROLE ghb_mcp;.
Payments
Billing sells nothing until Razorpay's keys are set (ADR 0018); checkouts answer 503 PAYMENTS_UNAVAILABLE. To start selling:
- In Razorpay's dashboard, generate an API key (test mode first:
rzp_test_...) and add a webhook tohttps://API_DOMAIN/webhooks/razorpaywith a secret of your own, subscribed tosubscription.activated,subscription.charged,subscription.pending,subscription.halted,subscription.cancelled,subscription.completed,payment_link.paid,payment_link.expired,payment_link.cancelled,refund.processedandrefund.failed. International payments must be enabled on the account for dollar Payment Links. - Set
RAZORPAY_KEY_ID,RAZORPAY_KEY_SECRETandRAZORPAY_WEBHOOK_SECRET(all three), andBILLING_SELLER_NAMEandBILLING_SELLER_ADDRESS, which production requires with them. SetBILLING_SELLER_GSTIN(and its state code,BILLING_SELLER_STATE) only once the business is registered for GST: invoices issued before state no tax. Deploy. - Buy the plan in test mode with Razorpay's test card or UPI id, and check that
GET /api/billing/subscriptionshows itactiveandGET /api/billing/invoiceshas its invoice. - Switch to live keys and a live webhook (Razorpay keeps them apart).
Billing's Razorpay plans are made on the first checkout of each price (billing.provider_refs). Changing a price is a new price or cohort row in a migration; never edit one somebody paid. A webhook that failed stays in Razorpay's dashboard, which retries it; each delivery is applied once (billing.webhook_events).
Restore
| Lost | Restore from |
|---|---|
| A database outside the self-hosted stack | An encrypted dump made by deploy/shared/db-backup/backup.sh: deploy/shared/db-backup/restore.sh latest <empty database URL> with the dumps' age key (steps). The dumps hold no grants: run migrate --roles on the restored database before the services connect as their roles |
| Data on a self-hosted machine | The nightly dump or the one made before the last deploy, in /var/backups/ghb: sudo ghb restore latest or sudo ghb restore <file>; the encrypted copies in S3, when set, with deploy/shared/db-backup/restore.sh (steps) |
| A user's repositories | Their own storage: the worker's README explains restoring from a bundle or tarball |
Rotate a secret
On a self-hosted machine store the new value in the selfhost profile of fnox.toml with fnox -P selfhost set <KEY>, commit, and copy it to the machine with make secrets-push-selfhost (one restart; SECRETS.md). A value changed with sudo ghb set (deploy/selfhost/README.md) goes into fnox too, or the next push puts the old one back. A key of the github profile (the Actions secrets) works the same way with make secrets-push-github.
| Secret | Held by | Effect of rotating it | Steps |
|---|---|---|---|
INTERNAL_SECRET (deprecated) | API, Observatory, MCP server, dashboard | Calls between services fail until all four have the new value | Change it everywhere in one deploy; unset it once ghb_legacy_internal_requests_total stops growing |
A service credential (ghb_svc_...) | the calling service's SERVICE_CREDENTIAL (dashboard, mcp, observatory); its hash in the API's and the Observatory's SERVICE_CREDENTIALS | none, if done in order | github-backup-api service-credential new <name> prints a new credential and its entry; add the entry next to the old one (two per name), deploy the API and the Observatory, give the service the new credential, then remove the old entry. The first time, the same order turns a service from INTERNAL_SECRET to its credential: the Observatory reads accounts through identity.accounts_v1, so migrate (000020) before deploying it |
JWT_SECRET | API, Observatory, dashboard | Signs everyone out | Change it everywhere; review tokens and agents created meanwhile in audit_events |
METRICS_TOKEN | API, Observatory, Prometheus | Scrapes fail until Prometheus has it | Change it and deploy |
RESEARCH_HMAC_KEY | API, self-hosted workers that record samples | New samples no longer match older ones | Rotate only when it leaked |
CREDENTIALS_ENCRYPTION_KEY | Observatory | Stored OpenRouter keys must stay readable | Put the new key first in the comma-separated list (it encrypts; every key in the list decrypts) and keep the old one after it while stored keys still use it. On the self-hosted machine, store the list in fnox's selfhost profile and push it: ghb import refuses a list that drops one of the machine's keys unless given --replace-encryption-keys |
NOTIFY_ENCRYPTION_KEY | notify | Stored Slack, Discord and webhook URLs and signing secrets must stay readable: one sealed with a key that is gone fails its deliveries for good | The same as CREDENTIALS_ENCRYPTION_KEY: the new key first, the old one after it; values are not sealed again, so the old key stays until the channels it sealed are deleted or created again |
| Personal and agent tokens | their users | Revoke on Settings > Access Tokens and Settings > Agents | |
An age key that opens fnox.toml (the owner's, CI's) | its machine | Nothing, if the new key is listed before the old one goes | Put the new public key into recipients, run fnox -P <profile> reencrypt -p age -f with a key already listed for every profile that holds ciphertext (selfhost and github; SECRETS.md) and commit; then remove the old key the same way. A profile left out stays readable only by the old key. Git history keeps the old ciphertext, so when a key may have leaked, rotate every value as well |
CLAUDE_CODE_OAUTH_TOKEN | the PR Review workflow | none, if replaced before it expires; after that reviews and @claude requests fail | claude setup-token on a machine signed in with the owner's Claude subscription, then fnox -P github set CLAUDE_CODE_OAUTH_TOKEN and make secrets-push-github (Pull request review) |
CI runners
Every job in .github/workflows runs on the owner's self-hosted runners: light jobs with runs-on: [self-hosted, linux, workstation], CPU-heavy jobs with runs-on: [self-hosted, linux, workstation, fast]. The one exception is CI autofix's fix job, which runs only on an isolated runner labelled autofix-sandbox (Pull request review); no runner on either machine carries that label. Nothing runs on runners GitHub hosts or on another CI provider, and there is no fallback (owner decision, 2026-11-05): when the machines are off, jobs wait for them, and GitHub fails a job that waited 24 hours. .github/actionlint.yaml declares the custom labels.
Two machines. The laptop (x86_64, 12 CPUs, 14 GB) registers six runners, laptop-ci-1 to laptop-ci-6, with the labels workstation and fast besides GitHub's self-hosted, Linux and X64. The owner's second machine, ms22-dell (Intel i5-5200U, 2 cores and 4 threads, 8 GB, a spinning disk, Wi-Fi), registers two, dell-ci-1 and dell-ci-2, with workstation and dell. The Dell's runners are set up on that machine, not from this repository: user systemd units dell-runner@N.service, a rootless Docker daemon of their own and a watchdog timer. A light job goes to whichever machine has an idle runner; a job that asks for fast waits for the laptop. Measured on 2026-11-07, heavy jobs do not fit on the Dell, and these ask for fast:
| Job (workflow) | Why it needs fast |
|---|---|
| Go (CI) | go test -race for the worker engine took 22-35 s on the laptop and 338-553 s on dell-ci-2, where it once hit the 10 min package timeout (job 128379686420) |
| Go Integration Tests, both shards (CI) | past 20 min on the Dell on a cold cache |
| Sites, docs site only (CI) | the Docusaurus build ran past 15 min on the Dell; the design site's build ran there without trouble |
| Frontend, Frontend E2E, Lighthouse (CI) | tsc, Vitest, Next.js production builds and Chromium; Lighthouse's timings depend on the CPU |
| Docker Images & Compose Smoke Test (CI) | builds every image and starts the stack |
| Publish (Publish Container Images) | multi-platform image builds, arm64 under the laptop's host QEMU (see below) |
| Check the Tag Is on main and Tests Pass, Build and Publish the GitHub Release (Release) | go test -race, cross-compiled binaries |
Everything else stays on workstation. Change detection, docs-check, contracts, the deployment configuration, the design site, the Python suite (522 s on dell-ci-1, against its 15 min timeout) and govulncheck (199 s and 261 s on dell-ci-2; its one failure there was a TLS handshake timeout to vuln.go.dev over Wi-Fi) ran on the Dell in the trial; scripts and hooks, the lockfile audits, gitleaks, Trivy, the daily live-site check (it builds nothing and drives the deployed sites with Chromium, which the Dell ran in Frontend E2E), triage, pull request review and the status jobs are light too. A new job takes [self-hosted, linux, workstation], and adds fast with a one-line comment that says why when it is CPU-heavy.
The laptop's runners. Each runner is a user systemd unit (ghb-runner@N.service), and its install, work directory, shared HOME and a rootless Docker daemon of its own (DOCKER_HOST=unix:///run/user/1000/docker.sock, data on a dedicated partition) stay apart from the machine's system Docker. How many run is decided by ghb-runner-scaler.service (deploy/workstation-runners/ghb_scaler.py, installed by deploy/workstation-runners/install.sh; only runner 1 and the scaler start at boot). Every 30 s it reads the runners, the queued jobs (GitHub, every 60 s), memory (MemAvailable, PSI), I/O stalls, the CPU's heat and throttling, free disk and whether the owner is at the desk (away only after 2 minutes). It counts as demand only the queued jobs its runners can take (labels that include workstation and are a subset of theirs, so a job that names dell or autofix-sandbox is not counted), and a laptop runner it started for a light job the Dell took stops after 4 idle minutes like any other. It starts a runner when jobs wait that no idle runner will take and the machine has room (one a minute at the desk, two a tick away), stops one idle for 4 minutes when nothing is queued, and drains runners above the ceiling (4 at the desk, 6 away; battery is no limit, by the owner's choice) or one more each minute while memory, heat or throttling stay high. A runner with a job, or one it cannot read, is never stopped: a drained runner stops once it has been between jobs for 3 s (its README has the rules and the measurements). Jobs run under a memory and CPU cap (a ci.slice: MemoryHigh 6 GB at the desk and 10 GB away with zram, and half the desktop's CPU weight); the scaler also restarts listeners that are gone or stay idle while jobs queue, and prunes the rootless daemon's build cache. Two lessons apply to any capped runner: the cap holds the steps, never the runner's own processes, because a throttled listener loses its long poll and a throttled Runner.Worker stops renewing the job's lease ("The self-hosted runner lost communication with the server", which a suspended or roaming laptop also causes); a bash first on each runner's PATH starts every run: step in a scope under the cap (systemd-run --user --scope --slice=ci.slice), and the rootless daemon puts the jobs' containers there too. The integration jobs start their PostgreSQL and Valkey from a step (scripts/ci-services.sh) rather than as service containers: rootless Docker takes a published port from the same range as the host's outgoing connections and the tests' own listeners, RootlessKit can then fail to bind it ("address already in use": three times in about 1,200 jobs from 2026-11-03 to 2026-11-05, once for the ingress check's Caddy and twice for a service container), and the runner does not retry a service container; the script binds 127.0.0.1 and tries another port. And the runners share an action archive cache (ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE), without which many jobs in a short time get 429 from codeload.github.com while downloading actions/checkout.
The runners on one machine share it. The laptop's keep one home between jobs: the Go caches, the pnpm store, the pnpm release's tarball (~/.cache/ghb-pnpm, checked against the sha512 in packageManager on every use by .github/actions/setup-pnpm), Trivy's database, Playwright's Chromium (~/.cache/ms-playwright) and the smoke job's ghb-smoke builder stay on its disk, so setup-go runs with cache: false and setup-node without a cache (saving them to GitHub's cache after every job tarred and uploaded gigabytes). The per-job pnpm directory, the per-job Docker configs, the smoke job's and the Trivy scan's turn-taking (lock files, $XDG_RUNTIME_DIR/ghb-docker-smoke.lock and ghb-trivy.lock, rather than a concurrency group, whose newest queued job cancels the pending one) and the browser tests' free ports (two Frontend E2E jobs would otherwise both listen on 4311 to 4313) exist because of it. Both machines have Chromium's system libraries, so Playwright installs only the browser. The publish job emulates arm64 with QEMU. A step must not assume a fresh machine.
arm64 images and registry logins on the laptop. The publish job emulates arm64 with the host's QEMU: qemu-user-binfmt (on Ubuntu 26.04 it replaces qemu-user-static) registers qemu-aarch64 at boot, and sudo systemctl restart systemd-binfmt registers it right after the install. The job skips docker/setup-qemu-action when the host has that handler with the F flag, then runs an arm64 container in the rootless daemon and fails with the fix in its message when that does not work; it builds with Docker's default builder, which has no emulator of its own and needs the daemon's containerd image store (Docker 29's default) for the multi-platform build and the cache export. In rootless Docker the action's binfmt_misc mount gives the daemon's user namespace a table of its own, which is empty again once the container exits and hides the host's handlers, so every arm64 RUN step failed with exec format error. Only a new namespace drops that table: restart the rootless daemon (systemctl --user restart docker, with no job running) if anything mounted binfmt_misc in it. The publish job points every step at a Docker config of its own, and the deploy job uses one for its login; both write an entry into it before docker login: from an empty config the Docker CLI keeps the login in a credential helper (pass on the laptop) that every runner shares, and one job logging out removed the login another job was pushing with (failed to fetch anonymous token, 403). The runners' shared home has its own ~/.docker/config.json with an entry too, so steps without a config of their own never use pass (an old ghcr.io token there refused anonymous pulls with denied).
scripts/setup.ps1 (Windows) and the macOS paths of scripts/setup.sh are not run on their own platforms in CI; the macOS bash 3.2 check runs in Docker (bash:3.2) on these runners.
Pull request review
.github/workflows/pr-review.yml runs Anthropic's Claude Code action (v1.0.268, pinned by commit) for three things:
-
Claude review runs when a pull request from this repository is opened, reopened, marked ready for review or pushed to. Drafts, Dependabot's pull requests and the design-system upgrade are skipped. It reads
AGENTS.md,CLAUDE.md, the skills that cover the change anddocs/architecture/doc-map.toml; checks correctness, security, missing tests, documentation and skills that were not updated, and the commit and pull request rules; posts an inline comment for each problem; and keeps one summary comment. A run after a push rewrites that comment with a section "Since the last review" instead of adding another, and a newer push cancels a review still running. The review can read the code, the diff and the CI results; it cannot edit, commit or push. -
Claude on request runs when the repository owner writes
@claudein a comment, a review comment or a review on an open pull request from this repository. Claude answers in a comment of its own, or commits the change to the pull request's branch: commits signed by GitHub, authorclaude[bot], messages in the format of.agents/skills/git-commit-workflow/SKILL.md. Its push starts CI and the review again, so the loop is: read the review, comment@claude fix the blockers(or name the findings), read the next review. It never pushes tomainor to another branch, never merges and never approves. It cannot change.github/workflows(the app has no workflow permission) and does not run the test suites, so CI checks its commits. Comments by anyone else and@claudeon an issue start no job; on a closed pull request, or one whose branch ismain, the job ends with a notice. -
CI autofix runs when a CI push run fails on a branch other than
mainthat has an open, non-draft pull request by the owner (owner's word, 2026-11-06). It is three jobs, split so that the agent's job holds no write scope of the GitHub token. The fix job stays off until the owner isolates it and sets the repository variableCI_AUTOFIX_AGENTtoisolated(see What bounds the agent); until then autofix only re-runs jobs the runner lost:-
CI autofix: decide (
scripts/ci-autofix-gate.sh) skips unless the branch has exactly one open pull request, its head is still the failed commit, it has no labelno-autofix, and the owner orclaude[bot]pushed that commit. It reads each failed job's check-run annotations (the aggregate CI Status job aside; the job holdschecks: read, and an annotation it cannot read fails the job rather than counting as a code failure). When every failed job failed on the runner, it re-runs them, up to the run's third attempt, and then stops. A runner failure is: the runner's own message on line 0 or 1 of the workflow (lost connection, full disk, runner shutdown) in a job with no failed step's exit code, so a test that prints the same words does not count; Docker not starting a service container when only the runner's setup steps failed; for such a setup failure, a busy port or an action that could not be downloaded in the job's log; and a cancelled job with no failed step. A job GitHub did not start stops it at once. Anything else, a job timeout included, goes to the fix, when a Claude secret is set andCI_AUTOFIX_AGENTisisolated; otherwise the job ends with a notice that says which is missing. The comment that hands a run to the fix carries a pending marker and the id of the workflow run that holds the fix, until the commit job's report replaces it. So the gate of a re-run of the same CI run hands nothing over while that workflow run is queued or in progress (it ends with a notice), and does again once it has completed, also when it ended without a report (cancelled by hand). A gate that cannot read or write that comment, or read the workflow run it names, fails instead of handing the run over. The failed jobs' names, which come from the branch'sci.yml, reach the comment with<!--,-->and@defused, like the agent's text below. -
CI autofix: fix runs only on the runner labelled
autofix-sandbox, one at a time per branch. It checks out the failed commit, and right after that, before the agent or any of the branch's code runs,scripts/ci-autofix-recheck.sh(the default branch's copy) looks again at what changed while the job waited in the queue. When the pull request has moved on, the agent does not start and the commit job only replaces the gate's "looking for the cause" comment (unless a newer run's gate has rewritten it). When the autofix comment is about a newer run, no longer carries the pending marker (a fix of this run has reported) or hands the run to another workflow run, the agent does not start and the commit job is skipped. Otherwise it runs Claude with the job's read-onlyGITHUB_TOKEN: it reads the failed jobs' logs (gh run view --log-failed), the pull request and the branch's diff, fixes the root cause in the working tree and runs the failed check again where it can:go test,go vetandgofmt(with the Go releasego.modnames, set up as in CI, and module and build caches of the job's own under its temporary directory),python3 -m unittest,bash tests/<name>_test.shand the docs, deps-ledger and skills checks. pnpm, uv and Docker are not set up there, so a frontend, observatory, Docker or end-to-end failure is fixed from its log and checked by CI on the push. It may not commit, push, callgh api, edit anything under.github/, the skills (.agents/) ordocs/architecture/doc-map.toml(it lists what should change there in its summary, for the owner), or skip, delete or weaken a test or check, and its own.claude/settings are not loaded. Claude Code removes the Claude secrets from the environment its commands inherit (CLAUDE_CODE_SUBPROCESS_ENV_SCRUB), which is a weak layer only: Claude Code keeps the secret in its own process and setsCLAUDE_PIDin every command, and a command running as the same user can read/proc/$CLAUDE_PID/environ(checked on the workstation). It writes a summary whose first line is the commit subject. -
What bounds the agent: its token can write nothing through the GitHub API, and its allowed commands name each check, with no program runner (
uv run,pnpm exec,go -exec) that would step around the deny list. None of that contains the code the checks run. They run the branch's code and any test the agent writes, which an injected log line can steer, as the runners' user (ms22, in thedockerandsudogroups). That code can:- replace the tools first on every runner's
PATH(~/.local/share/ghb-runner-tools/shim, writable by that user), so every later job on every runner runs it, the commit job with itsid-token: writeincluded. With that it can mint a Claude GitHub App token and push to any branch,maintoo: this private repository on the free plan has no branch protection or rulesets (the API answers 403), and a push tomainpublishes images. The commit script's refusals do not apply to such a push; - plant files in the other runners' work directories, read the owner's SSH keys and fnox identity, and reach root through the Docker socket;
- read the Claude secret from the Claude Code process, as above.
So the fix job runs only on a runner that carries the label
autofix-sandbox, which no workstation runner has (a job for it waits in the queue, and the scaler, which counts onlyworkstationjobs, starts nothing for it), and only when the repository variableCI_AUTOFIX_AGENTisisolated(the gate checks it and so does the job'sif). Register that runner and set the variable only after the job runs isolated (Turn it on, step 3). Job isolation alone still leaves the Claude secret readable by the checks, because they run as the same user as Claude Code; only running them in another PID namespace or as another user (Claude Code'ssandboxsetting withbwrap, which the workstation has) hides it. Isolation does not stop the checks from sending what they can read over the network either: the private source, the job's read-onlyGITHUB_TOKEN(the checkout keeps it for the fetch steps, and the agent'sghcommands get it from the action in any case) and the Claude token. Which isolation to use is the owner's decision. - replace the tools first on every runner's
-
CI autofix: commit (
scripts/ci-autofix-commit.sh, the default branch's copy) reads the pull request again and commits nothing when it was closed, merged, turned into a draft, labelledno-autofixor pushed to while the fix ran. It also runs after a fix job that failed or hit its timeout, to say so in the comment. It commits the change as one commit through GitHub's GraphQLcreateCommitOnBranch, signed by GitHub, with the Claude GitHub App's token (contents only, revoked at the end): a push with the job's token would start no CI. The commit expects the failed commit as the branch's head, so a push in between makes it fail instead of overwriting anything. It refuses changes under.github/(workflows, the composite actions CI runs and the linters' settings),.githooks/or.husky/(hooks that run on the owner's machine), to.claude/,.mcp.jsonor.claude.json(the agent's settings),AGENTS.md,CLAUDE.mdorCLAUDE.local.mdin any directory (src/apps/github-backup-design/CLAUDE.mdimports theAGENTS.mdbeside it), the skills under.agents/(also through theagents/skillslink) anddocs/architecture/doc-map.toml(instructions the next attempt and the owner's own sessions read, and skills thatsync-skills-upstream.ymlpublishes),.gitmodulesor.ripgreprc; that covers the files the action protects on other events but does not restore onworkflow_run. Paths are compared in lower case, because on a case-insensitive file system (macOS).Claude/is.claude/andAgents.mdisAGENTS.md; lockfiles and secret files are matched the same way. It also refuses file modes, a change to a file that is executable at the failed commit (until the live check below shows thatcreateCommitOnBranchkeeps its mode), files that hold or look like secrets (private keys and age identities included; binary files are scanned as text, and so is every added line), a lockfile whose whole path the summary does not name, more than 50 files or 2 MB, and a message with[skip ci]or another marker that would make GitHub skip CI and the review on the commit. A summary that looks like it holds a token is replaced by a fixed sentence before it becomes the message and the comment, and in the comment its<!--,-->and@are defused, so it can neither forge the comment's markers nor notify anyone. The same goes for the reason of a refusal, which names the agent's paths and quotes Git's and GitHub's messages (a file may be named<!-- ci-autofix-pending -->), and the log line of a refusal is kept on one line, so a path with a line break starts no workflow command. The subject is the summary's first line when it fits the commit format in at most 72 characters. The OIDC and app tokens reachcurlon its standard input, never on its command line. When the branch has a newer commit, it commits nothing and leaves the comment to that commit's run once that run's gate has rewritten it; a fix job that a newer one replaced in the queue, or whose second look found the pull request moved, ends this way too, without an error. Its message ends withCI-Autofix-Run: <run>andCI-Autofix-Attempt: <n>, and the push runs CI and the review again.
Each job writes one comment on the pull request, as
github-actions[bot], which the next run rewrites: what was re-run, what was committed with the summary, or why it stopped. Autofix stops after 3 autofix commits in a row at the head of the pull request; a commit by anyone else starts the count again. When the cause is outside the branch (a secret, a runner, a decision for the owner), the agent changes nothing and the comment says what to do. A second pass after an infrastructure re-run is not guaranteed: GitHub does not document whether a re-run requested with theGITHUB_TOKENstartsworkflow_runagain. When it does, that run's actor isgithub-actions[bot], which the fix step lists inallowed_bots(the action's agent mode refuses other bots); both are on the check list below. -
Turn it on.
-
Install the Claude GitHub App on this repository: https://github.com/apps/claude, Configure, Only select repositories. The jobs get the app's token through OIDC (
id-token: write) and post and push with it; their ownGITHUB_TOKENstays read-only. -
On a machine signed in to Claude Code with the owner's Claude subscription, run
claude setup-tokenand store the token it prints withfnox -P github set CLAUDE_CODE_OAUTH_TOKEN, thenmake secrets-push-github(SECRETS.md). An Anthropic API key works instead (fnox -P github set ANTHROPIC_API_KEY, thenmake secrets-push-github; billed per token); when both secrets exist the subscription token is used. -
Only for autofix's fix job, and only after isolating it as What bounds the agent describes:
- Set up a runner for it alone: a separate Unix user, or a rootless container, with no
dockerorsudogroup, no write access to~ms22, the runner tools or the workstation runners'_workdirectories, and a home of its own. - Limit its network to an allow-list: GitHub's hosts for self-hosted runners (GitHub's list in "About self-hosted runners", for the job, its logs and the artifact),
api.anthropic.com, and the hosts its setup downloads from (proxy.golang.organdsum.golang.org, the Go, Bun and Claude Code release hosts,registry.npmjs.orgfor the action's own packages), nothing else. A host list narrows the path out but does not close it:github.comtakes a push to any repository with credentials the code brings along, which only a proxy that allows this repository's paths alone would stop. - Register it with the labels
self-hosted,linuxandautofix-sandboxand noworkstationlabel (config.sh --labels autofix-sandbox), outsideghb-runner-scaler, and give no other runner that label. gh variable set CI_AUTOFIX_AGENT --body isolated.gh variable delete CI_AUTOFIX_AGENTturns it off again; so does removing the runner, after which a fix job waits in the queue until GitHub fails it after 24 hours.
- Set up a runner for it alone: a separate Unix user, or a rootless container, with no
Until one of the secrets exists, the jobs end with a notice that says so and run nothing; autofix still re-runs jobs the runner lost, which needs neither the secret nor the variable. The app accepts only the workflow as it is on main, so a pull request that changes pr-review.yml is not reviewed (the action skips with a warning). workflow_run starts only main's copy of the workflow too, so autofix runs only once its changes are merged; test a change to it on a throwaway pull request after the merge:
- Open a non-draft pull request from a branch whose only commit breaks one test (for example an
exit 1in atests/*_test.shthat CI runs). The comment should say "Autofix attempt 1 of 3", or, withCI_AUTOFIX_AGENTunset, the gate's notice should name it. - With the variable set, check that the commit job made one commit as
claude[bot]with theCI-Autofix-Run:trailer, that CI and the review ran on it, and that the comment links it. - Stop the runner of one of its CI jobs while the job runs (
systemctl --user stop ghb-runner@<n>) to get a runner failure: the gate re-runs it ("attempt 2 of 3"). Then make attempt 2 fail in the code: check thatworkflow_runstarts this workflow for the re-run at all, and that the fix step starts withgithub-actions[bot]as the actor. If no run starts, the comment stays at "attempt 2 of 3"; note it here. - Push twice while a fix runs: the older commit job ends without an error and leaves the newer run's comment alone.
- Re-run the failed CI jobs while a fix runs and let the re-run fail in the code again: its gate ends with the notice "already queued or running in workflow run
" and starts no second fix. Then cancel a fix's workflow run by hand and re-run the failed CI jobs once more: the gate hands the run over again. - Check that
createCommitOnBranchkeeps the executable bit: on the throwaway branch, rewrite an executable file (scripts/*.sh) through the same mutation (gh api graphql, asscripts/ci-autofix-commit.shbuilds it) and look atgit ls-tree origin/<branch> -- <path>. When it still says100755, lift the refusal of executable files inscripts/ci-autofix-commit.shand in the fix job's prompt; when not, note it here. - Close the pull request and delete the branch.
Cost. A run stops at its turn limit (50 for a review, 75 for a request, 100 for an autofix) or its job timeout (30, 45 and 45 minutes); autofix runs at most three times in a row on a pull request. The jobs use claude-opus-5-5; set the repository variable CLAUDE_MODEL to use another (gh variable set CLAUDE_MODEL --body claude-sonnet-5-5), and change --max-turns in the workflow. With the subscription token, runs count against the subscription's usage limits like local Claude Code sessions.
Turn it off. The label no-autofix (gh pr edit <number> --add-label no-autofix; scripts/github-labels-sync.sh creates it) keeps autofix off one pull request, and a draft gets none. gh workflow disable pr-review.yml stops all the jobs and gh workflow enable pr-review.yml starts them again. Deleting the secrets makes them skip with a notice; uninstalling the app (Settings > GitHub Apps) removes its access to the repository.
Runners and limits. The jobs run on [self-hosted, linux, workstation] like every other light job, so either machine takes them, apart from autofix's fix job, which runs on the autofix-sandbox runner; one autofix at a time per branch (concurrency). Each installs Bun into a home directory of its own under the runner's temporary directory, because the runners on one machine share one home. Bun's package cache stays in the runner's tool cache instead (BUN_INSTALL_CACHE_DIR): the action runs bun install for its own packages on every run, and with the cache in that new home it downloaded them again each time (147 s on 2026-11-04). Claude Code comes from the runner's tool cache (scripts/claude-code-binary.sh): the version the pinned action installs, read from the action's own source, downloaded once per runner with the release manifest's checksum and a stall timeout, and handed to the action as path_to_claude_code_executable. The action's own install fetches about 123 MB on every run and has no timeout when the transfer stalls. When the script cannot read the version it warns and the action installs Claude Code as before. The checkout keeps its credentials: the action fetches the pull request's head with them before it replaces them with the app's token. The summary comment is the oldest Claude comment on the pull request, so an @claude answer written before the first review (on a draft, for example) is the one the review rewrites.
Incidents
| Signal | First checks |
|---|---|
| The dead-man check alerts | Is the API up (/health)? If it is, the owner's last full run is older than OWNER_ALERT_AFTER: check the owner's machines (systemctl --user status, github-backup-worker auth status) and the latest run's errors on the dashboard. |
ServiceDown | sudo ghb status and sudo ghb logs <service>. |
SERVICE_BUSY (503) answers | The API sheds load beyond 4 requests per pooled connection; check slow queries and DB_MAX_CONNS. From the Observatory: every LLM slot stayed taken for LLM_SLOT_WAIT_SECONDS (ghb_observatory_llm_slots_total{outcome="busy"}); raise LLM_MAX_CONCURRENT_CALLS if OpenRouter keeps up. |
| New failures are not found by the assistant | The Observatory indexes them from observatory.run_failed jobs (ADR 0013). Check SELECT kind, state, count(*) FROM public.platform_jobs WHERE kind LIKE 'observatory.%' GROUP BY 1, 2; the runs service's startup warning about QUEUE_BACKEND (only PostgreSQL's queue reaches the Observatory); the Observatory's logs for its job runner; EMBEDDING_BACKGROUND_MAX_CALLS_PER_HOUR (0 turns embedding off) and the server key pool (OPENROUTER_API_KEY with OPENROUTER_ALLOW_SERVER_KEYS=true; the default false leaves background embedding off, and the owner embeds with POST /embeddings/process-batch on their own key). One pass by hand: curl -H "Authorization: Bearer $CRON_SECRET" <observatory>/internal/jobs/pass. |
| Disk or memory alerts | With Compose docker system df and log sizes (each container keeps 30 MB); Prometheus' 2 GB cap. |
JobsDead | SELECT kind, attempts, last_error FROM public.platform_jobs WHERE state = 'dead'. A dead job stays 30 days; once its cause is fixed, its work happens again on the next event or read (rollups rebuild when read). |
| CI jobs stay queued or are not started | Jobs wait for a runner labelled self-hosted, linux and workstation, and CPU-heavy jobs for one also labelled fast, which only the laptop's runners have (CI runners): on the laptop python3 ~/.local/share/ghb-runner-tools/ghb_scaler.py status (what the scaler sees and why it holds) and journalctl --user -u ghb-runner-scaler, and the repository's runner list (Settings > Actions > Runners) for the workstation and fast labels. |
OutboxLagging | The runs service relays runs.outbox on every pass of its job runner: check its logs for "A job runner step failed" and that it runs (docker compose ps runs). Events wait while the runs service is idle; to send old events again, set their published_at to NULL. |
| An account says alerts do not arrive | GET /api/alerts/deliveries (or SELECT status, last_error, count(*) FROM notify.deliveries WHERE account_id = $1 GROUP BY 1, 2): failed with the receiver's answer, held (beyond 20 an hour, a digest follows), suppressed (the rule's minimum interval), pending with not_before (quiet hours), skipped (the channel was disabled or deleted). No delivery at all: the account's rules, SELECT kind, state, count(*) FROM public.platform_jobs WHERE kind LIKE 'notify.%' GROUP BY 1, 2, and notify's logs. In the split deployment notify's jobs wait for its runner: within 2 minutes while it has traffic, up to 12 hours otherwise (ADR 0017). |