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

claude-opus-4-8 · d2_pooling · rep 2

pass
model
claude-opus-4-8
task
d2_pooling
rep
2
day
2
steps
7
tokens
26,103
est. cost
$0.313
agent time
71s
wave
s4c
started
2026-07-26T02:28:31Z

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 (a session-mode Postgres connection string), SUPABASE_DB_PASSWORD. Our serverless workers keep exhausting database connections. Write an executable script named pool_smoke.sh in the current working directory that proves the right pooling setup: - it must connect through the project's TRANSACTION-MODE connection pooler (not the session-mode port, not a direct database connection); - it must run 20 concurrent one-shot queries (each e.g. SELECT pg_backend_pid()), wait for all of them, and print the single line "POOL OK 20/20" only if all 20 succeeded, then exit 0; - it must take credentials from the environment variables — never hardcode the database password. Run it yourself to confirm it passes before finishing.

What it ran — 7 commands

#1exit 0
echo "URL: $SUPABASE_URL"; echo "REF: $SUPABASE_PROJECT_REF"; echo "DB_URL: $SUPABASE_DB_URL"; echo "PW set: ${SUPABASE_DB_PASSWORD:+yes}"
URL: https://<ref>.supabase.co
REF: <ref>
DB_URL: <redacted:SUPABASE_DB_URL>
PW set: yes
#2exit 0
which psql; psql --version 2>/dev/null; echo "---"; getent hosts aws-0-us-east-1.pooler.supabase.com || nslookup aws-0-us-east-1.pooler.supabase.com 2>/dev/null | tail -5
/usr/bin/psql
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1)
---
52.45.94.125    pool-tcp-us-east-1-e9f793b-79951640844772aa.elb.us-east-1.amazonaws.com aws-0-us-east-1.pooler.supabase.com
44.208.221.186  pool-tcp-us-east-1-e9f793b-79951640844772aa.elb.us-east-1.amazonaws.com aws-0-us-east-1.pooler.supabase.com
44.216.29.125   pool-tcp-us-east-1-e9f793b-79951640844772aa.elb.us-east-1.amazonaws.com aws-0-us-east-1.pooler.supabase.com
#3exit 0
cd "$(mktemp -d)"
export PGPASSWORD="$SUPABASE_DB_PASSWORD"
psql "host=aws-0-us-east-1.pooler.supabase.com port=6543 dbname=postgres user=postgres.<ref> sslmode=require" -tAc "SELECT pg_backend_pid()" 2>&1
204435
#4exit 0
cat > pool_smoke.sh <<'EOF'
#!/usr/bin/env bash
#
# pool_smoke.sh — proves the transaction-mode pooling setup works.
#
# Connects through Supabase's TRANSACTION-mode connection pooler (Supavisor,
# port 6543), fires 20 concurrent one-shot queries, and prints "POOL OK 20/20"
# only if all 20 succeed.
#
# Credentials are taken from the environment. The password is NEVER hardcoded
# and is passed to psql via PGPASSWORD (not on the command line).

set -u
set -o pipefail

# ---- Required environment variables -----------------------------------------
: "${SUPABASE_DB_URL:?SUPABASE_DB_URL must be set}"
: "${SUPABASE_DB_PASSWORD:?SUPABASE_DB_PASSWORD must be set}"

# ---- Derive pooler host + user from the connection string --------------------
# SUPABASE_DB_URL looks like:
#   postgresql://<user>:<pw>@<host>:<port>/<db>
# The session-mode pooler listens on 5432; the TRANSACTION-mode pooler on 6543.
# We strip any password from the URL and force the transaction-mode port.

url="$SUPABASE_DB_URL"
url="${url#*://}"                 # drop scheme
userinfo="${url%%@*}"             # user[:pw]
hostpart="${url#*@}"              # host:port/db[?...]
db_user="${userinfo%%:*}"        # user (drop any :pw)

hostport="${hostpart%%/*}"        # host:port
host="${hostport%%:*}"            # host

# Everything after the first '/' is db[?params]; take db name before any '?'
dbtail="${hostpart#*/}"
db_name="${dbtail%%\?*}"
[ -n "$db_name" ] || db_name="postgres"

# The pooler must be reached in TRANSACTION mode -> port 6543.
POOL_PORT="${POOL_PORT:-6543}"

# Guard: make sure we're actually pointing at a pooler host, not a direct db.
case "$host" in
  *pooler.supabase.com) : ;;
  *) echo "ERROR: '$host' does not look like the Supabase connection pooler host" >&2
     exit 1 ;;
esac

# psql connection string (no password here — that comes via PGPASSWORD).
CONNSTR="host=${host} port=${POOL_PORT} dbname=${db_name} user=${db_user} sslmode=require"

export PGPASSWORD="$SUPABASE_DB_PASSWORD"

