From f60147b4c24886c887ab7527e50ce2bf8ca57aa0 Mon Sep 17 00:00:00 2001
From: Patchalv
Date: Wed, 13 May 2026 23:07:11 +0200
Subject: [PATCH] fix(rc-entitlement-drift-check): extend cron pg_net timeout
to 60s
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The drift check runs ~30s with the current profile count (sequential
per-customer RC fetches), which exceeds pg_net's default 5s timeout.
The function itself completed correctly on every fire — Sentry events
fired, heartbeats logged — but net._http_response.status_code stayed
NULL for cron-triggered runs, making the cron's success/failure invisible
in pg_net's response table.
Uses cron.alter_job to replace just the command text on the existing
jobid; schedule and lock-table behavior are unchanged.
Surfaced during the first real smoke test of PR #68's per-profile-fetch
refactor — the manual invocation at request_id=37 hit the 5s timeout
even though the function ran to completion, while request_id=38 with
an explicit 60s pg_net timeout returned status_code=200 correctly.
Co-Authored-By: Claude Opus 4.7 (1M context)
---
...0003_extend_drift_check_pg_net_timeout.sql | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 supabase/migrations/20260513000003_extend_drift_check_pg_net_timeout.sql
diff --git a/supabase/migrations/20260513000003_extend_drift_check_pg_net_timeout.sql b/supabase/migrations/20260513000003_extend_drift_check_pg_net_timeout.sql
new file mode 100644
index 0000000..ce16085
--- /dev/null
+++ b/supabase/migrations/20260513000003_extend_drift_check_pg_net_timeout.sql
@@ -0,0 +1,32 @@
+-- Updates the rc-entitlement-drift-check cron command to pass an explicit
+-- 60-second pg_net timeout. The function takes ~30s with the current
+-- profile count because per-customer RC fetches are sequential, which
+-- exceeds pg_net's default 5-second timeout. The cron job itself was
+-- functioning correctly (function ran to completion, Sentry events fired,
+-- heartbeat logged), but `net._http_response.status_code` was recorded
+-- as NULL on every fire, harming observability of cron-triggered runs.
+--
+-- This migration uses `cron.alter_job` so the schedule and jobid stay
+-- unchanged — only the command text is replaced.
+--
+-- Function URL is environment-specific; if the project ref ever changes,
+-- both this migration and 20260513000002 must be re-applied.
+
+select cron.alter_job(
+ (select jobid from cron.job where jobname = 'rc-entitlement-drift-check'),
+ command := $$
+ select net.http_post(
+ url := 'https://doycewmbehxdqfumdgke.supabase.co/functions/v1/rc-entitlement-drift-check',
+ headers := jsonb_build_object(
+ 'Content-Type', 'application/json',
+ 'Authorization', 'Bearer ' || (
+ select decrypted_secret
+ from vault.decrypted_secrets
+ where name = 'rc_drift_check_invoke_secret'
+ )
+ ),
+ body := '{}'::jsonb,
+ timeout_milliseconds := 60000
+ );
+ $$
+);