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

tencent/hy3 · d2_pooling · rep 1

pass
model
tencent/hy3
task
d2_pooling
rep
1
day
2
steps
7
tokens
26,129
est. cost
$0.008
agent time
179s
wave
s4c
started
2026-07-26T02:47:11Z

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
env | grep -i supabase; echo "---"; which psql pg_isready; echo "---"; cat /etc/os-release 2>/dev/null | head -3
SUPABASE_DB_PASSWORD=<redacted:SUPABASE_DB_PASSWORD>
SUPABASE_DB_URL=<redacted:SUPABASE_DB_URL>
SUPABASE_URL=https://<ref>.supabase.co
SUPABASE_SERVICE_ROLE_KEY=<redacted:SUPABASE_SERVICE_ROLE_KEY>
SUPABASE_PROJECT_REF=<ref>
SUPABASE_ANON_KEY=<redacted:SUPABASE_ANON_KEY>
---
/usr/bin/psql
/usr/bin/pg_isready
---
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
#2exit 0
env | grep -i supabase | sed -E 's/(PASSWORD=).*/\1<hidden>/'
SUPABASE_DB_PASSWORD=<hidden>
SUPABASE_DB_URL=<redacted:SUPABASE_DB_URL>
SUPABASE_URL=https://<ref>.supabase.co
SUPABASE_SERVICE_ROLE_KEY=<redacted:SUPABASE_SERVICE_ROLE_KEY>
SUPABASE_PROJECT_REF=<ref>
SUPABASE_ANON_KEY=<redacted:SUPABASE_ANON_KEY>
#3exit 0
cd "$(pwd)"
# Derive the host from SUPABASE_DB_URL and test the transaction-mode port (6543)
netloc="${SUPABASE_DB_URL##*@}"
host="${netloc%%:*}"
echo "Pooler host: $host"
echo "--- pg_isready on session port 5432 ---"
pg_isready -h "$host" -p 5432 -U "postgres.${SUPABASE_PROJECT_REF}" 2>&1 || true
echo "--- pg_isready on transaction port 6543 ---"
pg_isready -h "$host" -p 6543 -U "postgres.${SUPABASE_PROJECT_REF}" 2>&1 || true
Pooler host: aws-0-us-east-1.pooler.supabase.com
--- pg_isready on session port 5432 ---
aws-0-us-east-1.pooler.supabase.com:5432 - accepting connections
--- pg_isready on transaction port 6543 ---
aws-0-us-east-1.pooler.supabase.com:6543 - accepting connections
#4exit 0
cd "$(pwd)"
netloc="${SUPABASE_DB_URL##*@}"
POOLER_HOST="${netloc%%:*}"
echo "POOLER_HOST=$POOLER_HOST"
TX_URL="postgresql://postgres.${SUPABASE_PROJECT_REF}:<redacted>@${POOLER_HOST}:6543/postgres?sslmode=require"
echo "--- single one-shot query via transaction pooler (port 6543) ---"
PGCONNECT_TIMEOUT=10 psql "$TX_URL" -t -A -c "SELECT pg_backend_pid();" 2>&1
POOLER_HOST=aws-0-us-east-1.pooler.supabase.com
--- single one-shot query via transaction pooler (port 6543) ---
196909
#5exit 0
cat > pool_smoke.sh <<'EOF'
#!/usr/bin/env bash
#
# pool_smoke.sh — prove the transaction-mode connection pooler is wired up
# correctly so serverless workers don't exhaust database connections.
#
# What it does:
#   * Connects ONLY through the project's TRANSACTION-MODE connection pooler
#     (port 6543 on the Supabase pooler host). It never touches the
#     session-mode port (5432) and never connects directly to the DB.
#   * Launches 20 concurrent one-shot queries (SELECT pg_backend_pid()),
#     waits for all of them, and prints "POOL OK 20/20" only if every one
#     succeeded, then exits 0.
#   * Reads all credentials from the environment — the DB password is never
#     hardcoded.
#
# Requirements: psql (from postgresql-client) on PATH.

set -u

# --- Config ---------------------------------------------------------------
N=20                                  # number of concurrent one-shot queries
POOLER_PORT=6543                      # transaction-mode pooler port (NOT 5432)

