# Running the server

Whoever deploys the server is its operator: lists and deletes projects, mints a recovery admin token, issues invite codes and finishes a half-done store move.

The operator never sees a token value and has no ticket access over the API; a `store: server` project keeps its store on the server's disk (`AITODO_SERVER_DATA`).

```console
$ tkt operator projects --server https://tkt.ideathon.me
```

## Details

- **Over HTTP** (for a server without a shell): the secret `AITODO_OPERATOR_TOKEN` (at least 32 characters; without it every `/v1/operator/**` is 404 and the CLI says it is off) is no project token and never stored in `server.db`. The CLI reads it from the variable or a hidden prompt, never an argument (no `--token`), and never prints it. A wrong secret: 401 `ERR_AUTH_REQUIRED`; a project token (even admin) never works here, nor the secret on project endpoints. One log line per call (action, project id, time, outcome; no secret).
- `tkt operator projects --server <url> --json` (id, name, created, by, how, tokens, last use, disk; first the disk's free space); `tkt operator project-delete <id> --server <url> --confirm <name-or-id>` (its tokens get 401 afterwards); `tkt operator admin-token --project <id> --name <n> --server <url>` (shown once); `tkt operator store-unfreeze <id> --server <url>` (back to the server) or `tkt operator store-release <id> --server <url>` (to the repo, the server copy archived).
- On the server host without HTTP: `tkt server admin-token --project <id> --name <n>`, `tkt server project-delete <id> --confirm <name-or-id> --json`.
- **Disk** (`AITODO_STORE_MAX_BYTES`, `AITODO_DISK_MIN_FREE_BYTES`): a project's quota counts its store with the whole git history and derived files, its archives (`stores/.archive/<id>-<date>`) and an import being built, as allocated on disk; before it refuses a write the server packs the store's loose git objects (every commit stays). Free space is the operator's: under 5120 MB (`AITODO_DISK_WARN_FREE_BYTES`, above the stop level) the server logs one warning line per 10 minutes at most and users see nothing; under 1024 MB every write that grows the disk (a forwarded write, a store create, an import) is paused for every project; reads, export and release go on. `tkt operator projects` shows the state (`ok`, `low`, `full`). Nothing is deleted on its own: an archive holds the server-side git history of a store that went back to its repo (the audit trail); remove one by hand only when that history is kept elsewhere.
- **Registration:** `AITODO_REGISTRATION=open|invite|closed`; unset: `invite` with a valid operator token, else `closed` (with one warning line); `open` only when set explicitly (a local or dev server). `closed`: 403 `ERR_AUTH_FORBIDDEN`; `GET /v1/meta` shows it in `registration`.
- **Limits** (never on the operator): 10 registrations and server store creations together per hour from one client address (`AITODO_REGISTRATION_RATE_LIMIT`; a refused try counts too; 429 `ERR_RATE_LIMITED`); at most 1000 projects on the server (`AITODO_MAX_PROJECTS`; then 403 `ERR_AUTH_FORBIDDEN`, the invite stays unused). A bad value stops the server at startup.
- **Proxy:** the container takes the client address (log, the hourly limit above) and the scheme (`https://` in links and redirects) from `X-Forwarded-For` / `X-Forwarded-Proto` only on a connection from `AITODO_TRUSTED_PROXIES`: IP addresses and CIDR networks, comma separated (the proxy's Docker network, e.g. `10.0.1.0/24`), `none` without a proxy. Headers from anywhere else do not count. Unset or a bad value (`*` too): the container does not start. Only the proxy should reach the container port.
- **Invites:** `tkt operator invite --name N --expires 7d|YYYY-MM-DD --server <url> --json`: a one-time code (`arc_…`), shown once, 7 days by default, `--name` fixes the name, only its hash is kept. `tkt operator invites --server <url>` (`open|used|expired|revoked`, never a code), `tkt operator invite-revoke <invite-id> --server <url>`. The registrant sets `AITODO_INVITE` or types it at the prompt (no `--invite`); it is used up in the transaction that creates the project. None or unknown: 401 `ERR_AUTH_REQUIRED`; used, expired, revoked or another `--name`: 403 `ERR_AUTH_FORBIDDEN`. A log line per mint, use and revoke, never the code.
- **Without an invite:** `tkt project register <url> --name N --operator` and `tkt store init --server <url> --register --name N --operator` go through `POST /v1/operator/projects` with the secret (never in the credentials file), in any mode; the rest is an ordinary registration (`--as`, default `$USER`; the pin rules), listed `via operator` (beside `via invite <id>`, `via open`). A set `AITODO_INVITE` stays unused: `AITODO_INVITE is set but ignored with --operator: the invite stays unused.` API off: 404 `ERR_NOT_FOUND`; a wrong secret or a project token: 401 `ERR_AUTH_REQUIRED`. Log line: `action=register`.
- **Health and diagnosis:** `GET /v1/healthz` is always 200 (liveness: a busy database must not restart the container); `status` is `ok` or `degraded`, `db` holds `read` and `write` (`ok`, `busy`, `error`), when busy the request holding the lock (`holder`: id, method, path) and for how long (`heldSeconds`); the probe never waits. The server writes to stderr the start of every request with its id (`request start`), the begin and end of every database write with the same id (`write begin`, `write end`), a write held over a second with where it opened (`slow write`), and a write that did not get the lock with its holder (`write lock busy`). `kill -USR1 1` in the container dumps every thread's stack.
- AI agents run these only when the user asks, and never ask for an invite code or the operator secret.

## Commands on this page

- [`tkt operator projects`](/en/docs/reference/commands/operator.md#tkt-operator-projects): Every project on the server: id, name, created, created by, how it was created (an invite id, open or operator), token counts, last use (never a token), its AI plan and AI use (calls ever, credits this month), and what it takes on the server's disk (its store with the git history, its archives); first the disk's free space
- [`tkt operator project-delete`](/en/docs/reference/commands/operator.md#tkt-operator-project-delete): Delete a project and everything the server keeps for it (tokens, LLM usage and caps, id counters, claim leases), e.g. one whose admin tokens are lost
- [`tkt operator admin-token`](/en/docs/reference/commands/operator.md#tkt-operator-admin-token): Mint a new admin token for a project (recovery when every admin token is lost); shown once
- [`tkt operator invite`](/en/docs/reference/commands/operator.md#tkt-operator-invite): Mint a one-time registration code (arc\_…) for a server that registers by invite (AITODO\_REGISTRATION=invite, the default with an operator token)
- [`tkt operator invites`](/en/docs/reference/commands/operator.md#tkt-operator-invites): Every invite: id, status (open, used, expired, revoked), the fixed project name, created, expires, and the project it created
- [`tkt operator invite-revoke`](/en/docs/reference/commands/operator.md#tkt-operator-invite-revoke): Revoke an unused invite by its id (from `tkt operator invites`); its code is refused from then on
- [`tkt operator store-unfreeze`](/en/docs/reference/commands/operator.md#tkt-operator-store-unfreeze): A `tkt store move --to repo` that never finished leaves the project's server store frozen (moving)
- [`tkt operator store-release`](/en/docs/reference/commands/operator.md#tkt-operator-store-release): Finish a store move left half-done (moving): the location becomes repo and the server's copy is archived under stores/.archive/ (never deleted)
- [`tkt server project-delete`](/en/docs/reference/commands/operator.md#tkt-server-project-delete): Delete a project straight in AITODO\_SERVER\_DATA, e.g. one whose admin tokens are lost
- [`tkt server admin-token`](/en/docs/reference/commands/operator.md#tkt-server-admin-token): Mint a new admin token straight in AITODO\_SERVER\_DATA (recovery, D8)

## Related

- Env var: [`AITODO_OPERATOR_TOKEN`](/en/docs/reference/env.md#AITODO_OPERATOR_TOKEN): The operator secret: on the server it enables /v1/operator/; on the client tkt operator sends it
- Env var: [`AITODO_REGISTRATION`](/en/docs/reference/env.md#AITODO_REGISTRATION): Who may register a project: open, invite or closed (default: invite with an operator token, else closed)
- Env var: [`AITODO_INVITE`](/en/docs/reference/env.md#AITODO_INVITE): The invite code tkt project register uses; never an argument
- Env var: [`AITODO_REGISTRATION_RATE_LIMIT`](/en/docs/reference/env.md#AITODO_REGISTRATION_RATE_LIMIT): Project registrations and server store creations per hour from one client address
- Env var: [`AITODO_MAX_PROJECTS`](/en/docs/reference/env.md#AITODO_MAX_PROJECTS): How many projects the server holds before a registration is refused (the operator's still work)
- Env var: [`AITODO_TRUSTED_PROXIES`](/en/docs/reference/env.md#AITODO_TRUSTED_PROXIES): The proxy addresses or CIDR networks whose X-Forwarded-For and X-Forwarded-Proto the container honours; none: no proxy; required by the container entrypoint…
- Env var: [`AITODO_DISK_MIN_FREE_BYTES`](/en/docs/reference/env.md#AITODO_DISK_MIN_FREE_BYTES): The free space the server keeps on its data disk, in bytes; under it every write that grows the disk is refused
- Env var: [`AITODO_DISK_WARN_FREE_BYTES`](/en/docs/reference/env.md#AITODO_DISK_WARN_FREE_BYTES): Under this much free space on the data disk the server logs a warning for the operator, in bytes; above AITODO\_DISK\_MIN\_FREE\_BYTES
