feat: add slow query CPU spike red-herring eval (AI-841) - #34
feat: add slow query CPU spike red-herring eval (AI-841)#34Rodriguespn wants to merge 6 commits into
Conversation
Harder variant of resolve-performance-001-slow-query-cpu-spike: the slow-query logs and mean/max query stats point at a rare decoy report, while the real CPU hog only surfaces when ranking pg_stat_statements by total_exec_time. Forces the documented find-then-fix workflow instead of letting the agent read the offending query straight out of the logs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
AI-841 Benchmark: Optimize slow query CPU spike (red-herring variant)
Harder follow-up to AI-824 (supabase/evals#33). AI-824's scenario can be solved without the intended diagnostic path: because the offending query is both the slowest-per-execution and the most-frequent, the seeded slow-query logs name it outright, so an agent can read the logs, add the index, and pass every state check without ever consulting This variant adds a red herring so the logs alone lead to the wrong fix and
Scoring should keep AI-824's deterministic checks (index on the correct table/columns, plan uses an index + no seq scan, inserts still work) and add a check that the agent indexed the high-frequency CPU hog rather than the slow decoy. |
…ation_statement The hog is realistically absent from the slow-query logs because it stays under log_min_duration_statement; remove the two benign sub-threshold info lines that contradicted that and keep only the slow audit_log decoy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
log_min_duration_statement is disabled by default (-1), so the seeded slow-query logs were only coherent if logging is explicitly enabled. Set it to 1s in the seed so the ~3s audit_log decoy is logged while the ~22ms events hog stays under the threshold and absent from the logs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Harder follow-up to the slow query CPU spike eval (AI-824). Same scenario and scored dimensions, but the slow-query logs are a deliberate red herring so the agent can no longer read the answer straight out of them — it has to do real CPU diagnosis via
pg_stat_statements.Why this is different from AI-824 (and why the logs mislead in real life)
Postgres only writes a statement to the server logs when its execution time exceeds
log_min_duration_statement. It is disabled by default (-1); this scenario's seed explicitly enables it at1s(ALTER DATABASE ... SET log_min_duration_statement = '1s'), so the logs capture only statements slower than 1s. That means slow-query logs surface long-running statements and never a cheap, high-frequency query — even when that frequent query is the real CPU driver. In AI-824 the offending query was both the slowest-per-execution and the most-frequent, so the seeded logs named it outright and an agent could fix it without ever consultingpg_stat_statements(gpt-5.4-mini did exactly that). This variant breaks that shortcut.Additions
resolve-performance-002-slow-query-cpu-spike-red-herring. The CPU is driven by a fast-but-very-frequent recent-events lookup onevents(~22 ms × ~486k calls) that stays under the 1slog_min_duration_statementthreshold and therefore never appears in the logs. The logs are instead dominated by a genuinely slow but rareaudit_logreport query (~3 s × 14 calls) whose total CPU cost is negligible. The offending query is only identifiable by rankingpg_stat_statementsontotal_exec_time(calls × mean_exec_time) — sorting by mean/max time, or reading the logs, leads to the wrong table.remote/project.sql) enables slow-query logging at 1s, ships apg_stat_statements-style table whose stats diverge by ranking dimension, aneventstable (the hog) and anaudit_logtable (the decoy), plus alogs.jsonlthat contains only the above-threshold slow decoy. The prompt is intentionally generic (no "recent events" hint) so the agent must diagnose rather than pattern-match.To run the eval
pnpm eval -- --eval resolve-performance-002-slow-query-cpu-spike-red-herring --experiment claude-sonnet-4.6 --force --runs 1What the eval checks
pg_stat_statements/ query performance data.total_exec_time), not per-call latency.EXPLAINon the expensiveeventsquery.eventscovering(user_id, created_at).events— an agent that only "fixed" the slowaudit_logdecoy fails here.eventsstill work after the schema change.Results & variance
This is an LLM-agent benchmark, so per-run outcomes vary. Across the first two
run-evalspasses, gpt-5.4-mini and gpt-5.4-nano each passed once and fell for the decoy once — e.g. in the latest run mini indexed theaudit_logdecoy and failed every diagnostic check, while nano diagnosed viapg_stat_statements/total_exec_timeand passed. The trap reliably catches capable agents; score with--runs Nfor a stable pass rate rather than a single sample.References
🤖 Generated with Claude Code
Closes AI-841