# --- Sanity-check environment ---------------------------------------------
required_vars=(SUPABASE_DB_URL SUPABASE_DB_PASSWORD SUPABASE_PROJECT_REF)
missing=0
for v in "${required_vars[@]}"; do
  if [ -z "${!v:-}" ]; then
    echo "ERROR: required environment variable $v is not set" >&2
    missing=1
  fi
done
[ "$missing" -eq 0 ] || exit 1

# --- Build the transaction-mode connection string from env -----------------
# Reuse the pooler host already present in SUPABASE_DB_URL, but force the
# transaction-mode port (6543). port 5432 would be session mode; a plain
# :5432 / direct host would bypass pooling entirely.
netloc="${SUPABASE_DB_URL##*@}"         # host:port/db  (and possibly ?opts)
pooler_host="${netloc%%:*}"             # strip port/db, keep host
pooler_host="${pooler_host%%/*}"        # just the hostname

POOLER_URI="postgresql://postgres.${SUPABASE_PROJECT_REF}:<redacted>@${pooler_host}:${POOLER_PORT}/postgres?sslmode=require"

# Guard against accidentally using the session-mode / direct port.
case "$POOLER_URI" in
  *:5432/*|*:5432) echo "ERROR: refusing to use session-mode / direct port 5432" >&2; exit 1 ;;
esac

# --- Run 20 concurrent one-shot queries ------------------------------------
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/pool_smoke.XXXXXX")"
trap 'rm -rf "$tmpdir"' EXIT

pids=()
for i in $(seq 1 "$N"); do
  (
    if PGCONNECT_TIMEOUT=10 psql "$POOLER_URI" -t -A -c "SELECT pg_backend_pid();" >/dev/null 2>&1; then
      echo 1 > "$tmpdir/$i"
    else
      echo 0 > "$tmpdir/$i"
    fi
  ) &
  pids+=($!)
done

# Wait for every background query to finish.
fail=0
for p in "${pids[@]}"; do
  wait "$p" || fail=1
done

# Tally results.
ok=0
for i in $(seq 1 "$N"); do
  [ "$(cat "$tmpdir/$i" 2>/dev/null)" = "1" ] && ok=$((ok+1))
done

if [ "$ok" -eq "$N" ]; then
  echo "POOL OK ${ok}/${N}"
  exit 0
else
  echo "POOL FAIL ${ok}/${N}" >&2
  exit 1
fi
EOF
chmod +x pool_smoke.sh
echo "written:"; ls -l pool_smoke.sh
written:
-rwxr-xr-x 1 root root 2882 Jul 26 02:50 pool_smoke.sh
#6exit 0
cd "$(pwd)"; ./pool_smoke.sh; echo "exit code: $?"
POOL OK 20/20
exit code: 0
#7exit 0
cd "$(pwd)"
# Simulate what would happen if someone forced the session port — prove the guard rejects it.
sed 's/POOLER_PORT=6543/POOLER_PORT=5432/' pool_smoke.sh > /tmp/pool_smoke_session.sh
chmod +x /tmp/pool_smoke_session.sh
/tmp/pool_smoke_session.sh; echo "session-mode run exit: $? (expected non-zero)"
session-mode run exit: 1 (expected non-zero)
ERROR: refusing to use session-mode / direct port 5432

What it said at the end

Done. The task is complete. ## Summary I created `pool_smoke.sh` in the working directory and confirmed it passes (`POOL OK 20/20`, exit 0). **What the script does:** - **Reads credentials from the environment only** — it derives the transaction-mode connection string from `SUPABASE_DB_URL`, `SUPABASE_DB_PASSWORD`, and `SUPABASE_PROJECT_REF`. The DB password is never hardcoded. - **Uses the TRANSACTION-MODE pooler exclusively** — it reuses the Supabase pooler host from `SUPABASE_DB_URL` but forces port **6543** (transaction mode). Port 5432 is session mode and a direct host would bypass pooling; the script includes an explicit guard that refuses port 5432 and exits non-zero if it's ever used. - **Runs 20 concurrent one-shot queries** — it launches 20 background `SELECT pg_backend_pid()` queries through the pooler, `wait`s for all of them, tallies successes, and prints `POOL OK 20/20` only if every one succeeded, then exits 0. **Verification:** - Positive run: `./pool_smoke.sh` → `POOL OK 20/20`, exit 0. - Negative test: I forced port 5432 and confirmed the script refuses it (`ERROR: refusing to use session-mode / direct port 5432`, exit 1), proving it genuinely uses the transaction-mode pooler and not session mode or a direct connection.

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