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

tencent/hy3 · d2_pooling · rep 3

pass
model
tencent/hy3
task
d2_pooling
rep
3
day
2
steps
6
tokens
16,975
est. cost
$0.005
agent time
212s
wave
s4c
started
2026-07-26T02:52:01Z

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

#1exit 0
echo "=== env (masked) ==="; for v in SUPABASE_URL SUPABASE_PROJECT_REF SUPABASE_DB_URL SUPABASE_DB_PASSWORD; do printf '%s=%s\n' "$v" "$(printenv "$v" | sed -E 's/(:.{0,}@)/:***@/')"; done; echo; echo "=== tools ==="; which psql pg_isready xargs awk sed 2>&1; echo "=== psql version ==="; psql --version 2>&1
=== env (masked) ===
SUPABASE_URL=https://<ref>.supabase.co
SUPABASE_PROJECT_REF=<ref>
SUPABASE_DB_URL=postgresql:***@aws-0-us-east-1.pooler.supabase.com:5432/postgres
SUPABASE_DB_PASSWORD=<redacted:SUPABASE_DB_PASSWORD>

=== tools ===
/usr/bin/psql
/usr/bin/pg_isready
/usr/bin/xargs
/usr/bin/awk
/usr/bin/sed
=== psql version ===
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1)
#2exit 0
echo "=== full DB_URL user@host (password hidden, user shown) ==="; printenv SUPABASE_DB_URL | sed -E 's#://([^:/]+):[^@]*@#://\1:***@#'; echo; echo "=== project ref ==="; printenv SUPABASE_PROJECT_REF; echo "=== host from DB_URL ==="; printenv SUPABASE_DB_URL | sed -E 's#.*@([^/]+)/.*#\1#'
=== full DB_URL user@host (password hidden, user shown) ===
postgresql://postgres.<ref>:***@aws-0-us-east-1.pooler.supabase.com:5432/postgres

=== project ref ===
<ref>
=== host from DB_URL ===
aws-0-us-east-1.pooler.supabase.com:5432
#3exit 0
PASS="${SUPABASE_DB_PASSWORD:?}"; HOST=$(printenv SUPABASE_DB_URL | sed -E 's#.*@([^:/]+):.*#\1#'); USER=$(printenv SUPABASE_DB_URL | sed -E 's#^postgresql://([^:/]+):.*#\1#'); DB=$(printenv SUPABASE_DB_URL | sed -E 's#.*/([^/?]+).*#\1#'); echo "host=$HOST user=$USER db=$DB"; PGSSLMODE=require PGPASSWORD="$PASS" psql -h "$HOST" -p 6543 -U "$USER" -d "$DB" -t -A -c "SELECT pg_backend_pid();" 2>&1 | head; echo "exit=${PIPESTATUS[0]}"
host=aws-0-us-east-1.pooler.supabase.com user=postgres.<ref> db=postgres
197624
exit=0
#4exit 0
cat > pool_smoke.sh <<'EOF'
#!/usr/bin/env bash
#
# pool_smoke.sh — proves the project's TRANSACTION-MODE connection pooler
# can absorb many short-lived, concurrent one-shot queries without exhausting
# connections. Serverless workers should connect via this pooler (port 6543),
# NOT the session-mode port (5432) and NOT a direct DB connection.
#
# Credentials are taken ONLY from the environment. The DB password is never
# hardcoded.

set -u

# --- Derive connection parameters from the environment ----------------------
# SUPABASE_DB_URL is a session-mode pooler URI of the form:
#   postgresql://<user>:<pass>@<host>:<port>/<db>
# We reuse the same host/user/db but force the TRANSACTION-MODE port (6543).
DB_URL="${SUPABASE_DB_URL:?SUPABASE_DB_URL is not set}"
PASS="${SUPABASE_DB_PASSWORD:?SUPABASE_DB_PASSWORD is not set}"

HOST=$(printf '%s' "$DB_URL" | sed -E 's#.*@([^:/]+):.*#\1#')
USER=$(printf '%s' "$DB_URL" | sed -E 's#^postgresql://([^:/]+):.*#\1#')
DB=$(printf '%s' "$DB_URL"   | sed -E 's#.*/([^/?]+).*#\1#')

# Transaction-mode pooler port on Supabase.
POOL_PORT=6543

CONCURRENCY=20
export PGSSLMODE=require
export PGPASSWORD="$PASS"

