Operations runbook

Environments and projects

Env GCP project URL Branch / trigger
sandbox snappy-agents-sandbox https://sandbox.agents.snappy.com every merge to main
prod snappy-agents-prod https://agents.snappy.com manual workflow_dispatch (env prod) with GitHub environment approval

Each project contains: VPC + Cloud NAT (static egress IP for Snappy allowlisting), Cloud SQL Postgres (private IP), Cloud Run service agents-api, Cloud Tasks queue, Cloud Scheduler (expire checkouts every 5 min, expire protocol sessions every 10 min), Secret Manager, Artifact Registry, global HTTPS load balancer with managed certificate, uptime check and alerting. See infra/terraform.

How a change reaches an environment

flowchart TD
  pr["Pull request"] --> ci["CI test job: pnpm install, build packages, typecheck, unit and component tests with coverage, build api, admin and docs, export and lint the OpenAPI document"]
  pr --> docker["CI docker job: build the image, boot it with fixtures, fake payments and sink messaging, curl healthz, readyz, manifest, openapi, docs, admin, then the Playwright smoke of the real user path on desktop and mobile"]
  pr --> tofuv["CI terraform job: tofu fmt and validate on every root"]
  pr -->|"infra/terraform/** changed"| plan["Infrastructure: format, validate every root and run the mocked module tests, with no cloud identity"]
  main["Push to main"] --> ci
  main --> docker
  main --> tofuv
  main -->|"any path except infra/** and *.md"| deploy["Deploy sandbox: pnpm test gate, Workload Identity Federation as the deployer SA, build and push the image to Artifact Registry, gcloud run deploy agents-api with only the image changed, smoke the public path"]
  main -->|"infra/terraform/** changed"| apply["Infrastructure: plan and apply sandbox with the apply service account"]
  dispatch["workflow_dispatch"] -->|"Deploy with environment=prod"| gate{"GitHub prod environment: required reviewers approve"}
  gate -->|approved| deployprod["Deploy prod: same steps, prod GCP identities are bound to the prod environment claim"]
  dispatch -->|"Infrastructure with environment=prod"| gate2{"prod approval"}
  gate2 -->|approved| applyprod["plan, and apply only when apply=true"]
  dispatch -->|"Logs with environment, minutes, path"| logs["Logs: load balancer requests, Cloud Run requests and application lines at WARNING or above, read with the plan service account"]
  human["Once, by a human: infra/terraform/bootstrap creates the two projects, state buckets, WIF pool and CI identities, then their outputs become GitHub environment variables"] -.-> plan

Credentials

Platform secrets (Terraform creates the containers, an operator adds the first version once):

Secret Source
auth-token-secret 32+ random bytes; rotating it signs every user and agent out
tasks-shared-secret Random; only used when TASKS_MODE=inline

Provider credentials are entered in the admin portal → Integrations and written to Secret Manager by the app (runtime identity has secretVersionAdder on those secrets only):

