{"slug":"deploy","title":"Deploying neoopensource","about":"The two apps, their variables, what must persist, backup and restore, limits, first start.","source":"docs/DEPLOY.md","markdown":"# Deploying neoopensource\n\nThe product is neoopensource; the server binary, the variables and the paths below keep their `jit` and `jithub`\nnames (see the README).\n\nTwo apps (decision 0054): the **back end**, built by the `Dockerfile` at the repository root (`jit-server`: the API,\ngit over HTTP and the data), and the **front end**, built by `web/Dockerfile` (the web pages, a Bun server that reads\nonly the back end's API). The back end keeps one data directory; the front end keeps nothing.\n\n| App | Build | Port | Volume | Health | Variables |\n| --- | --- | --- | --- | --- | --- |\n| back end | `Dockerfile` (context: repository root) | 7878 | `/data` | `GET /healthz` | `JIT_PUBLIC_URL` = the back end's public URL; `JIT_WEB_URL` = the front end's origin |\n| front end | `web/Dockerfile` (context: `web/`) | 3000 | none | `GET /healthz` | `JIT_API_URL` = how the front end reaches the back end; `JIT_PUBLIC_URL` = the front end's public URL |\n\nThe back end serves no pages (decision 0066): with `JIT_WEB_URL` set, `/` and `/r/…` on it redirect (`308`) to the same\npath on the front end; without it they answer `404` (JSON). A health check or uptime probe on the back end must use\n`/healthz`, never expect HTML at `/`.\n\n## The back end\n\n`jit-server` serves on one port:\n\n| Path | What |\n| --- | --- |\n| `/`, `/r/{repo}/…` | `GET`/`HEAD`: `308` to the same path and query on `JIT_WEB_URL`; without it, or other methods: `404` (the API's JSON error). The old view's `/assets/…` and `/theme/…`: `404` |\n| `/v1/…`, `/llms.txt` | the API |\n| `/{repo}.git/…` | git over smart HTTP (clone, fetch, push) |\n| `/healthz`, `/v1/health` | health |\n\n### The operator's checklist\n\nOne page; each line says where the detail is. `<c>` is the server's container; `neo` is the CLI (`jit` until the\nrename is on main). No token is ever typed, shown or put in a command's arguments: tokens live in files.\n\n**At the first start**\n\n1. Take the root token out without showing it: `( umask 077; docker exec <c> cat /data/trust/root-token > root.token )`.\n   It is valid 30 days and written once (\"First start: the root token\").\n2. Put the two key files away, offline, apart from every backup:\n   `docker exec <c> tar -C /data/trust -cf - instance.key log.key > keys.tar` (\"Backup and restore\", step 1).\n   Once sign-up exists on the instance there is a third file, `binding.key` (it ties each account to its\n   outside login): it joins this copy the day the first account is made, and an instance that holds accounts does\n   not start without it.\n3. Give yourself a principal of your own and stop using the root token for daily work (\"First start\", steps 1–3).\n4. Note the host's key, which never changes: `neo reflog <any repo> --head` → `signer`. Put it\n   in every runner's setup file as `host_key`, so a runner's request cannot be made for another host\n\n**Regularly**\n\n5. Before the root token's 30 days are over (or after: it does not matter), mint the next one offline:\n   `docker exec <c> jit-server token mint --key /data/trust/instance.key --out /data/trust/root-token.next`, copy it\n   out as in 1. The instance stays the same instance; tokens narrowed from the old one end with it.\n6. A runner's token lasts at most 30 days. The runner warns in its log three days before and then stops with\n   exit code 3 and the command to run: `jit-runner setup <setup file>` as you, not as the runner's user.\n7. Backups run daily on their own where the off-host backup is installed (\"Off-host backups\", in the production host's section); look at\n   `journalctl -u neo-backup` now and then, and run the restore drill once a quarter.\n\n**Before sign-up is switched on (not built yet; decision 0057)**\n\n8. From the first account on, the data directory requires reader version 2: **no build older than the one that\n   made that account can ever be started on it again; there is no rollback past that point.** So the deploy\n   script's check (an image's reader version against `trust/MIN_READER`, refusing a lower one) must be\n   live, and shown to refuse the previous image, before the switch; and a restore after that point starts\n   quarantined (decision 0057, point 14).\n   An image says its reader version without opening anything: `jit-server --version` prints one line,\n   `{\"reader_version\":2,\"version\":\"0.0.0\"}` (keys in that order today; read them by name). Refuse the image when\n   its `reader_version` is below the number in `<data-dir>/trust/MIN_READER` (decimal text and a newline, written\n   by jit-trust before the store's own fence is raised, so it is never lower). A **missing** file means the\n   directory was never opened by a build that writes it: unknown, never 0. Refuse, or open it once with the\n   current build, which writes the file.\n   On the production host that check is `jithub-autodeploy`'s reader fence (in that host's section). It is signed off once\n   trust's `MIN_READER` change is deployed and the fence has been seen to refuse: `jithub-autodeploy --check\n   <a commit from before #294>` must answer `refused …: the image does not report its reader version and the\n   data directory needs …` (`--check` swaps and records nothing).\n\n**If a token leaks or is lost**\n\n| What | Do | Effect |\n| --- | --- | --- |\n| any token you can still present | `neo --token-file LEAKED api POST /v1/tokens/revoke` | that token and everything narrowed from it are refused from the next request |\n| a runner's token (lost host, no file) | `neo --token-file admin.token api POST /v1/repos/<repo>/tokens/revoke --json '{\"revocation_id\":\"<id>\"}'`; the id is in what `jit-runner setup` printed (`token_revocation_id`) and in the repository's signed log (`neo reflog <repo>`, the entry of kind `runner_token`) | the same, and the revocation is an entry in that repository's signed log |\n| everything one principal can do on a repository | `neo --token-file admin.token grant set jp_… --repo <repo> --scopes ''` | every token of that principal stops there, also ones made with its own key |\n| the root token | revoke it with itself (first row), then mint the next one (5) | the leaked one and what was narrowed from it stop; the new one is unaffected |\n| `instance.key` or `log.key` | there is no rotation yet: stop the instance and ask | see the table in \"Backup and restore\" |\n\n**Which id.** A revocation id is one of a token's `revocation_ids` (`neo whoami` with that token, or the answer\nto minting it). It is not the token id the log shows, which is the hash of the token's text: revoking that stopped\nnothing and used to be accepted; it is now refused with a message that says so. The instance refuses an id it does\nnot know as a revocation id: it knows the ids already revoked, the ids of runner tokens minted here, and the\nblocks of every token presented since it last started. So **after a restart, an id is unknown until its token is\npresented again**: a runner token is still revoked by its id as in the table (its id is kept), a token you hold is\nrevoked by presenting it (first row), and for a token you do not hold and that has not been presented since the\nrestart the instance's administrator vouches for the id:\n\n```\nneo --token-file admin.token api POST /v1/tokens/revoke --json '{\"revocation_id\":\"<id>\",\"unseen\":true}'\n```\n\n(`neo admin revoke <revocation id> --unseen` once the CLI has it). Only an instance administrator may, through a\ntoken not narrowed below that: this is what \"instance root\" means here; a repository's admin and a narrowed admin\ntoken are `403`. The answer is the usual one plus `\"unseen\": true`. The field is explicit and never a fallback (an\nunknown id without it stays `400`, whose message names the field): a wrong id sent as unseen is recorded as revoked\nand stops nothing, so copy it, do not type it. **The record**: for a runner token's id the revocation is an entry\nin its repository's signed log; for any other id there is no signed log to write to, and the server's log gets one\nJSON line instead (`\"msg\":\"token revoked as unseen\"`, with `principal`: who revoked, `revocation_id`,\n`\"unseen\":true` and `newly`; never the token and never a client address). That line is the record until the\ninstance has a log of its own. On a build without the field, withdraw the principal's grant (third row), which\nstops every token of that principal on that repository.\n\nRevoking is idempotent; an event stream that is already open re-checks its token before every event of a private repository and at least every 15 seconds, and ends once the token no longer authenticates (decision 0059, limits and streams). **After a restore, redo\nevery revocation and grant change made since the backup**: a restore brings back what the backup knew (tested:\n`crates/jit-trust/tests/instance.rs`, the restore test).\n\n### What the platform needs to know\n\n| | |\n| --- | --- |\n| Build | the `Dockerfile` at the repository root (no build arguments) |\n| Port | `7878` (HTTP; TLS is the platform's proxy) |\n| Health check | `GET /healthz` answers `200` and `{\"status\":\"ok\"}`; the image also carries a `HEALTHCHECK` on it |\n| Persistent volume | `/data` |\n| User | `jit` (uid 10001), not root |\n| Stop | `SIGTERM`: open requests drain for up to 10 s, then exit 0 |\n\n### Variables (names only)\n\n| Name | Set by | Meaning |\n| --- | --- | --- |\n| `JIT_PUBLIC_URL` | **you, in the deployment** | The address people and agents reach the service at, for example the `https://` URL of the app. Clone URLs and links are built from it. Without it they point at `http://0.0.0.0:7878`. |\n| `JIT_BACKEND` | the image (`real`) | The real backend: repositories, git transport and tokens on disk. Do not change it: `mem` keeps nothing. |\n| `JIT_DATA_DIR` | the image (`/data`) | The data directory. |\n| `JIT_LISTEN` | the image (`0.0.0.0:7878`) | The listen address inside the container. |\n| `JIT_MAX_OBJECT_BYTES` | optional | The largest file a push may contain, in bytes. Default `134217728` (128 MiB). Also `[limits] max_object_bytes` in `config.toml`; the variable wins. See \"Limits on what a push may hold\". |\n| `JIT_MAX_PUSH_BYTES` | optional | The most pack bytes one push may send. Default `4294967296` (4 GiB). Also `[limits] max_push_bytes`. |\n| `JIT_MAX_DECODE_BYTES` | optional | The most one read may allocate to decode one stored object (with its delta chain). Default eight times `JIT_MAX_OBJECT_BYTES` (1 GiB). `0`, a value that is not a number of bytes, or one under four times `JIT_MAX_OBJECT_BYTES` (what reading an accepted file can need) does not start the server. Also `[limits] max_decode_bytes`. |\n| `JIT_MAX_BUNDLE_BYTES` | optional | The largest bundle `GET /v1/repos/{repo}/bundle` (`neo bundle`) serves, in bytes. Default `2147483648` (2 GiB, what `neo bundle` accepts by default). A larger one is answered `413 too_large` and its file removed. `0` or a value that is not a number of bytes does not start the server. Also `[limits] max_bundle_bytes`. Bundles are files under `<data-dir>/bundles/` (one per repository, of its current log position; earlier ones are removed, nothing to back up); no new one is written below `JIT_MIN_FREE_BYTES` (decision 0085). |\n| `JIT_WEB_URL` | optional (production: **you**) | The front end's origin, for example `https://neoopensource.com`: `/` and `/r/…` on the back end redirect there, so old links and bookmarks keep working. An `http`/`https` URL with a host and nothing after it (no path beyond `/`, query, fragment or user name); anything else stops the server at start-up naming the variable. Also `web_url` in `config.toml`; the variable wins. Without it those paths answer `404`. |\n| `JIT_CONFIG` | optional | A `config.toml` to read instead of `/data/config.toml` (rate limits, body cap; `docs/contracts/jit-server.md` section 1). It never holds secrets. |\n| `JIT_METRICS_LISTEN` | optional | Where Prometheus metrics are served (`GET /metrics`), for example `127.0.0.1:9100` or the container's address on an internal network. Unset: no metrics. See \"Metrics\" below. |\n| `JIT_NODE` | optional | This server's name in its metrics (the `node` label on every series), for example `us-1`; `[a-z0-9-]{1,32}`, default `primary`. |\n| `JIT_TRUSTED_PROXY` | **you, when a reverse proxy is in front** | IP addresses and CIDRs, comma-separated (for example `172.18.0.1,172.18.0.3`; exact addresses preferred over CIDRs): the peers (Caddy through Docker's gateway, the `web` container) whose right-most `X-Forwarded-For` entry is the client address the anonymous limits key on. Unset: every client is its TCP peer, so behind a proxy all anonymous callers share one bucket and anonymous clones have no per-client share (a warning at start-up says so). Precondition: the server's port is reachable only by Caddy and the `web` container (published on `127.0.0.1` or not at all). Verify the two host facts in \"The client address behind the proxy\" before setting it. |\n| `JIT_GIT_CONCURRENT`, `JIT_GIT_CONCURRENT_PER_CLIENT` | optional | Clones and fetches producing a pack at once, overall (default twice the CPUs) and per token or, behind a trusted proxy, per client address (default a quarter of the total). See \"Clones and fetches are capped\". |\n\n| `JIT_SIGNUP` | **leave unset** (production runs with it off) | Sign-up: `off` (the default), `preview` or `privy`. See \"Sign-up\" below. Off, the sign-up routes do not exist and nothing else here is read. |\n| `JIT_SIGNUP_ALLOW_FILE`, `PRIVY_APP_ID`, `PRIVY_APP_CLIENT_IDS`, `PRIVY_KEYS_FILE` | only with sign-up on | The preview's list, the Privy app and its client ids (public identifiers, never in the code), and the file of the app's public keys. See \"Sign-up\". |\n\nThere is no secret to put in the environment: the instance makes its own keys and its first token on first start.\n\n### Sign-up\n\n**The deployed instance runs with sign-up off** (`JIT_SIGNUP` unset). Then the sign-up routes\n(docs/contracts/accounts.md) answer exactly as paths that do not exist, except `POST /v1/session/end`, and every other\nroute behaves as before: off is what a cut deploys. Turning it on is a deliberate change of the deployment,\nafter item 8 of the operator's checklist above, never a side effect of a merge.\n\nTo turn it on, set in the deployment (each also a key of `[signup]` in `config.toml`; the variable wins):\n\n| Variable | Value |\n| --- | --- |\n| `JIT_SIGNUP` | `preview` (only the people on the list) or `privy` (anyone) |\n| `JIT_SIGNUP_ALLOW_FILE` | with `preview` only: a file of Privy DIDs, one per line (`#` comments allowed). Refused with `privy`. |\n| `PRIVY_APP_ID` | the Privy app's id (public) |\n| `PRIVY_APP_CLIENT_IDS` | the accepted client ids, comma-separated (public); not empty |\n| `PRIVY_KEYS_FILE` | `{\"checked_at\": <Unix seconds>, \"keys\": [JWK, …]}`: the app's P-256 public keys, one or two. Update `checked_at` whenever you compare the set with Privy's: after 7 days new sign-ins answer `503 keys_stale` (existing sessions keep working). |\n| `JIT_PUBLIC_URL` | **required, set explicitly**: the API's public origin as people dial it (`https://…`; `http` only for a loopback host). A machine's pairing poll must name it, so a pairing relayed through a mistyped address never completes. |\n| `JIT_TRUSTED_PROXY` | **required**: the reverse proxy's address. Without it the server refuses to start (unless it listens on loopback only), because the per-address limits of sign-up and pairing would otherwise be one limit for everyone behind the proxy. Verify \"The client address behind the proxy\" first. |\n\nThe server refuses to start on a missing or malformed one and names it (never a line of the allow list). The\nper-address limits (5 sign-ups a day, 10 pairings started and 10 lookups an hour, starting a login) are kept in memory\nand start again at every restart; the hourly bound on new accounts (100) and the per-account and per-session limits\nare kept by jit-trust in the store and hold across restarts. Switching back to `off` and restarting makes the routes\ndisappear again, and jit-trust refuses every account credential (sessions, machine keys) on every route but\n`POST /v1/session/end`, which still ends a session for good (`accounts_dormant`, set at start from `JIT_SIGNUP`).\n\n### Metrics\n\nSet `JIT_METRICS_LISTEN` to serve Prometheus metrics at `GET /metrics` on a second listener (for example\n`0.0.0.0:9100` inside the container, on a network only the Prometheus container shares). **Do not publish that\nport**: it has no authentication, the network is its only fence (it never shares the public port, and the server\nrefuses to start if you point it there). With host networking, or outside a container, use `127.0.0.1:9100`: `0.0.0.0` would put it on the public interface. Scrape it every 15 s or more; gauges are re-read at most every 15 s and the\ndisk size once a minute. Counters reset at each restart (each deploy). The list of metrics and their labels is\n`docs/contracts/metrics.md`; none carries a repository, a principal, a token, a path or an address. Every\nseries carries `node` (set `JIT_NODE` per server); the contract says which metrics to sum across nodes and which\nto read from one.\n\n```yaml\n# docker compose, sketch: the metrics port is on the internal network only, not under `ports:`\nservices:\n  jithub:\n    environment:\n      JIT_METRICS_LISTEN: \"0.0.0.0:9100\"\n    networks: [default, metrics]\n  prometheus:\n    networks: [metrics]   # scrapes http://jithub:9100/metrics\nnetworks:\n  metrics:\n    internal: true\n```\n\n### What must be persistent\n\nAll of `/data`, as one volume:\n\n- `/data/store/`: every repository (objects, packs, refs) and the metadata store, including the signed ref logs.\n- `/data/trust/`: the instance's keys and the first token. **Losing this directory loses the instance's identity**:\n  tokens issued before stop working and the ref logs can no longer be continued by the same signer.\n\nNothing outside `/data` is state. How to back it up and restore it is the next section.\n\n### Limits on what a push may hold\n\nInstance settings in bytes, read at start (a value that is not a positive whole number stops the start\nwith a message; `jit-server --print-config` shows what is in force):\n\n| Setting | Environment | `config.toml` | Default |\n| --- | --- | --- | --- |\n| The largest file in a push | `JIT_MAX_OBJECT_BYTES` | `[limits] max_object_bytes` | `134217728` (128 MiB) |\n| The most pack bytes in one push | `JIT_MAX_PUSH_BYTES` | `[limits] max_push_bytes` | `4294967296` (4 GiB) |\n| The most one read decodes for one object | `JIT_MAX_DECODE_BYTES` | `[limits] max_decode_bytes` | eight times the largest file: `1073741824` (1 GiB) |\n| The largest bundle served (`GET …/bundle`) | `JIT_MAX_BUNDLE_BYTES` | `[limits] max_bundle_bytes` | `2147483648` (2 GiB) |\n\n- A push that contains a larger file is refused as a whole, nothing of it is kept, and git shows the person why:\n  the file's size, the limit and its setting, and what to do (\"a file that large does not belong in git here: keep\n  it elsewhere, commit a reference to it, and push again\"). A push over the second limit is told to push the\n  history in smaller steps.\n- Why there is a per-file limit at all: a pack can describe a large file in a few kilobytes (a delta), so the\n  limit is what bounds how much memory a small request can make the server use. 128 MiB is in line with what hosted\n  forges accept.\n- **The limits are on what is received, not on what is served.** A repository that already holds a larger file\n  (the limit was lowered later) is cloned and fetched whole.\n- They apply to `git push` and to an import. The API's own body cap (`max_body_bytes`, 8 MiB) is separate.\n- **A push is authorized twice.** Once before its pack is read, and again inside the transaction that moves its\n  refs: a token revoked or expired, or a right withdrawn, while the pack was arriving refuses the whole push\n  (\"the token has been revoked\"), and nothing of it becomes reachable. This holds for `git push`. **It does not\n  yet hold for commits made through the API or for a landing made on a caller's behalf**: those authorize before\n  their write and do not ask again inside it.\n- **A chain of deltas is bounded at the push, and every read is bounded.** To read an object stored as a delta,\n  the server decodes its whole chain at once: two buffers of the chain's largest object and every delta's\n  instructions together. A push in which one chain's instructions come to more than twice `JIT_MAX_OBJECT_BYTES`\n  (256 MiB at the default) is refused (\"a chain of deltas in this push needs … bytes\"; the person repacks with\n  `git repack -adf --depth=50` and pushes again). And no read may allocate more than `JIT_MAX_DECODE_BYTES` (eight\n  times `JIT_MAX_OBJECT_BYTES`, 1 GiB at the default) for one object: past it that one request fails with an error\n  and the server goes on. A file within the push limits never needs that much. **If a legitimate object ever hits\n  it** (a repository imported or pushed before these limits held one larger than they now allow): its clone, fetch\n  or file read fails with a server error naming no object, and the server's log has the reading error; raise\n  `JIT_MAX_DECODE_BYTES` to cover it (at most about three times the object's size plus its chain) and restart, or\n  keep the file out of the repository.\n- **A floor of free disk space, off by default:** `JIT_MIN_FREE_BYTES` (or `[limits] min_free_bytes`), in bytes.\n  While the file system that holds `/data` has less than that available, a `git push` is refused before its pack\n  is read (\"this instance is short of disk space and takes no pushes for now\"), and clones and fetches go on. It\n  is one system call per push and keeps no state. A commit made through the API\n  (`POST /v1/repos/{repo}/commits`) is refused the same way. A token with `admin` on the instance may still push\n  and commit below it. Not yet covered: imports (no import route exists yet).\n- **Everything a push makes the server inflate counts against one total** (16 GiB a push): every object, every\n  delta's instructions, and what each delta builds. A push is refused at the entry that would pass the total,\n  before that entry is inflated.\n- **A tree that arrives is checked as git checks received objects**, and the push or import is refused, naming the\n  tree and the reason, when a tree holds: the same name twice (a file and a symlink, a file and a directory), entries\n  out of git's order, the name `.`, `..`, an empty name, a name with `/`, `.git` in any spelling a git client reads\n  as `.git`, `.gitmodules` as a symlink, a mode padded with a zero or a mode that is not a directory, file,\n  executable, symlink or submodule. Each of these has been a way to make a checkout write outside itself. Old\n  histories made by old tools sometimes hold zero-padded modes: such a repository is refused on import until it is\n  rewritten. A tree the repository already held is not judged again. Trees made through the API\n  (`commits.create`) are built by the server and meet all of this by construction.\n\n### Backup and restore\n\nTwo commands of the same binary, each printing one JSON object. A backup is taken **while the instance runs**; it\ndoes not stop or slow pushes.\n\n**1. Once, right after the first start: put the two key files somewhere a backup is not, offline.**\n\n```\ndocker exec <container> tar -C /data/trust -cf - instance.key log.key > jithub-keys.tar\n```\n\n`instance.key` is the instance's identity: every instance token is minted under it and verified against it.\n`log.key` signs every ref log entry and checkpoint. Neither changes after the first start. Keep `jithub-keys.tar`\nin a secret store, off this host: move it there, check that it opens, and delete it here.\n\n**A third file once people can sign up: `binding.key`.** It appears in `/data/trust/` at the first sign-in and\nnever changes. It links a person's outside identity to their account without the store holding the identity.\nTake the copy again right after the first sign-in, with all three:\n`docker exec <container> tar -C /data/trust -cf - instance.key log.key binding.key > jithub-keys.tar`.\nLost, every signed-up person is a stranger to their own account and the instance does not start on that data\n(it is never made again); leaked together with the store, accounts can be linked to identities. Like the\nother two it is in no backup unless you ask (`--with-keys`). They are **not** in a backup unless you ask for them (`--with-keys`), so that a backup that\nleaks cannot mint tokens or sign logs.\n\n| If it is | lost | leaked |\n| --- | --- | --- |\n| `instance.key` | every instance token is dead and a restore is a different instance | whoever has it mints root tokens; there is no rotation yet |\n| `log.key` | no existing ref log can be continued | whoever has it can sign a forked log that verifies |\n\n**An instance that has had its first sign-up has a third key, `trust/binding.key`** (jit-trust writes it once, at\nthe first account; an instance with no account has none). Keep it with the other two from that day on: it is what\nties each account to the person who signed up, the store of an instance with accounts does not start without it,\nand like the other two it is in a backup only with `--with-keys`. `backup.json` carries the id of the key the\nstore's accounts were made with (`binding_key_id`, a hash, never the key) and lists the file under\n`keep_separately`; a restore of such a backup refuses, before writing anything, keys that lack it or hold\nanother one.\n\n`root-token` is never in a backup, with or without `--with-keys`: it is a credential that expires, and a new one\nis minted from `instance.key` whenever needed (step 3).\n\n**2. A backup, as often as you like:**\n\n```\ndocker exec <container> jit-server backup --data-dir /data --to /data/backups/2026-11-29\ndocker cp <container>:/data/backups/2026-11-29 ./jithub-backup-2026-11-29     # off the volume, off the host\ndocker exec <container> rm -r /data/backups/2026-11-29                        # optional: free the volume\n```\n\nThe directory given to `--to` must not exist yet. The command asks the running server to take the snapshot (only\nthe process that has the store open can read it consistently). It proves itself with a token it mints on the spot\nfrom `/data/trust/instance.key`, valid for five minutes: being able to read the instance key is the right to back\nthe instance up, and nobody who was merely granted rights, not even `admin`, can ask for one. It prints what it\ncopied: repositories, tables, rows, object files and bytes, and how long it took. If no server is\nrunning on that data directory, the same command takes the backup itself.\n\nWhat a backup holds, all **as of one instant**:\n\n| In the backup | |\n| --- | --- |\n| `store/` | every repository: objects, packs, refs; and the metadata store with the **signed ref logs**, principals, grants, revocations, changes, reviews, claims, events, landing rules |\n| `config.toml`, `collab/` | if the instance has them |\n| `backup.json` | when it was taken, by which version, what was copied, and the public halves of the two keys |\n\n| Not in the backup | Keep it how |\n| --- | --- |\n| `trust/instance.key`, `trust/log.key` | step 1, once; or `--with-keys` to put them in this backup |\n| `trust/root-token` | not kept: mint a new one (step 3) |\n| `server.json`, `tmp/` | not state |\n\n\"One instant\" means: a ref and the log entry that moved it are in the backup together or not at all, and every\nobject a ref of the backup leads to is in it. A push that is acknowledged before the command starts is in the\nbackup; one that is acknowledged after it returns is not; one in between is in it wholly or not at all.\n\n**A backup is secret material even without the two key files.** `store/` holds the content of private\nrepositories and the root key seeds of every repository whose key the host holds in custody. Store it encrypted\nand access-controlled, like the keys, never as ordinary data.\n\n**3. Restore, into a new directory (here: a new volume mounted at `/data` of a container that is not running the\nserver yet):**\n\n```\ndocker run --rm -v jithub-new:/data -v \"$PWD\":/in --entrypoint sh <image> -c '\n  mkdir /tmp/keys && tar -C /tmp/keys -xf /in/jithub-keys.tar &&\n  jit-server restore --from /in/jithub-backup-2026-11-29 --data-dir /data/restored --keys-from /tmp/keys'\n```\n\nthen start the instance on it (`JIT_DATA_DIR=/data/restored`, or move its content to the volume's root), and mint\nyourself a root token, because a restored instance has no `root-token` file:\n\n```\ndocker exec <container> jit-server token mint --key /data/restored/trust/instance.key --out /tmp/root --ttl-s 2592000\n```\n\nRestore\n\n- refuses a target directory that is not empty;\n- refuses to finish without the instance's own keys, and checks the keys it is given against the public keys in\n  `backup.json` (an instance started on this data with other keys could not sign for its repositories, and no token\n  issued before would be valid);\n- copies, then opens the result and checks that every ref of every repository points at an object that is there.\n\nThen check from outside, per repository: `jit verify <repo>` (the signed log verifies and names the refs) and a\n`git clone`.\n\nWhat a restore means:\n\n- **The same instance.** Same identity, same log signer: tokens minted before the backup still verify until they\n  expire, and the instance signs new entries for its repositories.\n- **The instant of the backup, nothing later.** Pushes and changes after it are gone, **and so are token\n  revocations and grant changes**: a token revoked after the backup works again, a grant removed after it is back.\n  Redo those by hand before the instance is reachable.\n- **Clients and mirrors that saw the log after the backup will report a rollback** (`jit verify --since`: the\n  checkpoint they kept is larger, or of the same size with another root) as soon as the restored instance appends.\n  That is the audit working as designed; announce the restore to them.\n- **Never run the old and the restored instance at the same time.** Two logs signed with one key in different\n  directions is equivocation, and it is provable from the two signed checkpoints.\n- **A copy of `store/` without the two key files is not this instance.** `jit-server restore` refuses to finish\n  without them; do not work around it by letting a first start create new keys next to an old store.\n\n### What a crash leaves\n\nThe server can be killed at any moment (`kill -9`, a power cut, the platform replacing the container); there is no\nclean-shutdown step that the data depends on.\n\n- **A push that was acknowledged is there after the restart**: its objects were written and synced to disk, and the\n  transaction that moved its refs and added the signed log entry was committed and synced, before the client was\n  told \"ok\". The same holds for every API write that returned success.\n- **A push that was not acknowledged either left nothing visible or, if the server died after committing and\n  before answering, is there in full.** There is no third state: all refs of an atomic push move together or not at\n  all, with their signed log entry, in one transaction. If it did not commit, no ref moved, the log has no entry\n  for it, no object of it is served, and what was received of its pack sat in a quarantine directory that is\n  deleted the next time the repository is used. The tests kill the server halfway through a pack and right after an\n  answer; the window between the commit and the answer is not covered by a test, and is the case below.\n- **What a client does after a broken connection.** It cannot know which of the two happened, so it asks:\n  - `git push`: push again. If the first one landed, the second is a no-op (\"Everything up-to-date\"); if it did not,\n    it lands now. Reading the ref first (`git ls-remote`) tells which, if that matters.\n  - `POST /v1/repos/{repo}/commits`: send `expect` (what the branch pointed at before). A retry of a write that did\n    land answers `precondition_failed` with the branch's current value in `details.current`: compare it with the\n    commit you meant to make. Without `expect`, a retry makes a second commit on top of the first.\n  - **`Idempotency-Key` does not survive a restart**: the server remembers keys in memory only. After a broken\n    connection that may have been a restart, a repeated key is treated as a new request. Use `expect`.\n- **A crash while packs are being merged in the background** loses nothing: the merged pack is indexed, verified,\n  and fsynced into place before the packs it replaces are taken out of service. Leftover quarantine directories are\n  removed when that repository is first opened after a restart, and retired pack indices are swept on restart.\n  Background consolidation is copy-only by default; setting `JIT_CONSOLIDATE_DELTA=1` (or `consolidate_delta = true`\n  in `config.toml`) enables bounded cross-pack delta compression after a 30 s quiet period per repository (at most\n  2 worker threads, 128 MiB per merge). Either way a merge is skipped while less than 3× the merged size is free\n  on disk (a file system that cannot be asked is let through).\n  **`JIT_CONSOLIDATE_DELTA` is off by default. Turning it on is a trade:** a quarter to a half less disk where\n  history is compressible (measured: 105 to 73 MiB, and 1,605 to 1,073 MiB) and two to three times faster full\n  clones of a many-object repository, against **incremental fetches about a third slower** on a repository whose\n  trees it has deltified (measured on a small repository at 8 clients: 16,500 to 8,400-12,500 per second at the\n  same CPU), and a background pass that, 30 s after a repository's last push, rewrites up to 128 MiB of its packs\n  with two threads. Its memory is bounded by the number of objects (a crafted push of 100 near-identical\n  67 MiB trees repacked at 148 MiB), trees are at most 4 deltas deep and commits never deltified, objects over the\n  size limit are copied as they are stored, and every read is bounded by `JIT_MAX_DECODE_BYTES`. Turn it on\n  where disk matters more than fetch latency; leave it off on an instance that serves many incremental fetches.\n- **Full-clone pack cache**: repeated full clones of multi-pack repositories share an unlinked temporary pack under\n  `/data/pack-cache` (capped at 256 MiB per pack, 512 MiB total, and 64 entries LRU; never `/tmp`, not included in\n  backups). Leftover files in `/data/pack-cache` are swept at start-up, and any error creating or writing a cached\n  pack falls back to direct streaming without failing the clone.\n- **A crash during a backup** leaves an incomplete directory at `--to` (no `backup.json`, or restore refuses it):\n  remove it and take another.\n\n### \"Remove\" does not erase\n\nNothing on the host is ever deleted by taking something down, and this page should not be read as if it were:\n\n- **A commit that was force-pushed away, or whose branch was deleted, is no longer served**: asked for by id it\n  answers 404, exactly like an id that never existed, and a clone does not contain it. **Its bytes stay on disk**,\n  in the pack they arrived in, and the signed log still says which commit the branch pointed at before.\n- **Taking a repository or a ref down** (a `Withheld` entry) means the host stops serving it and says so in the\n  signed log. Any cached temporary packs for that repository in `/data/pack-cache` are dropped on explicit\n  invalidation, on repository removal, and on the first git request under an active withholding; the authoritative\n  object packs stay on the host. **A refs withholding hides refs, not content**: the named refs and\n  what only they reach are refused, but content that any other ref still reaches (another branch built on it, a\n  change's pin under `refs/changes/`, a tag) stays served under that ref and by commit id. To withhold content,\n  cover every ref that reaches it (a pattern may end in `*`) or withhold the whole repository, then check with a\n  fresh clone and by asking for the commit by id. A record withholding is for one record (a change, a review)\n  and touches no git content.\n- **Backups hold everything the store holds**, private repositories and removed content included, for as long as\n  the backups are kept.\n- Clones, forks and mirrors elsewhere keep what they have; no host can recall them.\n\nThere is no erasure command and no retention period today. If something must be gone from the host (a leaked\nsecret is the usual case: rotate the secret first), that is a manual operation on the data directory and on every\nbackup, and it is not built.\n\nAll of this assumes the volume keeps what was synced to it (a disk or a network volume that acknowledges a sync and\nthen loses the write is outside what software can promise). Tested with the real binary and `kill -9`:\n`crates/jit-server/tests/backup.rs`.\n\n### Taking a repository down\n\nWho can: an **instance administrator** only, that is the root token or a principal granted `admin` on the instance\n(`PUT /v1/grants/{principal}`), through a token not narrowed below that. An administrator of one repository cannot,\nand neither can an instance administrator's token attenuated to some repositories, operations or refs (`403`;\nanonymous `401`). Decision 0071.\n\nThe call, with that token:\n\n```\nneo api POST /v1/repos/<repo>/withhold --json '{\"scope\":{\"kind\":\"repository\"},\"reason\":\"legal\",\"reference\":\"order 2026-17\"}'\n```\n\n`reason` is one of `legal`, `policy`, `security`, `owner`; `reference` (a case or notice number, a URL) is public:\nit is in the repository's signed log. `scope` is one of:\n\n- `{\"kind\":\"repository\"}`: everything. Every API read of the repository answers `451 withheld` except its record\n  (`GET /v1/repos/<repo>`), its log and its withholdings; clone and fetch serve nothing; no write but grants,\n  revocations, withholding and restoring is accepted.\n- `{\"kind\":\"refs\",\"patterns\":[\"refs/heads/leak\"]}`: those ref names (exact, or a prefix ending in `*`) and what only\n  they reach. It does **not** cover a commit that another branch, a tag, a change's `refs/changes/…` pin or a queue\n  pin still reaches: that stays served, by that ref and by id (decision 0070). **Withholding a branch by name does\n  not stop its content being read through a change's pin**: if the branch is a change's head, its commits stay\n  readable (even as `?rev=<branch>`) through `refs/changes/<id>/<n>`. To take that content down, withhold the\n  change's pins (`refs/changes/<id>/*`) and its revision records too, or the whole repository. The names stay listed\n  (they are in the signed log). For a leaked secret, cover every ref that reaches it, or take the whole repository\n  down. A pattern that covers `refs/queue/` is refused unless the body says `\"include_queue\": true`. Each pattern\n  must be able to match a ref: an exact pattern must be a valid ref name (git's rules), a prefix the beginning of\n  one; `refs/heads/topic/` without `*`, `..`, a space, `~^:?[\\`, an empty or `.`-led component and the like are\n  refused (`400`) rather than written as a withholding of nothing. An exact name no ref has today is accepted: it\n  withholds that name in advance.\n- `{\"kind\":\"record\",\"record\":\"revision\",\"id\":\"<change>/<n>\"}`: one of jit-collab's records (`revision`, `review`,\n  `landing`, `landing_rules`, `target_override`); the record must exist (`404`). The id is exactly as the log\n  writes it (`<change id>/<n>`, `<change id>/<review id>`, `<change id>`, or the number): another spelling (`/01`,\n  `/+1`, upper case, a change's number in place of its id) is refused with the form to send. The API refuses the\n  change it belongs to and leaves it out of lists; bundles and mirrors leave the record out. It does **not** cover\n  the git content the record names: withhold its refs for that.\n\nSend an `Idempotency-Key` header: a retry with the same key and body answers the first entry and writes nothing\n(the same key with another body is `409`). A retry without one writes a second withholding (each is lifted on its\nown). Keys are kept in memory and a restart forgets them.\n\nThe answer is the signed `withheld` entry; keep its `seq`. To check it took effect:\n\n- `GET /v1/repos/<repo>/withholdings` lists every withholding in force there, oldest first, with `seq`, `scope`,\n  `reason`, `reference`, `at_ms`, `signer` and `binding` (`true`: signed by this host's key, so this host enforces\n  it; one an earlier host stated came with the log and binds nobody here). `GET /v1/repos/<repo>/reflog` shows the\n  entry itself.\n- An API read of covered content (`GET /v1/repos/<repo>/tree?rev=<branch>`, a blob, the change) answers `451\n  withheld` with `details.seq` naming the entry.\n- `git ls-remote <clone_url>` lists none of the covered refs (nothing at all for the whole repository), and a clone\n  or fetch of covered content is refused (`not our ref`); bundle exports leave it out.\n\n**When in doubt, withhold the whole repository** (`{\"kind\":\"repository\"}`): it is the one scope that leaves nothing\nof the repository's content served by another route, and it can be narrowed later (withhold the narrower scope, then\nlift the whole one).\n\n**Taking one change down** is several calls, because a change is several records and refs (there is no single\n\"change\" scope, decision 0071). With `<id>` the change id and `<branch>` its head branch:\n\n1. Its refs: `{\"scope\":{\"kind\":\"refs\",\"patterns\":[\"refs/changes/<id>/*\",\"refs/heads/<branch>\"]},…}`. Any other\n   branch or tag that contains its commits keeps serving them: add those patterns too.\n2. Each revision: `{\"scope\":{\"kind\":\"record\",\"record\":\"revision\",\"id\":\"<id>/<n>\"},…}` for n = 1 to the latest\n   (`GET /v1/repos/<repo>/changes/<id>` lists them).\n3. Each review: `{\"scope\":{\"kind\":\"record\",\"record\":\"review\",\"id\":\"<id>/<review id>\"},…}`; and, if it landed, its\n   landing: `{\"scope\":{\"kind\":\"record\",\"record\":\"landing\",\"id\":\"<id>\"},…}` (a landed change's commits are on the\n   target branch: only the whole repository takes those down).\n4. A revision or review added after these calls is not covered: withhold it too, or use the whole repository.\n\nKeep every `seq`: lifting is one restore per withholding.\n\nTo lift one: `neo api POST /v1/repos/<repo>/restore --json '{\"seq\":<seq>}'` writes a `restored` entry, and the\ncovered content is served again (unless another withholding in force covers it). `404` means no withholding is in\nforce at that number (never one, or already lifted). Lifting a narrower withholding while a wider one is in force\nserves nothing the wider one covers.\n\nGaps: the statement is written in that repository's log only. There is no instance-wide log of take-downs yet: the\nrepository-log entry is the record, and to list every withholding on the instance, ask each repository's `GET\n…/withholdings`. Nothing is deleted (see the section above).\n\n### First start: the root token\n\nOn the first start with an empty `/data`, the server writes one token to\n\n```\n/data/trust/root-token\n```\n\nIt is readable by the service's user only (mode `0600`), it belongs to the instance's own principal, which may do\neverything, and it is valid for **30 days**. It is written once: a restart does not replace it. The server never\nprints it: the logs name the file's path and nothing else (`cargo xtask container-proof` checks that the token is in\nneither stdout nor stderr, and that it is in no process's arguments while the proof uses it).\n\nCopy it once into a file only you can read, **without displaying it**. On the machine that runs the container (for\na platform such as Coolify: a shell on the server, over SSH):\n\n```\n( umask 077; docker exec <container> cat /data/trust/root-token > jithub-root.token )\n```\n\nThe redirect sends the token straight into `jithub-root.token` (mode `0600` because of the `umask`); nothing is\nshown. Do not `cat` it to a terminal, and do not use a web terminal for this (Coolify's app terminal can only\ndisplay): what a terminal shows stays in its scrollback, in screen shares and recordings, and in whatever logs the\nsession. Never put it in a command's arguments either (`curl -H \"Authorization: Bearer …\"`): any local user can read\nanother process's arguments with `ps`. The clients take the file instead: `neo --token-file jithub-root.token …` or\n`JIT_TOKEN_FILE`, and git through `neo git-credential` (`neo` is the CLI; its\nbinary is `jit` until the rename is on main). Treat the file like a root password: move it to a secret\nstore, not into a chat or a ticket.\n\nUse it straight away to give yourself a principal of your own, so that nothing depends on the 30-day token:\n\n1. Make a key on your machine: `jit-server key new --out me.key` (it prints the public id, `jp_…`; the file is\n   owner-only).\n2. Register it and give it rights, with the root token: `POST /v1/principals` (`{\"id\": \"jp_…\", \"name\": \"…\"}`), then\n   `PUT /v1/grants/jp_…` (`{\"scopes\": [...]}`); `GET /v1` lists the endpoints and scopes.\n3. Mint your own tokens from that key, offline: `jit-server token mint --key me.key --out me.token`.\n\nA new instance token, before or after the 30 days, is minted offline from the instance's key, inside the container,\ninto a file (never printed), and copied out the same way:\n\n```\ndocker exec <container> jit-server token mint --key /data/trust/instance.key --out /data/trust/root-token.next\n( umask 077; docker exec <container> cat /data/trust/root-token.next > jithub-root.token )\n```\n\n(Tested in jit-trust and against a running server, #118: the instance stays itself, and tokens narrowed from the old\nroot end with it.)\n\n### What this instance stores\n\nUnder `/data`, and nowhere else: repositories (git objects and refs) and their records (name, description,\nvisibility, creator); each repository's signed ref log and checkpoints; principals (a public key, a name label, when\nregistered) and their grants; tokens' revocation ids and the revocations themselves, never the text of a token, with\none exception, the root token written once to `/data/trust/root-token` (owner-only) for the operator to collect;\nthe instance's own keys (`/data/trust/`, owner-only) and the root keys of repositories it holds a key for; changes\nand their revisions, checks, reviews and comments where they exist, claims, landing rules and events. Commits carry\nthe author and committer names and e-mail addresses their authors wrote into them, as in any git host; commits made\nthrough the API name the principal (`<principal id>@jithub`). Not stored: agent sessions or transcripts, accounts,\npasswords, and request logs. The logs (JSON lines on stderr) record start-up, shutdown and backups only, with no\ntokens and no client addresses. In memory only, gone on every restart: the per-address counters of the anonymous\nrate limit, and the `Idempotency-Key` answers (`docs/contracts/jit-api.md` section 2).\n\nWith sign-up on (`JIT_SIGNUP` `preview` or `privy`, \"Sign-up\" above) the instance also stores accounts and what\njit-trust keeps for them (docs/contracts/accounts.md), and a pairing in flight keeps the normalized client address\nit was started from (an IPv4 address, or an IPv6 address as its /64) for at most ten minutes, deleted with the\npairing; it is never logged and is shown only to the session that types the pairing's code. The log then also\nrecords why a sign-in was refused, by the name of the rule, never a token, a code, a Privy subject or an address.\nThe per-address counts of sign-ups, logins started, pairings and lookups are in memory only.\n\n### Who can read what\n\n- The deployed instance creates public repositories only; an instance admin can create private ones (decision 0063).\n- A repository is **public unless an instance admin creates it with `\"public\": false`**. Public means anyone who can reach the\n  service can read it without a token: the front end, the API and `git clone`.\n- A private repository is invisible without a token: the front end and the API answer \"not found\", and git asks for\n  credentials.\n- Every write (creating a repository, a push) needs a token. Git sends it as the password of Basic auth (any user\n  name) or as a Bearer header.\n\nSo on a public address, decide per repository; nothing is writable anonymously.\n\n### Proving an image\n\n```\ncargo xtask container-proof\n```\n\nbuilds the image, runs it with a fresh volume, waits for the health check, checks `/healthz`, `/v1` and that `/` is a `404` (no pages on the back end), reads\nthe root token from the container, creates a private repository, pushes to it and clones it back with stock git,\nchecks that an anonymous clone is refused, that the logs do not contain the token and that the token was in no\nprocess's arguments while it was used. It then builds the front end's image from `web/`, runs it beside the back end\non a private network with `JIT_API_URL` and no token, waits for its health check, and checks that it is not root,\nthat its first page lists a public repository and not the private one, and that `/r/<private>` is 404 through it.\nIt then proves the runner's separation of the check command from its own user (`jit-runner`), in a throwaway\ncontainer, never on the host. Tests that switch users need root and report themselves skipped everywhere else.\nThe proof runs those tests (`as_another_user_…`) as root with `JIT_REQUIRE_ROOT_TESTS=1`, prints each name with\nits result, and fails if any fails, if any reports itself skipped, or if fewer than five ran (four in the library's tests, one in `tests/e2e.rs`: the checkout written by the `fetch_as` user). `cargo xtask\ncontainer-proof --runner-only` runs that step alone. Last it stops the back end (exit 0),\nand removes both containers, the volume, both images and the network. It needs a Docker daemon and about 4 GB of free\ndisk for the builds.\n\n## The front end (`web/`)\n\n| | |\n| --- | --- |\n| Build | `web/Dockerfile`, build context `web/` (Coolify: base directory `/web`, Dockerfile location `/Dockerfile`) |\n| Port | `3000` (`PORT` changes it) |\n| Health check | `GET /healthz` answers `200` `ok`; the image also carries a `HEALTHCHECK` on it |\n| Persistent volume | none: it keeps no state |\n| User | `bun` (uid 1000), not root |\n| Variables | `JIT_API_URL` (required): the back end as the front end reaches it, for example `http://<back-end-service>:7878` on the platform's internal network, or the back end's public `https://` URL. `JIT_PUBLIC_URL`: the front end's own public `https://` URL, used in the Markdown twins' links. `PORT` (default 3000). No secrets. |\n\nIt serves the pages (`/`, `/r/{repo}/…`), the stylesheet and fonts (`/assets/…`), and passes `GET /v1/…` and\n`/llms.txt` through to the back end, so every link on a page works from the front end's domain. Git over HTTP is not\npassed through: clone URLs are the back end's `JIT_PUBLIC_URL`, as the API reports them. A viewer's token (later, from\nsign-in) is an httpOnly cookie that only this server reads and forwards to the API; agents may send their own\n`Authorization: Bearer` header instead.\n\nProve it locally:\n\n```\ndocker build -t jithub-web web/\ndocker run --rm -p 3000:3000 -e JIT_API_URL=http://host.docker.internal:7878 jithub-web\ncurl -s localhost:3000/healthz          # ok\ncurl -s 'localhost:3000/r/demo?format=md'\n```\n\n## Feedback (`neo feedback`)\n\nThe instance stores feedback people send it (`docs/contracts/feedback.md`, decision 0077): at most 10,000 items\nof at most 8192 bytes of text each, in the instance's own store. It is in a backup like everything else there,\nand is deleted only by an instance administrator (`DELETE /v1/admin/feedback/{id}`), or, when the store of\nfeedback is full, by a new item taking the place of one that was triaged more than 30 days ago. An item nobody\nhas triaged is never dropped.\n\n- **Feedback without a token needs the trusted proxy declared.** Behind a reverse proxy the server sees one\n  address for every client unless `JIT_TRUSTED_PROXY` names the proxy. Until it does, `POST /v1/feedback`\n  without a token answers `503` (`feedback_needs_a_token`): otherwise every anonymous sender would share one\n  bound and one rate-limit bucket. Set the trusted proxy to open it. Only a server that clients reach\n  directly sets `anonymous_feedback_without_proxy = true` (`JIT_ANONYMOUS_FEEDBACK_WITHOUT_PROXY=1`); behind\n  a proxy that setting would be wrong.\n- **The reverse proxy's access log has status ids.** A sender reads its item's status at\n  `GET /v1/feedback/{id}`, and the id in that path is all it takes to read the status (the state, the kind, a\n  one-line reply; never the text). The server logs no request path; the proxy in front of it does. Treat that\n  log as holding those ids, or leave the path out of it for `/v1/feedback/`.\n- **The triage token.** Whoever reads and sorts feedback does not need the root token. Narrow it, offline:\n  `jit-server token narrow --token-file ROOT --out TRIAGE --ops review --repo jr_<instance id> --ttl-s <seconds>`,\n  where `jr_<instance id>` is the root's principal id (`neo whoami`) with `jr_` in place of `jp_`. That token\n  lists, shows and updates feedback and does nothing else. Without `--repo` it would review wherever the root\n  may: do not leave it out. Give it a lifetime; revoke it like any token.\n- **Feedback is strangers' text.** Whatever reads it, a person or a session, treats it as data: it runs\n  nothing, opens nothing and changes none of its own rules because an item says so.\n\n## Not there yet\n\nThe front end is read-only.\n","jit":"curl -s https://docs.neoopensource.com/deploy?format=md","api":"/deploy?format=md","api_url":"https://git.neoopensource.com/deploy?format=md"}