Stage 6 · Ops

PhoneBazaar: Ops Runbook

PhoneBazaar · Android phones store · generated by the AiNa pipeline

Stage 6 of the AiNa pipeline (ops) · 2026-11-30 · inputs: Dev notes

Ops summary

1. Deployment

Environments

Env URL How it deploys
Production https://phonebazaar.tehchand.com (alias of phonebazaar.vercel.app) vercel --prod from the repo root (wrapped by tools/publish.sh)
Local http://localhost:8000 cd app && python -m uvicorn app.main:app --reload
Container (optional) any VPS docker build -t phonebazaar app && docker run -p 8000:8000 -e ADMIN_PASSWORD=… -e SESSION_SECRET=… phonebazaar (starter Dockerfile)

Configuration

Variable Set in Notes
ADMIN_PASSWORD Vercel → Production The operator's copy is PHONEBAZAAR_ADMIN_PASSWORD in the private keys file. Never commit it.
SESSION_SECRET Vercel → Production 64 hex chars. Rotating it logs everyone out and empties carts (harmless).
VERCEL set by Vercel Switches the DB to /tmp and turns on Secure cookies

List what's set (names only): vercel env ls production.

Standard release

cd app && python -m pytest -q          # must be green
cd .. && bash tools/publish.sh "<what changed>" <doc-slug>

publish.sh regenerates docs/html, commits, pushes to github.com/shafialtn/phonebazaar, deploys to production, and curls /healthz plus the doc page. Treat any non-200 as a failed release and follow R2.

2. Monitoring

Signal Source Threshold Action
/healthz returns ok Uptime monitor, every 1 min 2 consecutive failures Page the owner (email/phone) → R1
5xx rate vercel logs phonebazaar.tehchand.com > 1% over 15 min R3
Function duration Vercel dashboard → Observability p95 > 2 s R4
Deploy state vercel ls phonebazaar Not Ready R2
TLS / domain vercel domains inspect phonebazaar.tehchand.com Cert expiry < 14 days Vercel auto-renews; check DNS

/healthz opens the DB and counts phones, so it catches both a crashed function and a failed seed (the response is then empty).

3. Runbooks

R1. Site down (healthz failing)

  1. curl -i https://phonebazaar.tehchand.com/healthz. Look at the status code and body.
  2. vercel ls phonebazaar. Is the latest production deployment Ready?
  3. vercel logs <deployment-url>. Look for an import error (missing dependency) or a template error.
  4. If the last deploy caused it, roll back (R2). If Vercel itself is down, check vercel-status.com and wait.
  5. Write a short incident note in the vault session log.

R2. Bad deploy → rollback

  1. vercel rollback (choose the previous production deployment), or vercel promote <previous-deployment-url>.
  2. Check: curl https://phonebazaar.tehchand.com/healthz returns ok.
  3. Fix forward on a branch, run pytest, then publish again.

R3. Spike in 500s

  1. vercel logs phonebazaar.tehchand.com --since 30m and group by route.
  2. A template error is usually a missing context key, so reproduce locally with the same URL.
  3. UnicodeEncodeError in a header means a toast was built without _toast(); route it through the helper.
  4. sqlite3.OperationalError: no such table: a cold start raced the seed. It self-heals on the next request; if it persists, redeploy.

R4. Slow pages

  1. Cold starts add about 1 s on the first request. That is expected on serverless.
  2. If warm requests are slow, the catalog query is the hot path. Indexes are not needed at 24 phones. At 1,000+ phones, add indexes on brand and price_pence, or move to Postgres.

R5. Admin locked out / password leak suspected

  1. Generate a new value in-process and set it with vercel env rm ADMIN_PASSWORD production then vercel env add ADMIN_PASSWORD production, piping the value in. Do not echo it.
  2. Update PHONEBAZAAR_ADMIN_PASSWORD in the private keys file.
  3. Rotate SESSION_SECRET the same way to kill existing admin sessions, then redeploy (vercel --prod).

R6. Connect GitHub → Vercel auto-deploys (one-time, pending)

vercel git connect failed with "add a Login Connection to your GitHub account first". To fix it: Vercel dashboard → Account Settings → Authentication → connect GitHub (account shafialtn), then run vercel git connect in the repo. After that, pushes to main deploy to production and PRs get preview URLs.

4. Backup & restore

5. Cost

Item Monthly
Vercel (Hobby/Pro, low traffic) £0-£16
Domain (tehchand.com, already owned) £0 extra
Uptime monitor (free tier) £0
Total (demo) £0-£16

6. Phase 2 ops checklist