Integration Fields Where to get them
Snappy Public API API key (secret), account, billing method, webhook token (secret) Snappy dashboard → Company Settings → Sharing & Access → API Access. Paste the key and the form loads the accounts the key can see; pick one and it loads that account's active billing methods. Both are dropdowns; the key is sent once for the lookup and never shown again.
Stripe secret key, webhook signing secret Stripe dashboard (test keys on sandbox)
SendGrid API key, from email/name SendGrid
Twilio account SID, auth token (secret), Messaging Service SID (10DLC), fallback number Twilio console; register the brand + campaign for A2P 10DLC first
Anthropic (negotiation AI) API key (secret), API base URL console.anthropic.com. Powers the price negotiator in ai mode; without it the negotiator runs on rules only
Stripe publishable key pk_… (not secret) Stripe dashboard; advertised to Google Pay as the gateway merchant id (UCP)
Google (UCP order webhook) partner id, order webhook API key (secret) Google's UCP onboarding email; pushes order created / shipped / delivered events to Google
Product feeds feed token (secret) Any long random string; protects /feeds/* for ChatGPT, Merchant Center and Shopify Catalog
Business signing keys ucp-signing-keys (secret, JSON JWK Set) Generated by the app on first use; rotate from admin → Protocols. Published at /.well-known/jwks.json

Until a provider is configured the platform degrades gracefully: fixture catalog and fake pay page on sandbox, sink messaging everywhere, and a clear *_not_configured error on prod.

One-time setup per environment

  1. tofu apply in infra/terraform/bootstrap (projects, state buckets, WIF). Then envs/<env>.
  2. Add the two platform secret versions (table above).
  3. Point DNS: agents.snappy.com / sandbox.agents.snappy.com A records → the load balancer IP from tofu output.
  4. Stripe: add webhook endpoint https://<host>/webhooks/stripe for checkout.session.completed, checkout.session.expired, checkout.session.async_payment_succeeded, refund.updated.
  5. Snappy dashboard: add webhook https://<host>/webhooks/snappy for order status, delivery status, order canceled, order out of stock. Snappy sends a verification token; the endpoint acknowledges it.
  6. Snappy: allowlist the Cloud NAT egress IP if the partner key is IP-restricted.
  7. Open https://<host>/admin (Identity-Aware Proxy asks for your Google Workspace account), go to Integrations and enter the Snappy key, account and billing method, then Stripe, SendGrid and Twilio.
  8. The first admin comes from ADMIN_EMAILS (bootstrap); manage the rest in the portal.
  9. Agentic commerce protocols (optional): Integrations → Product feeds → set a feed token, Integrations → Stripe → publishable key, then register each platform under Protocols and hand it the key. The platform-side steps (Stripe Shared Payment Tokens, OpenAI Business Hub, Merchant Center, Shopify Agentic plan) are listed under Going live.

Network gate (prod is internal only since November 2026)

agents.snappy.com is restricted to Snappy's Twingate egress addresses. sandbox.agents.snappy.com is public on purpose: it is where agent platforms, test webhooks and the deploy smoke test reach the service from the internet, and its environment does not set network_allowlist. On prod the edge Cloud Armor policy refuses every path except /healthz and /readyz with a 403 unless the request comes from network_allowlist, on both backends, before Identity-Aware Proxy and before Cloud Run.

This switches the external surfaces off, on purpose:

Not affected: Scheduler and Cloud Tasks (they call the run.app URL as internal traffic), the uptime check (/readyz), and outbound calls to Snappy, Stripe, SendGrid, Twilio, the platforms' webhook URLs and Google's order endpoint.

The admin portal has its own gate on the same addresses on both hosts (admin_network_allowlist, rules 140-149 of the edge policy, above the host gate), so reopening a host to agents and shoppers never reopens /admin; the sandbox smoke test expects /admin/ to answer 403 from the internet.

To reopen prod, remove the network_allowlist argument from infra/terraform/envs/prod/main.tf and apply; to gate sandbox as well, add the same argument and variable to envs/sandbox. The deploy smoke test reads the same line to decide what a runner on the internet should see, so the two cannot disagree silently. To change the addresses, edit the default in envs/prod/variables.tf; the list is capped at five ranges because the rule is one Cloud Armor expression with one inIpRange per address.

Admin portal

https://<host>/admin — reachable only from Snappy's Twingate addresses on both hosts (admin_network_allowlist in each env root; the edge policy allows those addresses on /admin* and the IAP callbacks and answers 403 to everyone else, before Identity-Aware Proxy), then behind Google Identity-Aware Proxy (@snappy.com accounts), allowlisted operators.

flowchart TD
  op["Operator opens https://host/admin"] --> lb["Load balancer routes /admin* to the IAP-enabled backend of the same Cloud Run service"]
  lb --> iap["Identity-Aware Proxy: Google sign-in, organisation accounts only"]
  iap --> app["App verifies X-Goog-IAP-JWT-Assertion, audience must be a backend of this project"]
  app --> dom{"email on the allowed domain and listed in admins (or in ADMIN_EMAILS for the first bootstrap)?"}
  dom -->|no| deny["403 admin_domain or admin_not_allowlisted"]
  dom -->|yes| role{"role"}
  role -->|viewer| read["Read: dashboard, users, orders, checkouts, support, negotiations, protocols (platforms, sessions, signing keys), integrations status, settings, admins, audit log, webhook deliveries"]
  role -->|admin| write["Write: every action is written to the audit log with actor, action, target and data"]
  write --> users["Users: suspend, revoke agent tokens"]
  write --> orders["Orders: cancel and refund, resync from Snappy, resend receipt"]
  write --> support["Support: take, refund partial or full, resolve, reject"]
  write --> neg["Negotiations: override with a new offer or a rejection"]
  write --> integ["Integrations: save or remove credentials (Secret Manager), test connection"]
  write --> protocols["Protocols: register, disable and re-key platforms, check a UCP profile, generate a new signing key, resend an order webhook"]
  write --> settings["Settings: service fee, ship-to countries, order cap, maintenance mode, support contacts, negotiation bounds and AI prompt, protocol switches and Google Pay (10 s cache)"]
  write --> clients["Agent clients: pre-provision, disable"]
  write --> admins["Admins: add viewer or admin, remove"]
  write --> audit[("audit_log")]
  alt["Session mode (ADMIN_AUTH_MODE=session): Google ID token sign-in, or the local-only dev sign-in with an ADMIN_EMAILS address, into a signed cookie"] -.-> dom
Page What you can do
Dashboard Users, orders, revenue and fees, checkout funnel
Users Search, detail (orders, checkouts, agent grants, messages), suspend, revoke agent tokens
Orders Filter by stage, detail with money breakdown and timeline, resync from Snappy, resend receipt, cancel and refund
Checkouts Funnel view incl. partially confirmed / failed / refunded with per-item reasons
Support Returns, damaged, wrong item, not received: take, refund (partial/full on the original payment), resolve, reject; the user is emailed
Negotiations Every price negotiation: list → offer, discount, decision, decided by (rules / AI / admin), round, status; detail with the shopper's ask, competitor evidence and verification, rules applied, AI reasoning and the event log; override with a new offer or a rejection. See Price negotiation
Integrations Snappy, Stripe (secret and publishable keys), SendGrid, Twilio, Anthropic, Google (UCP partner id and order-webhook key) and the product feed token (write-only, stored in Secret Manager) with "Test connection"
Agent clients Pre-provision or disable OAuth clients (including client_credentials clients for UCP platforms)
Protocols ACP, UCP and feed status with their discovery URLs; register, disable or re-key an agent platform (ChatGPT, Google, Shopify, partners), check a UCP profile, rotate the business signing keys, list protocol checkouts and resend an order webhook (delivery attempts and a feed refresh are on the admin API). See Agentic commerce
Settings Service fee, ship-to countries, featured collections, order cap, maintenance mode, support contacts, price negotiation (bounds, mode, AI prompt, per-product overrides), agentic commerce protocols (ACP and UCP switches, Stripe merchant id, AP2 and signing, Google Pay, feeds, policy links, session TTL)
Admins, Audit log, Webhooks Operators, every privileged action, raw delivery log

Spend cap

Each project carries a $100/month budget (infra/terraform/modules/budget, monthly_budget_usd) with email alerts at 50 %, 90 % and 100 % of actual spend and at 100 % of forecasted spend. GCP cannot stop spending by itself, so a kill switch is attached: budget notifications go to the billing-budget-alerts Pub/Sub topic and the billing-cap Cloud Run function detaches the project from the billing account when actual spend reaches the budget. Every paid resource then stops (Cloud Run, Cloud SQL, the load balancer) until billing is re-attached:

gcloud billing projects link snappy-agents-sandbox --billing-account 017C25-AFCFFA-B1502A

Raise the cap by changing monthly_budget_usd in envs/<env>/variables.tf; set hard_cap = false to keep alerts only.

Alerts

Cloud Monitoring policies (Terraform): 5xx ratio, uptime check on /readyz, Cloud Tasks queue depth, and a log-based alert on checkout.failed. Notification channel is an email group; add Slack via a Cloud Monitoring channel if desired.

Common procedures

Snappy Agents · agents.snappy.com · support@snappy.com