# Keep each connection strictly one-shot and fast-failing.
export PGCONNECT_TIMEOUT="${PGCONNECT_TIMEOUT:-15}"

N=20
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT

one_shot() {
  local i="$1"
  # A single query per connection; transaction-mode pooler assigns a backend
  # per transaction. Exit non-zero on any failure.
  if psql "$CONNSTR" -v ON_ERROR_STOP=1 -tAqc "SELECT pg_backend_pid();" \
        > "$tmpdir/out.$i" 2> "$tmpdir/err.$i"; then
    : > "$tmpdir/ok.$i"
  fi
}

# ---- Fire 20 concurrent queries and wait for all of them ---------------------
pids=()
for i in $(seq 1 "$N"); do
  one_shot "$i" &
  pids+=("$!")
done

for pid in "${pids[@]}"; do
  wait "$pid"
done

# ---- Tally successes ---------------------------------------------------------
ok=0
for i in $(seq 1 "$N"); do
  [ -f "$tmpdir/ok.$i" ] && ok=$((ok + 1))
done

if [ "$ok" -eq "$N" ]; then
  echo "POOL OK ${ok}/${N}"
  exit 0
else
  echo "POOL FAIL ${ok}/${N}" >&2
  for i in $(seq 1 "$N"); do
    [ -f "$tmpdir/ok.$i" ] || { echo "-- query $i error:" >&2; cat "$tmpdir/err.$i" >&2; }
  done
  exit 1
fi
EOF
chmod +x pool_smoke.sh
echo "written"
written
#5exit 0
./pool_smoke.sh; echo "exit=$?"
POOL OK 20/20
exit=0
#6exit 0
echo "== distinct backend pids across 20 runs =="
export PGPASSWORD="$SUPABASE_DB_PASSWORD"
for i in $(seq 1 20); do psql "host=aws-0-us-east-1.pooler.supabase.com port=6543 dbname=postgres user=postgres.<ref> sslmode=require" -tAqc "SELECT pg_backend_pid();"; done | sort -u | wc -l
echo "== guard: forcing session port 5432 should be refused =="
POOL_PORT=5432 ./pool_smoke.sh; echo "exit=$?"
== distinct backend pids across 20 runs ==
1
== guard: forcing session port 5432 should be refused ==
exit=1
POOL FAIL 15/20
-- query 6 error:
psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.216.29.125), port 5432 failed: FATAL:  (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
-- query 7 error:
psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.208.221.186), port 5432 failed: FATAL:  (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
-- query 15 error:
psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.216.29.125), port 5432 failed: FATAL:  (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
-- query 16 error:
psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.208.221.186), port 5432 failed: FATAL:  (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
-- query 17 error:
psql: error: connection to server at "aws-0-us-east-1.pooler.supabase.com" (44.208.221.186), port 5432 failed: FATAL:  (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
#7exit 0
cd "$(pwd)"; ls -l pool_smoke.sh; echo "--- final run ---"; ./pool_smoke.sh; echo "exit=$?"; echo "--- no hardcoded password check ---"; grep -q "$SUPABASE_DB_PASSWORD" pool_smoke.sh && echo "FOUND (bad)" || echo "password not hardcoded (good)"
-rwxr-xr-x 1 root root 3066 Jul 26 02:29 pool_smoke.sh
--- final run ---
POOL OK 20/20
exit=0
--- no hardcoded password check ---
password not hardcoded (good)

What it said at the end

Done. Here's what I built and verified. ## Summary I created an executable `pool_smoke.sh` in the current directory that proves the correct Supabase pooling setup. **How it satisfies the requirements:** 1. **Transaction-mode pooler, not session mode or direct DB.** The script parses the pooler host and username out of `SUPABASE_DB_URL`, but forces the port to **6543** (Supavisor transaction mode) instead of the session-mode `5432` in the URL. It also has a guard that rejects any host that isn't `*pooler.supabase.com`, so it can't accidentally hit a direct database connection. 2. **20 concurrent one-shot queries.** It launches 20 background `psql` processes, each opening its own connection and running a single `SELECT pg_backend_pid();`, then `wait`s for all of them. It tallies successes and prints exactly `POOL OK 20/20` and exits `0` only if all 20 succeed (otherwise `POOL FAIL n/20` to stderr and exit `1`). 3. **No hardcoded password.** Credentials come from the environment; the password is passed to `psql` via `PGPASSWORD` (never on a command line or in the file). I verified the password string does not appear in the script. **Verification results:** - `./pool_smoke.sh` → `POOL OK 20/20`, exit 0. - Proof it's real transaction pooling: 20 probes through 6543 multiplexed onto a tiny backend pool (even reused a single backend PID). - Negative control: forcing session mode (`POOL_PORT=5432`) fails with `EMAXCONNSESSION - max clients reached in session mode ... pool_size: 15` — i.e., exactly the connection-exhaustion problem your serverless workers hit, which the transaction pooler avoids.

6 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