echo "SUPABASE_URL: $SUPABASE_URL"
echo "SUPABASE_PROJECT_REF: $SUPABASE_PROJECT_REF"
echo "SUPABASE_ANON_KEY: ${SUPABASE_ANON_KEY:0:20}..."
echo "SUPABASE_SERVICE_ROLE_KEY: ${SUPABASE_SERVICE_ROLE_KEY:0:20}..."
echo "SUPABASE_DB_URL: ${SUPABASE_DB_URL:0:40}..."
echo "SUPABASE_DB_PASSWORD: ${SUPABASE_DB_PASSWORD:0:5}..."SUPABASE_URL: https://<ref>.supabase.co SUPABASE_PROJECT_REF: <ref> SUPABASE_ANON_KEY: eyJhbGciOiJIUzI1NiIs... SUPABASE_SERVICE_ROLE_KEY: eyJhbGciOiJIUzI1NiIs... SUPABASE_DB_URL: postgresql://postgres.pgepczuaratdpqugop... SUPABASE_DB_PASSWORD: 1a9f7...
psql "$SUPABASE_DB_URL" -c "\d public.signups"
Table "public.signups"
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+----------------------------------
id | bigint | | not null | generated by default as identity
email | text | | not null |
plan | text | | not null | 'free'::text
created_at | timestamp with time zone | | not null | now()
Indexes:
"signups_pkey" PRIMARY KEY, btree (id)
psql "$SUPABASE_DB_URL" -c "SELECT * FROM pg_extension WHERE extname IN ('pg_net', 'http', 'pg_cron');"oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition -----+---------+----------+--------------+----------------+------------+-----------+-------------- (0 rows)
psql "$SUPABASE_DB_URL" -c "CREATE EXTENSION IF NOT EXISTS pg_net SCHEMA extensions;"
CREATE EXTENSION
psql "$SUPABASE_DB_URL" -c "
-- Verify pg_net is available
SELECT net.http_post(
url := '${SUPABASE_URL}/functions/v1/hook-recorder',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ${SUPABASE_SERVICE_ROLE_KEY}'
),
body := '{\"email\": \"ping@test.com\", \"plan\": \"test\"}'::jsonb
);
" http_post
-----------
1
(1 row)
psql "$SUPABASE_DB_URL" <<'SQL'
-- Create the trigger function that fires an HTTP webhook on INSERT
CREATE OR REPLACE FUNCTION public.send_signup_webhook()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
payload jsonb;
jwt_token text;
BEGIN
payload := jsonb_build_object(
'email', NEW.email,
'plan', NEW.plan
);
-- Use the service-role key so the edge function trusts the caller
jwt_token := current_setting('app.settings.jwt', true);
PERFORM net.http_post(
url := current_setting('app.settings.webhook_url', true),
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ' || jwt_token
),
body := payload
);
RETURN NEW;
END;
$$;
-- Store config values the function reads at runtime
ALTER DATABASE postgres SET app.settings.webhook_url = '${SUPABASE_URL}/functions/v1/hook-recorder';
ALTER DATABASE postgres SET app.settings.jwt = '${SUPABASE_SERVICE_ROLE_KEY}';
SQLCREATE FUNCTION
ERROR: permission denied to set parameter "app.settings.webhook_url" ERROR: permission denied to set parameter "app.settings.jwt"
psql "$SUPABASE_DB_URL" <<'SQL'
-- Create the trigger function with values inlined
CREATE OR REPLACE FUNCTION public.send_signup_webhook()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
payload jsonb;
BEGIN
payload := jsonb_build_object(
'email', NEW.email,
'plan', NEW.plan
);
PERFORM net.http_post(
url := '${SUPABASE_URL}/functions/v1/hook-recorder',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ${SUPABASE_SERVICE_ROLE_KEY}'
),
body := payload
);
RETURN NEW;
END;
$$;
SQLCREATE FUNCTION
psql "$SUPABASE_DB_URL" -c " -- Attach the trigger to the signups table CREATE TRIGGER signup_webhook_trigger AFTER INSERT ON public.signups FOR EACH ROW EXECUTE FUNCTION public.send_signup_webhook(); "
CREATE TRIGGER
psql "$SUPABASE_DB_URL" -c "\d public.webhook_receipts"
Table "public.webhook_receipts"
Column | Type | Collation | Nullable | Default
-------------+--------------------------+-----------+----------+----------------------------------
id | bigint | | not null | generated by default as identity
received_at | timestamp with time zone | | not null | now()
payload | jsonb | | not null |
Indexes:
"webhook_receipts_pkey" PRIMARY KEY, btree (id)
psql "$SUPABASE_DB_URL" -c "
-- Test insert
INSERT INTO public.signups (email, plan) VALUES ('test-webhook@example.com', 'pro');
"ERROR: invalid URL "${SUPABASE_URL}/functions/v1/hook-recorder": Bad scheme
CONTEXT: SQL statement "insert into net.http_request_queue(method, url, headers, body, timeout_milliseconds)
values (
'POST',
net._encode_url_with_params_array(url, params_array),
headers,
convert_to(body::text, 'UTF8'),
timeout_milliseconds
)
returning id"
PL/pgSQL function net.http_post(text,jsonb,jsonb,jsonb,integer) line 37 at SQL statement
SQL statement "SELECT net.http_post(
url := '${SUPABASE_URL}/functions/v1/hook-recorder',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ${SUPABASE_SERVICE_ROLE_KEY}'
),
body := payload
)"
PL/pgSQL function send_signup_webhook() line 10 at PERFORM
psql "$SUPABASE_DB_URL" -c "SELECT pg_get_functiondef(oid) FROM pg_proc WHERE proname = 'send_signup_webhook';"
pg_get_functiondef
--------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.send_signup_webhook() +
RETURNS trigger +
LANGUAGE plpgsql +
SECURITY DEFINER +
AS $function$ +
DECLARE +
payload jsonb; +
BEGIN +
payload := jsonb_build_object( +
'email', NEW.email, +
'plan', NEW.plan +
); +
+
PERFORM net.http_post( +
url := '${SUPABASE_URL}/functions/v1/hook-recorder', +
headers := jsonb_build_object( +
'Content-Type', 'application/json', +
'Authorization', 'Bearer ${SUPABASE_SERVICE_ROLE_KEY}'+
), +
body := payload +
); +
+
RETURN NEW; +
END; +
$function$ +
(1 row)
cat <<'EOSQL' > /tmp/create_webhook_fn.sql
CREATE OR REPLACE FUNCTION public.send_signup_webhook()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
payload jsonb;
BEGIN
payload := jsonb_build_object(
'email', NEW.email,
'plan', NEW.plan
);
PERFORM net.http_post(
url := '__SUPABASE_URL__',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer __JWT__'
),
body := payload
);
RETURN NEW;
END;
$$;
EOSQL
# Now substitute the placeholders
sed -i "s|__SUPABASE_URL__|${SUPABASE_URL}/functions/v1/hook-recorder|g" /tmp/create_webhook_fn.sql
sed -i "s|__JWT__|${SUPABASE_SERVICE_ROLE_KEY}|g" /tmp/create_webhook_fn.sql
psql "$SUPABASE_DB_URL" -f /tmp/create_webhook_fn.sqlCREATE FUNCTION
psql "$SUPABASE_DB_URL" -c "SELECT pg_get_functiondef(oid) FROM pg_proc WHERE proname = 'send_signup_webhook';"
pg_get_functiondef
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION public.send_signup_webhook() +
RETURNS trigger +
LANGUAGE plpgsql +
SECURITY DEFINER +
AS $function$ +
DECLARE +
payload jsonb; +
BEGIN +
payload := jsonb_build_object( +
'email', NEW.email, +
'plan', NEW.plan +
); +
+
PERFORMpsql "$SUPABASE_DB_URL" -c " -- Clear any prior test data DELETE FROM public.signups WHERE email = 'test-webhook@example.com'; DELETE FROM public.webhook_receipts; "
DELETE 0 DELETE 1
psql "$SUPABASE_DB_URL" -c "
-- Test insert - this should trigger the webhook
INSERT INTO public.signups (email, plan) VALUES ('test-webhook@example.com', 'pro');
"INSERT 0 1
sleep 5 && psql "$SUPABASE_DB_URL" -c "SELECT * FROM public.webhook_receipts ORDER BY id DESC LIMIT 5;"
id | received_at | payload
----+-------------------------------+------------------------------------------------------
3 | 2026-07-26 03:46:36.545332+00 | {"plan": "pro", "email": "test-webhook@example.com"}
(1 row)
psql "$SUPABASE_DB_URL" -c "
INSERT INTO public.signups (email, plan) VALUES ('another-user@example.com', 'enterprise');
" && sleep 5 && psql "$SUPABASE_DB_URL" -c "SELECT * FROM public.webhook_receipts ORDER BY id DESC LIMIT 5;"INSERT 0 1
id | received_at | payload
----+-------------------------------+-------------------------------------------------------------
4 | 2026-07-26 03:46:47.432685+00 | {"plan": "enterprise", "email": "another-user@example.com"}
3 | 2026-07-26 03:46:36.545332+00 | {"plan": "pro", "email": "test-webhook@example.com"}
(2 rows)
psql "$SUPABASE_DB_URL" -c "
DELETE FROM public.signups WHERE email IN ('test-webhook@example.com', 'another-user@example.com');
DELETE FROM public.webhook_receipts;
"DELETE 2 DELETE 2
4 earlier narration turn(s) are in the raw transcript.
A shell script executed against the live project and asserted on the state the agent left behind. No model judged another model.
Raw transcript · Task definition and verifier · Every attempt