Skip to content

Instance limits

Instance limits cap what an instance can hold: how many operators, how many API clients, whether XRPC answers callers with no API client, and how long logs are kept. They’re meant for a hosting platform that sells instances on plans, but any operator can set them. An instance with no limits set has none, so a self-hosted instance behaves as the rest of these docs describe until you set one.

HappyView keeps its limits in memory and checks against that copy. A check never calls out to whatever set the limits, so an instance keeps serving while that is down.

LimitValueWhat it refuses
seatsmax, a whole numberAdding an operator once the instance has max, the superadmin included
api_clientsmax, a whole numberCreating or turning on an API client once the instance has max active ones
anonymous_xrpcallowed, true or falseWith false, XRPC calls from a caller who isn’t identified
log_retention_daysmax, a whole number from 1Keeping logs for more than max days

Leaving a limit out of the file sets no limit; leaving out anonymous_xrpc lets anonymous calls through. If you set a limit lower than the instance’s current count, existing operators and clients stay. Only new ones are refused, until the count is under the limit again.

POST /admin/users is refused while the number of operators is at or above max. Every operator counts, the superadmin included. The ways an instance gets its superadmin are never refused: the first sign-in, SUPERADMIN_DID, and a hosting platform setting the superadmin.

POST /admin/api-clients is refused while the number of active API clients is at or above max, and so is a PUT /admin/api-clients/{id} that turns an inactive client back on. Only the clients your operators register count. Child clients (those with a parent_client_id) don’t count, and neither does the client built in for hpy.

With allowed: false, HappyView refuses a call to a lexicon’s query or procedure, or a call it would proxy, when the caller is neither signed in nor another service using service auth, and has no API client that checks out. A client key that is unknown, or sent with the wrong Origin or secret, doesn’t check out.

A signed-in caller is never refused, whatever client key they send. A space credential identifies its caller only on the space routes, which check it themselves; on any other method, a call carrying only a space credential counts as anonymous.

HappyView’s built-in XRPC methods, such as app.bsky.actor.getProfile, com.atproto.repo.uploadBlob and dev.happyview.*, aren’t affected. Neither are the admin API, OAuth and /health.

The ceiling applies to two instance settings, event_log_retention_days and backfill_retention_days. An operator can save a shorter retention, but saving more than max days, or 0 (keep forever), is refused. The retention sweeps also enforce it: event logs, job logs, stored script metrics and backfill history are deleted after max days even when a setting, or its environment variable, asks for longer.

Protected events aren’t capped. They follow space_access_log_retention_days.

Its max can’t be 0. A 0 in the variable or in the limits file stops boot, and a 0 written into the file later is ignored in favour of the limits already loaded.

Use either a limits file or the environment variables. Boot stops if both are set.

Set HAPPYVIEW_LIMITS_FILE to the path of a JSON file. Each key is a limit from the table above:

{
"seats": {
"max": 5,
"message": "Your plan includes 5 seats.",
"actionUrl": "https://host.example/billing",
"actionLabel": "Add a seat"
},
"api_clients": { "max": 3 },
"anonymous_xrpc": { "allowed": false },
"log_retention_days": { "max": 30 }
}

Each limit can also carry the wording shown when it’s reached:

  • message replaces HappyView’s own sentence, such as “This instance allows 5 admins.”
  • actionUrl and actionLabel add a button. Both are needed, or neither is used.

An unknown key anywhere in the file is an error, so a misspelt limit can’t be read as unlimited.

The file has to exist and parse when HappyView starts, or it won’t start. While it runs, HappyView rereads the file every 2 seconds, so an edit takes effect without a restart. An edit that doesn’t parse, or a deleted file, logs a warning, and the limits loaded before it stay in force.

Without a limits file, these variables set the limits:

VariableValue
HAPPYVIEW_LIMIT_SEATSA whole number
HAPPYVIEW_LIMIT_API_CLIENTSA whole number
HAPPYVIEW_LIMIT_ANONYMOUS_XRPCtrue or false
HAPPYVIEW_LIMIT_LOG_RETENTION_DAYSA whole number, at least 1

They’re read once, at boot, and a value that can’t be read stops boot. They carry no wording, so a refusal uses HappyView’s sentence.

The admin API and XRPC answer 403 Forbidden with this body:

{
"error": "LimitReached",
"limit": "seats",
"max": 5,
"current": 5,
"message": "Your plan includes 5 seats.",
"actionUrl": "https://host.example/billing",
"actionLabel": "Add a seat"
}
FieldWhen it’s present
limitAlways. One of the four limit names
maxseats, api_clients and log_retention_days
currentseats and api_clients
messageAlways. The limit’s message, or HappyView’s sentence
actionUrl, actionLabelBoth, when the limit has both; otherwise neither

The dashboard shows the message in a notification, with the action as a button when its URL is http or https.

HappyView gets its limits from a LimitsProvider, a trait in the happyview-provider crate, the crate the record provider traits are in. HappyView asks the provider for a snapshot on every check, including every XRPC request, so the provider must answer from what it already holds. The limits file and the environment variables are the provider HappyView ships with.

A provider must validate every snapshot it takes in with Limits::validate. It refuses an invalid snapshot at boot by stopping, and on a later change by keeping its last valid snapshot.