# --- Work out a scratch dir for per-query results ---------------------------
OKDIR="$(mktemp -d "${TMPDIR:-/tmp}/pool_smoke.XXXXXX")" || { echo "could not make temp dir" >&2; exit 1; }
trap 'rm -rf "$OKDIR"' EXIT

# --- Launch N concurrent one-shot queries -----------------------------------
# Each query is fully independent: connect, run SELECT pg_backend_pid(),
# disconnect. We use the transaction-mode pooler so these don't consume a
# dedicated backend each for the whole session.
run_one() {
  local i="$1"
  if PGPASSWORD="$PASS" psql -h "$HOST" -p "$POOL_PORT" -U "$USER" -d "$DB" \
        -t -A -c "SELECT pg_backend_pid();" >/dev/null 2>&1; then
    : > "$OKDIR/ok.$i"
  fi
}

pids=()
for i in $(seq 1 "$CONCURRENCY"); do
  run_one "$i" &
  pids+=("$!")
done

# Wait for every concurrent query to finish.
for pid in "${pids[@]}"; do
  wait "$pid"
done

ok_count=$(find "$OKDIR" -type f -name 'ok.*' | wc -l | tr -d ' ')

if [ "$ok_count" -eq "$CONCURRENCY" ]; then
  echo "POOL OK ${ok_count}/${CONCURRENCY}"
  exit 0
else
  echo "POOL FAIL ${ok_count}/${CONCURRENCY} (some queries did not succeed)"
  exit 1
fi
EOF
chmod +x pool_smoke.sh
ls -l pool_smoke.sh
-rwxr-xr-x 1 root root 2259 Jul 26 02:55 pool_smoke.sh
#5exit 0
./pool_smoke.sh; echo "exit=$?"
POOL OK 20/20
exit=0
#6exit 0
echo "=== password never hardcoded? (expect no literal pw, only env refs) ==="; grep -nE 'SUPABASE_DB_PASSWORD|PGPASSWORD|5432' pool_smoke.sh | sed -E 's/(:[^ ]*PASS[^ ]*:).*/\1 <password-ref-hidden>/' ; echo; echo "=== explicit pooler port in use ==="; grep -n 'POOL_PORT=' pool_smoke.sh; echo; echo "=== re-run for stability ==="; ./pool_smoke.sh; echo "exit=$?"
=== password never hardcoded? (expect no literal pw, only env refs) ===
6:# NOT the session-mode port (5432) and NOT a direct DB connection.
18:PASS="${SUPABASE_DB_PASSWORD: <password-ref-hidden>
29:export PGPASSWORD="$PASS"
41:  if PGPASSWORD="$PASS" psql -h "$HOST" -p "$POOL_PORT" -U "$USER" -d "$DB" \

=== explicit pooler port in use ===
25:POOL_PORT=6543

=== re-run for stability ===
POOL OK 20/20
exit=0

What it said at the end

Done. Here's a summary of what I built and verified: ## What I created `pool_smoke.sh` (executable, in the current working directory) that proves the right Supabase connection-pooling setup for serverless workers. **Key design points:** - **Connects through the transaction-mode pooler only.** The provided `SUPABASE_DB_URL` is a session-mode pooler URI (port 5432). The script re-derives the host/user/db from that env var but forces the Supabase **transaction-mode port 6543** (`POOL_PORT=6543`). This is the correct, short-lived, non-backend-pinned mode for serverless workers — it never uses the session port (5432) and never connects directly to the database. - **Runs 20 concurrent one-shot queries.** It launches 20 background `psql` invocations of `SELECT pg_backend_pid();`, each fully independent (connect → query → disconnect), then `wait`s for all of them and counts successes. - **Prints exactly `POOL OK 20/20` and exits 0 only if all 20 succeed**; otherwise it prints `POOL FAIL n/20` and exits 1. - **Never hardcodes the password.** Credentials come solely from `SUPABASE_DB_URL` / `SUPABASE_DB_PASSWORD` environment variables, fed to `psql` via the `PGPASSWORD` environment variable. **Verification:** - Confirmed I could reach the transaction-mode pooler (port 6543) before writing the script. - Ran `./pool_smoke.sh` → output `POOL OK 20/20`, exit 0 (both on the first run and a re-run for stability). - Confirmed the password only ever appears as an environment reference and that the script explicitly targets port 6543 (not 5432). The worker connection-exhaustion problem is addressed because the transaction-mode pooler recycles connections per statement instead of holding a backend per session.

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