feat(backend)!: run the backend only as Cloudflare Workers, drop Supabase Edge Functions

Merged
RI
4h ago
+1718-5725

Summary

Local development, CI and every deployed environment now run the backend the way prod does: Cloudflare Workers only. Supabase Edge Functions are gone. Supabase still provides the database, auth and storage.

  • Local: bun backend runs Supabase (with edge_runtime disabled) plus the API, plugin and files workers under wrangler dev, on ports 8787, 8788 and 8789. The local queue dispatcher is on by default. The console's local api_domain is now localhost:8787. functions serve and supabase:functions:serve are removed.
  • Duplicated system dropped:
    • Every supabase/functions/<name>/index.ts Deno entrypoint is deleted, along with deno.json, deno.lock, supabase/functions/.env* and the Deno stats fallbacks.
    • The [functions.*] blocks in config.toml are removed, and scripts/supabase-cloud-functions.ts is deleted.
    • The deploy:supabase* scripts are removed, and the "Update functions" deploy step is gone.
    • The USE_CLOUDFLARE_WORKERS test switch is removed.
    • The edge-server CI jobs and steps are removed, including the duplicate test_backend_plugin job.
  • Queue consumers move into the API worker:
    • New migration 20261201025633_route_queue_wakeups_to_api_worker routes '*' to the outbox. Prod already has this row; the migration makes it the default for preprod, alpha, local, CI and self-host.
    • QueueDispatcher rewrites any .../functions/v1/<path> wakeup to its own API_SELF binding (/<path>). The DB keeps building get_db_url() || '/functions/v1/triggers/...', but nothing reaches Supabase Edge anymore, and the API secret never leaves the worker.
    • The queue consumer calls its per-message handlers on the same worker through API_SELF, not a public self-request (which gave 522s in prod).
    • Preprod and alpha API workers get the QUEUE_DISPATCHER and API_SELF bindings.
  • Legacy /functions/v1 callers keep working:
    • New functions_v1_compat.ts maps /functions/v1/<name>/... to the right worker: plugin for updates, stats and channel_self; files for files/* and private/{upload,download}_link; API for everything else.
    • In prod, the legacy_cli_manifest_warning snippet's rule widens to every sb.capgo.app/functions/v1/* path and proxies it, with no redirect, so old CLIs and Stripe/webhook callers still work.
    • Locally, the wrangler router applies the same mapping.
    • private/roles is added to the API worker; it was the only edge route with no worker equivalent.
  • Local-only webhook escape hatch narrowed: CAPGO_ALLOW_LOCAL_WEBHOOK_URLS now accepts only loopback IP URLs, so the webhook URL-rejection suites can run against the workers. Prod has the flag off.
  • Migration guide: docs/migrate-from-supabase-edge-functions.md covers local contributors, self-hosted installs (deploying the workers, moving secrets, queue routing, console/CLI/device/webhook URLs) and the Capgo Cloud rollout.

Rollout (Capgo Cloud)

  1. Merge and release. The snippet deploy widens the rule; the API worker deploy adds API_SELF routing and the preprod/alpha dispatcher bindings.
  2. Verify on prod, preprod and alpha: worker logs show /triggers/queue_consumer/sync, public.http_dispatch_outbox stays near 0, /queue_health is healthy, and curl https://sb.capgo.app/functions/v1/ok answers with x-capgo-snippet: legacy.
  3. Then delete the stale edge functions (triggers, bundle, channel, files, private) from the three Supabase projects, and drop the edge-only supabase secrets.

Test plan

  • bun run test:unit: 675 files and 8,139 tests passed before the Deno-shim cleanup; to re-run on the final head
  • bun run typecheck:backend, bun run lint:backend, bun run lint:deadcode
  • Local stack with no edge container. A pgmq message plus process_function_queue produces an outbox row with a /functions/v1 URL; the dispatcher calls /triggers/queue_consumer/sync on the API worker, which calls /triggers/<fn>.
  • /functions/v1/ok and /functions/v1/updates on the API port reach the API and plugin workers.
  • Worker integration suite (vitest.config.cloudflare.ts), plugin serial suite (133 tests), isolated backend suites, and the CLI suites including the pinned published CLI (cli-compat, published-cli-rpc-contract) all pass locally. One local run in a single process hit Postgres too many clients; the affected files pass when re-run in smaller groups.
  • CI

No rendered UI changes, so there are no screenshots.

šŸ¤– Generated with Claude Code