Operations

Deploy

Recommended deployment
ClientsLoad balancerno sticky sessionsrole=api × Nrole=worker × 1–2Managed PostgreSQL
You or your deviceSaved or publishedHover or tab to a box to trace it
# Container (published by CI for every services/api/vX.Y.Z tag)
docker run -p 8080:8080 \
  -e DATABASE_URL='postgres://…?sslmode=require' \
  -e BISCUIT_TOKEN_SECRETS='<32+ random bytes>' \
  -e BISCUIT_CORS_ORIGINS='https://app.example.com' \
  -e GROQ_API_KEY='…' \
  ghcr.io/nibir404/puku-bot-api:0.1.0

Recommended topology:

  • role=api × N behind a load balancer (no sticky sessions). Health checks: liveness /healthz, readiness /readyz.
  • role=worker × 1–2 (more if routines grow; workers are additive).
  • Managed PostgreSQL 14+ with automated backups and PITR. Add PgBouncer (transaction mode) beyond ~200 total connections — but keep the API's LISTEN connection direct to Postgres (LISTEN doesn't survive transaction pooling).
  • Load balancer idle timeout > 30 s (SSE heartbeats every 25 s). Disable response buffering for /v1/events and streamed replies (the API sends X-Accel-Buffering: no for nginx).

Migrations run automatically at startup under a Postgres advisory lock, so rolling deploys never race. To run them as a separate release step: biscuit-api migrate.

Migration policy (zero-downtime): additive changes only within a minor version (new tables, nullable columns, new indexes CONCURRENTLY in their own migration). Renames and drops take two releases: stop using → remove.

The bot's computer in production

  • The published image is distroless and has no Chrome, so the computer is off there (BISCUIT_COMPUTER=auto). Run computers on hosts or images with Chrome/Chromium and set BISCUIT_CHROME_PATH; size memory for BISCUIT_COMPUTER_MAX browsers (≈ 300 MB each).
  • A run lives on the node that started it. Route /v1/computer/{id}/* to that node, or give computers dedicated nodes.
  • Sessions left running by a crash are closed as failed at the next start.
  • Review GET /v1/computer/{id}/audit (or the computer_actions table) for what bots did and were refused.

Shutdown

On SIGTERM the server stops accepting connections, disables keep-alives and waits up to BISCUIT_SHUTDOWN_GRACE for in-flight requests; workers finish the current run. Set the orchestrator's termination grace period slightly above it.

Observability

Logs: structured (slog), JSON in production, one line per request with method, route, status, ms, bytes, req (request ID). Errors include the request ID that the client also received.

Metrics (GET /metrics, Prometheus):

Metric Type Use
biscuit_http_requests_total{route,status} counter Traffic and error rate per route pattern.
biscuit_http_request_duration_seconds{route} histogram Latency SLOs (p50/p95/p99).
biscuit_realtime_subscribers gauge Open event streams on this node.
biscuit_realtime_events_total{type} counter Committed changes fanned out.
biscuit_realtime_dropped_total counter Slow consumers dropped (should stay ≈ 0).
biscuit_llm_first_token_seconds{provider} histogram Time to first token.
biscuit_llm_reply_seconds{provider} histogram Full reply time.
biscuit_llm_errors_total{provider} counter Upstream failures.
biscuit_reply_backlog gauge Replies in flight (vs BISCUIT_REPLY_BACKLOG).
biscuit_reply_rejected_total counter 503 busy responses — scale out or raise concurrency.
biscuit_rate_limited_total counter 429s.
biscuit_routine_runs_total{status} / biscuit_routine_run_seconds counter / histogram Scheduler health.
biscuit_computer_runs_total{status} counter Live-browser tasks by outcome.
biscuit_computer_actions_total{action,decision} counter Agent actions and gateway decisions (watch deny/ask).

Suggested SLOs and alerts:

SLO Alert when
99.9% of non-streaming requests succeed (non-5xx) 5xx rate > 0.5% for 5 min
p95 latency of reads < 50 ms p95 > 100 ms for 10 min
p95 time to first token < 2 s > 4 s for 10 min
Reply backlog < 80% biscuit_reply_backlog / BISCUIT_REPLY_BACKLOG > 0.8 for 5 min
No dropped subscribers rate(biscuit_realtime_dropped_total[5m]) > 0

Runbook

Symptom Check Fix
/readyz 503 DB reachable? listener attached? Postgres status / credentials; the listener reconnects with backoff automatically.
Many 503 busy biscuit_reply_backlog at max, biscuit_llm_first_token_seconds high Provider slow or quota hit: raise BISCUIT_LLM_CONCURRENCY (within quota) or add API replicas.
Many 429 biscuit_rate_limited_total Legit traffic: raise BISCUIT_RATE_RPS/BURST. Abuse: block at the edge.
Clients miss live updates biscuit_realtime_dropped_total, proxy buffering Disable buffering for SSE; raise LB idle timeout > 30 s.
Routines not firing worker running? routine_runs errors Start a role=worker; inspect routine_runs.error.
too many connections replicas × BISCUIT_DB_MAX_CONNS Lower pool size or add PgBouncer.
Token secret leaked — Prepend a new secret, deploy, then remove the leaked one (all its sessions end).

Security notes

  • Passwords: argon2id (m = 19 MiB, t = 2, p = 1; OWASP baseline), parameters stored per hash.
  • Login timing is equalised for unknown emails (no account enumeration by latency).
  • Tokens: HMAC-SHA256, constant-time comparison, key IDs for rotation, expiry enforced.
  • Tenant isolation is structural (every query is workspace-scoped) and covered by tests.
  • No secrets in logs; request bodies are never logged.
  • Security headers: nosniff, no-referrer, no-store on API responses.
  • Run behind TLS; the container runs as non-root on distroless.