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

xiaomi/mimo-v2.5 · d2_webhooks · rep 1

pass
model
xiaomi/mimo-v2.5
task
d2_webhooks
rep
1
day
2
steps
18
tokens
54,354
est. cost
$0.011
agent time
81s
wave
s4c
started
2026-07-26T03:45:22Z

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 — 18 commands

#1exit 0
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...
#2exit 0
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)

#3exit 0
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)

#4exit 0
psql "$SUPABASE_DB_URL" -c "CREATE EXTENSION IF NOT EXISTS pg_net SCHEMA extensions;"
CREATE EXTENSION
#5exit 0
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)

#6exit 0
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}';
SQL
CREATE FUNCTION
ERROR:  permission denied to set parameter "app.settings.webhook_url"
ERROR:  permission denied to set parameter "app.settings.jwt"
#7exit 0
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;
$$;
SQL
CREATE FUNCTION
#8exit 0
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
#9exit 0
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)

#10exit 1
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
#11exit 0
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)

#12exit 0
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.sql
CREATE FUNCTION
#13exit 0
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
… 2,995 more bytes — full output in the raw record
#14exit 0
psql "$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
#15exit 0
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
#16exit 0
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)

#17exit 0
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)

#18exit 0
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

What it said at the end

Done. Here's what was implemented: **What I did:** 1. **Enabled `pg_net`** — the Supabase PostgreSQL extension that provides `net.http_post()` for making HTTP requests directly from SQL/PL/pgSQL. 2. **Created a trigger function** `public.send_signup_webhook()`: - `SECURITY DEFINER` so it can make outbound HTTP calls - Builds a JSON payload with `email` and `plan` from the new row - Calls `net.http_post()` to `SUPABASE_URL/functions/v1/hook-recorder` - Sets the `Authorization` header with the service-role JWT - `PERFORM` (fire-and-forget) so the INSERT isn't blocked by the network call 3. **Attached the trigger** `signup_webhook_trigger` to `public.signups` — fires `AFTER INSERT` for every row, regardless of which client performs the insert. 4. **Verified end-to-end:** - Inserted `('test-webhook@example.com', 'pro')` → `webhook_receipts` received `{"email":"test-webhook@example.com","plan":"pro"}` - Inserted `('another-user@example.com', 'enterprise')` → `webhook_receipts` received `{"email":"another-user@example.com","plan":"enterprise"}`

4 earlier narration turn(s) are in the raw transcript.

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