feat(backend)!: run the backend only as Cloudflare Workers, drop Supabase Edge Functions
Merged
RI
4h ago+1718+1718+0123456789012345678901234567890123456789-5725-5725-0123456789012345678901234567890123456789
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 backendruns Supabase (withedge_runtimedisabled) plus the API, plugin and files workers underwrangler dev, on ports 8787, 8788 and 8789. The local queue dispatcher is on by default. The console's localapi_domainis nowlocalhost:8787.functions serveandsupabase:functions:serveare removed. - Duplicated system dropped:
- Every
supabase/functions/<name>/index.tsDeno entrypoint is deleted, along withdeno.json,deno.lock,supabase/functions/.env*and the Deno stats fallbacks. - The
[functions.*]blocks inconfig.tomlare removed, andscripts/supabase-cloud-functions.tsis deleted. - The
deploy:supabase*scripts are removed, and the "Update functions" deploy step is gone. - The
USE_CLOUDFLARE_WORKERStest switch is removed. - The edge-server CI jobs and steps are removed, including the duplicate
test_backend_pluginjob.
- Every
- Queue consumers move into the API worker:
- New migration
20261201025633_route_queue_wakeups_to_api_workerroutes'*'to the outbox. Prod already has this row; the migration makes it the default for preprod, alpha, local, CI and self-host. QueueDispatcherrewrites any.../functions/v1/<path>wakeup to its ownAPI_SELFbinding (/<path>). The DB keeps buildingget_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_DISPATCHERandAPI_SELFbindings.
- New migration
- Legacy
/functions/v1callers keep working:- New
functions_v1_compat.tsmaps/functions/v1/<name>/...to the right worker: plugin forupdates,statsandchannel_self; files forfiles/*andprivate/{upload,download}_link; API for everything else. - In prod, the
legacy_cli_manifest_warningsnippet's rule widens to everysb.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/rolesis added to the API worker; it was the only edge route with no worker equivalent.
- New
- Local-only webhook escape hatch narrowed:
CAPGO_ALLOW_LOCAL_WEBHOOK_URLSnow 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.mdcovers 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)
- Merge and release. The snippet deploy widens the rule; the API worker deploy adds
API_SELFrouting and the preprod/alpha dispatcher bindings. - Verify on prod, preprod and alpha: worker logs show
/triggers/queue_consumer/sync,public.http_dispatch_outboxstays near 0,/queue_healthis healthy, andcurl https://sb.capgo.app/functions/v1/okanswers withx-capgo-snippet: legacy. - Then delete the stale edge functions (
triggers,bundle,channel,files,private) from the three Supabase projects, and drop the edge-onlysupabase 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_queueproduces an outbox row with a/functions/v1URL; the dispatcher calls/triggers/queue_consumer/syncon the API worker, which calls/triggers/<fn>. -
/functions/v1/okand/functions/v1/updateson 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 Postgrestoo 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