Can Agents Run It? · evidence — Issue 1: Supabase

openai/gpt-5.6-luna · d2_webhooks · rep 2

pass
model
openai/gpt-5.6-luna
task
d2_webhooks
rep
2
day
2
steps
8
tokens
17,433
est. cost
$0.049
agent time
41s
wave
s4b
started
2026-07-25T05:56:40Z

The task as the agent received it

You have operator access to a hosted Supabase project. Credentials are in environment variables: SUPABASE_URL, SUPABASE_PROJECT_REF, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY, SUPABASE_DB_URL, SUPABASE_DB_PASSWORD. Every INSERT into the existing table public.signups must deliver an HTTP webhook: a POST request with a JSON body containing at least the new row's email and plan values, sent to the receiver endpoint {SUPABASE_URL}/functions/v1/hook-recorder (an edge function that is already deployed on this project; SUPABASE_URL is in your environment). The receiver requires a valid project JWT in the Authorization header and records every payload it accepts. Implement the delivery from the database itself, so it fires for ANY insert into signups no matter which client performs it — no external workers, no cron, no client-side code. Delivery may be asynchronous (a few seconds is fine). Prove it end-to-end with a test insert before finishing: the receiver stores accepted payloads in public.webhook_receipts.

What it ran — 8 commands

#1exit 1
set -e
printf 'URL=%s\nREF=%s\n' "$SUPABASE_URL" "$SUPABASE_PROJECT_REF"
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -Atc "select current_database(), current_user; select extname from pg_extension where extname in ('pg_net','http'); \d+ public.signups; \d+ public.webhook_receipts"
URL=https://<ref>.supabase.co
REF=<ref>
ERROR:  syntax error at or near "\"
LINE 1: ... pg_extension where extname in ('pg_net','http'); \d+ public...
                                                             ^
#2exit 0
set -e
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "select current_database(), current_user; select extname from pg_extension where extname in ('pg_net','http');"
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c '\d+ public.signups' -c '\d+ public.webhook_receipts'
 current_database | current_user 
------------------+--------------
 postgres         | postgres
(1 row)

 extname 
---------
(0 rows)

                                                                Table "public.signups"
   Column   |           Type           | Collation | Nullable |             Default              | Storage  | Compression | Stats target | Description 
------------+--------------------------+-----------+----------+----------------------------------+----------+-------------+--------------+-------------
 id         | bigint                   |           | not null | generated by default as identity | plain    |             |              | 
 email      | text                     |           | not null |                                  | extended |             |              | 
 plan       | text                     |           | not null | 'free'::text                     | extended |             |              | 
 created_at | timestamp with time zone |           | not null | now()                            | plain    |             |              | 
Indexes:
    "signups_pkey" PRIMARY KEY, btree (id)
Access method: heap

                                                            Table "public.webhook_receipts"
   Column    |           Type           | Collation | Nullable |             Default              | Storage  | Compression | Stats target | Description 
-------------+--------------------------+-----------+----------+----------------------------------+----------+-------------+--------------+-------------
 id          | bigint                   |           | not null | generated by default as identity | plain    |             |              | 
 received_at | timestamp with time zone |           | not null | now()                            | plain    |             |              | 
 payload     | jsonb                    |           | not null |                                  | extended |             |              | 
Indexes:
    "webhook_receipts_pkey" PRIMARY KEY, btree (id)
Access method: heap

#3exit 0
set -e
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 <<'SQL'
create extension if not exists pg_net;
select extname, extversion from pg_extension where extname='pg_net';
select n.nspname, p.proname, pg_get_function_identity_arguments(p.oid) from pg_proc p join pg_namespace n on n.oid=p.pronamespace where p.proname='http_post';
SQL
CREATE EXTENSION
 extname | extversion 
---------+------------
 pg_net  | 0.20.4
(1 row)

 nspname |  proname  |                       pg_get_function_identity_arguments                        
---------+-----------+---------------------------------------------------------------------------------
 net     | http_post | url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer
(1 row)

#4exit 0
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -Atc "select extname from pg_extension where extname in ('vault','pgsodium'); select rolname from pg_roles where rolname in ('supabase_admin','service_role');"; printf 'anon length=%s service length=%s\n' "${#SUPABASE_ANON_KEY}" "${#SUPABASE_SERVICE_ROLE_KEY}"
service_role
supabase_admin
anon length=208 service length=219
#5exit 0
set -e
cat > /tmp/setup.sql <<'SQL'
create schema if not exists private;
revoke all on schema private from public;
create table if not exists private.webhook_config (
  name text primary key,
  value text not null
);
revoke all on private.webhook_config from public;
insert into private.webhook_config(name, value)
values ('hook_recorder_anon_jwt', :'anon_key')
on conflict (name) do update set value = excluded.value;

create or replace function private.deliver_signup_webhook()
returns trigger
language plpgsql
security definer
set search_path = pg_catalog, private
as $fn$
declare
  jwt text;
  request_id bigint;
begin
  select value into strict jwt
    from private.webhook_config
   where name = 'hook_recorder_anon_jwt';

  select net.http_post(
    url := 'https://<ref>.supabase.co/functions/v1/hook-recorder',
    body := jsonb_build_object('email', new.email, 'plan', new.plan),
    params := '{}'::jsonb,
    headers := jsonb_build_object(
      'Content-Type', 'application/json',
      'Authorization', 'Bearer ' || jwt
    ),
    timeout_milliseconds := 10000
  ) into request_id;
  return new;
end;
$fn$;

revoke all on function private.deliver_signup_webhook() from public;
drop trigger if exists signups_deliver_webhook on public.signups;
create trigger signups_deliver_webhook
after insert on public.signups
for each row execute function private.deliver_signup_webhook();
SQL
# safely pass key via psql variable
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 --set=anon_key="$SUPABASE_ANON_KEY" -f /tmp/setup.sql
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "select tgname, tgenabled from pg_trigger where tgrelid='public.signups'::regclass and not tgisinternal; select has_function_privilege('anon','private.deliver_signup_webhook()','EXECUTE');"
CREATE SCHEMA
REVOKE
CREATE TABLE
REVOKE
INSERT 0 1
CREATE FUNCTION
REVOKE
DROP TRIGGER
CREATE TRIGGER
         tgname          | tgenabled 
-------------------------+-----------
 signups_deliver_webhook | O
(1 row)

 has_function_privilege 
------------------------
 f
(1 row)

psql:/tmp/setup.sql:1: NOTICE:  schema "private" already exists, skipping
psql:/tmp/setup.sql:6: NOTICE:  relation "webhook_config" already exists, skipping
psql:/tmp/setup.sql:41: NOTICE:  trigger "signups_deliver_webhook" for relation "public.signups" does not exist, skipping
#6exit 1
set -e
TEST_EMAIL="db-trigger-$(date +%s)-$RANDOM@example.com"
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -v test_email="$TEST_EMAIL" -c "insert into public.signups(email, plan) values (:'test_email','pro') returning id,email,plan;"
for i in $(seq 1 12); do
  echo "poll $i"
  psql "$SUPABASE_DB_URL" -Atc "select id, payload from public.webhook_receipts where payload->>'email' = '$TEST_EMAIL' order by id desc limit 1" && true
  if psql "$SUPABASE_DB_URL" -Atqtc "select exists(select 1 from public.webhook_receipts where payload->>'email' = '$TEST_EMAIL' and payload->>'plan'='pro')" | grep -q t; then break; fi
  sleep 2
done
printf '\nnet requests:\n'
psql "$SUPABASE_DB_URL" -c "select id, status_code, error_msg, created, completed from net._http_response order by created desc limit 5;"
printf '\nreceipt:\n'
psql "$SUPABASE_DB_URL" -c "select id, received_at, payload from public.webhook_receipts where payload->>'email' = '$TEST_EMAIL';"
ERROR:  syntax error at or near ":"
LINE 1: insert into public.signups(email, plan) values (:'test_email...
                                                        ^
#7exit 1
set -e
TEST_EMAIL="db-trigger-$(date +%s)-$RANDOM@example.com"
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -v test_email="$TEST_EMAIL" -c "insert into public.signups(email, plan) values ('$TEST_EMAIL','pro') returning id,email,plan;"
for i in $(seq 1 15); do
  if psql "$SUPABASE_DB_URL" -Atqtc "select exists(select 1 from public.webhook_receipts where payload->>'email' = '$TEST_EMAIL' and payload->>'plan'='pro')" | grep -q t; then echo "receipt found on poll $i"; break; fi
  sleep 2
done
printf '\nnet requests:\n'
psql "$SUPABASE_DB_URL" -c "select id, status_code, error_msg, created, completed from net._http_response order by created desc limit 5;"
printf '\nreceipt:\n'
psql "$SUPABASE_DB_URL" -c "select id, received_at, payload from public.webhook_receipts where payload->>'email' = '$TEST_EMAIL';"
 id |                  email                  | plan 
----+-----------------------------------------+------
  1 | db-trigger-1784959047-21081@example.com | pro
(1 row)

INSERT 0 1
receipt found on poll 1

net requests:
ERROR:  column "completed" does not exist
LINE 1: select id, status_code, error_msg, created, completed from n...
                                                    ^
#8exit 0
psql "$SUPABASE_DB_URL" -c '\d net._http_response' -c "select id, status_code, error_msg, created, timed_out, content from net._http_response order by created desc limit 3;" -c "select id, received_at, payload from public.webhook_receipts order by id desc limit 3;"
                   Unlogged table "net._http_response"
    Column    |           Type           | Collation | Nullable | Default 
--------------+--------------------------+-----------+----------+---------
 id           | bigint                   |           |          | 
 status_code  | integer                  |           |          | 
 content_type | text                     |           |          | 
 headers      | jsonb                    |           |          | 
 content      | text                     |           |          | 
 timed_out    | boolean                  |           |          | 
 error_msg    | text                     |           |          | 
 created      | timestamp with time zone |           | not null | now()
Indexes:
    "_http_response_created_idx" btree (created)

 id | status_code | error_msg |            created            | timed_out |   content   
----+-------------+-----------+-------------------------------+-----------+-------------
  1 |         200 |           | 2026-07-25 05:57:28.310391+00 | f         | {"ok":true}
(1 row)

 id |          received_at          |                               payload                               
----+-------------------------------+---------------------------------------------------------------------
  2 | 2026-07-25 05:57:28.436731+00 | {"plan": "pro", "email": "db-trigger-1784959047-21081@example.com"}
(1 row)

What it said at the end

Implemented and verified database-level webhook delivery: - Enabled the `pg_net` Postgres extension. - Added a security-definer trigger function on `public.signups`. - Added an `AFTER INSERT` trigger that asynchronously POSTs: - URL: `https://<ref>.supabase.co/functions/v1/hook-recorder` - JSON body: `{"email": "...", "plan": "..."}` - Authorization: valid Supabase project JWT. - Stored the JWT in a restricted `private.webhook_config` table rather than exposing it publicly. - Tested with an insert: - Inserted email: `db-trigger-1784959047-21081@example.com` - Plan: `pro` - `pg_net` response: HTTP `200` - Receiver receipt: recorded in `public.webhook_receipts` with the expected payload.

How it was graded

A shell script executed against the live project and asserted on the state the agent left behind. No model judged another model.

exit 0 OK

Check it yourself

Raw transcript · Task definition and verifier · Every attempt