Skip to content

fix(dev): migration 337 cannot be applied — dev is missing both vault secrets the notification cron depends on #564

Closed

Description

@thinkclay

Found while reconciling dev's migration ledger. Dev is now at 178/179; 337_notification_cron_vault.sql is the one deliberately-unapplied migration, and it should stay that way until this is fixed.

Why it was skipped rather than applied

337 schedules six pg_cron jobs that each net.http_post to an edge function. The URL and the auth header are read from Vault at execution time:

url := (SELECT decrypted_secret FROM vault.decrypted_secrets WHERE name = 'edge_functions_url' LIMIT 1) || '/notify-send-worker'
headers := jsonb_build_object('Authorization', 'Bearer ' || (SELECT decrypted_secret FROM vault.decrypted_secrets WHERE name = 'service_role_key' LIMIT 1), ...)

Neither secret exists on dev. Prod has both.

edge_functions_url service_role_key
dev absent absent
prod present present

So applying 337 to dev as it stands would schedule six jobs — one of them every minute — that resolve url to NULL and send Authorization: Bearer with nothing after it. That is strictly worse than not applying it: six broken jobs firing forever, and a ledger entry claiming the notification cron is live on dev when it is not.

pg_cron and pg_net are both installed on dev, so the migration's own graceful-skip path (IF NOT EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'pg_cron')) would not trigger. It would run and produce the broken jobs.

Work

  1. Create the two Vault secrets on dev: edge_functions_url (dev project's functions base URL) and service_role_key (dev service-role key).
  2. Apply 337: ./scripts/apply-migration.sh dev 337_notification_cron_vault.sql
  3. Confirm six rows in cron.job matching notifications-%, and check cron.job_run_details for a successful first run rather than assuming.

Not agent-ready — step 1 is writing a credential into Vault and is a human call.

Worth fixing in the migration itself

337 guards on pg_cron being available but not on its secrets existing. A RAISE NOTICE ... RETURN when either secret is missing would have made this environment self-documenting instead of a footgun. Same class of issue as #559: a migration that "succeeds" while doing something useless.

Activity

  1. thinkclay commented on Sep 17, 2026

    @thinkclay
    ContributorAuthor

    Fixed on dev, 2026-09-17. It had got worse than the issue described: 337 had been applied to dev after all (ledger has it, six notifications-% jobs exist) with Vault still empty, so notifications-send-worker was failing every minute — 1,440 failures in the 24 h before this, all null value in column "url" of relation "http_request_queue".

    What was done, via the Management API query endpoint with the PAT in .env:

    1. vault.create_secret('https://pmtdqrfpumqwkdhpgwcz.supabase.co/functions/v1', 'edge_functions_url', …) — same shape as prod's.
    2. service_role_key: first set to the legacy service_role JWT from GET /v1/projects/{ref}/api-keys, which prod uses. The functions answered 401. Dev has moved to the new API-key format, so its function runtime holds the sb_secret_… key as SUPABASE_SERVICE_ROLE_KEY, and _shared/notifications/auth.ts compares the Bearer to that byte-for-byte. Swapped the Vault value to dev's default secret key (type: secret) with vault.update_secret.
    3. Verified: the 12:33 UTC run of notifications-send-worker got 200 {"ok":true,"processed":0,"results":[]} from pg_net; notifications-check-receipts likewise. No further failed rows in cron.job_run_details after 12:32.

    Two things worth knowing that came out of it:

    • Prod and dev now hold different key formats in Vault (prod: legacy JWT, dev: sb_secret_). Both are correct for their project, because the runtime env differs. When prod migrates to the new keys, its service_role_key Vault row has to be updated the same way or the cron silently 401s. That belongs in the key-rotation runbook.
    • The migration-hardening suggestion (RAISE NOTICE and return when either secret is missing) still stands and is not done here. 337 is applied everywhere now, so it would be a new numbered migration that re-creates the jobs behind a guard, or a guard inside the job command itself. Filing that separately rather than editing an applied migration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions